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@xxxxxxxxxx> > Signed-off-by: Paolo Abeni <pabeni@xxxxxxxxxx> 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