Skip to content

Commit 2924c81

Browse files
add s3fifo
1 parent c5dd692 commit 2924c81

13 files changed

Lines changed: 1066 additions & 1 deletion

cachelib/allocator/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ add_library (cachelib_allocator
3333
CacheAllocatorLru5BCacheWithSpinBuckets.cpp
3434
CacheAllocatorLruCache.cpp
3535
CacheAllocatorLruCacheWithSpinBuckets.cpp
36+
CacheAllocatorS3FIFOCache.cpp
37+
CacheAllocatorS3FIFO5BCache.cpp
3638
CacheAllocatorTinyLFU5BCache.cpp
3739
CacheAllocatorTinyLFUCache.cpp
3840
CacheAllocatorWTinyLFU5BCache.cpp

cachelib/allocator/CacheAllocator.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6077,6 +6077,8 @@ namespace facebook::cachelib {
60776077
extern template class CacheAllocator<LruCacheTrait>;
60786078
extern template class CacheAllocator<LruCacheWithSpinBucketsTrait>;
60796079
extern template class CacheAllocator<Lru2QCacheTrait>;
6080+
extern template class CacheAllocator<S3FIFOCacheTrait>;
6081+
extern template class CacheAllocator<S3FIFO5BCacheTrait>;
60806082
extern template class CacheAllocator<TinyLFUCacheTrait>;
60816083
extern template class CacheAllocator<WTinyLFUCacheTrait>;
60826084

@@ -6098,6 +6100,15 @@ using LruAllocatorSpinBuckets = CacheAllocator<LruCacheWithSpinBucketsTrait>;
60986100
using Lru2QAllocator = CacheAllocator<Lru2QCacheTrait>;
60996101
using Lru5B2QAllocator = CacheAllocator<Lru5B2QCacheTrait>;
61006102

6103+
// CacheAllocator with S3 FIFO eviction policy
6104+
// It maintains 2 queues, one for for probation and one for the main queue.
6105+
// New items are added to the probation queue, and if not accessed
6106+
// will be quickly removed from the cache to remove 1 hit wonders.
6107+
// If accessed while in probation, it will eventually be promoted to the main queue.
6108+
// Items in the tail of main queue will be reinserted if accessed.
6109+
using S3FIFOAllocator = CacheAllocator<S3FIFOCacheTrait>;
6110+
using S3FIFO5BAllocator = CacheAllocator<S3FIFO5BCacheTrait>;
6111+
61016112
// CacheAllocator with Tiny LFU eviction policy
61026113
// It has a window initially to gauage the frequency of accesses of newly
61036114
// inserted items. And eventually it will onl admit items that are accessed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#include "cachelib/allocator/CacheAllocator.h"
18+
19+
namespace facebook::cachelib {
20+
template class CacheAllocator<S3FIFO5BCacheTrait>;
21+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#include "cachelib/allocator/CacheAllocator.h"
18+
19+
namespace facebook::cachelib {
20+
template class CacheAllocator<S3FIFOCacheTrait>;
21+
}

cachelib/allocator/CacheTraits.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "cachelib/allocator/ChainedHashTable.h"
1919
#include "cachelib/allocator/MM2Q.h"
2020
#include "cachelib/allocator/MMLru.h"
21+
#include "cachelib/allocator/MMS3FIFO.h"
2122
#include "cachelib/allocator/MMTinyLFU.h"
2223
#include "cachelib/allocator/MMWTinyLFU.h"
2324
#include "cachelib/allocator/memory/CompressedPtr.h"
@@ -54,6 +55,20 @@ struct Lru2QCacheTrait {
5455
using CompressedPtrType = CompressedPtr4B;
5556
};
5657

58+
struct S3FIFOCacheTrait {
59+
using MMType = MMS3FIFO;
60+
using AccessType = ChainedHashTable;
61+
using AccessTypeLocks = SharedMutexBuckets;
62+
using CompressedPtrType = CompressedPtr4B;
63+
};
64+
65+
struct S3FIFO5BCacheTrait {
66+
using MMType = MMS3FIFO;
67+
using AccessType = ChainedHashTable;
68+
using AccessTypeLocks = SharedMutexBuckets;
69+
using CompressedPtrType = CompressedPtr5B;
70+
};
71+
5772
struct TinyLFUCacheTrait {
5873
using MMType = MMTinyLFU;
5974
using AccessType = ChainedHashTable;

cachelib/allocator/ContainerTypes.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "cachelib/allocator/ChainedHashTable.h"
1818
#include "cachelib/allocator/MM2Q.h"
1919
#include "cachelib/allocator/MMLru.h"
20+
#include "cachelib/allocator/MMS3FIFO.h"
2021
#include "cachelib/allocator/MMTinyLFU.h"
2122
#include "cachelib/allocator/MMWTinyLFU.h"
2223
namespace facebook::cachelib {
@@ -26,6 +27,7 @@ const int MMLru::kId = 1;
2627
const int MM2Q::kId = 2;
2728
const int MMTinyLFU::kId = 3;
2829
const int MMWTinyLFU::kId = 4;
30+
const int MMS3FIFO::kId = 5;
2931

3032
// AccessType
3133
const int ChainedHashTable::kId = 1;

0 commit comments

Comments
 (0)