Virtual memory management

Virtual memory management

Virtual Memory Manager (VMM) Overview

The Virtual Memory Manager (VMM) provides the virtual memory facilities that are used by the other parts of the system to implement the following:

·                         Virtual address space of processes

·                         Sharing of executables

·                         Shared memory segments

·                         Mapped files

The VMM implements virtual memory, allowing the creation of segments larger than the physical memory available in the system. The segments are divided into fixed-size units called pages. Each page in a segment can be in physical memory or stored on disk until it is needed. When a process accesses a page that is not present in physical memory, the VMM reads the page into memory; this is called a PageIn. When physical memory is not available, the VMM writes pages to disk; this is called a PageOut or PageSteal.

The following are some of the segment types:

Working storage

Segments are used to implement the data areas of processes and shared memory segments. The pages for working storage segments are stored in the paging spaces configured in the system.

Persistent storage

Segments are used to manipulate files and directories. When a persistent storage segment is accessed, the pages are read and written from its file system.

Client storage

Segments are used to implement some virtual file systems like Network File System (NFS) and the CD-ROM file system. The storage for client segment pages can be in a local or remote computer.

 

    

Virtual address space

内存映射文件的学习

Jeffrey RichterMemory-Mapping File已经讲述的很详细了,现在我们可以归纳以下:
一、功能
1.
简化对数据文件的操作。(利用内存映射文件,Windows将会负责文件数据在RAM的缓存及其和磁盘的数据交换,消除了我们很多麻烦)
2.
进程间共享数据和通讯。(主要是创建一个Memory-Mapping File对象,这个Memory-Mapping File对象使用INVALID_HANDLE_VALUE来模拟创建一个由Page File而不是硬盘上数据文件所支持的对象,然后在多个进程间共享这个对象(3种方法),然后利用更新同样的RAM数据来实现同步更新,及其通讯)
3.
理解操作系统的Loader机理。(OS Loader也是调用CreateFileCreateFileMapping及其MapViewOfFileEx 来加载一个.exe文件)

二、使用
CreateFile:    Calling CreateFile tells the operating system the location of the file mapping's physical storage.
CreateFileMapping:    Create a file-mapping kernel object that tells the system (1) the size of the file and (2) how you intend to access the file.(When you create a file-mapping object, the system does not reserve a region of address space and map the file's storage to the region)。如果此函数所指定的大小比硬盘上的文件大的话,文件将会扩展为此函数所指定的大小。
MapViewOfFileEx:     reserve a region of address space for the file's data and commit the file's data as the physical storage that is mapped to the region(note: if we do not touch much of the view, windows virtual memory manager will not page the physical storage into RAM)

三、实现细节
CreateFile
函数将一个hFile对象与磁盘上的一个文件对应起来
CreateFileMapping
将会将此hFile对应的磁盘文件映射到到一组RAM页面,不过并不为其保留进程的虚拟地址空间,也不为其提交内存?(它还没有被分配虚拟内存地址,所以根本不能被访问)
MapViewOfFile
将前面创建的FileMapping对象映射进进程的虚拟地址空间,并且提交内存。

由上面可以看到,相同的FileMapping对象代表着相同的RAM页面,所以对于同一个FileMapping对象的不同View修改会造成同一块内存页面被多次修改。

Tip:
1. CreateFileMapping
在已经有一个FileMapping存在的情况下返回值并不是NULL,而返回现在已经存在的FileMapping的句柄GetLastError returns ERROR_ALREADY_EXISTS,所以一定要看文档。

posted @ 2005-02-01 11:07 比尔盖房 阅读(203) | 评论 (0)编辑 收藏

2005 1 31 #

Windows内存管理

, Windows核心编程被翻译的太烂了。
我需要在这里将内存管理这一章的一些内容给解释清楚:

PartitionEach process's virtual address space is split into partitions.
Region(区域):是通过VirtualAllocEx函数进行保留的一段虚拟地址空间(The act of allocating a region is called reserving.
Virtual Memory==Physical Storage==Physical Memory(That is RAM)+ Page File(Or a Memory Mapping file on disk)
Reserve(保留):The act of allocating a regionin Vritual Address space is called reserving.
Commit(提交):allocate physical storage(not RAM) and then map this storage to the reserved region.
Block(块): A block is a set of contiguous pages that all have the same protection attributes and that are all backed by the same type of physical storage
Process Address SpaceA 4G virtual address space

Reserve
:开始地址向小的方向调整为分配粒度64K的倍数         保留大小为Page Size的倍数
Commit
:开始地址向小的方向调整为Page Size的倍数               保留大小为Page Size的倍数

Memory-mapped fileWhen a program's file image (that is, an .exe or a DLL file) on the hard disk is used as the physical storage for a region of address space, it is called a memory-mapped file

 

 
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值