3 ms·
So like DMA?
by bzb6 6y ago
So 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.