[Bug] AddressManager accepts size 0, breaks free list / ZeroDivisionError
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 88/100
Research direction
Start with AddressManager.allocate() and batched_allocate() in lmcache/v1/memory_management, then read the related tests in tests/v1/test_address_manager.py. Add coverage for zero and negative sizes, including batched allocation, and verify invalid sizes raise RuntimeError without corrupting the free list or causing ZeroDivisionError.
Written by the indexing model from the issue text.
Description
Hey team,
I found AddressManager.allocate() and batched_allocate() say size should be > 0 but don't check it. On dev (68b7e5f):
from lmcache.v1.memory_management import AddressManager
am = AddressManager(1 << 20)
a = am.allocate(4096)
z = am.allocate(0)
b = am.allocate(4096)
am.free(*z); am.free(*b); am.free(*a)
print([(x.start, x.size) for x in am._explicit_list])
# [(0, 4096), (4096, 4096), (8192, 1040384)] <- never coalesced
am.allocate(1 << 20)
# RuntimeError: no memory is available (everything is free)
AddressManager(1 << 20).batched_allocate(0, 3)
# ZeroDivisionError (block.size // aligned_size)
The ZeroDivisionError also gets past TensorMemoryAllocator.batched_allocate, which only catches RuntimeError.
I hit this through SegmentTokenDatabase: a leading/trailing/double separator gives an empty range (e.g. (4, 4)), and LMCacheEngine.store() allocates 0 bytes for it.
Fix I'd suggest: raise RuntimeError for size <= 0 in both (same as #5061 did for batch_size) and add tests in tests/v1/test_address_manager.py. Happy to send a PR.
- Dominant language
- Python
- Stars
- 11.9k
- Forks
- 1.9k
- Avg merge
- 3d 19h
- Merged PRs (30d)
- 135
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from LMCache/LMCache
-
good first issue help wanted
Difficulty 1/5 Under an hour Newbie friendliness 92/100
-
good first issue help wanted
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
-
good first issue help wanted
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
-
good first issue help wanted
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
good first issue help wanted
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100