I read that Linux has an O(1) scheduler, but this does not tell me actually how long a context switch roughly takes. Does someone have some current numbers?

I know it depends on a lot of factors like CPU type, frequency, DRAM connectivity, caches and what not, but I would be happy to know the order of magnitude in milli, micro, nano seconds or the rough number of processor cycles needed to preempt one process, decide for the next process to run and actually get it going.

  • I believe it's in the order of 10 milliseconds.
    – suspectus
    Nov 20, 2019 at 11:34
  • If you were right, then Linux would do exactly nothing, since 10ms is the frequency of the scheduler.
    – schily
    Nov 20, 2019 at 11:48
  • I answered this: " but this does not tell me actually how long a context switch roughly take"
    – suspectus
    Nov 20, 2019 at 11:54
  • 1
    @suspectus I usually reckon on microsecond-scale times, so approximately 10,000 times less. Nov 20, 2019 at 12:09
  • @schily I cited you in my answer, just want to let you know. (I agree with your comment)
    – user373503
    Nov 20, 2019 at 13:51

1 Answer 1


The default scheduler on Linux hasn’t been the O(1) scheduler for the last ten years, it’s the Completely Fair Scheduler, which is O(log n) on the number of tasks in the runqueue. You’d have to benchmark specific scenarios you’re interested in, on your specific systems and workloads; one can find benchmarks on the Internet, with figures typically on the order of 0.5-2 µs per context switch, even when switching to tasks not previously scheduled on the CPU.

As you mention, the overhead will vary a lot depending on circumstances, including code and data presence in the various caches. Nowadays the overhead also varies depending on the kernel version and configuration, in particular depending on what security countermeasures are active and how well they’re supported by the CPU. A recent paper gives relative figures for the latter, with variations from –14% to +98% compared to a 4.0 baseline.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .