3 ms·
If you don’t modify the original buffer then it can me an mmapped file..?
by willvarfar 6y ago
If you don’t modify the original buffer then it can me an mmapped file..?
- thethirdone 6y agoI was thinking about using MAP_PRIVATE to prevent write-back. I not sure that doesn't come with a performance penalty on write, but it should at least be better copying in userspace.
- saagarjha 6y agoThat would likely trigger the “copy” part of copy-on-write and not be particularly fast.
- thethirdone 6y agoDo you have any benchmarks that show that? It seems plausible, but a lot of COW systems optimize for the case where there is only 1 reference and modify in-place. I don't MMAP much, but it would be nice to know if Linux doesn't do the optimization I think is possible. In this particular case, I would hope it only copies to memory from disk. If only one program is accessing a file, I would expect the "copy" of copy-on-write to be the copy to memory.
- saagarjha 6y agoSadly I do not, and I’m on a device running Darwin that I can’t readily do benchmarks on :( But yes, if you are the exclusive owner of a page you won’t get an extra copy. However, you’re still not really going any faster, as this is just the same as the kernel giving you the file in a buffer that you can freely modify…
- sgtnoodle 6y agoWhen reading mostly sequentially, is a memory mapped file any faster than reading into a buffer? The data is presumably still copied into memory, it's just done on a page fault rather than an explicit function call.
- deleted 6y ago[deleted]
- sgtnoodle 6y agoApparently there is one less memory copy when using mmap, since read() copies from the intermediate buffer that mmap provides access to. Neat! https://medium.com/@sasha_f/why-mmap-is-faster-than-system-calls-24718e75ab37 https://medium.com/@sasha_f/why-mmap-is-faster-than-system-c...