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>, Roman Penyaev <rpenyaev@suse.de>,
netdev@vger.kernel.org, Carlos Maiolino <cmaiolino@redhat.com>
Subject: Re: [PATCH v2] epoll: use refcount to reduce ep_mutex contention
Date: Thu, 24 Nov 2022 15:02:45 -0800 [thread overview]
Message-ID: <Y3/4FW4mqY3fWRfU@sol.localdomain> (raw)
In-Reply-To: <f35e58ed5af8131f0f402c3dc6c3033fa96d1843.1669312208.git.pabeni@redhat.com>
On Thu, Nov 24, 2022 at 06:57:41PM +0100, Paolo Abeni wrote:
> 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. ep_free() doesn't touch
> anymore the event RB tree, it just unregisters the existing callbacks
> and drops a reference to the ep struct. The struct itself is freed when
> the reference count reaches 0. The reference count updates are protected
> by the mtx mutex so no additional atomic operations are needed.
So, the behavior before this patch is that closing an epoll file frees all
resources associated with it. This behavior is documented in the man page
epoll_create(2): "When all file descriptors referring to an epoll instance have
been closed, the kernel destroys the instance and releases the associated
resources for reuse."
The behavior after this patch is that the resources aren't freed until the epoll
file *and* all files that were added to it have been closed.
Is that okay? I suppose in most cases it is, since the usual use case for epoll
is to have a long-lived epoll instance and shorter lived file descriptors that
are polled using that long-lived epoll instance.
But probably some users do things the other way around. I.e., they have a
long-lived file descriptor that is repeatedly polled using different epoll
instances that have a shorter lifetime.
In that case, the number of 'struct eventpoll' and 'struct epitem' in kernel
memory will keep growing until 'max_user_watches' is hit, at which point
EPOLL_CTL_ADD will start failing with ENOSPC.
Are you sure that is fine?
I'll also note that there is a comment at the top of fs/eventpoll.c that
describes the locking scheme, which this patch forgets to update.
- Eric
next prev parent reply other threads:[~2022-11-24 23:02 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-24 17:57 [PATCH v2] epoll: use refcount to reduce ep_mutex contention Paolo Abeni
2022-11-24 21:57 ` Soheil Hassas Yeganeh
2022-11-24 23:02 ` Eric Biggers [this message]
2022-11-25 7:37 ` Paolo Abeni
2022-11-28 17:50 ` Paolo Abeni
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=Y3/4FW4mqY3fWRfU@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=rpenyaev@suse.de \
--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