Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Disable Copy-on-write and zero filled on demand for mmap()

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

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 ?

Thanks, Harish

like image 428
Harish Avatar asked Jun 21 '12 06:06

Harish


1 Answers

There is MMAP_POPULATE flag of mmap(2):

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

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.

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

like image 154
osgx Avatar answered Sep 20 '22 14:09

osgx