liu meihua [email protected] chapter 3 memory management chapter 3 memory management —— 3.5...
TRANSCRIPT
2
Outline
Kernel virtual memory layout
Kernel memory slab allocator
3
3.5.1 Kernel virtual memory layout The Kernel uses virtual memory. The Kernel uses the memory management
unit(MMU) to translate its virtual memory addresses into physical pages.
The Kernel has its own address space and corresponding virtual memory layout.
Most of the kernel’s memory is nonpageable. Kernel memory consists of a variety of mappings. Nonpageable kernel memory is mapped with the
segkmem kernel segment driver. Pageable kernel memory is mapped with the segkp segment driver.
4
3.5.1 Kernel virtual memory layout Kernel Address Space The Kernel Text and Data Segments Virtual Memory Data Structures Loadable kernel Module Text and Data The Kernel Address Space and Segments
5
Kernel Address Space
It contains the following major mappings: The kernel text and data (mappings of the
kernel binary) The kernel map space (data structures,
caches, etc.) A 32-bit kernel map, for module text and data
(64-bit kernels only) The trap table Critical virtual memory data structures (TSB,
etc.) A place for mapping the file system cache
(segmap)
6
Solaris 7 64-Bit Virtual Address Space
7
The text segments contain the instructions The data segments contains the initialized
variables from the kernel/unix image file. They are mapped into the kernel address space
by the Open Boot PROM
The Kernel Text and Data Segments
8
Virtual Memory Data Structures
9
Loadable Kernel Module Text and Data
10
Loadable Kernel Module Text and Data
Looking at the module load address with the modinfo command
11
Solaris does allow some portions of the kernel to be allocated from pageable memory.
Pageable memory is restricted to those structures that are not required by the kernel when the process is swapped out: Lightweight process stacks The TNF Trace buffers Special pages, such as the page of memory that is
shared between user and kernel for scheduler preemption control
Pageable memory is allocated and swapped by the seg_kp segment.
Loadable Kernel Module Text and Data
12
The Kernel Address Space and Segments
13
The Kernel Address Space and SegmentsThe full list of segment drivers the kernel uses to create
and manage kernel mappings is shown in following table.
14
Outline
Kernel virtual memory layout
Kernel memory slab allocator
15
3.5.2 The Kernel Memory Slab Allocator
Slab Allocator Overview Object Caching Slab Allocator Implementation The CPU Layer The Depot Layer The Global (Slab) Layer
The slab allocator: the general-purpose memory allocator.
16
Slab Allocator Overview
The slab allocator consumes large slabs of memory and then allocates smaller requests with portions of each slab.
Use the slab allocator for memory requests that are: Smaller than a page size Not an even multiple of a page size Frequently going to be allocated and freed, so would
otherwise fragment the kernel map
17
Slab Allocator Overview
Performance comparison of the slab allocator.
18
The slab allocator uses the following terms: object to describe a single memory allocation unit cache to refer to a pool of like objects slab to refer to a group of objects that reside within
the cacheEach object type has one cache, which is
constructed from one or more slabs.
Slab Allocator Overview
19
Objects, Caches, Slabs, and Pages of Memory
20
Object Caching
The allocator tries to defer most of the real work associated with allocation and deallocation until it is really necessary, by keeping the objects alive until memory needs to be returned to the back end.
21
Slab Allocator Implementation
22
The CPU Layer
The CPU layer caches groups of objects to minimize the number of times that an allocation will need to go down to the lower layers.
23
The Depot Layer
The depot layer assembles groups of objects into magazines. Unlike a slab, a magazine’s objects are not necessarily allocated from contiguous memory; rather, a magazine contains a series of pointers to objects within slabs.
24
The Global (Slab) Layer
The global slab layer allocates slabs of objects from contiguous pages of physical memory and hands them up to the magazine layer for allocation. The global slab layer is used only when the upper layers need to allocate or deallocate entire slabs of objects to refill their magazines.