(1) 請比較與說明幾個 memory management 相關 kernel functions: --get_free_pages(), kmalloc(), vmalloc(), brk(), 其管理機制、使用時機、特性比較。
[Ans]
_ _ get_free_pages | Page frame management | Kernel | Physical |
kmalloc | Memory area management | Kernel | Physical |
vmalloc | Non-contiguous memory area management | Kernel | Physical/ virtual |
brk | Process address space management | User process | viirtual |
a. __get_free_pages() :
對象: Contiguous Page frame
Allocate方式: Buddy System Algorithm
b. kmalloc():
對象: Contiguous Memory Area
Allocate方式: Slab Allocator
c. vmalloc() :
對象: Non-Contiguous Memory Area
Allocate方式: Slab Allocator
d. brk() :
對象: Memory Region (User Process Address Space)
作用: Change heap size of the process
[Notes]
(1) 在Linux上, Physical memory 依Size固定與否,分成兩種概念:
Page Frame: Fixed Length (4KB)
Memory Area: Arbitrary Length
相對應這兩種, 各用不同的實體記憶體管理方式(allocate/release)
Buddy System Algorithm --> Page Frame
Slab Allocator --> Memory Area
[Notice]
不管 page frame 或 memory area都是指"contiguous physical address",
只是有分固定或任意長度的差別.
(2) __get_free_page: “ Used to request 2 order contiguous page frame “
kmalloc(): “ Used to allocate contiguous general objects .(memory area) “
[Notice]
-因用Buddy System Algorithm,故是2order Size.
-在Slab Allocator把每個memory area視為 Object. 雖然 Memory area 可任意長度,但在Linux Implement 作法是把Object的Size 定為geometrically distributed size (ranging from 32 ~1331072).
(3) kmalloc() 與 vmalloc() 主要差別是, vmalloc()所要到的 Memory area 是非連續的.
即 “ linear address is assigned to noncontiguous memory area ”, 每個 Memory area是連續的
physical address , 但個別 memory area是不相連的.
(4) Memory Region 是指 “ interval of user process address space “, 通常起始位址與長度是4096的倍數, 故 process 的 address space 就由 a set of memory region list來代表在Linear address space上的位置. brk() 這個System Call即是在User Level 向Kernel要求調整Process 的heap Size.