# Wed 31 Jan 00:36:01 GMT 2018c++
第九章 虛擬內存(Virtual Memory)app
9.3 VM as a tool for cachingide
virtual pages(VPs). phsical pages are also referred
to as page frames(頁幀)工具
the set of VPs is into 3 subsets:ui
+ Unallocated. they don't have any data associated.
+ Cached. Allocated pages that are currently cached
in physical memory.
+ Uncached. Allocated pages that are not cached in ~操作系統
# 'SRAM' cache to denote the L1,L2,L3 cache memories
# between the cpu and main memory. and 'DRAM' caches
# to denote the VM system's cache that caches virtual
# in main memory.pwa
Because of the large miss penalty and the expense of
the expense of accessing the first byte, virtual pages
tend to be large -- typically 4KB to 2 MB.翻譯
9.3.2 page tables進程
A data structure stored in physical memory known as
page table that maps virtual pages to physical pages.
The address translations hardware(in the MMU) reads the
page table each time it converts a virtual address to a
physical address. The operating system is responsible
for maintaining the contents of the page table and
transferring pages back and forth between disk and DRAM.內存
9.3.4 page faults
A DRAM cache miss is known as a 'page fault'.
9.4 虛擬內存做爲內存管理的工具
實際上,操做系統爲每一個進程提供了一個獨立的頁表,於是
也就是一個獨立的虛擬地址空間。
#將一組連續的虛擬頁映射到任意一個文件中的任意位置的表示
#法稱爲內存映射(memory mapping).
+ 簡化連接。
+ 簡化加載
+ 簡化共享
+ 簡化內存分配
9.5 虛擬內存做爲內存保護的工具
在PTE中添加許可位來設置權限,如 可讀,可寫,超級用戶等
9.6 地址翻譯
CPU中的一個控制寄存器,頁表基址寄存器(Page Table Base
Register,PTBR)指向當前頁表。
9.6.2 利用TLB加速地址翻譯
翻譯後備緩衝器(Translation Lookaside Buffer,TLB).
9.6.3 多級頁表
+ 若是一級頁表中的一個PTE是空的,相應的二級頁表就不存在
+ 只有一級頁表才須要老是在主存中
9.6.4 putting it together: end-to-end address translation
9.7.2 Linux Virtual Memory system
Linux Virtual Memory Areas
Linux organizes the virtual memory as a collection of
areas( also called segmant). An area is a contiguous chunk
of existing (allocated) virtual memory whose pages are
related in some way.
9.8 Memory Mapping
Linux initializes the contents of a virtual memory
area by associating it with an object on disk, a process
known as memory mapping. Areas can be mapped to one of
two types of objects:
1. Regular file. Such as an executable object file.
2. Anonymous file. Created by the kernel.
mmap function and munmap function for create or delete.
9.9 Dynamic memory allocation
Maintaining an area of a process's virtual memory
known as the 'heap'.
We assume that the heap is an area of demand-zero
memory that begins immediately after the uninitialized
data area and grows upward. For each process,the kernel
maintains a variable 'brk' that points to the top of the
heap.
An allocator maintains the heap as a collection of
various-size blocks. it has two basic styles. Both styles
require the application to explicitly allocate blocks.
+ Explicit allocators. Such as malloc function. or the
new and delete calls in c++.
+ implicit allocators. Also known as 'garbage'
'collection'.
void *sbrk( intptr_t incr);
The sbrk function grows or shrinks the heap by adding'incr' to the kernel's brk pointer.