1

I appreciate that under Linux, threads are mapped onto processes. What I am unclear about is the difference in magnitude between thread switch overhead and process switch overhead using the Native POSIX Threads Library (i.e. kernels >= 2.6), and I'm having problems finding well-informed articles quantifying the difference.

Does anyone here have useful references to quantify?

Thanks!

Jon Green
  • 141
  • 6
  • 1
    possible duplicate of [Threads vs Processes in Linux](http://stackoverflow.com/questions/807506/threads-vs-processes-in-linux) – assylias Jan 03 '13 at 16:10
  • Have you considered just making a little benchmark of your own and measuring? Sometimes things like this are heavily dependent on the actual use case... – thkala Jan 03 '13 at 16:58
  • @assylias - not really; I'm very aware of the difference between thread and process operations, and that article doesn't give any rough metrics. – Jon Green Jan 03 '13 at 17:22
  • @thkala - it's not that easy to measure: how would you go about timing the period from context switch commencement to end of context switch, for each type of switch? I wish I had time to instrument the kernel/lib sources; probably the only way to know for sure! I agree that use case matters to an extent (no. of pages mapped per proc, phys mem usage, etc.), but I'm hoping someone will be able to give an approximate rule-of-thumb ratio between process and thread switch overheads regardless, or some existing measurements. – Jon Green Jan 03 '13 at 17:30
  • I don't have enough knowledge on that matter to make a real answer. My opinion is that even if the kernel structures are almost the same between a thread and a full fledged process, there is certainly a gain in using threads, from the memory cache perspective. Intuitively shouldn't a thread switch incur less cache invalidation that a process one? – didierc Jan 03 '13 at 17:40
  • perhaps the same issue exists at the memory paging level (page faulting more likely with processes)? – didierc Jan 03 '13 at 17:43
  • Of course, if the processes are running the same program (no `exec` done by the child), and most memory is shared (no memory writing to avoid cow triggering, excepted in a shared memory - `shmget`), then the problem might be mitigated enough. – didierc Jan 03 '13 at 17:46
  • @JonGreen: you would not measure the context switch itself, of course. You would measure the macroscopic effect on the execution speed of a specific algorithm... – thkala Jan 03 '13 at 18:44
  • @JonGreen: in any case, selecting between threads and processes is usually based on functionality, rather than performance - as far as the kernel is concerned processes are just threads with several differences in how they are set-up. Is there a specific reason you are asking about the overhead, or is it just academic interest? – thkala Jan 03 '13 at 18:47

0 Answers0