Not included:
CVE-2018-5703 : Skipped due to fix rejected upstream
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.

Task A
    ---> preempted

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 <>
[ Ported on top of thp refcount rework, changelog, comments, fixes. ]
Signed-off-by: Davidlohr Bueso <>
Reviewed-by: Thomas Gleixner <>
Cc: Chris Mason <>
Cc: Darren Hart <>
Cc: Hugh Dickins <>
Cc: Linus Torvalds <>
Cc: Mel Gorman <>
Cc: Peter Zijlstra <>
Cc: Sebastian Andrzej Siewior <>
Signed-off-by: Ingo Molnar <>
Signed-off-by: Chenbo Feng <>
Signed-off-by: Greg Kroah-Hartman <>

1 file changed