From: Eric Biggers <ebiggers@kernel.org>
To: Paolo Abeni <pabeni@redhat.com>
Cc: linux-fsdevel@vger.kernel.org,
Soheil Hassas Yeganeh <soheil@google.com>,
Al Viro <viro@zeniv.linux.org.uk>,
Davidlohr Bueso <dave@stgolabs.net>,
Jason Baron <jbaron@akamai.com>,
netdev@vger.kernel.org, Carlos Maiolino <cmaiolino@redhat.com>
Subject: Re: [PATCH v3] epoll: use refcount to reduce ep_mutex contention
Date: Mon, 12 Dec 2022 22:01:11 -0800 [thread overview]
Message-ID: <Y5gVJz+qDfw0tEP1@sol.localdomain> (raw)
In-Reply-To: <1aedd7e87097bc4352ba658ac948c585a655785a.1669657846.git.pabeni@redhat.com>
On Mon, Nov 28, 2022 at 07:00:10PM +0100, Paolo Abeni wrote:
> We are observing huge contention on the epmutex during an http
> connection/rate test:
>
> 83.17% 0.25% nginx [kernel.kallsyms] [k] entry_SYSCALL_64_after_hwframe
> [...]
> |--66.96%--__fput
> |--60.04%--eventpoll_release_file
> |--58.41%--__mutex_lock.isra.6
> |--56.56%--osq_lock
>
> The application is multi-threaded, creates a new epoll entry for
> each incoming connection, and does not delete it before the
> connection shutdown - that is, before the connection's fd close().
>
> Many different threads compete frequently for the epmutex lock,
> affecting the overall performance.
>
> To reduce the contention this patch introduces explicit reference counting
> for the eventpoll struct. Each registered event acquires a reference,
> and references are released at ep_remove() time.
>
> Additionally, this introduces a new 'dying' flag to prevent races between
> ep_free() and eventpoll_release_file(): the latter marks, under f_lock
> spinlock, each epitem as before removing it, while ep_free() does not
> touch dying epitems.
>
> The eventpoll struct is released by whoever - among ep_free() and
> eventpoll_release_file() drops its last reference.
>
> With all the above in place, we can drop the epmutex usage at disposal time.
>
> Overall this produces a significant performance improvement in the
> mentioned connection/rate scenario: the mutex operations disappear from
> the topmost offenders in the perf report, and the measured connections/rate
> grows by ~60%.
>
> Tested-by: Xiumei Mu <xmu@redhat.com>
> Signed-off-by: Paolo Abeni <pabeni@redhat.com>
I am trying to understand whether this patch is correct.
One thing that would help would be to use more standard naming:
ep_put => ep_refcount_dec_and_test (or ep_put_and_test)
ep_dispose => ep_free
ep_free => ep_clear_and_put
- Eric
next prev parent reply other threads:[~2022-12-13 6:01 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-28 18:00 [PATCH v3] epoll: use refcount to reduce ep_mutex contention Paolo Abeni
2022-11-29 0:06 ` Jacob Keller
2022-11-29 9:05 ` Paolo Abeni
2022-11-29 18:25 ` Jacob Keller
2022-12-13 6:01 ` Eric Biggers [this message]
2022-12-13 18:21 ` Paolo Abeni
2022-12-13 18:59 ` Eric Biggers
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=Y5gVJz+qDfw0tEP1@sol.localdomain \
--to=ebiggers@kernel.org \
--cc=cmaiolino@redhat.com \
--cc=dave@stgolabs.net \
--cc=jbaron@akamai.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=soheil@google.com \
--cc=viro@zeniv.linux.org.uk \
/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