From 9ac42450e195b4d455c123f9534e97ce353b1594 Mon Sep 17 00:00:00 2001 From: leavelet Date: Sat, 20 Jun 2026 18:43:25 +0000 Subject: [PATCH] 2b.3 observability: log shared-L2 pool report in lane-stats The CP_HICACHE_LANE_STATS occ/used_tokens are derived from _cp_counts, which the accounting explicitly skips for shared-L2 metadata (_cp_account_*: `not _is_cp_shared_l2_metadata`), so they read 0 with l2 pooling on regardless of actual fill -- wrong gauge for the shared pool. Add cache_controller .cp_shared_l2_cache_report() (pages_used / pages_capacity / objects_committed / objects_aborted / objects_evicted + load_hits/misses from the replicated CpSharedL2PageAllocator stats) to the lane-stats line as `shared_l2_pool=...` when the allocator is constructed, so fill->evict->load-back is observable. Read-only; rank-0 only; takes effect on next restart. Co-Authored-By: Claude Opus 4.8 (1M context) --- python/sglang/srt/mem_cache/hiradix_cache.py | 21 +++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/python/sglang/srt/mem_cache/hiradix_cache.py b/python/sglang/srt/mem_cache/hiradix_cache.py index 537dac798..04d60b8d5 100644 --- a/python/sglang/srt/mem_cache/hiradix_cache.py +++ b/python/sglang/srt/mem_cache/hiradix_cache.py @@ -3293,10 +3293,28 @@ class HiRadixCache(RadixCache): } self._cp_fallback_counts_last = dict(fallback_counts) + # Shared physical L2 pool report -- the REAL occupancy when l2 pooling is on. + # occ/used_tokens above are derived from _cp_counts, which the accounting + # explicitly skips for shared-L2 metadata (_cp_account_*: `not + # _is_cp_shared_l2_metadata`), so they read 0 even when the pool is full. The + # shared pool tracks its own pages_used/objects_committed/objects_evicted + + # load_hits/misses in the replicated CpSharedL2PageAllocator stats. + shared_l2_report = None + controller = getattr(self, "cache_controller", None) + if controller is not None and getattr( + controller, "cp_shared_l2_page_allocator", None + ) is not None: + report_fn = getattr(controller, "cp_shared_l2_cache_report", None) + if report_fn is not None: + try: + shared_l2_report = report_fn() + except Exception: + shared_l2_report = None + logger.info( "[CP_HICACHE_LANE_STATS] occ=%s cap_tokens=%s used_tokens=%s max=%.3f " "min=%.3f spread=%.3f imbalance=%s hot_prefix_short=%d hot_prefix_long=%d " - "skew_token_threshold=%d drops_since_last=%s drops_total=%s", + "skew_token_threshold=%d drops_since_last=%s drops_total=%s shared_l2_pool=%s", [round(x, 3) for x in occ], list(capacity), list(used), @@ -3309,6 +3327,7 @@ class HiRadixCache(RadixCache): skew_token_threshold, drops_since_last, dict(fallback_counts), + shared_l2_report, ) def _probe_existing_radix_prefix_len_no_split(self, key: RadixKey) -> int: