News for hackers. Stuff that matters.
Re:Re: 100k Threads? (2002) by Sesse__ on Saturday September 23, 2023 @08:05AM (#37622524)
The page tables change in a kernel context switch, whereas they don't in a user context switch. Depending on your CPU and OS, this may or may not matter; e.g., modern CPUs typically have caches that are tagged with the context (e.g. PCID on Intel), but the Spectre flavor of the day may require that you simply flush the entire L1 cache on context switch anyway if you're unlucky.

The biggest cost of a context switch, though, is typically that your CPU goes to do something else, which reduces the efficiency of any caches (including branch prediction etc.). This is the same whether you have kernel or userspace context switches, assuming the threads you're switching between touch different code and/or data.

Re:Re: 100k Threads? (2002) by gpderetta on Saturday September 23, 2023 @08:07AM (#37622534)
Well, page tables don't change on a thread context switch, that is relevant for this discussion.
Re:Re: 100k Threads? (2002) by PhilipRoman on Saturday September 23, 2023 @10:04AM (#37623320)
Why do page tables need to change in a context switch between two threads? AFAIK the kernel is mapped in every process, just not accessible in user mode.