Skip to content

Minimum Limit For Cache Allocation? #316

Closed

Description

@aaditya2200

Hi,

I have been using cachelib to build a swap space. I want the cache to be of a certain size based on an input parameter, and I have designed it as follows:

cache::cache(backing_store *bs, uint64_t n)
: backstore(bs), max_in_memory_objects(n) {
auto itemDestructor =
[&](const facebook::cachelib::LruAllocator::DestructorData &data) {
write_back(data.item);
};
Cache::Config config;
config.setCacheSize(1 * sizeof(object) * n)
.setCacheName("Lru_nodes")
.setAccessConfig({25, 10})
.setItemDestructor(itemDestructor)
.validate();
gcache_ = std::make_unique(config);
default_pool = gcache_->addPool("default_pool",
gcache_->getCacheMemoryStats().ramCacheSize);
}

n here is the cache size as an input parameter. What I have noticed is that for small values of n, the allocation fails with the error

E20240526 08:58:46.625504 68212 ExceptionTracer.cpp:222] exception stack complete
terminate called after throwing an instance of 'std::invalid_argument'
what(): not enough memory for slabs

The minimum n for which I can get an allocation seems to be 150K. I was wondering if there is any lower bound to the amount of memory we can allocate?

Activity

  1. therealgymmy commented on Jun 12, 2024

    @therealgymmy
    Contributor

    cachelib uses slab allocator underneath. The cache size needs to be a multiple of 4MBs. (Tho you don't have to specify the exact number we'll internally round down to 4MB-aligned size). Anyway that means you need to make the cache at least 2 Slabs. (we use 1 slab for internal metadata for other slabs).

    Typically I would suggest just make the cache 10 slabs or 100 slabs for testing.

  2. locked and limited conversation to collaborators on Jul 19, 2024
  3. converted this issue into a discussion #326 on Jul 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions