Search code examples
linux-kernelschedulingcfs

Scheduler data structures


Does any body know that where CFS scheduling algorithm's data (for example content of suspend or ready queue, task duration, ...) is stored in Linux? (Is there any special file or data structure for this goal?)

Thanks.


Solution

  • CFS keeps a different runqueue for each processing unit in the system (i.e., it is not a global scheduler, but rather it relies on task migration among the different runqueues). The data structure is struct cfs_rq in the kernel/sched/sched.h file.

    Then, each runqueue internally keeps tasks ordered through a Red-Black Tree data structure. The implementation of this data structure is contained in the include/linux/rbtree.h file. It is a generic implementation in the sense that it is not strictly related to scheduling, and thus it can be used by any kernel component that needs to keep data sorted with this kind of data structure.

    Within the kernel code, the data structure containing information about a process (or a thread) is task_struct, contained inside include/linux/sched.h. This is the main task data structure, used by all scheduling policies (i.e., SCHED_FAIR, SCHED_FIFO/SCHED_RR, SCHED_DEADLINE, etc.)

    A good documentation about how CFS works is contained inside the Documentation/scheduler directory.