Skip to content

use rwlock in order to reduce ep_poll_callback() contention

Roman Penyaev linux-fsdevel lkml 2 versions – New

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest4 patches 0 repliesNew
  2. v13 patches 7 repliesSuperseded

Changes in v2 from the cover letter

o I was wrong saying that ep_poll_callback() can't be called concurrently for the same epi: several wait queues can be attached to the single epoll item, thus several event sources can signal in parallel. To cover this case lockless element addition has to detect that the same @epi is not yet in the list. This is done by extra cmpxchg() operation.

o unify awaking of wakeup source calling ep_pm_stay_awake_rcu(epi) in all the cases from ep_poll_callback() path.

o more explicit comments

[1] https://github.com/rouming/test-tools/blob/master/stress-epoll.c

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/4epoll: make sure all elements in ready list are in FIFO orderfs/eventpoll.c+5 -10 replies
2/4epoll: loosen irq safety in ep_poll_callback()fs/eventpoll.c+8 -30 replies
3/4epoll: unify awaking of wakeup source on ep_poll_callback() pathfs/eventpoll.c+1 -80 replies
4/4epoll: use rwlock in order to reduce ep_poll_callback() contentionfs/eventpoll.c+121 -350 replies

Reviews trailers per patch

1 of 4 patches has a Reviewed-by or Acked-by.

PatchDavidlohr Bueso
1/4R-b
2/4
3/4
4/4

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v2 thread

Cover letter [PATCH v2 0/4] use rwlock in order to reduce ep_poll_callback() contention

The last patch targets the contention problem in ep_poll_callback(), which can be very well reproduced by generating events (write to pipe or eventfd) from many threads, while consumer thread does polling.

The following are some microbenchmark results based on the test [1] which starts threads which generate N events each. The test ends when all events are successfully fetched by the poller thread:

spinlock
========

threads events/ms run-time ms

       8       6402        12495
      16       7045        22709
      32       7395        43268

rwlock + xchg
=============

threads events/ms run-time ms

       8      10038         7969
      16      12178        13138
      32      13223        24199

According to the results bandwidth of delivered events is significantly increased, thus execution time is reduced.

This series is based on linux-next/akpm.

v2:
o I was wrong saying that ep_poll_callback() can't be called concurrently for the same epi: several wait queues can be attached to the single epoll item, thus several event sources can signal in parallel. To cover this case lockless element addition has to detect that the same @epi is not yet in the list. This is done by extra cmpxchg() operation.

o unify awaking of wakeup source calling ep_pm_stay_awake_rcu(epi) in all the cases from ep_poll_callback() path.

o more explicit comments

[1] https://github.com/rouming/test-tools/blob/master/stress-epoll.c

Roman Penyaev (4):
epoll: make sure all elements in ready list are in FIFO order
epoll: loosen irq safety in ep_poll_callback()
epoll: unify awaking of wakeup source on ep_poll_callback() path
epoll: use rwlock in order to reduce ep_poll_callback() contention

 fs/eventpoll.c | 178 ++++++++++++++++++++++++++++++++++++-------------
 1 file changed, 133 insertions(+), 45 deletions(-)
Cc Davidlohr Bueso <[email protected]>
Cc Jason Baron <[email protected]>
Cc Al Viro <[email protected]>
Cc "Paul E. McKenney" <[email protected]>
Cc Linus Torvalds <[email protected]>
Cc Andrew Morton <[email protected]>
Signature · 1 line
2.19.1