Skip to content

fix(umbp): SSD tier gives disk back a segment at a time - #775

Merged
TianDi101 merged 4 commits into
mainfrom
fix/umbp-ssd-segment-reclaim
Oct 16, 2026
Merged

TianDi101 merged 4 commits into
mainfrom
fix/umbp-ssd-segment-reclaim

Conversation

@TianDi101

@TianDi101 TianDi101 commented Oct 15, 2026 •

Copy link
Copy Markdown
Collaborator

Addresses #755. The file SSD tier now gives disk back: an emptied segment file is deleted, and eviction empties whole segments instead of scattering per-key holes through all of them.

Why

SSDTier is an append-only segment log, and nothing ever deleted a segment. Evict() only dropped the key from the index, and admission counted live bytes only, so after any eviction new writes were admitted and appended. Disk use, segment files and open fds all grew with bytes written, not with capacity_bytes.

This is no longer theoretical. A 200 GB pure-SSD e2e arm (2 drives, DSv4, agentic load) evicted correctly by its own accounting (28 eviction windows, tier at 71–90%), but wrote 1,311 GB of segment files. That filled the shared /data drive to 0 bytes free, and then 1,154 SSD write failed followed.

Change

Disk is accounted on disk. Capacity() and write admission count every segment's append extent, dead records included. That's what the drive holds, so the eviction watermarks, the placement policy and the master all see the real number.

Emptied segments are deleted. A segment file is unlinked, then closed off the tier lock, once all of these hold:

  • it is sealed (no longer the active segment);
  • no key maps into it;
  • no read or write holds its fd.

Pins:

  • Reads and writes look up the fd under the lock and do the I/O without it, so they pin the segment for that window. Without the pin, a closed fd's number can be reused by the next segment, and a late pread would return another file's bytes.
  • An overwrite also pins the segment holding the record it replaces, because a failed write restores that record.

Edge cases:

  • An emptied active segment is rolled past so it can go too.
  • At startup, segments with nothing live (every record superseded) are deleted.

Eviction ranks segments, not keys. Disk only comes back a whole segment at a time, so SSDTier::EvictionOrder() hands out whole segments' keys:

  • A sealed segment scores (age + 1) / live_fraction, highest first. Cold segments go first, and a mostly dead segment goes much sooner than its age alone would send it.
  • Within a segment, keys go coldest first. The active segment comes last.
  • Each key is credited with its share of the file, so evicting a segment's last key credits exactly the file's size. The pool's budget, which is now in disk bytes, then stops after the right number of segments.
  • ShardedSsdTier offers the fullest drive first.
  • PeerSsdManager uses this order when the tier keeps one (TierCapabilities::orders_eviction), and keeps its own LRU otherwise (SPDK proxy, test fakes).

The SSD tier keeps its own order. MediumBackend::OwnsEvictionOrder() makes PeerPool's local eviction skip the master's ranking for such a medium. Per-key recency picks keys scattered across segments, which can leave every segment partly live and free nothing.

GDS. BatchResolve hands a GDS reader a FileRef (fd + offset) with no lease or pin. With UMBP_ENABLE_GDS:

  • a deleted segment's fd stays open for UMBP_SSD_READ_LEASE_MS;
  • SsdBackend drops its cached handle for that fd before the fd closes and its number can be reused.

(TierBackend::SetRetiredFileHook.)

Room for a new segment. A new segment is opened only while the filesystem has a segment's worth of free space. A drive that something else is filling then fails writes cleanly, with a rate-limited ERROR, instead of hitting ENOSPC partway through a record.

Segment size.

  • New UMBP_SSD_SEGMENT_SIZE environment variable; the default stays 4 GiB.
  • A drive whose share is under 8 segments uses capacity / 8, so a small tier always has sealed segments to evict. Previously a 1 MiB tier had one 4 GiB segment.

Fixed on the way

On-disk admission makes these reachable:

  • SSDTier::BatchWrite reports each key. A key refused for space used to come back true, and a fully refused batch counted as success. PeerSsdManager then owned keys the tier never stored: every read of them failed, and evicting them failed forever ("keeping for retry").
  • Index::RollbackWrite rewinds the append cursor only while its record is still the segment's tail. Before, it could hand a later reservation's bytes to the next writer. It also no longer restores the previous record over a newer write of the same key, or resurrects a key evicted mid-write.

Behaviour to be aware of

  • The used SSD figure now includes dead records. Dashboards will show higher SSD usage than before for the same live data. Before, the true number was simply invisible.
  • Eviction is coarser. A segment's still-useful keys go with it. Smaller UMBP_SSD_SEGMENT_SIZE makes the step finer, at the cost of more files and fds.
  • UMBP_EVICTION_MODE=master still lets the master's rounds pick SSD keys per key, alongside the node's own SSD watermark eviction. Disk stays bounded, because the node empties the sparse segments those picks leave, but the two can together evict more than needed. A follow-up would give the master a per-tier peer-driven flag.
  • ReadOnlyShared followers keep a deleted segment's fd until they restart, so its blocks are freed only then. That mode is used only in test_ssd_tier.

vs #755's proposal

#755 proposes a block allocator, as in SpdkSsdTier. This PR takes the alternative that issue considered: keep the log, delete segments once they are empty, and make eviction empty them. It needs no on-disk format change, keeps restart recovery and follower mode, and does no extra writes. There is no compaction. A mostly dead segment is emptied by evicting its few live keys, which is acceptable for a cache, rather than by copying them forward. Copy-forward of recently read keys, or hole punching, can come later if hit rate needs it.

Metrics

TierBackend::SpaceStats() (it replaces three test-only SSDTier accessors) feeds:

  • mori_umbp_backend_medium_events_total{event="segment_deleted"} and medium_bytes_total{event="segment_deleted"}: segment files deleted, and the disk they held.
  • medium_state{state="live_bytes"}: how much of capacity used (now on-disk bytes) still holds keys.
  • medium_state{state="segment_files"}, and medium_events_total{event="segment_no_room"} for new segments refused because the filesystem was full.

