Questions tagged [futex]

"A futex (short for “fast userspace mutex”) is a kernel system call that programmers can use to implement basic locking, or as a building block for higher-level locking abstractions such as semaphores and POSIX mutexes or condition variables." -- From Wikipedia

https://en.wikipedia.org/wiki/Futex

107 questions
56
votes
5 answers

Why is a pthread mutex considered "slower" than a futex?

Why are POSIX mutexes considered heavier or slower than futexes? Where is the overhead coming from in the pthread mutex type? I've heard that pthread mutexes are based on futexes, and when uncontested, do not make any calls into the kernel. It…
Jason
  • 31,834
  • 7
  • 59
  • 78
40
votes
1 answer

What is the difference between FUTEX_WAIT and FUTEX_WAIT_PRIVATE?

I have been tracing a process with strace and have seen entries such as: futex(0x7ffff79b3e00, FUTEX_WAKE_PRIVATE, 1) = 1 futex(0x7ffff79b3e00, FUTEX_WAIT_PRIVATE, 2, NULL) = 0…
Gabriel Southern
  • 9,602
  • 12
  • 56
  • 95
18
votes
2 answers

Java periodically hangs at futex and very low IO output

Currently my application periodically blocked in IO , and the output is very low . I use some command to trace the process. By using jstack i found that the app is hanging at FileOutputStream.writeBytes. By using strace -f -c -p pid to collect…
bforevdr
  • 271
  • 1
  • 2
  • 5
17
votes
1 answer

High system CPU usage when contending futex

I have observed that when the linux futexes are contended, the system spends A LOT of time in the spinlocks. I noticed this to be a problem even when futexes are not used directly, but also when calling malloc/free, rand, glib mutex calls, and…
Alex Fiddler
  • 213
  • 1
  • 3
  • 8
15
votes
2 answers

Using libcurl in a multithreaded environment causes VERY slow performance related to DNS lookup

You'll have to pardon the rather large-ish block of code, but I believe this is a near-minimal reproduction of my problem. The problem is not isolated to example.com but persists across many other sites. If I have 4 threads actively making network…
druckermanly
  • 2,694
  • 15
  • 27
15
votes
1 answer

How to debug a futex contention shown in strace?

I'm debugging an issue in a multi-threaded linux process, where a certain thread appears to not execute for few seconds. Looking at strace output revealed it waits for futex e.g. 1673109 14:36:28.600329 futex(0x44b8d20, FUTEX_WAIT_PRIVATE, 1673109…
Aman Jain
  • 10,927
  • 15
  • 50
  • 63
12
votes
2 answers

Using std::atomic with futex system call

In C++20, we got the capability to sleep on atomic variables, waiting for their value to change. We do so by using the std::atomic::wait method. Unfortunately, while wait has been standardized, wait_for and wait_until are not. Meaning that we cannot…
David Haim
  • 25,446
  • 3
  • 44
  • 78
10
votes
2 answers

The futex facility returned an unexpected error code?

Two threads in same process using rwlock object stored in shared memory encounter crash during pthreads stress test. I spent a while trying to find memory corruption or deadlock but nothing so far. is this just an less than optimal way of informing…
Bob L
  • 101
  • 1
  • 1
  • 5
9
votes
2 answers

Debug a futex lock

I have a process waiting on a futex: # strace -p 5538 Process 5538 attached - interrupt to quit futex(0x7f86c9ed6a0c, FUTEX_WAIT, 20, NULL How can I best debug such a situation? Can I identify who holds the futex? Are there any tools similar to…
user300811
  • 158
  • 1
  • 6
7
votes
3 answers

Python 2.6 vs 2.7 Multi-Threaded performance Issue (futex)

I have a simple Monte-Carlo Pi computation program. I tried running it on 2 different boxes(same hardware with slightly different kernel versions). I am seeing significant performance drop in one case(twice the time). Without threads, performance is…
Anoop
  • 1,757
  • 1
  • 19
  • 24
7
votes
1 answer

fast user space inter-process notify approach on Linux?

We have two Linux process communicate with domain socket, the performance goal is 5k iops with 4k request size through single domain socket connection, in order to reduce cpu cost we replace domain socket with a io-ring(shared memory based), but…
drewlu
  • 79
  • 3
6
votes
1 answer

Linux futex syscall spurious wakes with return value 0?

I've run into an issue with the Linux futex syscall (FUTEX_WAIT operation) sometimes returning early seemingly without cause. The documentation specifies certain conditions that may cause it to return early (without a FUTEX_WAKE) but these all…
R.. GitHub STOP HELPING ICE
  • 208,859
  • 35
  • 376
  • 711
6
votes
0 answers

Debug dotnet core process hanging at futex

I am running a dotnet core 2.1 application on the following linux embedded system: Linux arm 4.14.67-1.0.7+ #52 SMP PREEMPT armv7l GNU/Linux The application hangs since a couple of days at a futex: root@arm:/# strace -p 525 strace: Process 525…
nico1000
  • 71
  • 3
6
votes
1 answer

See stacktrace of hanging Python in futex(..., FUTEX_WAIT_BITSET_PRIVATE|...)

A Python process hangs in futex(): root@pc:~# strace -p 9042 strace: Process 9042 attached futex(0x1e61900, FUTEX_WAIT_BITSET_PRIVATE|FUTEX_CLOCK_REALTIME, 0, NULL, ffffffff I want to see the stacktrace if the hanging process. Unfortunately ctrl-c…
guettli
  • 25,042
  • 81
  • 346
  • 663
6
votes
2 answers

Share futex between unrelated processes

How can unrelated processes cooperate using a futex? Let's say I have unrelated processes, one being, say, an apache subprocess with my module, another being e.g. a background script. I'd like to establish a condition variable with a mutex between…
Dima Tisnek
  • 11,241
  • 4
  • 68
  • 120
1
2 3 4 5 6 7 8