Linux Kernel logical address space organisation

kernelkernel-moduleslinuxmemory

According to "Write Great Code" in almost all OS run time memory is organized into following regions:

OS | Stack | Heap | Text | Static | Storage/BSS

[In increasing address fashion]

User space process uses higher memory region for its different types of data objects.

Kernel space process also have different types of data objects. Do these objects share the user space memory regions (stack, heap etc) or do they have there own separate sub-sections(heap, stack etc) located in OS region.And, if so, what is the order in which they are arranged.
Thanks,

Best Answer

It is wrong about the ordering. The OS is located at the top of memory, which is generally above the 3 GB mark ( 0xC0000000 ) in the 32bit kernel, and in the 64bit kernel it is the half way point of 0x8000000000000000 IIRC.

The location of the stack and heap are randomized. There is no real rule about the ordering of the text/data/bss segments within the main program, and every dynamic library has its own set of these, so there are many of them scattered all over memory.

Back when dinosaurs ruled the earth ( 20+ years ago ), the program address space was linear ( no holes ) and the order was text, data, bss, stack, heap. There were also no dynamic libraries or threading back then. That all changed with virtual memory.

Kernel processes are entirely contained within the kernel part of the address space; the user portion is ignored. This allows the kernel to speed up context switching between kernel threads beacuse it does not have to update the page tables since all processes share the same kernel portion of the page tables.

Related Question