History

futex: Add basic infrastructure for local task local hash

The futex hash is system wide and shared by all tasks. Each slot is hashed based on futex address and the VMA of the thread. Due to randomized VMAs (and memory allocations) the same logical lock (pointer) can end up in a different hash bucket on each invocation of the application. This in turn means that different applications may share a hash bucket on the first invocation but not on the second and it is not always clear which applications will be involved. This can result in high latency's to acquire the futex_hash_bucket::lock especially if the lock owner is limited to a CPU and can not be effectively PI boosted. Introduce basic infrastructure for process local hash which is shared by all threads of process. This hash will only be used for a PROCESS_PRIVATE FUTEX operation. The hashmap can be allocated via: prctl(PR_FUTEX_HASH, PR_FUTEX_HASH_SET_SLOTS, num); A `num' of 0 means that the global hash is used instead of a private hash. Other values for `num' specify the number of slots for the hash and the number must be power of two, starting with two. The prctl() returns zero on success. This function can only be used before a thread is created. The current status for the private hash can be queried via: num = prctl(PR_FUTEX_HASH, PR_FUTEX_HASH_GET_SLOTS); which return the current number of slots. The value 0 means that the global hash is used. Values greater than 0 indicate the number of slots that are used. A negative number indicates an error. For optimisation, for the private hash jhash2() uses only two arguments the address and the offset. This omits the VMA which is always the same. [peterz: Use 0 for global hash. A bit shuffling and renaming. ]

Sebastian Andrzej Siewior committed 1 year ago

Commit 80367ad1 parent 9a9bdfd8 files · +244 −21Browse files

Showing the changes to include/uapi/linux (1 of 8 files). Show all

Unified · Split

include/uapi/linux/prctl.h+5−0
@@ -364,4 +364,9 @@ struct prctl_mm_map { · 363 unmodified lines
364# define PR_TIMER_CREATE_RESTORE_IDS_ON 1364# define PR_TIMER_CREATE_RESTORE_IDS_ON 1
365# define PR_TIMER_CREATE_RESTORE_IDS_GET 2365# define PR_TIMER_CREATE_RESTORE_IDS_GET 2
366 366
367/* FUTEX hash management */
368#define PR_FUTEX_HASH 78
369# define PR_FUTEX_HASH_SET_SLOTS 1
370# define PR_FUTEX_HASH_GET_SLOTS 2
371
367#endif /* _LINUX_PRCTL_H */372#endif /* _LINUX_PRCTL_H */

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t