Top all-time · #4355
Tsuna's blog
Personal blog · blog.tsunanet.netprogrammingsystems
Tsuna's blog is a personal blog at blog.tsunanet.net about programming and systems. Since 2010, 18 different Hacker News readers have linked it 19 times, most often “How long does it take to make a context switch? (2010)”. The last post was in 2023, but the archive is still widely read.
Too few sampled comments (11) to say how often HN recommends it.?
Why HN links it
Commenters repeatedly cite one 2010 post measuring the cost of a context switch on Linux, about 30µs, in discussions of threads, syscalls and caches. It is the most-linked reference on that topic here.
Summarised by Claude from a sample of 11 HN comments that link here. Each comment is marked recommending, critical or neutral (citing without judging); how this works.
In code we trust.
Most-linked posts?
- How long does it take to make a context switch? (2010)11 people · 11 mentions · first linked 2010-11-27
- /2010/11/how-long-does-it-take-to-make-context.html3 people · 3 mentions · first linked 2019-07-03
- Perforce killed my productivity again2 people · 2 mentions · first linked 2012-11-12
What Hacker News says?
If you read the article linked to in the article I linked to above (which is fairly out of date, from 2010): https://blog.tsunanet.net/2010/11/how-long-does-it-take-to-m... you will find that on Linux a context switch takes about 30 usec. More recent measurements that take account of the effect of the TLB flush put the range at 10-300usec. That means that in 2010, on Linux , you could reasonably expect to do at leas…
Comment linking /2010/11/how-long-does-it-take-to-make-context.html
on “Bespoke Synth 1.0 – open-source software modular synthesizer”Submitted How long does it take to make a context switch? (2010) as a story · 87 points
HN discussionThe syscall overhead isn't the problem, that's dirt cheap as you say. The problem is the context-switch overhead. Calling into the OS flushes a lot of data and instructions from the cache, and that lost performance after returning can easily add up to around 30µs.[1] [1] http://blog.tsunanet.net/2010/11/how-long-does-it-take-to-ma...
Comment linking /2010/11/how-long-does-it-take-to-make-context.html
on “Non-volatile Storage: CPUs no longer more performant than I/O devices”Submitted How long does it take to make a context switch? as a story · 13 points
HN discussionI heard that, especially with spectre, most of the cost of context switching comes from messing up your caches + TLB ( https://blog.tsunanet.net/2010/11/how-long-does-it-take-to-m... ). There's a graph on Dan Luu's blog about how it takes 14,000 cycles to get back to full performance after a syscall: https://danluu.com/images/new-cpu-features/flexsc_ipc_recove... .
Comment linking /2010/11/how-long-does-it-take-to-make-context.html
on “Ways of Implementing a System Call”Submitted Perforce killed my productivity again as a story · 5 points
HN discussionIt's a bit dated, but here's a reference: https://blog.tsunanet.net/2010/11/how-long-does-it-take-to-m...
Comment linking /2010/11/how-long-does-it-take-to-make-context.html
on “Why Continuations Are Coming to Java”Submitted Ext4 2x faster than XFS? as a story · 3 points
HN discussionI can't explain completely, but check out http://blog.tsunanet.net/2010/11/how-long-does-it-take-to-ma... . Relatively speaking, I don't think context switching is _that_ expensive compared to other areas you can focus on like doing smarter memory management. I don't know exactly what they mean by threads having heavy memory overhead, but possibly they mean cache interference mentioned in that link? I'd be curious i…
Comment linking /2010/11/how-long-does-it-take-to-make-context.html
on “Futures for C++11 at Facebook”Submitted How long does it take to make a context switch? as a story · 2 points
HN discussionThere is nothing fundamentally new described in the blog post, although pinning threads to core is almost never the default operation mode (though many popular servers expose an option for turning this one). As someone else stated in another post, SO_REUSEPORT and accept4() is best, all things considered, way to accept connections across multiple threads. Again, most modern servers support this by default, if suppor…
Comment linking /2010/11/how-long-does-it-take-to-make-context.html
on “Fast Servers”Submitted Java IO: slowest readLine ever as a story · 1 points
HN discussion> Context switches are really fast on modern x86. Not context switching is even faster. How fast is really fast, how modern is modern? some results from 2010 [1] show at least 1000 nanoseconds per context switch (even with optimizations for the kernel switching between threads of the same process). That's not that slow, but it is a lot of time you could be doing something else. [1] http://blog.tsunanet.net/2010/11/h…
Comment linking /2010/11/how-long-does-it-take-to-make-context.html
on “Fix for Golang runtime memory corruption bug”Submitted Perforce killed my productivity. Again as a story · 1 points
HN discussionYou should clarify your terminology: -- "context switch" (expensive) is the switch among active (running on this CPU) tasks/threads/processes. -- switching between kernel and userspace would be "mode switch", much less expensive and of "constant" cost (see, for example, http://blog.tsunanet.net/2010/11/how-long-does-it-take-to-ma... ). Your phrase already carries this contradiction: "__can__ be fairly expensive" poi…
Comment linking /2010/11/how-long-does-it-take-to-make-context.html
on “Unicore: A new Unikernel project”"Context switching is expensive. My rule of thumb is that it'll cost you about 30µs of CPU overhead. This seems to be a good worst-case approximation. Applications that create too many threads that are constantly fighting for CPU time (such as Apache's HTTPd or many Java applications) can waste considerable amounts of CPU cycles just to switch back and forth between different threads." http://blog.tsunanet.net/2010/…
Comment linking /2010/11/how-long-does-it-take-to-make-context.html
on “Dyad: Minimal, portable async networking library for C”A case of only so many words in the English language. Easy to fix if we distinguish hardware fast path from the software variant. Software fast paths are worth looking into since context switches are costly to the tune of thousands of CPU cycles [0,1]. Those thousands of CPU instructions going up in smoke could've done quite a lot of useful work. [0] http://blog.tsunanet.net/2010/11/how-long-does-it-take-to-ma... [1…
Comment linking /2010/11/how-long-does-it-take-to-make-context.html
on “New approaches to network fast paths”I enjoyed it when I first read it a couple of years ago and the recent blog post from tsuna on context switching reminded me of it ( http://blog.tsunanet.net/2010/11/how-long-does-it-take-to-ma... ). Glad to see some other folks like it, as well.
Comment linking /2010/11/how-long-does-it-take-to-make-context.html
on “A Comparison of Software and Hardware Techniques for x86 Virtualization”