Tests

New umbp_ssd_segment_reclaim:

  • UMBP file SSD tier never reclaims space: disk use and fds grow with bytes written; manage it by blocks like SpdkSsdTier #755's churn repro: 40 rounds of 100 writes then 100 evictions, about 31× the capacity. On-disk use stays at or under one segment, with at most 2 files and at most 2 fds. A restart resurrects nothing.
  • Admission: evicting one key from each of 8 full segments frees nothing, and the next write is refused. Emptying the segment the eviction order picks frees exactly one file.
  • Eviction order: a mostly dead segment ranks before a cold one, which ranks before a just-read one, with the active segment last. Credits add up to the file size.
  • Batch results: a batch that only partly fits reports each key, and the refused keys do not exist.
  • Overwrite: overwriting every record deletes the old segment.
  • Startup: of two identical segments, a restart deletes one.
  • GDS grace: the deleted segment's fd stays open and readable for the grace, and the hook fires once, at close.
  • Segment-size cap, and sharded order (the fullest drive goes first, and draining it frees that drive).
  • Read race: a 2-second race of readers, an evictor and a writer with CRC off, so a read through a reused fd would return wrong bytes. No bad reads; more than 10 segments churned. The test passed 5 of 5 repeats.

Updated test_ssd_backend (CandidatesAreColdestFirstAndSkipALeasedKey): offers now carry on-disk bytes and OwnsEvictionOrder() is true. PoolLocalEvictionDrainsTheSsdMediumThroughEvict now drains disk, not just live bytes, and passes unchanged.

