Repository navigation
[HiCache] Fix cgroup page-cache accounting and the sizing fallback when cgroup discovery fails - #42420
Merged
Conversation
…en cgroup discovery fails The cgroup headroom used by the HiCache host pools was `limit - usage`, and charged usage includes the page cache the process populated, most visibly the checkpoint it just read. That cache is reclaimable and host MemAvailable already treats it as free, so right after a large model loads an explicitly sized host pool could fail with "Not enough host memory available" although the kernel would have served it by reclaiming the cache. The headroom now subtracts the file-LRU pages (`active_file` + `inactive_file`, hierarchical `total_*` counters on cgroup v1) from charged usage, clamped at zero; shared memory sits on the anonymous LRU and stays charged. When cgroup discovery fails (no cgroupfs mounted, a mounted hierarchy that does not contain the process, or a missing counter for a known limit), the default auto-sized pool no longer sizes against host RAM as if that were the container's allowance: it raises and asks for an explicit --hicache-size. An explicit --hicache-size or --hicache-ratio keeps a warned fallback to the host-memory check. Readable limits are enforced in both modes. SGLANG_HICACHE_HOST_MEMORY_BYTES is removed; --hicache-size is the supported way to size the pool without cgroup discovery. Co-authored-by: xiezhq-hermann <xiezhq-hermann@users.noreply.github.com> Co-authored-by: nvjullin <nvjullin@users.noreply.github.com>
metamergebot
requested review from
Ying1123,
alphabetc1,
hanming-lu,
hnyls2002,
huangtingwei9988,
hzh0425,
ispobock,
merrymercy,
xiezhq-hermann and
yizhang2077
as code owners
October 3, 2026 19:21
Collaborator
Author
|
This port clears our bar on gate 20✓✗2✂4 lint✓ build✓ A✓ B✓ C✗2⏳8 other 6✓✂6 · accel ✗amd,b200,npu,xpu @merrymercy @xiezhq-hermann — could one of you take a look and merge it if you are happy? Nothing else is waiting on our side. |
3 of 5 tasks
This was referenced Oct 6, 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.
Motivation
Two problems in how HiCache sizes its host pools against the process cgroup.
Charged page cache counted as used. Since [HiCache] Auto-size the host pool to fit available host memory #40135 the host-pool budget is bounded by the cgroup headroom
limit - memory.current(memory.usage_in_byteson v1). Charged usage includes the page cache the process populated, most visibly the checkpoint it just read. That cache is reclaimable, and hostMemAvailable(psutil'savailable) already treats it as free, but the cgroup bound treated it as used. Right after a large model loads, an explicitly sized host pool could therefore fail withNot enough host memory availablealthough the kernel would have served it by reclaiming the cache, and the same command passed or failed depending on how much cache the job happened to have charged.Auto-sizing against host RAM when the container limit is unreadable. [HiCache] Fall back to host memory when no cgroup fs is mounted #42120 made a missing cgroup filesystem size the pool against host available memory with a warning, and added
SGLANG_HICACHE_HOST_MEMORY_BYTESas an override. For the default auto-sized pool that is the wrong failure mode: when the limit cannot be read, assuming the host's RAM is the container's allowance sizes a pool the limit may not hold, and the OOM kill arrives later and far from the cause. An explicit--hicache-sizeor--hicache-ratiois different: the user has stated what they want, so the probe is only a sanity check and a warned fallback is appropriate.The page-cache accounting is the same fix as #42039; this PR carries it together with the sizing-policy change because both edit the same function and tests, and the second part depends on the
memory.statread the first one introduces.Modifications
mem_cache/host_memory.pyusage - (active_file + inactive_file)(total_active_file + total_inactive_fileon v1, whose unprefixed counters omit descendants), clamped at zero. These are the file-LRU pagesMemAvailablecounts as reclaimable; shared memory sits on the anonymous LRU and stays charged, which is whymemory.stat'sfile/cachetotals are not used. A missingmemory.statfor a known limit is an error like a missing usage file.available_host_memory_bytes(*, allow_cgroup_fallback=False): when cgroup discovery fails (no cgroupfs mounted, a mounted hierarchy that does not contain the process, or an unreadable counter for a known limit), it raisesRuntimeErrorasking for an explicit--hicache-size. Withallow_cgroup_fallback=Trueit logs a warning and checks against host available memory instead. Readable limits are enforced in both modes.SGLANG_HICACHE_HOST_MEMORY_BYTESoverride are removed.mem_cache/pool_host/base.py:host_memory_budget_bytes(requested_bytes=0, *, auto_size=False); the explicit-size checks in the host pools keep the default and so get the warned fallback.mem_cache/hicache_auto_size.py: the auto-sizing path passesauto_size=True, so it requires successful cgroup discovery.environ.py:SGLANG_HICACHE_HOST_MEMORY_BYTESis unregistered. It was added in [HiCache] Fall back to host memory when no cgroup fs is mounted #42120, which is not in any release tag, so it is removed outright rather than deprecated;--hicache-sizeis the supported way to size the pool without cgroup discovery.test/registered/unit/mem_cache/test_host_memory.py: the synthetic procfs now writesmemory.stat; a regression test covers the page-cache accounting on v2 and v1 (hierarchical counters, a shared-memory decoy, and the clamp when v1 usage trails the counters); the no-cgroupfs, unmatched-hierarchy and missing-counter cases assert the actionable error by default and the host-memory fallback when allowed. The tests for the removed override are dropped.Behavior is unchanged when cgroup discovery succeeds and no page cache is charged, and when the process has no cgroup membership.
Accuracy Tests
N/A: model outputs are unaffected.
Speed Tests and Profiling
N/A: the only cost is one extra
memory.statread per limited cgroup level at host-pool init.Validation:
test/registered/unit/mem_cache/test_host_memory.py,test_hicache_auto_size.pyandtest_mem_pool_host.py::TestHostMemoryBudgetpass locally; the new page-cache test fails on the previous accounting.Checklist
CI States
Latest PR Test (Base): 🚫 Run #37147602776⚠️ Not enabled -- add
Latest PR Test (Extra):
run-ci-extralabel to opt in.Latest PR Test (AMD ROCm 10): ❌ Run #37147602737