From: Cruz Zhao <CruzZhao@linux.alibaba.com>
To: peterz@infradead.org, mingo@redhat.com, boqun.feng@gmail.com,
will@kernel.org, longman@redhat.com
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH] percpu_rwsem: let percpu_rwsem writer get rwsem faster
Date: Fri, 28 Mar 2025 11:05:17 +0800 [thread overview]
Message-ID: <20250328030519.897032-1-CruzZhao@linux.alibaba.com> (raw)
In the scenario where a large number of containers are created
at the same time, there will be a lot of tasks created in a
short time, and they will be written into cgroup.procs.
copy_process() will require the cgroup_threadgroup_rwsem read
lock, cgroup_procs_write will require the cgroup_threadgroup_rwsem
write lock. As the readers will pre-increase the read_count and
then check whether there is any writers, resulting that the
writer may be starving, especially when there is a steady stream
of readers.
To alleviate this problem, we add one more check whether there
are writers waiting before increasing the read_count, to make
writers getting lock faster.
Signed-off-by: Cruz Zhao <CruzZhao@linux.alibaba.com>
---
kernel/locking/percpu-rwsem.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/kernel/locking/percpu-rwsem.c b/kernel/locking/percpu-rwsem.c
index 6083883c4fe0..66bf18c28b43 100644
--- a/kernel/locking/percpu-rwsem.c
+++ b/kernel/locking/percpu-rwsem.c
@@ -47,6 +47,11 @@ EXPORT_SYMBOL_GPL(percpu_free_rwsem);
static bool __percpu_down_read_trylock(struct percpu_rw_semaphore *sem)
{
+ if (unlikely(atomic_read_acquire(&sem->block))) {
+ rcuwait_wake_up(&sem->writer);
+ return false;
+ }
+
this_cpu_inc(*sem->read_count);
/*
--
2.43.5
next reply other threads:[~2025-03-28 3:05 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-28 3:05 Cruz Zhao [this message]
2025-03-28 3:58 ` Waiman Long
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250328030519.897032-1-CruzZhao@linux.alibaba.com \
--to=cruzzhao@linux.alibaba.com \
--cc=boqun.feng@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=longman@redhat.com \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=will@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®