第九章 虚拟内存(Virtual Memory)

Posted 孤灯下的守护者

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了第九章 虚拟内存(Virtual Memory)相关的知识,希望对你有一定的参考价值。

# Wed 31 Jan 00:36:01 GMT 2018

第九章 虚拟内存(Virtual Memory)

9.3 VM as a tool for caching

virtual pages(VPs). phsical pages are also referred
to as page frames(页帧)

the set of VPs is into 3 subsets:

+ 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.

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.

以上是关于第九章 虚拟内存(Virtual Memory)的主要内容,如果未能解决你的问题,请参考以下文章

第九章 虚拟内存

操作系统概念笔记——第九章:虚拟内存

虚拟内存(Virtual Memory)

操作系统第九章

27 windows_27_windows_Virtual_Memory 虚拟内存

什么是虚拟内存(virtual memory)