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:
@@ -1,11 +1,14 @@
|
||||
import torch
|
||||
|
||||
from benchmark.hicache.bench_cp_hicache_allocator_overhead import (
|
||||
HostChurnBenchResult,
|
||||
StandaloneCPSharedPagedAllocator,
|
||||
StandaloneHostAllocator,
|
||||
_bench_host_churn_case,
|
||||
_host_pages_from_gb,
|
||||
_make_host_free_slots,
|
||||
_make_page_compute_owners,
|
||||
_page_run_lengths_from_token_slots,
|
||||
_parse_int_list,
|
||||
)
|
||||
|
||||
@@ -49,6 +52,65 @@ def test_host_random_fragmented_has_requested_size():
|
||||
assert torch.unique(free_slots).numel() == free_slots.numel()
|
||||
|
||||
|
||||
def test_page_run_lengths_from_token_slots_counts_lpf_descriptors():
|
||||
page_size = 4
|
||||
selected = torch.tensor(
|
||||
[
|
||||
*range(10 * page_size, 13 * page_size),
|
||||
*range(20 * page_size, 22 * page_size),
|
||||
*range(25 * page_size, 26 * page_size),
|
||||
],
|
||||
dtype=torch.int64,
|
||||
)
|
||||
|
||||
assert _page_run_lengths_from_token_slots(selected, page_size) == [3, 2, 1]
|
||||
|
||||
|
||||
def test_host_churn_case_reports_l2_run_quality():
|
||||
result = _bench_host_churn_case(
|
||||
impl="standalone",
|
||||
method="contiguous",
|
||||
total_pages=48,
|
||||
request_pages=4,
|
||||
page_size=8,
|
||||
target_occupancy=0.75,
|
||||
evict_pages=4,
|
||||
eviction_pattern="random",
|
||||
repeat=4,
|
||||
warmup=1,
|
||||
seed=7,
|
||||
)
|
||||
|
||||
assert isinstance(result, HostChurnBenchResult)
|
||||
assert result.bench == "host_churn"
|
||||
assert result.repeat == 4
|
||||
assert result.page_first_descriptors_per_op == 4
|
||||
assert 0 < result.lpf_descriptor_ratio_mean <= 1
|
||||
assert result.run_count_p50 >= 1
|
||||
assert result.max_run_pages_mean >= 1
|
||||
|
||||
|
||||
def test_host_churn_prefill_node_pages_can_model_fragmented_free_chunks():
|
||||
result = _bench_host_churn_case(
|
||||
impl="standalone",
|
||||
method="fifo",
|
||||
total_pages=64,
|
||||
request_pages=8,
|
||||
page_size=4,
|
||||
target_occupancy=0.75,
|
||||
evict_pages=8,
|
||||
eviction_pattern="random",
|
||||
prefill_node_pages=1,
|
||||
repeat=8,
|
||||
warmup=2,
|
||||
seed=11,
|
||||
)
|
||||
|
||||
assert result.prefill_node_pages == 1
|
||||
assert result.run_count_p50 > 1
|
||||
assert result.lpf_descriptor_ratio_mean > 1 / result.request_pages
|
||||
|
||||
|
||||
def test_standalone_l1_allocator_reports_owner_lane_stats():
|
||||
allocator = StandaloneCPSharedPagedAllocator(
|
||||
physical_pages=4,
|
||||
@@ -79,3 +141,25 @@ def test_standalone_l1_allocator_allocates_owner_matching_pages():
|
||||
logical_pages = (selected.view(-1, allocator.page_size)[:, 0] // allocator.page_size)
|
||||
selected_owners = torch.remainder(logical_pages - 1, allocator.cp_size).tolist()
|
||||
assert selected_owners == owners
|
||||
|
||||
|
||||
def test_host_churn_burnin_exposes_fragmented_evicted_nodes_after_cold_tail():
|
||||
result = _bench_host_churn_case(
|
||||
impl="standalone",
|
||||
method="fifo",
|
||||
total_pages=32,
|
||||
request_pages=8,
|
||||
page_size=4,
|
||||
target_occupancy=0.75,
|
||||
evict_pages=8,
|
||||
eviction_pattern="random",
|
||||
prefill_node_pages=1,
|
||||
burnin=1,
|
||||
repeat=1,
|
||||
warmup=0,
|
||||
seed=23,
|
||||
)
|
||||
|
||||
assert result.burnin == 1
|
||||
assert result.run_count_p50 > 1
|
||||
assert result.lpf_descriptor_ratio_mean > 1 / result.request_pages
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user