Address memory reclaim follow-ups from #41096 - #41171
Merged
Ben Hillis (benhillis) merged 3 commits intoJul 27, 2026
Merged
Conversation
- Parse the /proc/stat cpu line with std::regex instead of a manual strtoull cursor loop, while retaining the O_CLOEXEC bounded read. - Use drop_caches=3 in DropCache mode to also drop reclaimable slab (dentries/inodes), matching the SReclaimable slab counted by GetReclaimableCacheBytes. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 0e37f3d5-68e7-4973-8c27-bf4329c8fd9b
Blue (OneBlue)
previously approved these changes
Jul 24, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR addresses review follow-ups from #41096 in the Linux mini-init memory reclaim implementation by updating CPU idle sampling parsing and broadening DropCache reclaim behavior.
Changes:
- Updated
ReadCpuBusyIdle()to parse the aggregatecpuline from/proc/statusingstd::regex, keeping the same busy/idle bucket semantics. - Switched DropCache mode from
drop_caches=1todrop_caches=3to also drop reclaimable slab (dentries/inodes), aligning with the cache accounting logic.
ECMAScript \s matches newlines, so on a truncated aggregate cpu line the optional irq/softirq/steal groups could consume digits from the next line in the read buffer. Use [ \t] so the match cannot span lines. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 0e37f3d5-68e7-4973-8c27-bf4329c8fd9b
The regex submatch points directly into the null-terminated buffer and ends at a non-digit delimiter, so strtoull can read from match.first and avoid allocating a std::string per field. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 0e37f3d5-68e7-4973-8c27-bf4329c8fd9b
Blue (OneBlue)
approved these changes
Jul 27, 2026
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.
What this changes
Addresses the two review follow-ups from #41096 in
src/linux/init/util.cpp:Parse
/proc/statwithstd::regex(per Blue (@OneBlue)'s suggestion).ReadCpuBusyIdle()now matches the aggregatecpuline with a regex instead of a manualstrtoullcursor loop. The five leading fields (user, nice, system, idle, iowait) are required and irq/softirq/steal are optional, preserving the previous "at least 5 fields" semantics.Idle = idle + iowaitandBusy = user + nice + system + irq + softirq + stealare unchanged. The rawopen() + O_CLOEXEC + TEMP_FAILURE_RETRYbounded read is retained so the fd is not leaked to forked children and reads still retry onEINTR.drop_caches=3in DropCache mode (per Blue (@OneBlue)'s suggestion). Switching from1to3also drops reclaimable slab (dentries/inodes), matching theSReclaimableslab already counted byGetReclaimableCacheBytes().Validation
clang-formatclean.O_CLOEXEC/EINTRguarantees were retained per review feedback.