Skip to content

Address memory reclaim follow-ups from #41096 - #41171

Merged
Ben Hillis (benhillis) merged 3 commits into
masterfrom
benhillis/memory-reclaim-followups
Jul 27, 2026
Merged

Address memory reclaim follow-ups from #41096#41171
Ben Hillis (benhillis) merged 3 commits into
masterfrom
benhillis/memory-reclaim-followups

Conversation

@benhillis

Copy link
Copy Markdown
Member

What this changes

Addresses the two review follow-ups from #41096 in src/linux/init/util.cpp:

  1. Parse /proc/stat with std::regex (per Blue (@OneBlue)'s suggestion). ReadCpuBusyIdle() now matches the aggregate cpu line with a regex instead of a manual strtoull cursor 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 + iowait and Busy = user + nice + system + irq + softirq + steal are unchanged. The raw open() + O_CLOEXEC + TEMP_FAILURE_RETRY bounded read is retained so the fd is not leaked to forked children and reads still retry on EINTR.

  2. drop_caches=3 in DropCache mode (per Blue (@OneBlue)'s suggestion). Switching from 1 to 3 also drops reclaimable slab (dentries/inodes), matching the SReclaimable slab already counted by GetReclaimableCacheBytes().

Validation

  • clang-format clean.
  • Multi-model code review (Opus, GPT, Gemini) — no outstanding issues; the original O_CLOEXEC/EINTR guarantees were retained per review feedback.

- 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
@benhillis
Ben Hillis (benhillis) requested a review from a team as a code owner July 24, 2026 22:43
Copilot AI review requested due to automatic review settings July 24, 2026 22:43
OneBlue
Blue (OneBlue) previously approved these changes Jul 24, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 aggregate cpu line from /proc/stat using std::regex, keeping the same busy/idle bucket semantics.
  • Switched DropCache mode from drop_caches=1 to drop_caches=3 to also drop reclaimable slab (dentries/inodes), aligning with the cache accounting logic.

Comment thread src/linux/init/util.cpp Outdated
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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.

Comment thread src/linux/init/util.cpp
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
Copilot AI review requested due to automatic review settings July 24, 2026 23:07

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

@benhillis
Ben Hillis (benhillis) merged commit 88f76dd into master Jul 27, 2026
12 checks passed
@benhillis
Ben Hillis (benhillis) deleted the benhillis/memory-reclaim-followups branch July 27, 2026 19:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants