From: K Prateek Nayak <kprateek.nayak@amd.com>
To: Nam Cao <namcao@linutronix.de>,
Alexander Viro <viro@zeniv.linux.org.uk>,
Christian Brauner <brauner@kernel.org>, Jan Kara <jack@suse.cz>,
Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
John Ogness <john.ogness@linutronix.de>,
Clark Williams <clrkwllms@kernel.org>,
Steven Rostedt <rostedt@goodmis.org>,
linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-rt-devel@lists.linux.dev, linux-rt-users@vger.kernel.org,
Joe Damato <jdamato@fastly.com>,
Martin Karsten <mkarsten@uwaterloo.ca>,
Jens Axboe <axboe@kernel.dk>
Cc: Frederic Weisbecker <frederic@kernel.org>,
Valentin Schneider <vschneid@redhat.com>
Subject: Re: [PATCH v3] eventpoll: Fix priority inversion problem
Date: Mon, 30 Jun 2025 20:38:52 +0530 [thread overview]
Message-ID: <773266ac-aa33-497f-b889-6d9f784e850b@amd.com> (raw)
In-Reply-To: <20250527090836.1290532-1-namcao@linutronix.de>
Hello Nam,
On 5/27/2025 2:38 PM, Nam Cao wrote:
> The ready event list of an epoll object is protected by read-write
> semaphore:
>
> - The consumer (waiter) acquires the write lock and takes items.
> - the producer (waker) takes the read lock and adds items.
>
> The point of this design is enabling epoll to scale well with large number
> of producers, as multiple producers can hold the read lock at the same
> time.
>
> Unfortunately, this implementation may cause scheduling priority inversion
> problem. Suppose the consumer has higher scheduling priority than the
> producer. The consumer needs to acquire the write lock, but may be blocked
> by the producer holding the read lock. Since read-write semaphore does not
> support priority-boosting for the readers (even with CONFIG_PREEMPT_RT=y),
> we have a case of priority inversion: a higher priority consumer is blocked
> by a lower priority producer. This problem was reported in [1].
>
> Furthermore, this could also cause stall problem, as described in [2].
>
> To fix this problem, make the event list half-lockless:
>
> - The consumer acquires a mutex (ep->mtx) and takes items.
> - The producer locklessly adds items to the list.
>
> Performance is not the main goal of this patch, but as the producer now can
> add items without waiting for consumer to release the lock, performance
> improvement is observed using the stress test from
> https://github.com/rouming/test-tools/blob/master/stress-epoll.c. This is
> the same test that justified using read-write semaphore in the past.
>
> Testing using 12 x86_64 CPUs:
>
> Before After Diff
> threads events/ms events/ms
> 8 6932 19753 +185%
> 16 7820 27923 +257%
> 32 7648 35164 +360%
> 64 9677 37780 +290%
> 128 11166 38174 +242%
>
> Testing using 1 riscv64 CPU (averaged over 10 runs, as the numbers are
> noisy):
>
> Before After Diff
> threads events/ms events/ms
> 1 73 129 +77%
> 2 151 216 +43%
> 4 216 364 +69%
> 8 234 382 +63%
> 16 251 392 +56%
>
I gave this patch a spin on top of tip:sched/core (PREEMPT_RT) with
Jan's reproducer from
https://lore.kernel.org/all/7483d3ae-5846-4067-b9f7-390a614ba408@siemens.com/.
On tip:sched/core, I see a hang few seconds into the run and rcu-stall
a minute after when I pin the epoll-stall and epoll-stall-writer on the
same CPU as the Bandwidth timer on a 2vCPU VM. (I'm using a printk to
log the CPU where the timer was started in pinned mode)
With this series, I haven't seen any stalls yet over multiple short
runs (~10min) and even a longer run (~3Hrs).
Feel free to include:
Tested-by: K Prateek Nayak <kprateek.nayak@amd.com>
> Reported-by: Frederic Weisbecker <frederic@kernel.org>
> Closes: https://lore.kernel.org/linux-rt-users/20210825132754.GA895675@lothringen/ [1]
> Reported-by: Valentin Schneider <vschneid@redhat.com>
> Closes: https://lore.kernel.org/linux-rt-users/xhsmhttqvnall.mognet@vschneid.remote.csb/ [2]
> Signed-off-by: Nam Cao <namcao@linutronix.de>
> ---
> v3:
> - get rid of the "link_used" and "ready" flags. They are hard to
> understand and unnecessary
> - get rid of the obsolete lockdep_assert_irqs_enabled()
> - Add lockdep_assert_held(&ep->mtx)
> - rewrite some comments
> v2:
> - rename link_locked -> link_used
> - replace xchg() with smp_store_release() when applicable
> - make sure llist_node is in clean state when not on a list
> - remove now-unused list_add_tail_lockless()
--
Thanks and Regards,
Prateek
next prev parent reply other threads:[~2025-06-30 15:09 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-27 9:08 Nam Cao
2025-05-30 5:08 ` Christian Brauner
2025-06-25 15:35 ` Sebastian Andrzej Siewior
2025-06-26 13:35 ` Frederic Weisbecker
2025-06-26 13:51 ` Sebastian Andrzej Siewior
2025-06-25 14:50 ` Sebastian Andrzej Siewior
2025-06-25 15:27 ` Nam Cao
2025-06-25 15:33 ` Sebastian Andrzej Siewior
2025-06-25 15:57 ` Nam Cao
2025-06-25 16:02 ` Nam Cao
2025-06-26 15:23 ` John Ogness
2025-06-26 15:49 ` Sebastian Andrzej Siewior
2025-06-26 15:56 ` Nam Cao
2025-06-30 15:08 ` K Prateek Nayak [this message]
2025-07-01 20:33 ` Florian Bezdeka
2025-07-01 12:03 ` Christian Brauner
2025-07-10 3:08 ` Xi Ruoyao
2025-07-10 3:48 ` Nam Cao
2025-07-10 4:06 ` Nam Cao
2025-07-10 4:10 ` Xi Ruoyao
2025-07-10 6:21 ` Nam Cao
2025-07-10 6:54 ` Xi Ruoyao
2025-07-10 8:32 ` Nam Cao
2025-07-10 9:47 ` Xi Ruoyao
2025-07-11 5:02 ` Nam Cao
2025-07-11 9:44 ` Christian Brauner
2025-07-11 9:48 ` Xi Ruoyao
2025-07-11 9:58 ` Nam Cao
2025-07-11 12:09 ` Xi Ruoyao
2025-07-11 12:21 ` Nam Cao
2025-07-12 0:09 ` Nam Cao
2025-07-12 8:54 ` Xi Ruoyao
2025-07-11 9:50 ` Nam Cao
2025-07-14 8:59 ` Christian Brauner
2025-07-14 10:14 ` Nam Cao
2025-07-15 9:37 ` Yann Ylavic
2025-07-15 10:08 ` Nam Cao
2025-07-14 16:16 ` Linus Torvalds
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=773266ac-aa33-497f-b889-6d9f784e850b@amd.com \
--to=kprateek.nayak@amd.com \
--cc=axboe@kernel.dk \
--cc=bigeasy@linutronix.de \
--cc=brauner@kernel.org \
--cc=clrkwllms@kernel.org \
--cc=frederic@kernel.org \
--cc=jack@suse.cz \
--cc=jdamato@fastly.com \
--cc=john.ogness@linutronix.de \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rt-devel@lists.linux.dev \
--cc=linux-rt-users@vger.kernel.org \
--cc=mkarsten@uwaterloo.ca \
--cc=namcao@linutronix.de \
--cc=rostedt@goodmis.org \
--cc=viro@zeniv.linux.org.uk \
--cc=vschneid@redhat.com \
/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®