BACKPORT: futex: Remove requirement for lock_page() in get_futex_key()
commit 65d8fc777f6dcfee12785c057a6b57f679641c90 upstream.
When dealing with key handling for shared futexes, we can drastically reduce
the usage/need of the page lock. 1) For anonymous pages, the associated futex
object is the mm_struct which does not require the page lock. 2) For inode
based, keys, we can check under RCU read lock if the page mapping is still
valid and take reference to the inode. This just leaves one rare race that
requires the page lock in the slow path when examining the swapcache.
Additionally realtime users currently have a problem with the page lock being
contended for unbounded periods of time during futex operations.
Now any other task trying to lock that page will have to wait until
task A gets scheduled back in, which is an unbound time.
With this patch, we pretty much have a lockless futex_get_key().
Experiments show that this patch can boost/speedup the hashing of shared
futexes with the perf futex benchmarks (which is good for measuring such
change) by up to 45% when there are high (> 100) thread counts on a 60 core
Westmere. Lower counts are pretty much in the noise range or less than 10%,
but mid range can be seen at over 30% overall throughput (hash ops/sec).
This makes anon-mem shared futexes much closer to its private counterpart.
Signed-off-by: Mel Gorman <email@example.com>
[ Ported on top of thp refcount rework, changelog, comments, fixes. ]
Signed-off-by: Davidlohr Bueso <firstname.lastname@example.org>
Reviewed-by: Thomas Gleixner <email@example.com>
Cc: Chris Mason <firstname.lastname@example.org>
Cc: Darren Hart <email@example.com>
Cc: Hugh Dickins <firstname.lastname@example.org>
Cc: Linus Torvalds <email@example.com>
Cc: Mel Gorman <firstname.lastname@example.org>
Cc: Peter Zijlstra <email@example.com>
Cc: Sebastian Andrzej Siewior <firstname.lastname@example.org>
Signed-off-by: Ingo Molnar <email@example.com>
Signed-off-by: Chenbo Feng <firstname.lastname@example.org>
Signed-off-by: Greg Kroah-Hartman <email@example.com>
1 file changed