Skip to content

Commit 829a434

Browse files
authored
Merge pull request #19 from vinser52/fix_allocator_test
Fix ReaperSkippingSlabTraversalWhileSlabReleasing test
2 parents a4c4ab3 + 187bbf4 commit 829a434

File tree

3 files changed

+31
-16
lines changed

3 files changed

+31
-16
lines changed

cachelib/allocator/CacheAllocator-inl.h

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1641,7 +1641,13 @@ typename CacheAllocator<CacheTrait>::WriteHandle
16411641
CacheAllocator<CacheTrait>::tryEvictToNextMemoryTier(
16421642
TierId tid, PoolId pid, Item& item) {
16431643
if(item.isChainedItem()) return {}; // TODO: We do not support ChainedItem yet
1644-
if(item.isExpired()) return acquire(&item);
1644+
if(item.isExpired()) {
1645+
auto handle = removeIf(item, [](const Item& it) {
1646+
return it.getRefCount() == 0;
1647+
});
1648+
1649+
if (handle) { return handle; }
1650+
}
16451651

16461652
TierId nextTier = tid; // TODO - calculate this based on some admission policy
16471653
while (++nextTier < getNumTiers()) { // try to evict down to the next memory tiers
@@ -3067,16 +3073,12 @@ CacheAllocator<CacheTrait>::evictNormalItem(Item& item,
30673073
// We remove the item from both access and mm containers. It doesn't matter
30683074
// if someone else calls remove on the item at this moment, the item cannot
30693075
// be freed as long as we have the moving bit set.
3070-
auto handle = accessContainer_->removeIf(item, std::move(predicate));
3071-
3076+
auto handle = removeIf(item, std::move(predicate));
30723077
if (!handle) {
30733078
return handle;
30743079
}
30753080

3076-
XDCHECK_EQ(reinterpret_cast<uintptr_t>(handle.get()),
3077-
reinterpret_cast<uintptr_t>(&item));
30783081
XDCHECK_EQ(1u, handle->getRefCount());
3079-
removeFromMMContainer(item);
30803082

30813083
// now that we are the only handle and we actually removed something from
30823084
// the RAM cache, we enqueue it to nvmcache.
@@ -3188,6 +3190,21 @@ CacheAllocator<CacheTrait>::evictChainedItemForSlabRelease(ChainedItem& child) {
31883190
return parentHandle;
31893191
}
31903192

3193+
template <typename CacheTrait>
3194+
template <typename Fn>
3195+
typename CacheAllocator<CacheTrait>::WriteHandle
3196+
CacheAllocator<CacheTrait>::removeIf(Item& item, Fn&& predicate) {
3197+
auto handle = accessContainer_->removeIf(item, std::forward<Fn>(predicate));
3198+
3199+
if (handle) {
3200+
XDCHECK_EQ(reinterpret_cast<uintptr_t>(handle.get()),
3201+
reinterpret_cast<uintptr_t>(&item));
3202+
removeFromMMContainer(item);
3203+
}
3204+
3205+
return handle;
3206+
}
3207+
31913208
template <typename CacheTrait>
31923209
bool CacheAllocator<CacheTrait>::removeIfExpired(const ReadHandle& handle) {
31933210
if (!handle) {
@@ -3196,14 +3213,7 @@ bool CacheAllocator<CacheTrait>::removeIfExpired(const ReadHandle& handle) {
31963213

31973214
// We remove the item from both access and mm containers.
31983215
// We want to make sure the caller is the only one holding the handle.
3199-
auto removedHandle =
3200-
accessContainer_->removeIf(*(handle.getInternal()), itemExpiryPredicate);
3201-
if (removedHandle) {
3202-
removeFromMMContainer(*(handle.getInternal()));
3203-
return true;
3204-
}
3205-
3206-
return false;
3216+
return (bool)removeIf(*(handle.getInternal()), itemExpiryPredicate);
32073217
}
32083218

32093219
template <typename CacheTrait>

cachelib/allocator/CacheAllocator.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1806,6 +1806,12 @@ class CacheAllocator : public CacheBase {
18061806
// handle on failure. caller can retry.
18071807
WriteHandle evictChainedItemForSlabRelease(ChainedItem& item);
18081808

1809+
// Helper function to remove a item if predicates is true.
1810+
//
1811+
// @return last handle to the item on success. empty handle on failure.
1812+
template <typename Fn>
1813+
WriteHandle removeIf(Item& item, Fn&& predicate);
1814+
18091815
// Helper function to remove a item if expired.
18101816
//
18111817
// @return true if it item expire and removed successfully.

run_tests.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
#!/bin/bash
22

33
# Newline separated list of tests to ignore
4-
BLACKLIST="allocator-test-AllocatorTypeTest
5-
allocator-test-NavySetupTest
4+
BLACKLIST="allocator-test-NavySetupTest
65
shm-test-test_page_size"
76

87
if [ "$1" == "long" ]; then

0 commit comments

Comments
 (0)