Chapter 1. Understanding the Linux operating system 9
Draft Document for Review May 4, 2007 11:35 am 4285ch01.fm
򐂰Data segment
The data segment consist of these three area.
Data: The area where initialized data such as static variables are stored.
BSS: The area where zero-initialized data is stored. The data is initialized to zero.
Heap: The area where malloc() allocates dynamic memory based on the demand.
The heap grows toward higher addresses.
򐂰Stack segment
The area where local variables, function parameters, and the return address of a function
is stored. The stack grows toward lower addresses.
The memory allocation of a user process address space can be displayed with the pmap
command. You can display the total size of the segment with the ps command. Refer to
2.3.10, “pmap” on page52 and 2.3.4, “ps and pstree” on page 44.
1.1.9 Linux CPU scheduler
The basic functionality of any computer is, quite simply, to compute. To be able to compute,
there must be a means to manage the computing resources, or processors, and the
computing tasks, also known as threads or processes. Thanks to the great work of Ingo
Molnar, Linux features a kernel using a O(1) algorithm as opposed to the O(n) algorithm used
to describe the former CPU scheduler. The term O(1) refers to a static algorithm, meaning
that the time taken to choose a process for placing into execution is constant, regardless of
the number of processes.
The new scheduler scales very well, regardless of process count or processor count, and
imposes a low overhead on the system. The algorithm uses two process priority arrays:
򐂰active
򐂰expired
As processes are allocated a timeslice by the scheduler, based on their priority and prior
blocking rate, they are placed in a list of processes for their priority in the active array. When
they expire their timeslice, they are allocated a new timeslice and placed on the expired array.
When all processes in the active array have expired their timeslice, the two arrays are
switched, restarting the algorithm. For general interactive processes (as opposed to real-time
processes) this results in high-priority processes, which typically have long timeslices, getting
more compute time than low-priority processes, but not to the point where they can starve the
low-priority processes completely. The advantage of such an algorithm is the vastly improved
scalability of the Linux kernel for enterprise workloads that often include vast amounts of
threads or processes and also a significant number of processors. The new O(1) CPU
scheduler was designed for kernel 2.6 but backported to the 2.4 kernel family. Figure 1-8
illustrates how the Linux CPU scheduler works.