From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: WangYuli <wangyuli@uniontech.com>
Cc: viro@zeniv.linux.org.uk, brauner@kernel.org, jack@suse.cz,
linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
yushengjin@uniontech.com, zhangdandan@uniontech.com,
guanwentao@uniontech.com, zhanjun@uniontech.com,
oliver.sang@intel.com, ebiederm@xmission.com,
colin.king@canonical.com, josh@joshtriplett.org,
penberg@cs.helsinki.fi, manfred@colorfullife.com, mingo@elte.hu,
jes@sgi.com, hch@lst.de, aia21@cantab.net, arjan@infradead.org,
jgarzik@pobox.com, neukum@fachschaft.cup.uni-muenchen.de,
oliver@neukum.name, dada1@cosmosbay.com, axboe@kernel.dk,
axboe@suse.de, nickpiggin@yahoo.com.au, dhowells@redhat.com,
nathans@sgi.com, rolandd@cisco.com, tytso@mit.edu,
bunk@stusta.de, pbadari@us.ibm.com, ak@linux.intel.com,
ak@suse.de, davem@davemloft.net, jsipek@cs.sunysb.edu,
jens.axboe@oracle.com, ramsdell@mitre.org, hch@infradead.org,
torvalds@linux-foundation.org, akpm@linux-foundation.org,
randy.dunlap@oracle.com, efault@gmx.de, rdunlap@infradead.org,
haveblue@us.ibm.com, drepper@redhat.com, dm.n9107@gmail.com,
jblunck@suse.de, davidel@xmailserver.org,
mtk.manpages@googlemail.com, linux-arch@vger.kernel.org,
vda.linux@googlemail.com, jmorris@namei.org, serue@us.ibm.com,
hca@linux.ibm.com, rth@twiddle.net, lethal@linux-sh.org,
tony.luck@intel.com, heiko.carstens@de.ibm.com, oleg@redhat.com,
andi@firstfloor.org, corbet@lwn.net, crquan@gmail.com,
mszeredi@suse.cz, miklos@szeredi.hu, peterz@infradead.org,
a.p.zijlstra@chello.nl, earl_chew@agilent.com, npiggin@gmail.com,
npiggin@suse.de, julia@diku.dk, jaxboe@fusionio.com,
nikai@nikai.net, dchinner@redhat.com, davej@redhat.com,
npiggin@kernel.dk, eric.dumazet@gmail.com,
tim.c.chen@linux.intel.com, xemul@parallels.com, tj@kernel.org,
serge.hallyn@canonical.com, gorcunov@openvz.org,
levinsasha928@gmail.com, penberg@kernel.org, amwang@redhat.com,
bcrl@kvack.org, muthu.lkml@gmail.com, muthur@gmail.com,
mjt@tls.msk.ru, alan@lxorguk.ukuu.org.uk, raven@themaw.net,
thomas@m3y3r.de, will.deacon@arm.com, will@kernel.org,
josef@redhat.com, anatol.pomozov@gmail.com,
koverstreet@google.com, zab@redhat.com, balbi@ti.com,
gregkh@linuxfoundation.org, mfasheh@suse.com, jlbec@evilplan.org,
rusty@rustcorp.com.au, asamymuthupa@micron.com, smani@micron.com,
sbradshaw@micron.com, jmoyer@redhat.com, sim@hostway.ca,
ia@cloudflare.com, dmonakhov@openvz.org, ebiggers3@gmail.com,
socketpair@gmail.com, penguin-kernel@i-love.sakura.ne.jp,
w@1wt.eu, kirill.shutemov@linux.intel.com, mhocko@suse.com,
vdavydov.dev@gmail.com, vdavydov@virtuozzo.com,
hannes@cmpxchg.org, mhocko@kernel.org, minchan@kernel.org,
deepa.kernel@gmail.com, arnd@arndb.de, balbi@kernel.org,
swhiteho@redhat.com, konishi.ryusuke@lab.ntt.co.jp,
dsterba@suse.com, vegard.nossum@oracle.com, axboe@fb.com,
pombredanne@nexb.com, tglx@linutronix.de,
joe.lawrence@redhat.com, mpatocka@redhat.com, mcgrof@kernel.org,
keescook@chromium.org, linux@dominikbrodowski.net,
jannh@google.com, shakeelb@google.com, guro@fb.com,
willy@infradead.org, khlebnikov@yandex-team.ru, kirr@nexedi.com,
stern@rowland.harvard.edu, elver@google.com,
parri.andrea@gmail.com, paulmck@kernel.org, rasibley@redhat.com,
jstancek@redhat.com, avagin@gmail.com, cai@redhat.com,
josef@toxicpanda.com, hare@suse.de, colyli@suse.de,
johannes@sipsolutions.net, sspatil@android.com,
alex_y_xu@yahoo.ca, mgorman@techsingularity.net,
gor@linux.ibm.com, jhubbard@nvidia.com, crope@iki.fi,
yzaikin@google.com, bfields@fieldses.org, jlayton@kernel.org,
kernel@tuxforce.de, steve@sk2.org, nixiaoming@huawei.com,
0x7f454c46@gmail.com, kuniyu@amazon.co.jp,
alexander.h.duyck@intel.com, kuni1840@gmail.com,
soheil@google.com, sridhar.samudrala@intel.com,
Vincenzo.Frascino@arm.com, chuck.lever@oracle.com,
Kevin.Brodsky@arm.com, Szabolcs.Nagy@arm.com,
David.Laight@aculab.com, Mark.Rutland@arm.com,
linux-morello@op-lists.linaro.org, Luca.Vizzarro@arm.com,
max.kellermann@ionos.com, adobriyan@gmail.com, lukas@schauer.dev,
j.granados@samsung.com, djwong@kernel.org,
kent.overstreet@linux.dev, linux@weissschuh.net,
kstewart@efficios.com
Subject: Re: [RESEND PATCH] fs/pipe: Introduce a check to skip sleeping processes during pipe read/write
Date: Wed, 25 Dec 2024 15:30:05 +0200 [thread overview]
Message-ID: <Z2wI3dmmrhMRT-48@smile.fi.intel.com> (raw)
In-Reply-To: <75B06EE0B67747ED+20241225094202.597305-1-wangyuli@uniontech.com>
Don't you think the Cc list is a bit overloaded?
On Wed, Dec 25, 2024 at 05:42:02PM +0800, WangYuli wrote:
> When a user calls the read/write system call and passes a pipe
> descriptor, the pipe_read/pipe_write functions are invoked:
>
> 1. pipe_read():
> 1). Checks if the pipe is valid and if there is any data in the
> pipe buffer.
> 2). Waits for data:
> *If there is no data in the pipe and the write end is still open,
> the current process enters a sleep state (wait_event()) until data
> is written.
> *If the write end is closed, return 0.
> 3). Reads data:
> *Wakes up the process and copies data from the pipe's memory
> buffer to user space.
> *When the buffer is full, the writing process will go to sleep,
> waiting for the pipe state to change to be awakened (using the
> wake_up_interruptible_sync_poll() mechanism). Once data is read
> from the buffer, the writing process can continue writing, and the
> reading process can continue reading new data.
> 4). Returns the number of bytes read upon successful read.
>
> 2. pipe_write():
> 1). Checks if the pipe is valid and if there is any available
> space in the pipe buffer.
> 2). Waits for buffer space:
> *If the pipe buffer is full and the reading process has not
> read any data, pipe_write() may put the current process to sleep
> until there is space in the buffer.
> *If the read end of the pipe is closed (no process is waiting
> to read), an error code -EPIPE is returned, and a SIGPIPE signal may
> be sent to the process.
> 3). Writes data:
> *If there is enough space in the pipe buffer, pipe_write() copies
> data from the user space buffer to the kernel buffer of the pipe
> (using copy_from_user()).
> *If the amount of data the user requests to write is larger than
> the available space in the buffer, multiple writes may be required,
> or the process may wait for new space to be freed.
> 4). Wakes up waiting reading processes:
> *After the data is successfully written, pipe_write() wakes up
> any processes that may be waiting to read data (using the
> wake_up_interruptible_sync_poll() mechanism).
> 5). Returns the number of bytes successfully written.
>
> Check if there are any waiting processes in the process wait queue
> by introducing wq_has_sleeper() when waking up processes for pipe
> read/write operations.
>
> If no processes are waiting, there's no need to execute
> wake_up_interruptible_sync_poll(), thus avoiding unnecessary wake-ups.
>
> Unnecessary wake-ups can lead to context switches, where a process
> is woken up to handle I/O events even when there is no immediate
> need.
>
> Only wake up processes when there are actually waiting processes to
> reduce context switches and system overhead by checking
> with wq_has_sleeper().
>
> Additionally, by reducing unnecessary synchronization and wake-up
> operations, wq_has_sleeper() can decrease system resource waste and
> lock contention, improving overall system performance.
>
> For pipe read/write operations, this eliminates ineffective scheduling
> and enhances concurrency.
>
> It's important to note that enabling this option means invoking
> wq_has_sleeper() to check for sleeping processes in the wait queue
> for every read or write operation.
>
> While this is a lightweight operation, it still incurs some overhead.
>
> In low-load or single-task scenarios, this overhead may not yield
> significant benefits and could even introduce minor performance
> degradation.
>
> UnixBench Pipe benchmark results on Zhaoxin KX-U6780A processor:
>
> With the option disabled: Single-core: 841.8, Multi-core (8): 4621.6
> With the option enabled: Single-core: 877.8, Multi-core (8): 4854.7
>
> Single-core performance improved by 4.1%, multi-core performance
> improved by 4.8%.
...
> +config PIPE_SKIP_SLEEPER
> + bool "Skip sleeping processes during pipe read/write"
> + default n
'n' is the default 'default', no need to have this line.
> + help
> + This option introduces a check whether the sleep queue will
> + be awakened during pipe read/write.
> +
> + It often leads to a performance improvement. However, in
> + low-load or single-task scenarios, it may introduce minor
> + performance overhead.
> + If unsure, say N.
Illogical, it's already N as you stated by putting a redundant line, but after
removing that line it will make sense.
...
> +static inline bool
Have you build this with Clang and `make W=1 ...`?
> +pipe_check_wq_has_sleeper(struct wait_queue_head *wq_head)
> +{
> + if (IS_ENABLED(CONFIG_PIPE_SKIP_SLEEPER))
> + return wq_has_sleeper(wq_head);
> + else
Redundant.
> + return true;
if (!foo)
return true;
return bar(...);
> +}
--
With Best Regards,
Andy Shevchenko
next prev parent reply other threads:[~2024-12-25 13:30 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-25 9:42 [RESEND PATCH] fs/pipe: Introduce a check to skip sleeping processes during pipe read/write WangYuli
2024-12-25 13:30 ` Andy Shevchenko [this message]
2024-12-25 15:42 ` WangYuli
2024-12-26 16:00 ` Oleg Nesterov
2024-12-26 19:02 ` Linus Torvalds
2024-12-26 20:11 ` Oleg Nesterov
2024-12-27 18:39 ` Manfred Spraul
2024-12-28 14:32 ` Oleg Nesterov
2024-12-28 15:22 ` Oleg Nesterov
2024-12-28 16:32 ` Oleg Nesterov
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=Z2wI3dmmrhMRT-48@smile.fi.intel.com \
--to=andriy.shevchenko@linux.intel.com \
--cc=0x7f454c46@gmail.com \
--cc=David.Laight@aculab.com \
--cc=Kevin.Brodsky@arm.com \
--cc=Luca.Vizzarro@arm.com \
--cc=Mark.Rutland@arm.com \
--cc=Szabolcs.Nagy@arm.com \
--cc=Vincenzo.Frascino@arm.com \
--cc=a.p.zijlstra@chello.nl \
--cc=adobriyan@gmail.com \
--cc=aia21@cantab.net \
--cc=ak@linux.intel.com \
--cc=ak@suse.de \
--cc=akpm@linux-foundation.org \
--cc=alan@lxorguk.ukuu.org.uk \
--cc=alex_y_xu@yahoo.ca \
--cc=alexander.h.duyck@intel.com \
--cc=amwang@redhat.com \
--cc=anatol.pomozov@gmail.com \
--cc=andi@firstfloor.org \
--cc=arjan@infradead.org \
--cc=arnd@arndb.de \
--cc=asamymuthupa@micron.com \
--cc=avagin@gmail.com \
--cc=axboe@fb.com \
--cc=axboe@kernel.dk \
--cc=axboe@suse.de \
--cc=balbi@kernel.org \
--cc=balbi@ti.com \
--cc=bcrl@kvack.org \
--cc=bfields@fieldses.org \
--cc=brauner@kernel.org \
--cc=bunk@stusta.de \
--cc=cai@redhat.com \
--cc=chuck.lever@oracle.com \
--cc=colin.king@canonical.com \
--cc=colyli@suse.de \
--cc=corbet@lwn.net \
--cc=crope@iki.fi \
--cc=crquan@gmail.com \
--cc=dada1@cosmosbay.com \
--cc=davej@redhat.com \
--cc=davem@davemloft.net \
--cc=davidel@xmailserver.org \
--cc=dchinner@redhat.com \
--cc=deepa.kernel@gmail.com \
--cc=dhowells@redhat.com \
--cc=djwong@kernel.org \
--cc=dm.n9107@gmail.com \
--cc=dmonakhov@openvz.org \
--cc=drepper@redhat.com \
--cc=dsterba@suse.com \
--cc=earl_chew@agilent.com \
--cc=ebiederm@xmission.com \
--cc=ebiggers3@gmail.com \
--cc=efault@gmx.de \
--cc=elver@google.com \
--cc=eric.dumazet@gmail.com \
--cc=gor@linux.ibm.com \
--cc=gorcunov@openvz.org \
--cc=gregkh@linuxfoundation.org \
--cc=guanwentao@uniontech.com \
--cc=guro@fb.com \
--cc=hannes@cmpxchg.org \
--cc=hare@suse.de \
--cc=haveblue@us.ibm.com \
--cc=hca@linux.ibm.com \
--cc=hch@infradead.org \
--cc=hch@lst.de \
--cc=heiko.carstens@de.ibm.com \
--cc=ia@cloudflare.com \
--cc=j.granados@samsung.com \
--cc=jack@suse.cz \
--cc=jannh@google.com \
--cc=jaxboe@fusionio.com \
--cc=jblunck@suse.de \
--cc=jens.axboe@oracle.com \
--cc=jes@sgi.com \
--cc=jgarzik@pobox.com \
--cc=jhubbard@nvidia.com \
--cc=jlayton@kernel.org \
--cc=jlbec@evilplan.org \
--cc=jmorris@namei.org \
--cc=jmoyer@redhat.com \
--cc=joe.lawrence@redhat.com \
--cc=johannes@sipsolutions.net \
--cc=josef@redhat.com \
--cc=josef@toxicpanda.com \
--cc=josh@joshtriplett.org \
--cc=jsipek@cs.sunysb.edu \
--cc=jstancek@redhat.com \
--cc=julia@diku.dk \
--cc=keescook@chromium.org \
--cc=kent.overstreet@linux.dev \
--cc=kernel@tuxforce.de \
--cc=khlebnikov@yandex-team.ru \
--cc=kirill.shutemov@linux.intel.com \
--cc=kirr@nexedi.com \
--cc=konishi.ryusuke@lab.ntt.co.jp \
--cc=koverstreet@google.com \
--cc=kstewart@efficios.com \
--cc=kuni1840@gmail.com \
--cc=kuniyu@amazon.co.jp \
--cc=lethal@linux-sh.org \
--cc=levinsasha928@gmail.com \
--cc=linux-arch@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-morello@op-lists.linaro.org \
--cc=linux@dominikbrodowski.net \
--cc=linux@weissschuh.net \
--cc=lukas@schauer.dev \
--cc=manfred@colorfullife.com \
--cc=max.kellermann@ionos.com \
--cc=mcgrof@kernel.org \
--cc=mfasheh@suse.com \
--cc=mgorman@techsingularity.net \
--cc=mhocko@kernel.org \
--cc=mhocko@suse.com \
--cc=miklos@szeredi.hu \
--cc=minchan@kernel.org \
--cc=mingo@elte.hu \
--cc=mjt@tls.msk.ru \
--cc=mpatocka@redhat.com \
--cc=mszeredi@suse.cz \
--cc=mtk.manpages@googlemail.com \
--cc=muthu.lkml@gmail.com \
--cc=muthur@gmail.com \
--cc=nathans@sgi.com \
--cc=neukum@fachschaft.cup.uni-muenchen.de \
--cc=nickpiggin@yahoo.com.au \
--cc=nikai@nikai.net \
--cc=nixiaoming@huawei.com \
--cc=npiggin@gmail.com \
--cc=npiggin@kernel.dk \
--cc=npiggin@suse.de \
--cc=oleg@redhat.com \
--cc=oliver.sang@intel.com \
--cc=oliver@neukum.name \
--cc=parri.andrea@gmail.com \
--cc=paulmck@kernel.org \
--cc=pbadari@us.ibm.com \
--cc=penberg@cs.helsinki.fi \
--cc=penberg@kernel.org \
--cc=penguin-kernel@i-love.sakura.ne.jp \
--cc=peterz@infradead.org \
--cc=pombredanne@nexb.com \
--cc=ramsdell@mitre.org \
--cc=randy.dunlap@oracle.com \
--cc=rasibley@redhat.com \
--cc=raven@themaw.net \
--cc=rdunlap@infradead.org \
--cc=rolandd@cisco.com \
--cc=rth@twiddle.net \
--cc=rusty@rustcorp.com.au \
--cc=sbradshaw@micron.com \
--cc=serge.hallyn@canonical.com \
--cc=serue@us.ibm.com \
--cc=shakeelb@google.com \
--cc=sim@hostway.ca \
--cc=smani@micron.com \
--cc=socketpair@gmail.com \
--cc=soheil@google.com \
--cc=sridhar.samudrala@intel.com \
--cc=sspatil@android.com \
--cc=stern@rowland.harvard.edu \
--cc=steve@sk2.org \
--cc=swhiteho@redhat.com \
--cc=tglx@linutronix.de \
--cc=thomas@m3y3r.de \
--cc=tim.c.chen@linux.intel.com \
--cc=tj@kernel.org \
--cc=tony.luck@intel.com \
--cc=torvalds@linux-foundation.org \
--cc=tytso@mit.edu \
--cc=vda.linux@googlemail.com \
--cc=vdavydov.dev@gmail.com \
--cc=vdavydov@virtuozzo.com \
--cc=vegard.nossum@oracle.com \
--cc=viro@zeniv.linux.org.uk \
--cc=w@1wt.eu \
--cc=wangyuli@uniontech.com \
--cc=will.deacon@arm.com \
--cc=will@kernel.org \
--cc=willy@infradead.org \
--cc=xemul@parallels.com \
--cc=yushengjin@uniontech.com \
--cc=yzaikin@google.com \
--cc=zab@redhat.com \
--cc=zhangdandan@uniontech.com \
--cc=zhanjun@uniontech.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;
as well as URLs for NNTP newsgroup(s).