[英]Use cases of mmap
I'm currently studying for my OS finals. 我目前正在研究OS决赛。 The teacher in some papers is briefly mentioning the
mmap
function (memory map). 在某些论文中,老师简短地提到了
mmap
函数(内存图)。
As I understand it ( correct me if i'm wrong ), mmap is used to load some files from the physical memory to the RAM (after a page default). 据我了解( 如果我错了 ,请纠正我 ),mmap用于将某些文件从物理内存加载到RAM(在默认页面之后)。 The problem is that I don't see any practical reason for this other then to make the access time to that file faster.
问题在于,除了使访问该文件的时间更快之外,我看不到任何实际的原因。
Am I correct? 我对么? Is mmap only used for this?
mmap仅用于此吗?
"mmap" has lots of purposes: “ mmap”有很多用途:
Mapping a file for faster read/write access is certainly one use 映射文件以实现更快的读/写访问肯定是一种用途
Shared memory (eg for interprocess communications) is another 共享内存(例如,用于进程间通信)是另一个
mmap is also used to map I/O port addresses for low-level device communications mmap还用于映射I / O端口地址以进行低级设备通信
mmap is used to load some files from the physical memory to the RAM (after a page default)
mmap用于将某些文件从物理内存加载到RAM(在默认页面后)
to load the missing pages . 加载缺少的页面 。 also modifications can be written to the disk the same way!
也可以用相同的方式将修改内容写入磁盘!
mmap takes memory management out of the hands of the programmer to a large extent, and puts it in the hands of the OS. mmap在很大程度上将内存管理从程序员的手中解放了出来,并将其交给操作系统。
It's about demand paging using the virtual memory subsystem from disk to physical memory. 这是关于使用虚拟内存子系统从磁盘到物理内存的需求分页。
So to look at the 11111th byte of a file, instead of seeking and reading, you can mmap and use an array index. 因此,要查看文件的第11111个字节,可以查找并使用数组索引,而不是查找和读取。 The OS will keep surroundiung data in its "buffer cache" (page cache really).
操作系统会将周围的数据保留在其“缓冲区高速缓存”(实际上是页面高速缓存)中。
Here's an example: http://stromberg.dnsalias.org/~strombrg/pbmonherc.html 这是一个示例: http : //stromberg.dnsalias.org/~strombrg/pbmonherc.html
The example's a little messy because it was written at a time when Linux had mmap support in its kernel, but the C library didn't yet have a stub for calling it. 该示例有点混乱,因为它是在Linux内核中支持mmap的时候编写的,但是C库尚未有调用它的存根。 But you can pretty much ignore mmap.c.
但是您几乎可以忽略mmap.c。 The example uses mmap to set pixels on and off using a monochromatic display adapter.
该示例使用mmap通过单色显示适配器设置像素的开和关。
Another reasonable use is for a bloom filter: http://stromberg.dnsalias.org/~strombrg/drs-bloom-filter/ 另一个合理的用途是使用布隆过滤器: http : //stromberg.dnsalias.org/~strombrg/drs-bloom-filter/
...but on 32 bit OS's, the maximum size of an mmap'd memory region kinda hurts. ...但是在32位OS上,mmap的内存区域的最大大小有点麻烦。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.