如何禁用mmap()的按需复制和零填充 [英] How to Disable Copy-on-write and zero filled on demand for mmap()

查看:186
本文介绍了如何禁用mmap()的按需复制和零填充的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用mmap()实现cp(文件复制)命令. 为此,我将源文件映射为MAP_PRIVATE(我只想读取)模式,将目标文件映射为MAP_SHARED模式(因为我必须写回目标文件的更改内容).

I am implementing cp(file copy) command using mmap(). For that I mapped the source file in MAP_PRIVATE (As I just want to read)mode and destination file in MAP_SHARED mode(As I have to writeback the changed content of destination file).

在执行此操作时,我观察到由于2个原因导致的许多次要页面错误而导致性能下降. 1)在为源文件调用mmap(MAP_PRIVATE)时按需零填充. 2)在调用mmap(MAP_SHARED)作为目标文件时写时复制.

While doing this I have observed performance penalty due to lots of minor page faults that occurs due to 2 reason. 1) Zero fill on demand while calling mmap(MAP_PRIVATE) for source file. 2) Copy on write while calling mmap(MAP_SHARED) for destination file.

有什么方法可以禁用按需填零和写时复制吗?

Is there any way to disable Zero-fill-on-demand and Copy-on-write ?

谢谢, 赶快

推荐答案

有mmap(2)的MMAP_POPULATE标志:

There is MMAP_POPULATE flag of mmap(2):

http://linux.die.net/man/2/mmap

MAP_POPULATE(从Linux 2.5.46开始) 填充(故障前)页表以进行映射.对于文件映射,这将导致文件上的预读.页面错误不会阻止以后对映射的访问.从Linux 2.6.23开始,仅私有映射支持MAP_POPULATE.

MAP_POPULATE (since Linux 2.5.46) Populate (prefault) page tables for a mapping. For a file mapping, this causes read-ahead on the file. Later accesses to the mapping will not be blocked by page faults. MAP_POPULATE is only supported for private mappings since Linux 2.6.23.

它应该预先对mmapped区域中的所有页面进行故障处理.它应该适用于问题(1),而不适用于问题(2)(共享).

It should pre-fault all pages in mmapped region. It should work for question (1), and may not work for question (2) (shared).

这篇关于如何禁用mmap()的按需复制和零填充的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