Local run in mori-dev:sglang-0.5.19 (grpc 1.30), Release, gfx950: the 16 SSD/eviction tests (including the test_* ones CI's regex skips) and the other 43 UMBP tests all pass, 59/59.

E2E rerun of the 200 GB pure-SSD arm with this patch: pending, results to follow here.

🤖 Generated with Claude Code

The file SSD tier is an append-only segment log, and nothing ever deleted
a segment: evicting a key only dropped it from the index, admission
counted live bytes only, so disk use, segment files and open fds grew
with every byte written (#755).  A 200 GB pure-SSD e2e arm filled its
/data drive to 0 bytes free this way and then failed every SSD write.

Space now comes back whole segment files at a time:

- Admission and Capacity() count bytes on disk (every segment's append
  extent, dead records included), so the eviction watermarks and the
  master see what the drive actually holds.
- A segment file is deleted (unlinked, then closed off the tier lock)
  once it is sealed, no key maps into it, and no read or write holds its
  fd.  Reads and writes pin the segment for the I/O they do outside the
  lock; an overwrite also pins the segment of the record it replaces,
  which a failed write restores.  An emptied active segment is rolled
  past so it can go too, and a restart deletes segments it finds nothing
  live in.
- Eviction ranks segments, not keys: the tier offers whole segments'
  keys, a sealed segment scoring (age + 1) / live_fraction so cold and
  mostly-dead segments go first, the active segment last, and each key
  credited with its share of the file.  ShardedSsdTier offers the
  fullest drive first.  PeerPool no longer substitutes the master's
  per-key ranking for a medium that owns its order, since that could
  leave every segment partly live and free nothing.
- GDS file refs carry an fd with no lease, so with UMBP_ENABLE_GDS a
  deleted segment's fd stays open for the SSD read-lease TTL, and the
  cached GDS handle is dropped before the fd number can be reused.
- A new segment is opened only while the filesystem has a segment's
  worth of free space, so a drive filled by something else fails writes
  cleanly instead of with ENOSPC mid-record.
- Segment size: UMBP_SSD_SEGMENT_SIZE env var, and a tier smaller than
  8 segments uses capacity / 8 so eviction always has sealed segments.

Also fixed on the way, since on-disk admission makes them reachable:
- SSDTier::BatchWrite reports each key; a key refused for space used to
  come back true (and an all-refused batch as success), leaving
  PeerSsdManager owning keys the tier never stored.
- RollbackWrite rewinds the append cursor only when its record is still
  the segment's tail, and no longer restores a previous record over a
  newer write of the same key.

Tests: new umbp_ssd_segment_reclaim (#755's churn repro stays bounded,
on-disk admission, eviction order and credits, per-key batch results,
overwrite and startup reclaim, the GDS grace, segment-size cap, sharded
order, and a read/evict/write race that would expose a reused fd).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@TianDi101
TianDi101 marked this pull request as ready for review October 15, 2026 09:11
TianDi101 and others added 2 commits October 15, 2026 09:46
TierBackend::SpaceStats() reports live bytes, segment files on disk,
files deleted and the bytes they held, and new segments refused because
the filesystem was full.  SsdBackend publishes them as
medium_events_total{event="segment_deleted"|"segment_no_room"},
medium_bytes_total{event="segment_deleted"} and
medium_state{state="live_bytes"|"segment_files"}, so a run shows disk
coming back, and how much of "used" is dead records.  It replaces the
three SSDTier accessors only the tests read, and the refusal count is
now per tier instead of process-wide.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
TianDi101 added a commit that referenced this pull request Oct 16, 2026
…ect-migration

Brings in #775 (segment reclaim) and #784, which this PR now merges after.
A reserved record's value is written through its segment's fd outside the
lock, so Reserve/Commit/AbortRecord pin that segment (and the replaced
record's) until the reservation ends, as Write does; a sharded reserve
refreshes its placement hints like a sharded write.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
TianDi101 added a commit that referenced this pull request Oct 16, 2026
…nt-staging

Moves extent staging and the pipelined local get onto #762's holds: an extent
stage keeps a hold and is reclaimed with the read leases once the last one
drops; a pipeline part's holds live in its Stage, so the release paths (scope
guards, drain-ahead) are gone.  Brings in #775, with whose ShardedSsdTier
capabilities the ranged_read check is combined.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@TianDi101
TianDi101 merged commit 6eda033 into main Oct 16, 2026
TianDi101 added a commit that referenced this pull request Oct 16, 2026
…ce-read-touch

# Conflicts:
#	src/umbp/include/umbp/local/tiers/sharded_ssd_tier.h
#	src/umbp/include/umbp/local/tiers/ssd_tier.h
#	src/umbp/local/tiers/sharded_ssd_tier.cpp
#	src/umbp/local/tiers/ssd_tier.cpp
#	tests/cpp/umbp/local/test_ssd_segment_reclaim.cpp
TianDi101 added a commit that referenced this pull request Oct 16, 2026
…-ssd-direct-migration

# Conflicts:
#	src/umbp/distributed/peer/backend/ssd_backend.cpp
#	src/umbp/distributed/pool/peer_pool.cpp
#	src/umbp/include/umbp/distributed/peer/backend/page_backend.h
#	src/umbp/include/umbp/distributed/peer/backend/ssd_backend.h
TianDi101 added a commit that referenced this pull request Oct 16, 2026
fix(umbp): an in-place SSD read counts as an access (#793)

SSDTier::LocateRecord gave GDS and in-place migration readers a record's
fd without touching the segment index, so segment eviction could drop a
segment while a load was still reading it. It now touches the key and
its segment like any other read.

Re-lands #784, which merged into #775's branch after #775 was squashed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Hoipang added a commit to Hoipang/mori that referenced this pull request Dec 1, 2026
…-key reclaim)

This commit has 5 parts. Each part below was one commit before the squash.

Part 1: refactor(umbp): move OffsetAllocator to local/tiers/offset

OffsetAllocator does not use SPDK. The build already compiles it in
every configuration (UMBP_CORE_SRCS). The next commit lets the file SSD
tier use it too. Thus the allocator moves next to the SSD tiers that use
it, beside local/tiers/segment, which manages space for the segment log:

- include/umbp/storage/spdk/offset_allocator.hpp
  -> include/umbp/local/tiers/offset/offset_allocator.h
- storage/spdk/offset_allocator.cpp
  -> local/tiers/offset/offset_allocator.cpp

The header now uses .h, as the other UMBP headers do. The code does not
change. Only the paths and the #include lines change.

Part 2: feat(umbp): file SSD tier can free space per key with UMBP_SSD_LAYOUT=offset_allocator

The segment log returns disk a whole segment at a time (ROCm#775).  So
eviction must empty segments, and it drops recently used keys with them.
On the WEKA trace replica (Qwen3.8-27B TP4, 70 users, 1 TiB SSD pool),
this keeps the SSD tier's hit rate below DRAM's 46.7-47.8%.  The SSD tier
gets 10-11% with the default 4 GiB segments, and 33-34% with 32 MiB ones.
An opt-in offset_allocator layout manages each drive's file the way
SpdkSsdTier manages its device (ROCm#755).  It keeps one preallocated file per
tier directory, and it places each record at an OffsetAllocator
allocation instead of the append cursor.

- Evict, overwrite and abort free the key's allocation as soon as no read
  or write holds it, so capacity counts allocated bytes.  In-flight I/O
  pins the allocation.  Under a retired-file grace (GDS), the tier does
  not reuse a freed allocation until the grace ends.  A deleted segment's
  fd keeps the same promise.  Meanwhile its bytes count as free, as a
  deleted segment's do.  So PeerPool's watermark pass does not evict again
  for them on every 100 ms poll of the lease.  But placement does not get
  them (SsdBackend's max_allocatable_bytes is capacity - allocated, and
  ShardedSsdTier places by allocated bytes).
- orders_eviction is false, so PeerSsdManager evicts in its own per-key
  LRU order and PeerPool takes the master's ranking.
- The tier asks the allocator for the size it really holds
  (OffsetAllocator::allocationSize).  So Capacity() and
  offset_allocator_allocated_bytes count what allocations hold.
  live_bytes stays the records' bytes.  The difference is
  SpaceStats::padding_bytes and the offset_allocator_padding_bytes backend
  metric.  Counting only the requested bytes stopped every drive at 93%
  allocated with uniform 13 MiB records.  Such a drive was full on disk
  but under the eviction watermark, so nothing was ever evicted again.
- A record that no free range can hold (fragmentation, or a full drive)
  fails cleanly.  Capacity() then reports the drive full until one of
  these is true:
    - a range that size is free.
    - a record that size is placed.
    - a key is evicted.
  So one refusal buys one eviction batch, and a retried write that is
  refused again asks again.  A record over 1/8 of the drive gets none.  To
  make it a hole, eviction in LRU order would have to empty most of the
  drive.  The pool's watermark eviction, which a refused put already
  wakes, then frees a hole.  Meanwhile ShardedSsdTier places new keys on
  other drives.  SpaceStats reports the allocated bytes and the largest
  free range (offset_allocator_allocated_bytes /
  offset_allocator_largest_free_bytes).
- OffsetAllocator needs a node per allocation and one per free range.  It
  refuses every allocation once all nodes are in use.  The tier sizes the
  limit so that records averaging 64 KiB or more fill the drive.  The
  limit is 2 x capacity / 64 KiB + 1 nodes, at least 1024 and at most
  2^28.  It is never more than the drive's 4 KiB units + 1.  A node is
  32 B (measured: VmSize +32 B per node when the allocator is created, RSS
  +32 B per node in use).  So the limit reserves 443 MB of address space
  for a 454 GB drive and 3.4 GB for a 3.5 TB one.  This memory becomes
  resident only as the allocator uses the nodes.  The tier logs a refusal
  for want of a node as such, not as fragmentation, and counts it
  (SpaceStats::node_limit_refusals, offset_allocator_node_limit_refusals).
- The tier opens and preallocates the data file when it is constructed.
  If open, fallocate or ftruncate fails (ENOSPC, EOPNOTSUPP, segment files
  of the other layout still holding the disk), construction throws with
  the path and errno.  It does the same for a directory it cannot create.
  Construction does not leave a tier that reports itself empty and
  refuses every write.  Clear() keeps the file and starts a fresh
  allocator on it.
- The layout keeps no index on disk: every open starts empty and says so.
  There is no follower mode.  The standalone client passes the layout to
  its server.

The record format, I/O drivers, ranged reads, CRC and the reserve/commit
path are unchanged.  The segment layout stays the default and behaves as
before.

Tests:
- umbp_ssd_offset_allocator_layout (new):
    - write/read/verify.
    - evict frees at once.
    - bounded churn.
    - no reuse while a read holds the allocation or before the
      retired-file grace ends.
    - overwrite and abort free.
    - fragmentation fails cleanly.
    - mixed sizes.
    - KV-like records fill the tier, and churn never refuses with room.
    - a refused record does not keep the tier evicting.
    - the node limit is reported apart.
    - restart starts empty.
    - a data file that cannot be opened throws.
    - UMBP_SSD_LAYOUT (a bad value throws).
  Records of 64 KiB keep its writes small.
- test_ssd_backend: the pool evicts a fragmented offset_allocator tier
  below its watermarks.  It evicts once, not on every pass, while freed
  allocations wait for the end of a 60 s read lease.
- test_peer_ssd_eviction: an offset_allocator tier evicts in the
  manager's LRU order.

Part 3: feat(umbp): offset_allocator SSD tier packs same-size records without padding

OffsetAllocator rounds every allocation up to its size class (3 mantissa
bits) and keeps the whole class.  A 13,635,584 B KV record (3,329 units of
4 KiB) held 3,584 units, 7.66% padding.  The tier counts what an
allocation holds, so a drive of KV records held only ~92% of its capacity
as live data.

- createAligned(..., exact_fit) puts the allocator in exact-fit mode: an
  allocation holds exactly its granularity units.  A freed hole of a
  record's own size sits in the bin below the request's round-up bin,
  where the O(1) search never looks.  So the request tries, in this order:
    1. a few nodes of that bin (the first that fits, which keeps larger
       holes whole),
    2. the larger bins,
    3. the whole bin.
  It fails only if no free node can hold it.  The default mode is
  unchanged, so SpdkSsdTier and the SPDK proxy behave as before.
  umbp_offset_allocator replays three fixed random traces (4M operations):
    - a mostly full 1 GiB range,
    - a 4096-node limit,
    - a 32 TiB range with 16 KiB granularity.
  It matches the hash of every offset and metric that 74ec17c's
  allocator gives for them.
- The offset_allocator tier uses it.  Same-size records pack with no
  padding, and the next record reuses a freed allocation at once.  Freed
  neighbours coalesce, so space moves between record sizes as soon as it
  is free.
- canAllocate() is the exact test for the starved state.  The tier
  reports itself full while the last refused record fits no free range.
  It does not compare with the largest free bin, which undercounts holes
  that are not a bin size.

Measured with test_ssd_offset_allocator_layout at full size (13 MiB KV
records, a 256 MiB tier with 10x its capacity written):
- 13 MiB records fill a 32.5-record tier to 32 records (98.5% live, 0%
  padding).  It was 30 with 7.66% padding.
- A 1 / 2.5 / 13 MiB mix is 97.6% live on average when a write is
  refused, with oldest-first eviction (was 90.1%).  With random victims,
  it is 90.9% (was 85.6%).
The test now runs 16x smaller, where the mix is 98.3% and 88.8%.  It uses
a 209-unit record, one unit over a size class as the 3,329-unit one is.
It writes 4x the capacity.

The end-to-end run used the WEKA trace replica (Qwen3.8-27B TP4, 70
users, 1 TiB SSD pool, SSD watermarks 0.97/0.93).  With this change, the
offset_allocator layout hit 39.0-39.7% (3 runs).  32 MiB segments at the
same watermarks hit 34.9-38.0%.

Tests: umbp_offset_allocator (new, CPU only) checks:
- the default-mode traces above.
- allocationSize() in both modes and past ~15 TiB.
- exact fit packs 32 KV-size records into 32.5 records' room and reuses
  each freed hole at its own offset.
- freed neighbours coalesce.
- over 200k random operations in each mode:
    - no two allocations overlap.
    - canAllocate() always predicts allocate().
    - an exact-fit refusal (other than for want of a node) leaves no gap
      that fits.
- the node limit refuses with bytes free.

Part 4: fix(umbp): offset_allocator SSD tier keeps headroom so mixed-size writes are not refused

A Kimi-K3 prefill peer with UMBP_SSD_LAYOUT=offset_allocator at the
0.99/0.97 watermarks refused 7 writes on its 454 GB drive. Each write
needed 11,874,304 B in one piece while 4,967,755,776 B were free. But the
largest free range was 11,849,728 B, so the tier refused the write as
fragmented. One commit failed. The watermark keeps 1% of a drive free,
and KV objects of mixed sizes (1-12 MB) cut that into holes smaller than
the largest record. The tier reported itself full only after a refusal,
so eviction always came one write late.

SSDTier::Capacity() now also reports the drive full while one of these
is true:
  - less than max(ssd.offset_allocator_min_free_bytes, 8 x the largest
    recent record) is free.
  - no free range holds two of the largest recent records.
So watermark eviction runs before a write is refused. The setting is
UMBP_SSD_OFFSET_ALLOCATOR_MIN_FREE (default min(1 GiB, 1/64 of the
drive), capped at 1/8 of the drive). 1 GiB is ~150 ms of one drive's
writes, more than one 100 ms eviction poll.
The largest recent record is the largest placed in this or the previous
window of 1/8 of the drive's capacity in writes. Only placed records
count, not refused ones. An outlier stops counting after at most a
quarter of a drive's worth of writes.
PeerPool's pass re-reads Capacity() after every batch of victims. So it
evicts coldest first until such a hole exists, then continues to the low
watermark, within one round's budget.

Limits:
  - LRU order does not aim at contiguity. On a badly fragmented drive, a
    round can evict well past the hole it needed, up to its budget,
    (1 - low) x capacity.
  - Two of the largest records in one hole is a proxy for "a hole for
    each of the next few". A batch of many large records can still find
    too few.
  - Freed allocations held for the GDS read lease count as free. Once a
    floor's worth of them wait, the headroom and refused-record checks no
    longer apply: evicting more cannot make room sooner.
  - On a 454 GB drive 1 GiB is under what 0.99 leaves free, so there only
    the hole rule acts.
  - Under 64 GiB, the default floor is 1/64 of the drive, just over the 1%
    0.99 leaves (104 MiB of 6.5 GiB). A flat 1 GiB, capped at 1/8, held
    DeepSeek-V4.1-Flash's 6.5 GiB drives (0.22 MB records) at 87.5% full.
    It cut hits from 83.7% to 73.2%. A value set in the env is used as
    given.
  - UMBP_SSD_OFFSET_ALLOCATOR_MIN_FREE=0 restores the previous behaviour.

ShardedSsdTier: when every shard reports itself full, a new record goes
to the shard whose largest free range fits it (its 4 KiB prefix
included). It is not refused. A headroom-short shard still has room.

Tests (no GPU):
- HeadroomMixedSizes writes Kimi-like values through a drive at 0.99/0.97
  in batches of 8, with a pool-like pass between batches. At full size
  (1, 3, 7 and 11.9 MB values, a 2 GiB drive, 6x its capacity written):
    - off: 251 records refused.
    - 8 x the largest record, and the default: none.
  The test now runs the mix 32x smaller (64 MiB, 3x its capacity):
    - off: 88 refused.
    - the default: none.
  Every resident value is intact when read.
- A sweep (2-12 GiB, batches of 1, 8 and 32) tested a 1 GiB floor
  (UMBP_SSD_OFFSET_ALLOCATOR_MIN_FREE=1073741824, capped at 1/8). It
  prevented every refusal except at 2-4 GiB with batches of 32 (1,724 ->
  1,405 and 1,576 -> 228). There, a batch outweighs a round's budget.
- HeadroomReportsFullEarly covers the floor, the hole rule, the lease
  gate and the sharded fallback.
- PoolMakesAHoleBeforeAFragmentedOffsetAllocatorTierRefuses runs the real
  PeerPool pass.
- These two tests failed on the code before this change
  (HeadroomReportsFullEarly now runs with 64 KiB records).
- HeadroomSmallDriveFills fills a 64 MiB drive of 64 KiB records to 98.5%
  before it reports full, also after evictions in random order. With a
  flat 1 GiB floor (set explicitly, as it still can be), it stops at
  87.5%. (At its earlier size, a 256 MiB drive of 8 KiB records, 98.4%.)
- HeadroomForgetsAnOldLargeRecord: after one 4-record record comes and
  goes, the drive fills to the floor of its 1-record records.
- RefusedRecordsDoNotKeepTheTierEvicting: a refused 40-record write does
  not raise the floor.

The layout test binary (umbp_ssd_offset_allocator_layout) writes 1.37 GB
through write syscalls in 0.9 s. Before it was made smaller, it wrote
62.4 GB in 21.2 s. Both were measured on vllm-001, in a container, with
/tmp on the node's disk.

Part 5: perf(umbp): offset_allocator SSD tier defaults to 0.99/0.97 watermarks

With UMBP_SSD_LAYOUT=offset_allocator, the SSD tier frees each key's
allocation the moment the key is evicted.  So the eviction band only has
to absorb the writes that land while a pass runs.  The default band
(0.9/0.7) keeps 10-30% of the tier empty, and the hit rate follows the
live bytes.  Hit rate by SSD high/low watermark, measured on the WEKA
trace replica (Qwen3.8-27B TP4, 40-day trace, 70 users, 1 TiB SSD pool,
offset_allocator layout):

  0.95/0.90   33.3%
  0.97/0.93   39.7%
  0.98/0.95   43.7%
  0.99/0.97   47.5%, 49.0% (2 runs)
  DRAM tier   46.7-47.8%  (same 1 TiB, DRAM watermarks 0.97/0.93)

Every run had 0 write failures.  At 0.99/0.97, the SSD tier matches DRAM.
0.9/0.7 itself was not run.  It holds less live data than 0.95/0.90.

ssd.high_watermark / low_watermark are now optional.  Unset, the band
follows the layout, however it was chosen (UMBP_SSD_LAYOUT, C++ or
Python).  UMBPSsdConfig::EffectiveWatermarks() gives:
  - 0.99 / 0.97 for the offset_allocator layout on the file backend.
  - 0.9 / 0.7 for the segment log and for the SPDK backends, which
    ignore the layout.
PoolClient and Validate() use it.  The standalone client passes its
server only the watermarks that are set, so the server derives the same
band.  Python reads None until a watermark is set.
ssd.effective_watermarks() gives the band.  UMBP_SSD_HIGH_WM /
UMBP_SSD_LOW_WM still override.  One set alone keeps the other's default.
Validate() rejects a band with low >= high and names the values, as
before.  For example, UMBP_SSD_HIGH_WM=0.95 alone under offset_allocator
gives 0.95 / 0.97, a startup error.  It needs UMBP_SSD_LOW_WM too.  A tiered
UMBP_BACKEND_POLICY still uses its tiers' own watermarks.

The segment layout keeps 0.9/0.7.  It returns disk a whole segment at a
time (ROCm#775), and it counts dead records until then.  segment_index.cpp
refuses a write once disk_used + record > capacity.  Its segment size is
capped at 1/8 of a drive's share (kMinSegmentsPerTier in ssd_tier.cpp).
This cap makes one pass of the 0.9 -> 0.7 band span a couple of segments.
A 0.99/0.97 band is 2% of the drive.  Segments are larger than that in
two cases:
  - the default 4 GiB segments on any drive share under ~200 GiB.
  - every tier near the 1/8 cap.
Then one pass cannot empty a segment.  So nothing is freed while the 1%
above the high watermark fills, and writes are refused.  This was not
measured.  It follows from the code.

Tests in umbp_ssd_offset_allocator_layout:
  - WatermarksFollowTheLayout: the layout set from code, an SPDK backend,
    one watermark set alone.
  - EnvFlag: the layout from the env, a caller that returns to the
    segment log, overrides.
Hoipang added a commit to Hoipang/mori that referenced this pull request Dec 2, 2026
…-key reclaim)

This commit has 5 parts. Each part below was one commit before the squash.

Part 1: refactor(umbp): move OffsetAllocator to local/tiers/offset

OffsetAllocator does not use SPDK. The build already compiles it in
every configuration (UMBP_CORE_SRCS). The next commit lets the file SSD
tier use it too. Thus the allocator moves next to the SSD tiers that use
it, beside local/tiers/segment, which manages space for the segment log:

- include/umbp/storage/spdk/offset_allocator.hpp
  -> include/umbp/local/tiers/offset/offset_allocator.h
- storage/spdk/offset_allocator.cpp
  -> local/tiers/offset/offset_allocator.cpp

The header now uses .h, as the other UMBP headers do. The code does not
change. Only the paths and the #include lines change.

Part 2: feat(umbp): file SSD tier can free space per key with UMBP_SSD_LAYOUT=offset_allocator

The segment log returns disk a whole segment at a time (ROCm#775).  So
eviction must empty segments, and it drops recently used keys with them.
On the WEKA trace replica (Qwen3.8-27B TP4, 70 users, 1 TiB SSD pool),
this keeps the SSD tier's hit rate below DRAM's 46.7-47.8%.  The SSD tier
gets 10-11% with the default 4 GiB segments, and 33-34% with 32 MiB ones.
An opt-in offset_allocator layout manages each drive's file the way
SpdkSsdTier manages its device (ROCm#755).  It keeps one preallocated file per
tier directory, and it places each record at an OffsetAllocator
allocation instead of the append cursor.

- Evict, overwrite and abort free the key's allocation as soon as no read
  or write holds it, so capacity counts allocated bytes.  In-flight I/O
  pins the allocation.  Under a retired-file grace (GDS), the tier does
  not reuse a freed allocation until the grace ends.  A deleted segment's
  fd keeps the same promise.  Meanwhile its bytes count as free, as a
  deleted segment's do.  So PeerPool's watermark pass does not evict again
  for them on every 100 ms poll of the lease.  But placement does not get
  them (SsdBackend's max_allocatable_bytes is capacity - allocated, and
  ShardedSsdTier places by allocated bytes).
- orders_eviction is false, so PeerSsdManager evicts in its own per-key
  LRU order and PeerPool takes the master's ranking.
- The tier asks the allocator for the size it really holds
  (OffsetAllocator::allocationSize).  So Capacity() and
  offset_allocator_allocated_bytes count what allocations hold.
  live_bytes stays the records' bytes.  The difference is
  SpaceStats::padding_bytes and the offset_allocator_padding_bytes backend
  metric.  Counting only the requested bytes stopped every drive at 93%
  allocated with uniform 13 MiB records.  Such a drive was full on disk
  but under the eviction watermark, so nothing was ever evicted again.
- A record that no free range can hold (fragmentation, or a full drive)
  fails cleanly.  The tier then reports a contiguous need of that size
  (Part 4) until one of these is true:
    - a range that size is free.
    - a record that size is placed.
    - a key is evicted.
  So one refusal buys one eviction batch, and a retried write that is
  refused again asks again.  A record over 1/8 of the drive gets none.  To
  make it a hole, eviction in LRU order would have to empty most of the
  drive.  The pool's watermark eviction, which a refused put already
  wakes, then frees a hole.  Meanwhile ShardedSsdTier places new keys on
  other drives.  SpaceStats reports the allocated bytes and the largest
  free range (offset_allocator_allocated_bytes /
  offset_allocator_largest_free_bytes).
- OffsetAllocator needs a node per allocation and one per free range.  It
  refuses every allocation once all nodes are in use.  The tier sizes the
  limit so that records averaging 64 KiB or more fill the drive.  The
  limit is 2 x capacity / 64 KiB + 1 nodes, at least 1024 and at most
  2^28.  It is never more than the drive's 4 KiB units + 1.  A node is
  32 B (measured: VmSize +32 B per node when the allocator is created, RSS
  +32 B per node in use).  So the limit reserves 443 MB of address space
  for a 454 GB drive and 3.4 GB for a 3.5 TB one.  This memory becomes
  resident only as the allocator uses the nodes.  The tier logs a refusal
  for want of a node as such, not as fragmentation, and counts it
  (SpaceStats::node_limit_refusals, offset_allocator_node_limit_refusals).
- The tier opens and preallocates the data file when it is constructed.
  If open, fallocate or ftruncate fails (ENOSPC, EOPNOTSUPP, segment files
  of the other layout still holding the disk), construction throws with
  the path and errno.  It does the same for a directory it cannot create.
  Construction does not leave a tier that reports itself empty and
  refuses every write.  Clear() keeps the file and starts a fresh
  allocator on it.
- The layout keeps no index on disk: every open starts empty and says so.
  There is no follower mode.  The standalone client passes the layout to
  its server.

The record format, I/O drivers, ranged reads, CRC and the reserve/commit
path are unchanged.  The segment layout stays the default and behaves as
before.

Tests:
- umbp_ssd_offset_allocator_layout (new):
    - write/read/verify.
    - evict frees at once.
    - bounded churn.
    - no reuse while a read holds the allocation or before the
      retired-file grace ends.
    - overwrite and abort free.
    - fragmentation fails cleanly.
    - mixed sizes.
    - KV-like records fill the tier, and churn never refuses with room.
    - a refused record does not keep the tier evicting.
    - the node limit is reported apart.
    - restart starts empty.
    - a data file that cannot be opened throws.
    - UMBP_SSD_LAYOUT (a bad value throws).
  Records of 64 KiB keep its writes small.
- test_ssd_backend: the pool evicts a fragmented offset_allocator tier
  below its watermarks.  It evicts once, not on every pass, while freed
  allocations wait for the end of a 60 s read lease.
- test_peer_ssd_eviction: an offset_allocator tier evicts in the
  manager's LRU order.

Part 3: feat(umbp): offset_allocator SSD tier packs same-size records without padding

OffsetAllocator rounds every allocation up to its size class (3 mantissa
bits) and keeps the whole class.  A 13,635,584 B KV record (3,329 units of
4 KiB) held 3,584 units, 7.66% padding.  The tier counts what an
allocation holds, so a drive of KV records held only ~92% of its capacity
as live data.

- createAligned(..., exact_fit) puts the allocator in exact-fit mode: an
  allocation holds exactly its granularity units.  A freed hole of a
  record's own size sits in the bin below the request's round-up bin,
  where the O(1) search never looks.  So the request tries, in this order:
    1. a few nodes of that bin (the first that fits, which keeps larger
       holes whole),
    2. the larger bins,
    3. the whole bin.
  It fails only if no free node can hold it.  The default mode is
  unchanged, so SpdkSsdTier and the SPDK proxy behave as before.
  umbp_offset_allocator replays three fixed random traces (4M operations):
    - a mostly full 1 GiB range,
    - a 4096-node limit,
    - a 32 TiB range with 16 KiB granularity.
  It matches the hash of every offset and metric that 74ec17c's
  allocator gives for them.
- The offset_allocator tier uses it.  Same-size records pack with no
  padding, and the next record reuses a freed allocation at once.  Freed
  neighbours coalesce, so space moves between record sizes as soon as it
  is free.
- canAllocate() is the exact test for the starved state.  The tier
  reports a need while the last refused record fits no free range.
  It does not compare with the largest free bin, which undercounts holes
  that are not a bin size.

Measured with test_ssd_offset_allocator_layout at full size (13 MiB KV
records, a 256 MiB tier with 10x its capacity written):
- 13 MiB records fill a 32.5-record tier to 32 records (98.5% live, 0%
  padding).  It was 30 with 7.66% padding.
- A 1 / 2.5 / 13 MiB mix is 97.6% live on average when a write is
  refused, with oldest-first eviction (was 90.1%).  With random victims,
  it is 90.9% (was 85.6%).
The test now runs 16x smaller, where the mix is 98.3% and 88.8%.  It uses
a 209-unit record, one unit over a size class as the 3,329-unit one is.
It writes 4x the capacity.

The end-to-end run used the WEKA trace replica (Qwen3.8-27B TP4, 70
users, 1 TiB SSD pool, SSD watermarks 0.97/0.93).  With this change, the
offset_allocator layout hit 39.0-39.7% (3 runs).  32 MiB segments at the
same watermarks hit 34.9-38.0%.

Tests: umbp_offset_allocator (new, CPU only) checks:
- the default-mode traces above.
- allocationSize() in both modes and past ~15 TiB.
- exact fit packs 32 KV-size records into 32.5 records' room and reuses
  each freed hole at its own offset.
- freed neighbours coalesce.
- over 200k random operations in each mode:
    - no two allocations overlap.
    - canAllocate() always predicts allocate().
    - an exact-fit refusal (other than for want of a node) leaves no gap
      that fits.
- the node limit refuses with bytes free.

Part 4: fix(umbp): a refused offset_allocator write starts one eviction pass

A Kimi-K3 prefill peer with UMBP_SSD_LAYOUT=offset_allocator at the
0.99/0.97 watermarks refused 7 writes on its 454 GB drive. Each write
needed 11,874,304 B in one piece while 4,967,755,776 B were free. But the
largest free range was 11,849,728 B, so the tier refused the write as
fragmented. One commit failed. The watermark keeps 1% of a drive free,
and KV objects of mixed sizes (1-12 MB) cut that into holes smaller than
the largest record.

A refused write must start eviction, also below the watermark. This is
the starved rule (Part 2). When the tier refuses a record because no free
range holds it, Capacity() still reports the real use. The tier also
reports a contiguous need of the record's size:
  - TierBackend::ContiguousNeedBytes(), through PeerSsdManager.
  - TierCapacity::contiguous_need_bytes from SsdBackend::Capacity().
  - the offset_allocator_contiguous_need_bytes gauge.
PeerPool's watermark pass runs for a need, also below the high watermark.
Such a pass has the budget from full to the low watermark. It stops when the need clears and the use is at the
low watermark. One of these events clears the need:
  - a key is evicted.
  - a record of that size or larger is placed.
  - a free range of that size exists.
So one refusal starts one eviction pass. The pass does not start again
on each 100 ms poll. This is also true while freed allocations wait for
the GDS read lease. A write that is refused again starts one more pass.
A record over 1/8 of the drive does not start a pass. Other backends
report no need, so their eviction does not change. The master does not
get the need.

The tier also reports its largest free range. The largest free node is
in the top non-empty bin. OffsetAllocator::largestFreeRange() scans the
nodes of that bin, so the value is exact. get_metrics() gives only a
lower bound. SsdBackend sets max_allocatable_bytes to at most this range.
So the router does not send a record larger than the largest range to
that drive. The GDS lease cap (capacity - allocated) stays.

In an offline replay, refused writes are about 0.2% of writes, and each
one starts one eviction pass.

ShardedSsdTier: a shard with a need counts as full for placement. When
every shard is full or has a need, a new record goes to the shard whose
largest free range holds it. The record's 4 KiB prefix counts. The tier
does not refuse it. Records that have a shard but are not written yet
(a batch, or concurrent writes) count against that range. Thus the
records of one batch spread over the shards. The sharded tier reports
the largest shard need. It
reports 0 when one shard has a free range for that need, because
placement then puts the record there.

Limits:
  - LRU order does not aim at contiguity. On a fragmented drive, one
    eviction batch can evict more than the hole needs, or it can make no
    hole. Then the write is refused again and starts one more pass.
  - The router compares the value size with max_allocatable_bytes. The
    record also holds a 4 KiB prefix. So the drive can refuse a value
    just under the largest range, and that refusal starts one pass.

Tests (no GPU):
- RefusedRecordsDoNotKeepTheTierEvicting: a refused 8-record write makes
  the tier report its real use and a need of 8 records. One pass evicts
  one key, and the need clears. A write that is
  refused again gets one more eviction. A refused 40-record write (over
  1/8 of the drive) gets none.
- RefusedRecordUnderTheReadLeaseGetsOneBatch: a write refused while
  freed allocations wait for the read lease gets one eviction. It fits
  when the lease ends.
- ShardsWithANeedStillTakeARecordThatFits: two shards with a need still
  take a record that fits a hole. The sharded need clears when one shard
  has a free range for it.
- LargestFreeRangeIsExact: the largest free range equals a brute-force
  walk of the gaps between records. A record of that size fits. A record
  4 KiB larger does not.
- ShardFallbackCountsTheRecordsOfABatch: two shards each have a need
  and one 32 KiB free range. A batch of eight 8 KiB records puts 4 on
  each shard, and all 8 fit. Before, all 8 went to the first shard and 4
  failed.
- ShardFallbackCountsConcurrentWrites: the same with 8 concurrent Write
  calls.
- ShardFallbackSeesEveryRangeOfTheTopBin: 71 free ranges in one bin. The
  largest (897,024 B) is the last node of the bin. get_metrics() reads
  64 nodes and gives 856,064 B. The sharded tier reports 897,024 B and
  places a record of that size.
- PoolEvictsAFragmentedOffsetAllocatorTierUnderItsWatermark (Part 2) runs
  the real PeerPool pass: a refused put leads to one eviction round
  through the need, and the put that follows fits. Capacity() reports the
  real use, and max_allocatable_bytes is the largest free range.
- AContiguousNeedGetsOnePassUnderTheHighWatermark (test_peer_pool): a
  mock backend at 10% use gets no pass without a need. With a need, it
  gets one pass.

The layout test binary (umbp_ssd_offset_allocator_layout) now writes
0.83 GB through write syscalls (measured on a local workstation). Before
it was made smaller, it wrote 62.4 GB in 21.2 s on vllm-001.

Part 5: perf(umbp): offset_allocator SSD tier defaults to 0.99/0.97 watermarks

With UMBP_SSD_LAYOUT=offset_allocator, the SSD tier frees each key's
allocation the moment the key is evicted.  So the eviction band only has
to absorb the writes that land while a pass runs.  The default band
(0.9/0.7) keeps 10-30% of the tier empty, and the hit rate follows the
live bytes.  Hit rate by SSD high/low watermark, measured on the WEKA
trace replica (Qwen3.8-27B TP4, 40-day trace, 70 users, 1 TiB SSD pool,
offset_allocator layout):

  0.95/0.90   33.3%
  0.97/0.93   39.7%
  0.98/0.95   43.7%
  0.99/0.97   47.5%, 49.0% (2 runs)
  DRAM tier   46.7-47.8%  (same 1 TiB, DRAM watermarks 0.97/0.93)

Every run had 0 write failures.  At 0.99/0.97, the SSD tier matches DRAM.
0.9/0.7 itself was not run.  It holds less live data than 0.95/0.90.

ssd.high_watermark / low_watermark are now optional.  Unset, the band
follows the layout, however it was chosen (UMBP_SSD_LAYOUT, C++ or
Python).  UMBPSsdConfig::EffectiveWatermarks() gives:
  - 0.99 / 0.97 for the offset_allocator layout on the file backend.
  - 0.9 / 0.7 for the segment log and for the SPDK backends, which
    ignore the layout.
PoolClient and Validate() use it.  The standalone client passes its
server each watermark that the config sets.  For a watermark that the
config does not set, it removes UMBP_SSD_HIGH_WM / UMBP_SSD_LOW_WM from
the server's environment.
Thus the server derives the same band, also when the client inherited
these variables.  Python reads None until a watermark is set.
ssd.effective_watermarks() gives the band.  UMBP_SSD_HIGH_WM /
UMBP_SSD_LOW_WM still override.  One set alone keeps the other's default.
Validate() rejects a band with low >= high and names the values, as
before.  For example, UMBP_SSD_HIGH_WM=0.95 alone under offset_allocator
gives 0.95 / 0.97, a startup error.  It needs UMBP_SSD_LOW_WM too.

In a tiered UMBP_BACKEND_POLICY, the tier's high_watermark and
low_watermark are now optional.  A tier that sets one or both uses its
band, as before (an unset value is 0.9 / 0.7).  An SSD in a tier that
sets neither uses its own band, so offset_allocator keeps 0.99 / 0.97.
Before this change, such an SSD got 0.9 / 0.7.

The segment layout keeps 0.9/0.7.  It returns disk a whole segment at a
time (ROCm#775), and it counts dead records until then.  segment_index.cpp
refuses a write once disk_used + record > capacity.  Its segment size is
capped at 1/8 of a drive's share (kMinSegmentsPerTier in ssd_tier.cpp).
This cap makes one pass of the 0.9 -> 0.7 band span a couple of segments.
A 0.99/0.97 band is 2% of the drive.  Segments are larger than that in
two cases:
  - the default 4 GiB segments on any drive share under ~200 GiB.
  - every tier near the 1/8 cap.
Then one pass cannot empty a segment.  So nothing is freed while the 1%
above the high watermark fills, and writes are refused.  This was not
measured.  It follows from the code.

Tests in umbp_ssd_offset_allocator_layout:
  - WatermarksFollowTheLayout: the layout set from code, an SPDK backend,
    one watermark set alone.
  - EnvFlag: the layout from the env, a caller that returns to the
    segment log, overrides.
Test in umbp_storage_config:
  - ServerGetsTheWatermarksOfTheClient: the client inherited
    UMBP_SSD_HIGH_WM=0.95 and sets neither watermark.  The server gets
    0.99 / 0.97.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant