5 ms·
Call me pedantic, but mmap is a syscall. The title would have been better as "Why memory mapped files are faster". The author does address this with "Mmap stand
by correct_horse 6y ago
Call me pedantic, but mmap is a syscall. The title would have been better as "Why memory mapped files are faster". The author does address this with "Mmap stands for memory-mapped files." It does? I thought mmap stands for memory map. To be clear I enjoyed the contents of the article.
- dyingkneepad 6y agoBut you call mmap only once per file: it gives you a pointer and then you just use the pointer normally. While for read() you have to call once per read() operation (minus some user space buffering).
- correct_horse 6y agommap is more general than memory mapping files. It "establish[es] a mapping between an address space of a process and a memory object". In particular, many allocators (malloc and friends) use mmap to get a block of memory from the OS with mmap(0, size, PROT_READ|PROT_WRITE, MAP_ANONYMOUS, -1, 0); or similar.
- mhh__ 6y agoDo any allocators use anything else these days? D's std.experimental.allocator module is helpful for building allocators bit by bit even for eventual use in C++ or C.
- JoshTriplett 6y ago> Do any allocators use anything else these days? Yes, some allocators still support using sbrk, though that's a bad idea for security reasons (ASLR).
- jashmatthews 6y agoIIUC, glibc malloc still manages one arena with sbrk and then grabs other arenas via mmap.
- morei 6y agoYes, the more accurate title would be "Why is it faster to read data from a file via mmap() than via the read() system call?"
- inopinatus 6y ago> Call me pedantic Surely persnickety, no? If we're wordsmithing anyway.
- chrisseaton 6y agoWhat's the difference between the two words?
- bch 6y ago3
- xeromal 6y agoPersnickety is more fun
- inopinatus 6y agoThe wale of one's trousers.
- chrisseaton 6y ago> Call me pedantic, but mmap is a syscall. You're misunderstanding. You call mmap once, which is a system call, and then instead of using system calls you just access memory which performs the operations as needed through loading on page faults, not through system calls. This compares to using system calls all the time.