3. Outline
• Memory in Linux
– Dynamic Allocation
– Contiguous Allocation
•Memory Allocation
– Buddy System
– Zone
– SLAB Allocator
• Per-CPU data
12/4/26 Linux - Memory Management 3
4. MMU - Simple History
Early Linux on x86
Linux 2.5.46
(MMU)
Embedded Developer?!
µClinux
(Linux for microconcroller)
Jeff Dionne et al.1998
12/4/26 Linux - Memory Management 4
5. All about PAGE
• Physical page -> page frame
– Page descriptor, page
– All pages, mem_map
12/4/26 Linux - Memory Management 5
6. Initialization
query or invoke Kernel
BIOS
machine_specific_memory_setup()
setup_memory_map()
struct page* mem_map
Physical Memory
12/4/26 Linux - Memory Management 6
11. Hierarchy Overview
App w/ glibc heap
Zone Allocator
Slab Allocator
glibc
Buddy Allocator
MMU
Kernel Physical
Subsystems VM Subsystem Memory
kswapd
App w/ heap
bdflush Disk
Driver
User Space Kernel Space Disk
12/4/26 Linux - Memory Management 11
19. Per-CPU Allocation
• Request/Release single page
– Frequently
• Per-CPU
– Reducing cache invalidation
– Reducing locking
– A simple data array
• In 2.4 kernel
– get_cpu(), preemption disabled
– Access array directly
• In 2.6 kernel
– Wrapper
– percpu interface
– Cache alignment
12/4/26 Linux - Memory Management 19
20. Review
App w/ glibc heap
Zone Allocator
Slab Allocator
glibc
Buddy Allocator
MMU
Kernel Physical
Subsystems VM Subsystem Memory
kswapd
App w/ heap
bdflush Disk
Driver
User Space Kernel Space Disk
12/4/26 Linux - Memory Management 20
21. Reference
• Linux Kernel Development, 3rd
• Understanding the Linux Kernel, 3rd
– http://www.makelinux.net/books/ulk3/t
oc
• Understanding the Virtual Memory
Manager
– http://www.kernel.org/doc/gorman/htm
l/understand/index.html
12/4/26 Linux - Memory Management 21