Linux Kernel Architecture

(Jacob Rumans) #1
Mauerer app04.tex V1 - 09/04/2008 6:12pm Page 1238

Appendix D: System Startup


__initcall_start = .;
INITCALLS
__initcall_end = .;
}
...

. = ALIGN(2 PAGE_SIZE);
__init_end = .;
/
Freed after init ends here */


A few other sections are also added to the initialization section that includes, for example, the initcalls
discussed previously. However, for the sake of clarity, this appendix does not describe all data and
function types removed from memory by the kernel on completion of booting.

free_initmemis one of the last actions invoked byinitto free kernel memory between__init_begin
and__init_end. The value of the variable is set automatically by the linker as follows:

arch/i386/mm/init.c
void free_init_pages(char *what, unsigned long begin, unsigned long end)
{
unsigned long addr;

for (addr = begin; addr < end; addr += PAGE_SIZE) {
ClearPageReserved(virt_to_page(addr));
init_page_count(virt_to_page(addr));
memset((void *)addr, POISON_FREE_INITMEM, PAGE_SIZE);
free_page(addr);
totalram_pages++;
}
printk(KERN_INFO "Freeing %s: %luk freed\n", what, (end - begin) >> 10);
}

void free_initmem(void)
{
free_init_pages("unused kernel memory",
(unsigned long)(&__init_begin),
(unsigned long)(&__init_end));
}

Although this is an architecture-specific function, its definition is virtually identical on all supported
architectures. For brevity’s sake, only the IA-32 version is described. The code iterates through the indi-
vidual pages reserved by the initialization data and returns them to the buddy system usingfree_page.
A message is then output indicating how much memory was freed, usually around 200 KiB.

Starting Userspace Initialization


As its final action,initinvokesinit_post— which, in turn, launches a program that continues initial-
ization in userspace in order to provide users with a system on which they can work. UnderUnixand
Linux, this task is traditionally delegated to/sbin/init. If this program is not available, the kernel tries a
number of alternatives. The name of an alternative program can be passed to the kernel byinit=program
in the command line. An attempt is then made to start this program before the default options (the name
Free download pdf