From: Stefan Hajnoczi <stefanha@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Kevin Wolf" <kwolf@redhat.com>,
"Daniel P. Berrangé" <berrange@redhat.com>,
"Tingting Mao" <timao@redhat.com>,
"Honghao Wang" <wanghonghao@bytedance.com>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Philippe Mathieu-Daudé" <philmd@redhat.com>,
"Daniele Buono" <dbuono@linux.vnet.ibm.com>,
"Serge Guelton" <sguelton@redhat.com>
Subject: Re: [PATCH v2] coroutine: resize pool periodically instead of limiting size
Date: Mon, 11 Oct 2021 13:43:38 +0100 [thread overview]
Message-ID: <YWQxepmvtbtl73WA@stefanha-x1.localdomain> (raw)
In-Reply-To: <20210913153524.1190696-1-stefanha@redhat.com>
[-- Attachment #1: Type: text/plain, Size: 3261 bytes --]
On Mon, Sep 13, 2021 at 04:35:24PM +0100, Stefan Hajnoczi wrote:
> It was reported that enabling SafeStack reduces IOPS significantly
> (>25%) with the following fio benchmark on virtio-blk using a NVMe host
> block device:
>
> # fio --rw=randrw --bs=4k --iodepth=64 --runtime=1m --direct=1 \
> --filename=/dev/vdb --name=job1 --ioengine=libaio --thread \
> --group_reporting --numjobs=16 --time_based \
> --output=/tmp/fio_result
>
> Serge Guelton and I found that SafeStack is not really at fault, it just
> increases the cost of coroutine creation. This fio workload exhausts the
> coroutine pool and coroutine creation becomes a bottleneck. Previous
> work by Honghao Wang also pointed to excessive coroutine creation.
>
> Creating new coroutines is expensive due to allocating new stacks with
> mmap(2) and mprotect(2). Currently there are thread-local and global
> pools that recycle old Coroutine objects and their stacks but the
> hardcoded size limit of 64 for thread-local pools and 128 for the global
> pool is insufficient for the fio benchmark shown above.
>
> This patch changes the coroutine pool algorithm to a simple thread-local
> pool without a maximum size limit. Threads periodically shrink the pool
> down to a size sufficient for the maximum observed number of coroutines.
>
> The global pool is removed by this patch. It can help to hide the fact
> that local pools are easily exhausted, but it's doesn't fix the root
> cause. I don't think there is a need for a global pool because QEMU's
> threads are long-lived, so let's keep things simple.
>
> Performance of the above fio benchmark is as follows:
>
> Before After
> IOPS 60k 97k
>
> Memory usage varies over time as needed by the workload:
>
> VSZ (KB) RSS (KB)
> Before fio 4705248 843128
> During fio 5747668 (+ ~100 MB) 849280
> After fio 4694996 (- ~100 MB) 845184
>
> This confirms that coroutines are indeed being freed when no longer
> needed.
>
> Thanks to Serge Guelton for working on identifying the bottleneck with
> me!
>
> Reported-by: Tingting Mao <timao@redhat.com>
> Cc: Serge Guelton <sguelton@redhat.com>
> Cc: Honghao Wang <wanghonghao@bytedance.com>
> Cc: Paolo Bonzini <pbonzini@redhat.com>
> Cc: Daniele Buono <dbuono@linux.vnet.ibm.com>
> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
> ---
> v2:
> * Retained minimum pool size of 64 to keep latency low for threads that
> perform I/O infrequently and to prevent possible regressions [Daniele]
> ---
> include/qemu/coroutine-pool-timer.h | 36 ++++++++++++++++
> include/qemu/coroutine.h | 7 +++
> iothread.c | 6 +++
> util/coroutine-pool-timer.c | 35 +++++++++++++++
> util/main-loop.c | 5 +++
> util/qemu-coroutine.c | 66 ++++++++++++++++-------------
> util/meson.build | 1 +
> 7 files changed, 126 insertions(+), 30 deletions(-)
> create mode 100644 include/qemu/coroutine-pool-timer.h
> create mode 100644 util/coroutine-pool-timer.c
Applied to my block-next tree:
https://gitlab.com/stefanha/qemu/commits/block-next
Stefan
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
prev parent reply other threads:[~2021-10-11 12:45 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-13 15:35 [PATCH v2] coroutine: resize pool periodically instead of limiting size Stefan Hajnoczi
2021-10-11 12:43 ` Stefan Hajnoczi [this message]
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=YWQxepmvtbtl73WA@stefanha-x1.localdomain \
--to=stefanha@redhat.com \
--cc=berrange@redhat.com \
--cc=dbuono@linux.vnet.ibm.com \
--cc=kwolf@redhat.com \
--cc=pbonzini@redhat.com \
--cc=philmd@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=sguelton@redhat.com \
--cc=timao@redhat.com \
--cc=wanghonghao@bytedance.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).