Reduce CP HiCache L2 allocator scan cost

Host HiCache reservations were paying token-level free-slot scans when trying to preserve page contiguity. The allocator now keeps a lazy page-extent index so availability checks and contiguous-preferred allocations avoid materializing the full 220GB-equivalent free-slot metadata path.

The companion benchmark models steady-state L2 churn near full occupancy, including burn-in and historical node-size effects, so LPF/RDMA descriptor quality can be separated from ETE noise.

Constraint: CP HiCache host allocations are page-shaped, but existing callers may still read free_slots directly.
Rejected: Sort and scan free_slots on each alloc_contiguous_preferred call | measured ms-level CPU overhead on 220GB-equivalent metadata.
Rejected: Remove free_slots compatibility | storage/tests still rely on the public tensor surface.
Confidence: medium
Scope-risk: moderate
Directive: Do not reintroduce per-allocation full free_slots scans on HostKVCache; preserve page-extent metadata or benchmark before changing allocator shape.
Tested: Local py_compile for memory_pool_host.py, allocator benchmark, and related tests.
Tested: Local test_cp_hicache_allocator_bench.py 10 passed.
Tested: Remote g0034 test_hicache_controller_cp.py 67 passed; test_cp_hicache_allocator_bench.py 10 passed.
Tested: Remote 220GB-equivalent host_churn benchmark: contiguous path reduced from ms-level to ~30-292us p50 depending on fragmentation.
Not-tested: Full CUDA ETE run after allocator change.
Not-tested: Production long-run fragmentation behavior under live traffic.
This commit is contained in:
laoyao0822
2026-06-02 23:35:45 +08:00
parent 7c8fa2f71c
commit 401de0f8ce
5 changed files with 925 additions and 2 deletions
@@ -1016,6 +1016,29 @@ class TestHiCacheControllerCPWrite(CustomTestCase):
self.assertEqual(selected.tolist(), [8, 9, 10, 11, 12, 13, 14, 15])
self.assertEqual(host_pool.free_slots.tolist(), [100, 101, 102, 103])
def test_host_alloc_contiguous_preferred_uses_lazy_extent_index(self):
host_pool = DummyHostKVCacheForAlloc.__new__(DummyHostKVCacheForAlloc)
host_pool.page_size = 4
host_pool.lock = __import__("threading").RLock()
pages = [50, 51, 52, 53, 100, 7, 8]
host_pool.free_slots = torch.tensor(
[page * 4 + offset for page in pages for offset in range(4)],
dtype=torch.int64,
)
selected = host_pool.alloc_contiguous_preferred(16)
self.assertEqual(
selected.tolist(),
[page * 4 + offset for page in [50, 51, 52, 53] for offset in range(4)],
)
self.assertEqual(host_pool.available_size(), 12)
self.assertTrue(host_pool._free_slots_dirty)
self.assertEqual(
host_pool.free_slots.tolist(),
[page * 4 + offset for page in [7, 8, 100] for offset in range(4)],
)
def test_cp_reserve_zero_owned_queues_no_ack_until_submit(self):
host_pool = FakeHostPool(torch.tensor([], dtype=torch.int64))
controller = self.make_controller(host_pool, cp_rank=3)