Repository navigation
Conversation
…keinterface into avoid-memmap-in-binary-read
|
No, I did more tests and this is the better and fastest approach. Updated original PR message |
|
This is great! Maybe this is too big of a change, but I wonder if cache=False should be the default? I wonder if we expect most recordings to fit in most people's memory? |
|
Merci Alessio for asking your secret friend to work on this. On linux/darwin we should alwas use the preadv approach with no cache at all. We are generally reading chunks once. And if we read chunk twice or more, it is impoissible that caching will help because of the size of files we are dealing with.
In short lets not have the cache option and prevent any cache always. In any case we should have somewhere a function that do |
UPDATED
Fixes #4968
BinaryRecordingSegment.get_tracesmemory-maps every chunk. A sorter that reads a large binary in several full passes (dartsort makes six) re-reads every page, so Linux keeps the whole file on the active page cache. When the file is bigger than the container's memory limit, the kernel spends its time reclaiming cache that is about to be needed again: memory pressure stays at 60–98%, the GPU and disk sit idle, and sorts that should take ~4 h run past 12 h.This PR adds a
cacheoption (defaultTrue, unchanged behaviour) toBinaryRecordingExtractor,BinaryFolderRecordingandsave(format="binary"). Withcache=False, each chunk is read into a new array withos.preadv, and then dropped from the page cache withposix_fadvise(POSIX_FADV_DONTNEED). The returned traces are identical to the mmap path and read-only like them. Wherepreadvis missing (Windows), reads fall back toseek+readintounder a lock. Whereposix_fadviseis missing (Windows, macOS), the drop is skipped.Run time and memory, dartsort 0.5.34, ~120 GB binary per probe, 60 GiB container limit, one task per g4dn.4xlarge, one run per probe:
madvise(MADV_SEQUENTIAL)on each chunk's mmap #4970cache=False(this PR)*Probe B with
cache=Falseran on a g4dn.12xlarge (same 16 vCPUs and 60 GiB limit), and the log ends 3.4 h in, before the last two passes; the total is estimated from probe C's timings.Both rows were made by monkeypatching
get_traceswith exactly these changes. With 130 GiB, so that the whole file fits in cache, the same sorts took 3.2–4.2 h, socache=Falsegets about the same speed with less than half the memory.Why not
madvise(MADV_SEQUENTIAL)? It's a one-line alternative (#4970) that tells the kernel not to promote the mapped pages to the active list. It helps a lot, butcache=Falseis better:cache=False: matching, for example, took 59 instead of 72 min. Overall, sorts took about 22% less time.madvisethe pages are still cached, so the container stays at its limit and still has bursts of reclaim (pressure up to 96%). Withcache=False, nothing builds up, which also leaves memory for other tasks on a shared instance.madviseis only a hint, and how Linux handles it depends on the kernel version and LRU implementation.fadvise(DONTNEED)drops the pages explicitly.The cost is that
cache=Falsenever hits the page cache, and copies each chunk. A recording that fits in memory reads faster from cache, so the option stays off by default.