Skip to content

Commit 4f14c28

Browse files
sourcehawkclaude
andcommitted
fix(skills/bounding-heavy-commands): leave the reclaimable slab out of the held memory on a newer kernel
The 'kernel' line of memory.stat includes slab_reclaimable, the cache of file names and inodes, which the kernel can take back under the cap. The held memory counted it, so a command that walks many files got a larger held peak than it needs. The wrapper now subtracts slab_reclaimable from the kernel line. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 554e1c1 commit 4f14c28

2 files changed

Lines changed: 4 additions & 1 deletion

File tree

‎skills/bounding-heavy-commands/scripts/bounded_run.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -863,6 +863,9 @@ def cgroup_held_mib(directory: str) -> Optional[int]:
863863
parts = line.split()
864864
if len(parts) == 2 and parts[1].isdigit():
865865
fields[parts[0]] = int(parts[1])
866+
if "kernel" in fields:
867+
# The 'kernel' line also counts the reclaimable slab, the cache of file names and inodes.
868+
fields["kernel"] = max(0, fields["kernel"] - fields.get("slab_reclaimable", 0))
866869
names = HELD_FIELDS + (("kernel",) if "kernel" in fields else KERNEL_PARTS)
867870
found = [fields[name] for name in names if name in fields]
868871
return math.ceil(sum(found) / (1024 * 1024)) if found else None

‎skills/bounding-heavy-commands/scripts/tests/test_bounded_run.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1326,7 +1326,7 @@ def test_held_memory_is_what_the_kernel_cannot_take_back_at_once(self):
13261326
with tempfile.TemporaryDirectory() as directory:
13271327
self.write_stat(directory, anon=100, file=5000, kernel=20, kernel_stack=1, slab_unreclaimable=2, shmem=30,
13281328
file_dirty=40, file_writeback=50, inactive_file=4000, active_file=900, slab_reclaimable=10)
1329-
self.assertEqual(bounded_run.cgroup_held_mib(directory), 240)
1329+
self.assertEqual(bounded_run.cgroup_held_mib(directory), 230)
13301330

13311331
def test_held_memory_without_the_kernel_line_adds_the_parts_of_kernel_memory(self):
13321332
with tempfile.TemporaryDirectory() as directory:

0 commit comments

Comments
 (0)