Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cachelib/allocator/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ add_library (cachelib_allocator
CacheAllocatorLru5BCacheWithSpinBuckets.cpp
CacheAllocatorLruCache.cpp
CacheAllocatorLruCacheWithSpinBuckets.cpp
CacheAllocatorS3FIFOCache.cpp
CacheAllocatorS3FIFO5BCache.cpp
CacheAllocatorTinyLFU5BCache.cpp
CacheAllocatorTinyLFUCache.cpp
CacheAllocatorWTinyLFU5BCache.cpp
Expand Down
10 changes: 10 additions & 0 deletions cachelib/allocator/CacheAllocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -6077,6 +6077,7 @@ namespace facebook::cachelib {
extern template class CacheAllocator<LruCacheTrait>;
extern template class CacheAllocator<LruCacheWithSpinBucketsTrait>;
extern template class CacheAllocator<Lru2QCacheTrait>;
extern template class CacheAllocator<S3FIFOCacheTrait>;
extern template class CacheAllocator<TinyLFUCacheTrait>;
extern template class CacheAllocator<WTinyLFUCacheTrait>;

Expand All @@ -6098,6 +6099,15 @@ using LruAllocatorSpinBuckets = CacheAllocator<LruCacheWithSpinBucketsTrait>;
using Lru2QAllocator = CacheAllocator<Lru2QCacheTrait>;
using Lru5B2QAllocator = CacheAllocator<Lru5B2QCacheTrait>;

// CacheAllocator with S3 FIFO eviction policy
// It maintains 2 queues, one for for probation and one for the main queue.
// New items are added to the probation queue, and if not accessed
// will be quickly removed from the cache to remove 1 hit wonders.
// If accessed while in probation, it will eventually be promoted to the main queue.
// Items in the tail of main queue will be reinserted if accessed.
using S3FIFOAllocator = CacheAllocator<S3FIFOCacheTrait>;
using S3FIFO5BAllocator = CacheAllocator<S3FIFO5BCacheTrait>;

// CacheAllocator with Tiny LFU eviction policy
// It has a window initially to gauage the frequency of accesses of newly
// inserted items. And eventually it will onl admit items that are accessed
Expand Down
21 changes: 21 additions & 0 deletions cachelib/allocator/CacheAllocatorS3FIFO5BCache.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "cachelib/allocator/CacheAllocator.h"

namespace facebook::cachelib {
template class CacheAllocator<S3FIFO5BCacheTrait>;
}
21 changes: 21 additions & 0 deletions cachelib/allocator/CacheAllocatorS3FIFOCache.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "cachelib/allocator/CacheAllocator.h"

namespace facebook::cachelib {
template class CacheAllocator<S3FIFOCacheTrait>;
}
15 changes: 15 additions & 0 deletions cachelib/allocator/CacheTraits.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "cachelib/allocator/ChainedHashTable.h"
#include "cachelib/allocator/MM2Q.h"
#include "cachelib/allocator/MMLru.h"
#include "cachelib/allocator/MMS3FIFO.h"
#include "cachelib/allocator/MMTinyLFU.h"
#include "cachelib/allocator/MMWTinyLFU.h"
#include "cachelib/allocator/memory/CompressedPtr.h"
Expand Down Expand Up @@ -54,6 +55,13 @@ struct Lru2QCacheTrait {
using CompressedPtrType = CompressedPtr4B;
};

struct S3FIFOCacheTrait {
using MMType = MMS3FIFO;
using AccessType = ChainedHashTable;
using AccessTypeLocks = SharedMutexBuckets;
using CompressedPtrType = CompressedPtr4B;
};

struct TinyLFUCacheTrait {
using MMType = MMTinyLFU;
using AccessType = ChainedHashTable;
Expand Down Expand Up @@ -89,6 +97,13 @@ struct Lru5B2QCacheTrait {
using CompressedPtrType = CompressedPtr5B;
};

struct S3FIFO5BCacheTrait {
using MMType = MMS3FIFO;
using AccessType = ChainedHashTable;
using AccessTypeLocks = SharedMutexBuckets;
using CompressedPtrType = CompressedPtr5B;
};

struct TinyLFU5BCacheTrait {
using MMType = MMTinyLFU;
using AccessType = ChainedHashTable;
Expand Down
2 changes: 2 additions & 0 deletions cachelib/allocator/ContainerTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "cachelib/allocator/ChainedHashTable.h"
#include "cachelib/allocator/MM2Q.h"
#include "cachelib/allocator/MMLru.h"
#include "cachelib/allocator/MMS3FIFO.h"
#include "cachelib/allocator/MMTinyLFU.h"
#include "cachelib/allocator/MMWTinyLFU.h"
namespace facebook::cachelib {
Expand All @@ -26,6 +27,7 @@ const int MMLru::kId = 1;
const int MM2Q::kId = 2;
const int MMTinyLFU::kId = 3;
const int MMWTinyLFU::kId = 4;
const int MMS3FIFO::kId = 5;

// AccessType
const int ChainedHashTable::kId = 1;
Expand Down
Loading