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
write(2)
might be more efficient for the copy? Specify the private map as the buffer to write. It also avoids the step of expanding the new file, sincewrite(2)
will do it for you. – Collarbonemadvice()
andmlock()
syscalls. They may affect number of page faults. And for fast file copy, check syscallsendfile()
. – Cruciferouscp
performace under Linux is probably the best case in point forsplice
. Saves the roundtrip to user space alltogether. – Kail