Victim block cache size budget undercounts memory and can exceed maxSizeBytes hard cap

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Unresolved
    • Priority: Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • Storage Engines - Persistence
    • ALL
    • SE Persistence backlog
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      Background

      The victim block cache is sized and evicted by bytes: SizedLRUCache tracks _curSize and evicts least-recently-used entries while _curSize > _maxSize. The per-entry size is computed by GetCacheItemSize:

      struct GetCacheItemSize {
          std::size_t operator()(const CacheItem& item) const {
              return item->data.capacity();
          }
      };
      

      (See src/mongo/db/modules/atlas/src/disagg_storage/pali/block_cache/pali_block_cache.h and sized_lru_cache.h.)

      Problem

      GetCacheItemSize counts only the page payload (data.capacity()). It excludes the per-entry overhead that the cache actually allocates for each entry:

      • the std::list node (the ListEntry pair plus list pointers),
      • the stdx::unordered_map node,
      • the CacheItemContent struct metadata (the lsn, backlink_lsn, base_lsn, checkpoint ids, delta_count fields, plus the SharedBuffer holder),
      • allocator/SharedBuffer headers.

      As a result the cache's true memory footprint exceeds the configured maxSizeBytes by roughly count * per-entry-overhead. Eviction keeps only the summed payload bytes under the limit, not the real footprint.

      Atlas relies on maxSizeBytes as a hard memory cap — exceeding it risks OOM. The current accounting therefore allows the process to use more memory than the operator configured, with the overshoot scaling with the number of cached entries (worst case: many small pages).

      Proposed work

      Make the size accounting reflect real memory use so eviction keeps the true footprint within maxSizeBytes. Options:

      • Add a fixed per-entry overhead constant to the size function so each entry is charged payload + overhead, or
      • Otherwise reserve headroom in the budget.

      Note the interaction with the kPageSize assumption tracked in SERVER-121337 — both concern how accurately the cache models per-entry memory cost, and should be considered together.

      Add/extend unit tests in sized_lru_cache_test.cpp to assert the tracked size accounts for overhead and that eviction respects the true cap.

            Assignee:
            Unassigned
            Reporter:
            Etienne Petrel
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: