Skip to content

Commit 6a54c6c

Browse files
rlyerlymeta-codesync[bot]
authored andcommitted
Add getSlabMemoryInfo() for IO registration
Summary: Expose CacheLib slab memory base address and size via public API. This allows IO operations (e.g., RDMA, io_uring) to pre-register the entire cache arena for zero-copy get/put operations, avoiding per-API overhead. Returns the user-visible slab data region only, excluding internal slab headers at the start of the memory arena. This prevents IO from corrupting CacheLib metadata. Reviewed By: AlnisM Differential Revision: D110330084 fbshipit-source-id: 87811ebfb14f714b16689811de89efdaf30dcc97
1 parent e178997 commit 6a54c6c

3 files changed

Lines changed: 19 additions & 0 deletions

File tree

cachelib/allocator/CacheAllocator.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1283,6 +1283,12 @@ class CacheAllocator : public CacheBase {
12831283
// return cache's memory usage stats
12841284
CacheMemoryStats getCacheMemoryStats() const override final;
12851285

1286+
// Return slab memory base address and size; useful for APIs that want to
1287+
// pre-register buffers to avoid IO overhead (e.g., mapping pages in kernel).
1288+
std::pair<const void*, size_t> getSlabMemoryInfo() const noexcept {
1289+
return allocator_->getSlabMemoryInfo();
1290+
}
1291+
12861292
// return the nvm cache stats map
12871293
util::StatsMap getNvmCacheStatsMap() const override final;
12881294

cachelib/allocator/memory/MemoryAllocator.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,11 @@ class MemoryAllocator {
499499
return (slab && slabAllocator_.isValidSlab(slab));
500500
}
501501

502+
// Get slab memory base address and size
503+
std::pair<const void*, size_t> getSlabMemoryInfo() const noexcept {
504+
return slabAllocator_.getSlabMemoryInfo();
505+
}
506+
502507
// fetch the allocation size for the pool id and class id.
503508
//
504509
// @param pid the pool id

cachelib/allocator/memory/SlabAllocator.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,14 @@ class SlabAllocator {
363363
#endif
364364
}
365365

366+
// Returns the user-visible slab data region, excluding internal slab headers
367+
// at the start of the memory arena.
368+
std::pair<const void*, size_t> getSlabMemoryInfo() const noexcept {
369+
auto slabStart = reinterpret_cast<uintptr_t>(slabMemoryStart_);
370+
auto memStart = reinterpret_cast<uintptr_t>(memoryStart_);
371+
return {slabMemoryStart_, memorySize_ - (slabStart - memStart)};
372+
}
373+
366374
private:
367375
// null Slab* presenttation. With 4M Slab size, a valid slab index would never
368376
// reach 2^16 - 1;

0 commit comments

Comments
 (0)