3 ms·
> A legitimate problem here is the case where you need to read from or write to many locations at once. With the memory-mapped scheme as described, you can only
by majke 2y ago
> A legitimate problem here is the case where you need to read from or write to many locations at once. With the memory-mapped scheme as described, you can only issue as many concurrent page faults as you have threads in the program.
> Unfortunately, I don’t have great answers here, and view this as a legitimate use case that warrants a dedicated code path using other mechanisms at your disposal.
Right. I think it’s similar on linux. Mmap makes sense until the data size is too large and tlb misses start to add up.
- vlovich123 2y agoWhy would the TLB misses be any different than if you read the file into memory? The article is describing a separate problem where you can’t issue concurrent reads although that doesn’t feel true if you make use of madvise.
- majke 2y agoRight. Not tlb, but more of memory subsystem stress. Typically changes to vm layout cant be done concurrently. Also, if the vm area is large, pages might be thrashing, requiring the kernel to do loads of work swapping things in and out and changing the pagetable struct.
- vlovich123 2y ago> Also, if the vm area is large, pages might be thrashing, requiring the kernel to do loads of work swapping things in and out and changing the pagetable struct. I doubt that that's any different than allocating memory assuming your working set would be the same. Largely it should be unless the mmap design makes it easier to facilitate a random access pattern in your data structure that you would think twice about if you actually had to issue the reads yourself. The bigger issue is that madvise & friends risk cross table shootdowns since Linux might not have relevant support for DONT_NEED other than unmapping (vs scheduling an unmapping to happen lazily). However, that isn't necessarily the case with Windows.
- sirjee 2y agoLinux have madvise(MADV_DONTNEED).
- vlovich123 2y agoYou’re replying to a statement I wasn’t making and missing what I am saying. Linux just takes that as a hint to unmap immediately and this results in a cross tlb shoot down. Cross tlb shoot downs are crazy expensive. Windows might have better support for doing it lazily and not paying the cost. https://news.ycombinator.com/item?id=23216590 https://news.ycombinator.com/item?id=23216590