Repository navigation
Keep ROOT's cluster buffers in ramdump's heap - #131
Merged
Merged
Conversation
On 0.2.0 a full read of NA12878's HiSeq chromosome 20 took 135,000 to 902,000 minor page faults and up to 3 s more of system time than at 530933b, with the same user time. They were in pread from ROOT's cluster pool into the buffer of each cluster, about 15 MB: glibc gave the buffer back to the kernel when it was freed, more or less often with the heap's layout, which #128 changed, and the next cluster faulted its pages in. ramdump now sets glibc's mmap threshold to 32 MB and its trim threshold to 64 MB, in the tool, since both hold for the whole process. On z840, against 0.2.0: HiSeq's full read 23.7 to 24.8 s instead of 24.3 to 27.5 s, 49,000 to 98,000 faults; chromosome 20 on eight threads 1.0 s of system time instead of 3.2 s, a 10 Mb region 0.15 s instead of 0.56 s. Peak memory grows on eight threads, 640 MB instead of 580 MB, and for the region, 67 MB instead of 60 MB.
|
clang-tidy review says "All clean, LGTM! 👍" |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #131 +/- ##
===========================================
+ Coverage 89.38% 89.40% +0.01%
===========================================
Files 26 26
Lines 3722 3728 +6
Branches 1267 1274 +7
===========================================
+ Hits 3327 3333 +6
Misses 203 203
Partials 192 192
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
mvassilev
added a commit
that referenced
this pull request
Nov 8, 2026
A full read read each cluster several times: 2.04 GB for chromosome 20's 418 MB file, 6.6 GB for HiSeq chromosome 20's 2.2 GB. ROOT's cluster cache keeps the cluster it is asked for and the next one; the block readers read ahead at the last row of each block, near the end of a cluster in the next one, and so dropped the cluster the records were still in, which they then read again. Every block lies in one cluster, so the readers of names, qualities and bases now read ahead only blocks of their block's cluster, when the file is read with the cluster cache. A block of fqzcomp, 25 times slower to decode, still reads ahead from the next cluster. RAMFile says whether its reader uses the cache. A test checks with ROOT's metrics that a full read reads no more than the file holds. On z840, against #131: HiSeq chromosome 20 reads 2.17 GB, in 19.3 to 19.9 s instead of 23.8 to 24.4 s, with 1.3 s of system time instead of 6.0 s; chromosome 20 reads 0.42 GB, in 14.5 to 15.2 s instead of 15.1 to 16.0 s. Regions, -@ N and fqzcomp files take the same time.
mvassilev
added a commit
that referenced
this pull request
Nov 9, 2026
* Read ahead blocks only within the records' cluster A full read read each cluster several times: 2.04 GB for chromosome 20's 418 MB file, 6.6 GB for HiSeq chromosome 20's 2.2 GB. ROOT's cluster cache keeps the cluster it is asked for and the next one; the block readers read ahead at the last row of each block, near the end of a cluster in the next one, and so dropped the cluster the records were still in, which they then read again. Every block lies in one cluster, so the readers of names, qualities and bases now read ahead only blocks of their block's cluster, when the file is read with the cluster cache. A block of fqzcomp, 25 times slower to decode, still reads ahead from the next cluster. RAMFile says whether its reader uses the cache. A test checks with ROOT's metrics that a full read reads no more than the file holds. On z840, against #131: HiSeq chromosome 20 reads 2.17 GB, in 19.3 to 19.9 s instead of 23.8 to 24.4 s, with 1.3 s of system time instead of 6.0 s; chromosome 20 reads 0.42 GB, in 14.5 to 15.2 s instead of 15.1 to 16.0 s. Regions, -@ N and fqzcomp files take the same time. * Format as clang-format 18 does; no array subscript in the test * Parentheses and a reserve in the cluster test, as clang-tidy 19 asks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
On 0.2.0 a full read of NA12878's HiSeq chromosome 20 got slower than at 530933b, while
chromosome 20's got faster: 26.1 s and 41.0 s of CPU against 24.9 s and 38.7 s. Run in turn on
z840's socket 0, 530933b, 14b2aae (#128) and 0.2.0 spend the same user time, 32.6 to 33.5 s.
The difference is in the kernel: 73,000 to 100,000 minor page faults at 530933b, 124,000 to
1,075,000 at 14b2aae and 0.2.0, with up to 3 s more of system time. It is the same with the
whole genome's 72 GB in the page cache and without.
perf record -e page-faultsputs 98% of them inpreadfromRClusterPool::ExecReadClusters,into the buffer ROOT allocates for each cluster, about 15 MB in this file. glibc often gives
such a buffer back to the kernel when it is freed, and the next cluster faults its pages in
again. How often depends on the heap's layout, which #128 changed: the same code faults 124,000
times in one run and 1,075,000 in the next. ROOT's buffers are not ours to change, but the
process's malloc is.
The change
ramdumpstarts by setting glibc's mmap threshold to 32 MB, its largest, so that the bufferscome from the heap, and its trim threshold to 64 MB, so that the heap keeps them when they are
freed. Setting either stops glibc from raising the mmap threshold itself, so both are set. They
hold for the whole process, so they are in the tool and not in the library, which Python and
RDataFrame load too. Other C libraries, and macOS, are left as they are.
Tried with
GLIBC_TUNABLESon 0.2.0's build first: a trim threshold of 32 MB still faulted415,000 to 1,248,000 times; 64 MB, 128 MB and 1 GB gave the same times and memory. An mmap
threshold of 16 MB gave the same as 32 MB, memory included.
What it does
z840 socket 0, this build against 0.2.0's, in turn, on 0.2.0's files; the output of HiSeq's
full read has the same md5:
-@ 8Three runs each, five for the 10 Mb region and nine for the 1 kb one. The cost is memory the
process keeps instead of giving back: about 60 MB more on eight threads, 7 MB for the 10 Mb
region, 1 MB for a small one. HiSeq's full read peaks lower, since it no longer holds a buffer
being given back and a new one at once.
14 of 14 tests pass on z840 (ROOT 6.40.04, htslib 1.25).
Found on the way, not changed
A full read reads each cluster about three times:
preadreads 6.50 GB of HiSeq's 2.20 GB fileat 0.2.0, 6.82 GB at 530933b. ROOT's cluster pool keeps the cluster asked for and the next, and
the block readers read ahead at the last row of a block, often in the next cluster, so the
cluster the records are still in is dropped and read again. Reading the block columns through
a page source of their own would avoid it; that is a change of its own.
Changelog
ramdumpkeeps the buffers ROOT reads clusters into in the heap; HiSeq's full readtakes 49,000 to 98,000 page faults instead of up to 902,000.