Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reason why CFS scheduler using red black tree?

CFS scheduler picks next process based on minimum virtual time and to get this value efficiently its using Red-Black tree(rbtree), using rbtree we will get minimum O(h) here h is height of rbtree. But, using min-heap we can get min virtual time process in O(1) time only. I just want to know why min-heap is not consider in CFS implementation and is there any difficulties using min-heap in kernel level?

like image 478
noman pouigt Avatar asked Oct 17 '15 20:10

noman pouigt


People also ask

Is red black tree is used for kernel scheduling?

There are a number of red-black trees in use in the kernel. The deadline and CFQ I/O schedulers employ rbtrees to track requests; the packet CD/DVD driver does the same. The high-resolution timer code uses an rbtree to organize outstanding timer requests.

What is a feature of the completely fair scheduler CFS?

CFS is quite simple algorithm for the process scheduling and it is implemented using RED BLACK Trees and not queues. So all the process which are on main memory are inserted into Red Black trees and whenever a new process comes it is inserted into the tree.

Which scheduling algorithm is used in Linux operating system?

Linux uses a Completely Fair Scheduling (CFS) algorithm, which is an implementation of weighted fair queueing (WFQ). Imagine a single CPU system to start with: CFS time-slices the CPU among running threads.

How does completely fair scheduler work?

CFS gives every task a fair share of processor resources in a low-fuss but highly efficient way. Linux takes a modular approach to processor scheduling in that different algorithms can be used to schedule different process types. A scheduling class specifies which scheduling policy applies to which type of process.


1 Answers

The reason is: Heaps are array based and hence require contiguous memory in kernel space. This is because the way heaps are implemented in Linux. See the files lib/prio_heap.c and include/linux/prio_heap.h and you'll note that heap is kmalloc'd using heap_init. Once the multi-programming space becomes huge, maintaining thousands of struct sched_entity requires lot of contiguous space (it runs in several pages). From time and performance point of view, one would prefer heap as hepify operation can run in background once min vruntime is picked but it's space requirement which makes bottleneck.

As rbtree is readily available, kernel developers didn't think of implementing pointer based heap, in fact one doesn't need.

like image 81
Vishal Sahu Avatar answered Sep 24 '22 04:09

Vishal Sahu