[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CACSApvY_pj-tReFEpoH5e6xvUuk2ih9Nc+cc6AZzd5yvFCiTQg@mail.gmail.com>
Date: Tue, 7 Mar 2023 16:21:27 -0500
From: Soheil Hassas Yeganeh <soheil@...gle.com>
To: "Keller, Jacob E" <jacob.e.keller@...el.com>
Cc: Paolo Abeni <pabeni@...hat.com>,
"netdev@...r.kernel.org" <netdev@...r.kernel.org>,
Al Viro <viro@...iv.linux.org.uk>,
Carlos Maiolino <cmaiolino@...hat.com>,
Eric Biggers <ebiggers@...nel.org>,
Andrew Morton <akpm@...ux-foundation.org>,
Jens Axboe <axboe@...nel.dk>,
Christian Brauner <brauner@...nel.org>,
"linux-fsdevel@...r.kernel.org" <linux-fsdevel@...r.kernel.org>
Subject: Re: [PATCH v4 RESEND] epoll: use refcount to reduce ep_mutex contention
On Tue, Mar 7, 2023 at 4:17 PM Keller, Jacob E <jacob.e.keller@...el.com> wrote:
>
>
>
> > -----Original Message-----
> > From: Paolo Abeni <pabeni@...hat.com>
> > Sent: Tuesday, March 7, 2023 10:47 AM
> > To: netdev@...r.kernel.org
> > Cc: Soheil Hassas Yeganeh <soheil@...gle.com>; Al Viro
> > <viro@...iv.linux.org.uk>; Carlos Maiolino <cmaiolino@...hat.com>; Eric
> > Biggers <ebiggers@...nel.org>; Keller, Jacob E <jacob.e.keller@...el.com>;
> > Andrew Morton <akpm@...ux-foundation.org>; Jens Axboe <axboe@...nel.dk>;
> > Christian Brauner <brauner@...nel.org>; linux-fsdevel@...r.kernel.org
> > Subject: [PATCH v4 RESEND] epoll: use refcount to reduce ep_mutex contention
> >
> > 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
> > the EP file close() and the monitored file close().
> > ep_eventpoll_release() marks, under f_lock spinlock, each epitem as before
> > removing it, while EP file close() does not touch dying epitems.
> >
> > The eventpoll struct is released by whoever - among EP file close() and
> > and the monitored file close() 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%.
> >
> > To make the change more readable this additionally renames ep_free() to
> > ep_clear_and_put(), and moves the actual memory cleanup in a separate
> > ep_free() helper.
> >
> > Tested-by: Xiumei Mu <xmu@...hiat.com>
> > Reviewed-by: Jacob Keller <jacob.e.keller@...el.com>
> > Acked-by: Soheil Hassas Yeganeh <soheil@...gle.com>
> > Signed-off-by: Paolo Abeni <pabeni@...hat.com>
> > ---
> > This is a repost of v4, with no changes. Kindly asking if FS maintainers
> > could have a look.
>
> This (still) looks good to me.
>
> Thanks,
> Jake
Thank you! Still looks great to me as well.
Powered by blists - more mailing lists