Skip to content

Tag: mmap

can /proc/self/exe be mmap’ed?

Can a process read /proc/self/exe using mmap? This program fails to mmap the file: Answer You are making 2 mistakes here: Mapped size must be > 0. Zero-size mappings are invalid. You have to specify, if you want to create a shared (MAP_SHARED) or a private (MAP_PRIVATE) mapping. The following should work f…

Can mmap and O_DIRECT be used together?

As I understand it, when you mmap a file you are basically mapping the pages from the page cache for that file directly into your process, and when you use O_DIRECT you are bypassing the page cache. Does it ever make sense to use the two together? If my understanding is right how would it even work? mmap seem…

Write-only mapping a O_WRONLY opened file supposed to work?

Is mmap() supposed to be able to create a write-only mapping of a O_WRONLY opened file? I am asking because following fails on a Linux 4.0.4 x86-64 system (strace log): The errno equals EACCESS. Replacing the open-flag O_WRONLY with O_RDWR yields a successful mapping. The Linux mmap man page documents the err…

mmap vs sbrk, performance comparison

Which of these calls is faster on average? I’ve heard that mmap is faster for smaller allocations but I haven’t heard a comparison of either. Any information on performance for these would be nice. Answer You should tag this with a particular implementation (like linux) since the answer surely var…