liu meihua [email protected] chapter 3 memory management chapter 3 memory management —— 3.5...

25
Liu Meihua [email protected] Chapter 3 Memory Chapter 3 Memory management management —— 3.5 Kernel Memory

Upload: aspen-chadderton

Post on 14-Dec-2015

227 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Liu Meihua lmh123@bit.edu.cn Chapter 3 Memory management Chapter 3 Memory management —— 3.5 Kernel Memory

Liu [email protected]

Chapter 3 Memory managementChapter 3 Memory management

—— 3.5 Kernel Memory

Page 2: Liu Meihua lmh123@bit.edu.cn Chapter 3 Memory management Chapter 3 Memory management —— 3.5 Kernel Memory

2

Outline

Kernel virtual memory layout

Kernel memory slab allocator

Page 3: Liu Meihua lmh123@bit.edu.cn Chapter 3 Memory management Chapter 3 Memory management —— 3.5 Kernel Memory

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.

Page 4: Liu Meihua lmh123@bit.edu.cn Chapter 3 Memory management Chapter 3 Memory management —— 3.5 Kernel Memory

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

Page 5: Liu Meihua lmh123@bit.edu.cn Chapter 3 Memory management Chapter 3 Memory management —— 3.5 Kernel Memory

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)

Page 6: Liu Meihua lmh123@bit.edu.cn Chapter 3 Memory management Chapter 3 Memory management —— 3.5 Kernel Memory

6

Solaris 7 64-Bit Virtual Address Space

Page 7: Liu Meihua lmh123@bit.edu.cn Chapter 3 Memory management Chapter 3 Memory management —— 3.5 Kernel Memory

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

Page 8: Liu Meihua lmh123@bit.edu.cn Chapter 3 Memory management Chapter 3 Memory management —— 3.5 Kernel Memory

8

Virtual Memory Data Structures

Page 9: Liu Meihua lmh123@bit.edu.cn Chapter 3 Memory management Chapter 3 Memory management —— 3.5 Kernel Memory

9

Loadable Kernel Module Text and Data

Page 10: Liu Meihua lmh123@bit.edu.cn Chapter 3 Memory management Chapter 3 Memory management —— 3.5 Kernel Memory

10

Loadable Kernel Module Text and Data

Looking at the module load address with the modinfo command

Page 11: Liu Meihua lmh123@bit.edu.cn Chapter 3 Memory management Chapter 3 Memory management —— 3.5 Kernel Memory

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

Page 12: Liu Meihua lmh123@bit.edu.cn Chapter 3 Memory management Chapter 3 Memory management —— 3.5 Kernel Memory

12

The Kernel Address Space and Segments

Page 13: Liu Meihua lmh123@bit.edu.cn Chapter 3 Memory management Chapter 3 Memory management —— 3.5 Kernel Memory

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.

Page 14: Liu Meihua lmh123@bit.edu.cn Chapter 3 Memory management Chapter 3 Memory management —— 3.5 Kernel Memory

14

Outline

Kernel virtual memory layout

Kernel memory slab allocator

Page 15: Liu Meihua lmh123@bit.edu.cn Chapter 3 Memory management Chapter 3 Memory management —— 3.5 Kernel Memory

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.

Page 16: Liu Meihua lmh123@bit.edu.cn Chapter 3 Memory management Chapter 3 Memory management —— 3.5 Kernel Memory

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

Page 17: Liu Meihua lmh123@bit.edu.cn Chapter 3 Memory management Chapter 3 Memory management —— 3.5 Kernel Memory

17

Slab Allocator Overview

Performance comparison of the slab allocator.

Page 18: Liu Meihua lmh123@bit.edu.cn Chapter 3 Memory management Chapter 3 Memory management —— 3.5 Kernel Memory

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

Page 19: Liu Meihua lmh123@bit.edu.cn Chapter 3 Memory management Chapter 3 Memory management —— 3.5 Kernel Memory

19

Objects, Caches, Slabs, and Pages of Memory

Page 20: Liu Meihua lmh123@bit.edu.cn Chapter 3 Memory management Chapter 3 Memory management —— 3.5 Kernel 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.

Page 21: Liu Meihua lmh123@bit.edu.cn Chapter 3 Memory management Chapter 3 Memory management —— 3.5 Kernel Memory

21

Slab Allocator Implementation

Page 22: Liu Meihua lmh123@bit.edu.cn Chapter 3 Memory management Chapter 3 Memory management —— 3.5 Kernel Memory

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.

Page 23: Liu Meihua lmh123@bit.edu.cn Chapter 3 Memory management Chapter 3 Memory management —— 3.5 Kernel Memory

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.

Page 24: Liu Meihua lmh123@bit.edu.cn Chapter 3 Memory management Chapter 3 Memory management —— 3.5 Kernel Memory

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.

Page 25: Liu Meihua lmh123@bit.edu.cn Chapter 3 Memory management Chapter 3 Memory management —— 3.5 Kernel Memory

25

End

[email protected]