3

I was trying to understand the Linux process management and scheduling. I know that the scheduler schedules different processes based on priority/time slicing. But there are kernel tasks (I am not mentioning the process' system calls which takes the process to kernel mode) which have to be processed as well (eg: scheduler/timers or some kernel code which runs forever). I did not understand if the scheduler schedules CPU for different processes how the kernel tasks are serviced in between.

2

Kernel tasks which aren’t run “in process” (to service a system call, or an interrupt) are handled as separate processes themselves, and you can see them in ps’s output:

root         2  0.0  0.0      0     0 ?        S    Sep16   0:02 [kthreadd]
root         3  0.0  0.0      0     0 ?        I<   Sep16   0:00 [rcu_gp]
root         4  0.0  0.0      0     0 ?        I<   Sep16   0:00 [rcu_par_gp]
root         6  0.0  0.0      0     0 ?        I<   Sep16   0:00 [kworker/0:0H-kblockd]
root         8  0.0  0.0      0     0 ?        I<   Sep16   0:00 [mm_percpu_wq]
root         9  0.0  0.0      0     0 ?        S    Sep16   9:11 [ksoftirqd/0]
root        10  0.2  0.0      0     0 ?        I    Sep16 173:25 [rcu_sched]
root        11  0.0  0.0      0     0 ?        I    Sep16   0:00 [rcu_bh]
root        12  0.0  0.0      0     0 ?        S    Sep16   0:20 [migration/0]
root        14  0.0  0.0      0     0 ?        S    Sep16   0:00 [cpuhp/0]
root        15  0.0  0.0      0     0 ?        S    Sep16   0:00 [cpuhp/1]

These processes are scheduled in the same way as processes you’re more familiar with.

A common pattern for such tasks is workqueues; the kernel documentation for those is quite good, I encourage you to read it if you’re interested in the topic.

  • This link is to a API "workqueue". OQ: "(I am not mentioning the process' system calls which takes the process to kernel mode) " – user373503 Nov 4 '19 at 7:57
  • Workqueues don’t involve system calls. – Stephen Kitt Nov 4 '19 at 8:12
  • So why you link? – user373503 Nov 4 '19 at 8:14
  • Because it provides useful context to understand how kernel tasks are commonly set up. – Stephen Kitt Nov 4 '19 at 8:16
  • I understand the Q is about the in-between, the mysterious SCHED kernel subunit. What orchestrates these tasks visible in ps. Elemantary computer science. You have to tackle the hen-and-egg problem: if A shaves all non-self-shavers, does A shave himself? (this is some trad. philosophic paradoxon). Translate to "preempt" and "cpu-thread". – user373503 Nov 4 '19 at 8:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.