Skip to content

Cache Replacement Policy

When the cache device is full and a new chunk needs a slot, flexBlock evicts a clean chunk. The replacement policy decides which one. The default suits most workloads; this page explains it and the alternatives.

The default policy, twoq-meta, is a 2Q variant that understands filesystem metadata:

  • New chunks go to a probationary queue (A1in).
  • Filesystem metadata, which the kernel tags on each request, goes straight to a protected main queue (Am).
  • Recently evicted chunks are remembered, by identity only, in a ghost list (A1out). A chunk that comes back soon after eviction goes straight to Am.

The effect is that a large sequential scan passes through A1in and out again without evicting the working set held in Am.

lru is a plain least-recently-used policy. It suits workloads with no reuse structure. Under lru, the Am and A1out metrics stay at zero by design.

FlagDefaultMeaning
--a1in-ratio <R>0.25Fraction of slots for the probationary A1in queue, in (0.05, 0.50].
--a1out-multiple <M>0.5Ghost-list size as a multiple of slots, in [0.5, 64]; twoq-meta only. Holds identities, not data.
--cache-io-mode <direct|buffered>directWhether cache device I/O bypasses the page cache.
--cache-policy <lru|twoq-meta>twoq-metaReplacement policy.
--read-prefetch <N|off>32Largest window of chunks to fetch ahead of a sequential cold read, at most 64. Each is one chunk of speculative download.
Terminal window
sudo flexblock start /dev/nvme1n1p1 --cache-policy lru

When a cold read misses on a chunk just past an earlier miss, flexBlock treats it as a sequential scan. It fetches the next two chunks in the background and doubles that window each time a read or partial write reaches a prefetched chunk, up to --read-prefetch. A scan of cold data is then not paced by one object storage round trip per chunk, while a random read that spans a few chunks fetches only a few more. off disables prefetch.

WhatSeries
Hit rateflexblock_cache_hits_total against flexblock_cache_misses_total
Active policyflexblock_cache_policy_info (policy label)
Queue sizesflexblock_cache_a1in_size, flexblock_cache_am_size, flexblock_cache_a1out_size
Ghost-list reuseflexblock_cache_a1out_promotions_total
Prefetchflexblock_prefetch_issued_total, flexblock_prefetch_completed_total, flexblock_prefetch_failed_total

The full list is in the Metrics Reference.