5 ms·
Hold up. Isn't mmap a system call?
by bigdict 6y ago
Hold up. Isn't mmap a system call?
- chrisseaton 6y ago> Hold up. Isn't mmap a system call? That's not what they mean. You set up a memory map with the mmap system call, yes, but that's not the point. The point is then that you can read and write mapped files by reading and writing memory addresses directly - you do not have to use a system call to perform each read and write.
- bzb6 6y agoSo like DMA?
- _0ffh 6y agoI think that comparison would be more confusing than helpful.
- ndesaulniers 6y agoDMA is more like a bulk memory transfer operation usually facilitated by specific hardware that generally is asynchronous and requires manual synchronization. Usually hardware devices perform DMAs of memory regions, like a memcpy() but between physical memories. Memory mappings established via mmap() more so set up the kernel to map in pages when faults on accesses occur. In this case you're not calling into the kernel, the TLB is generating an interrupt when you go to read an address referring to memory that's not yet paged in, which the kernel than handles and restores control flow to userspace without userspace being any wiser (unless userspace is keeping track of time). Handling page faults is faster than the syscalls involved in read() calls, it would seem.
- magicalhippo 6y agoNo. Using mmap is pretending you read your entire file into memory but all the memory got swapped to disk, and so the pages has to be swapped back into memory when you access them. Except you didn't do the initial read into memory, and instead of the system swap file it's using the file you actually want to read when paging data back into memory.
- deleted 6y ago[deleted]