News for hackers. Stuff that matters.
Re:Without the Futex, It's Futile by nromiun on Tuesday August 19, 2025 @11:06AM (#44952420)
Is it just me or moving things out of kernel space improves performance in general? Like context switching, mutex or entire TCP stack. I wonder what else can be moved into user space.
Re:Without the Futex, It's Futile by whstl on Tuesday August 19, 2025 @11:39AM (#44952847)
You're right. With the caveat that it's the moving in and out of the kernel that's the expensive part, so putting things inside it also helps with performance... at the expense of security and reliability, of course, so userspace it is!
Re:Without the Futex, It's Futile by viega on Tuesday August 19, 2025 @11:23AM (#44952643)
It depends on the relative cost of what you're doing of course, but in general, yes, the cost of entering the kernel can be impactful, if you are making a lot of calls into it, since a lot of work has to happen every time.

There are definitely user-land TCP/IP implementations, thread implementations (Go's being particularly notable) and even file systems (FUSE).

Re:Without the Futex, It's Futile by bicolao on Tuesday August 19, 2025 @11:46AM (#44952925)
fuse probably isn't a good example here because you still have to enter kernel space if i'm not mistaken, then out again to the fs driver in userspace then probably back to kernel space (block driver). fuse has many upsides, but I don't think performance is one of them.
Re:Without the Futex, It's Futile by viega on Tuesday August 19, 2025 @11:55AM (#44953035)
Well, you still have to enter the kernel to actually queue an OS-level thread w/ a futex. The kernel supporting being able to move stuff to userland sure doesn't guarantee better performance-- the main opportunity from that perspective is minimizing how often you cross the boundary.

You're 100% right that there are plenty of other considerations, often positive for lifting things out, like minimization of ring 0 attack surface.

Re:Without the Futex, It's Futile by Jtsummers on Tuesday August 19, 2025 @11:23AM (#44952636)
Most things can be moved into user space.

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

Re:Without the Futex, It's Futile by toast0 on Tuesday August 19, 2025 @01:38PM (#44954120)
Piling on with others; it's avoiding the context switching and copying between user and kernel that improves performance.

If you can stay in user space, or stay in kernel space, that is likely to be better performance than going back and forth.

This is why sendfile is great; rather than storage -> kernel memory -> user memory -> kernel memory -> network, you get storage -> kernel memory -> network. That's two less copies, and fewer context switches.

Re:Without the Futex, It's Futile by the8472 on Tuesday August 19, 2025 @04:17PM (#44955850)
io_uring alleviates a lot of those problems by essentially providing a batched, asynchronous syscall API, including futex calls, as mentioned in other comments.
Re:Without the Futex, It's Futile by senderista on Tuesday August 19, 2025 @07:46PM (#44957320)
Futexes can be moved into user space!

https://webkit.org/blog/6161/locking-in-webkit/

Re:Without the Futex, It's Futile by tialaramex on Wednesday August 20, 2025 @05:53AM (#44960390)
While I'm sure it sounds great to Apple fans, this ends up just being a circle in practice. We need a way to fall asleep when contended. Apple calls this a "Parking Lot" Linux calls it a "Futex" and as we've seen Microsoft have a different name.

Like Microsoft's Apple's approach is slightly smaller (one byte not four) and over a decade later.

Re:Without the Futex, It's Futile by gpderetta on Wednesday August 20, 2025 @08:50AM (#44961474)
Well, but with a parking_lot abstraction, you only need a wait primitive per thread (as a thread_local for example), so it doesn't need to be a futex. It could be a eventfd which is interesting for integrating with other event loops.
Re:Without the Futex, It's Futile by senderista on Wednesday August 20, 2025 @11:28AM (#44962828)
By putting the wait queues in userspace you can customize behavior with callbacks, as the article shows.
Re:Without the Futex, It's Futile by omgtehlion on Wednesday August 20, 2025 @05:09AM (#44960123)
Yes it is. In hft (or any algo trading nowadays) it is commonplace to use usermode networking since like ~2010 or even earlier.

The part of NICs address space is mapped to a process (control registers and memory rings), and whole driver just runs in your process without going through the kernel. Of course, it ignores usual stuff like firewalls, iptables, etc, but who cares when all you need is the lowest latency possible )