Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 2: Process Management and Scheduling


InterpretingBinary Formats


Each binary format is represented in the Linux kernel by an instance of the following (simplified) data
structure:

<binfmts.h>
struct linux_binfmt {
struct linux_binfmt * next;
struct module *module;
int (*load_binary)(struct linux_binprm *, struct pt_regs * regs);
int (*load_shlib)(struct file *);
int (*core_dump)(long signr, struct pt_regs * regs, struct file * file);
unsigned long min_coredump; /* minimal dump size */
};

Each binary format must provide three functions:


  1. load_binaryto load normal programs.

  2. load_shlibto load ashared library, that is, a dynamic library.

  3. core_dumpto write a core dump if there is a program error. This dump can subsequently be
    analyzed using a debugger (e.g.,gdb) for troubleshooting purposes.min_coredumpis a lower
    bound on the core file size from which a coredump will be generated (usually, this is the size
    of a single memory page).


Each binary format must first be registered in the kernel usingregister_binfmt. The purpose of this
function is to add a new binary format to a linked list whose list head is represented by theformats
global variable fromfs/exec.c.Thelinux_binfmtinstances are linked with each other by means of
theirnextelement.

2.4.4 Exiting Processes


Processes must terminate with theexitsystem call. This gives the kernel the opportunity to free the
resources used by the processes to the system.^19 The entry point for this call is thesys_exitfunction
that requires an error code as its parameter in orderto exit the process. Its definition is architecture-
independent and is held inkernel/exit.c. Its implementation is not particularly interesting because it
immediately delegates its work todo_exit.

Suffice it to say that the implementation of this function consists essentially of decrementing reference
counters and returning memory areas to memory management once the reference counter has reverted
to 0 and the corresponding structure is no longer being used by any process in the system.

2.5 Implementation of the Scheduler


A unique description of each process is held in memory and is linked with other processes by means of
several structures. This is the situation facing the scheduler, whose task is to share CPU time between
the programs to create the illusion of concurrent execution. As discussed above, this task is split into two
different parts — one relating to the scheduling policy and the other to context switching.

(^19) exitcan be called explicitly by the programmer. However, the compiler automatically adds a corresponding call to the end of
themainfunction (or to the main function used by the particular language).

Free download pdf