[Bug] AddressManager accepts size 0, breaks free list / ZeroDivisionError

Open Beginner friendly
#5,115 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
88/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
python
Domain
backend

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from LMCache/LMCache

All issues in LMCache/LMCache

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.