@@ -823,28 +823,29 @@ CacheAllocator<CacheTrait>::releaseBackToAllocator(Item& it,
823
823
824
824
removeFromMMContainer (*head);
825
825
826
- // If this chained item is marked as exclusive , we will not free it.
827
- // We must capture the exclusive state before we do the decRef when
826
+ // If this chained item is marked as moving , we will not free it.
827
+ // We must capture the moving state before we do the decRef when
828
828
// we know the item must still be valid
829
- const bool wasExclusive = head->isExclusive ();
829
+ const bool wasMoving = head->isMoving ();
830
+ XDCHECK (!head->isMarkedForEviction ());
830
831
831
832
// Decref and check if we were the last reference. Now if the item
832
- // was marked exclusive , after decRef, it will be free to be released
833
+ // was marked moving , after decRef, it will be free to be released
833
834
// by slab release thread
834
835
const auto childRef = head->decRef ();
835
836
836
- // If the item is already exclusive and we already decremented the
837
+ // If the item is already moving and we already decremented the
837
838
// refcount, we don't need to free this item. We'll let the slab
838
839
// release thread take care of that
839
- if (!wasExclusive ) {
840
+ if (!wasMoving ) {
840
841
if (childRef != 0 ) {
841
842
throw std::runtime_error (folly::sformat (
842
843
" chained item refcount is not zero. We cannot proceed! "
843
844
" Ref: {}, Chained Item: {}" ,
844
845
childRef, head->toString ()));
845
846
}
846
847
847
- // Item is not exclusive and refcount is 0, we can proceed to
848
+ // Item is not moving and refcount is 0, we can proceed to
848
849
// free it or recylce the memory
849
850
if (head == toRecycle) {
850
851
XDCHECK (ReleaseRes::kReleased != res);
@@ -1170,7 +1171,7 @@ bool CacheAllocator<CacheTrait>::moveChainedItem(ChainedItem& oldItem,
1170
1171
1171
1172
// This item has been unlinked from its parent and we're the only
1172
1173
// owner of it, so we're done here
1173
- if (!oldItem.isInMMContainer () || oldItem.isOnlyExclusive ()) {
1174
+ if (!oldItem.isInMMContainer () || oldItem.isOnlyMoving ()) {
1174
1175
return false ;
1175
1176
}
1176
1177
@@ -1201,7 +1202,7 @@ bool CacheAllocator<CacheTrait>::moveChainedItem(ChainedItem& oldItem,
1201
1202
1202
1203
// In case someone else had removed this chained item from its parent by now
1203
1204
// So we check again to see if the it has been unlinked from its parent
1204
- if (!oldItem.isInMMContainer () || oldItem.isOnlyExclusive ()) {
1205
+ if (!oldItem.isInMMContainer () || oldItem.isOnlyMoving ()) {
1205
1206
return false ;
1206
1207
}
1207
1208
@@ -1217,7 +1218,7 @@ bool CacheAllocator<CacheTrait>::moveChainedItem(ChainedItem& oldItem,
1217
1218
// parent's chain and the MMContainer.
1218
1219
auto oldItemHandle =
1219
1220
replaceChainedItemLocked (oldItem, std::move (newItemHdl), *parentHandle);
1220
- XDCHECK (oldItemHandle->isExclusive ());
1221
+ XDCHECK (oldItemHandle->isMoving ());
1221
1222
XDCHECK (!oldItemHandle->isInMMContainer ());
1222
1223
1223
1224
return true ;
@@ -1246,7 +1247,7 @@ CacheAllocator<CacheTrait>::findEviction(PoolId pid, ClassId cid) {
1246
1247
: toRecycle;
1247
1248
1248
1249
// make sure no other thead is evicting the item
1249
- if (candidate->getRefCount () != 0 || !candidate->markExclusive ()) {
1250
+ if (candidate->getRefCount () != 0 || !candidate->markMoving ()) {
1250
1251
++itr;
1251
1252
continue ;
1252
1253
}
@@ -1261,11 +1262,11 @@ CacheAllocator<CacheTrait>::findEviction(PoolId pid, ClassId cid) {
1261
1262
? advanceIteratorAndTryEvictChainedItem (itr)
1262
1263
: advanceIteratorAndTryEvictRegularItem (mmContainer, itr);
1263
1264
evictionSuccessful = toReleaseHandle != nullptr ;
1264
- // destroy toReleseHandle . The item won't be released to allocator
1265
- // since we marked it as exclusive .
1265
+ // destroy toReleaseHandle . The item won't be released to allocator
1266
+ // since we marked for eviction .
1266
1267
}
1267
1268
1268
- const auto ref = candidate->unmarkExclusive ();
1269
+ const auto ref = candidate->unmarkMoving ();
1269
1270
if (ref == 0u ) {
1270
1271
// Invalidate iterator since later on we may use this mmContainer
1271
1272
// again, which cannot be done unless we drop this iterator
@@ -2352,7 +2353,7 @@ void CacheAllocator<CacheTrait>::releaseSlabImpl(
2352
2353
// Need to mark an item for release before proceeding
2353
2354
// If we can't mark as moving, it means the item is already freed
2354
2355
const bool isAlreadyFreed =
2355
- !markExclusiveForSlabRelease (releaseContext, alloc, throttler);
2356
+ !markMovingForSlabRelease (releaseContext, alloc, throttler);
2356
2357
if (isAlreadyFreed) {
2357
2358
continue ;
2358
2359
}
@@ -2397,8 +2398,8 @@ bool CacheAllocator<CacheTrait>::moveForSlabRelease(
2397
2398
stats_.numMoveAttempts .inc ();
2398
2399
2399
2400
// Nothing to move and the key is likely also bogus for chained items.
2400
- if (oldItem.isOnlyExclusive ()) {
2401
- oldItem.unmarkExclusive ();
2401
+ if (oldItem.isOnlyMoving ()) {
2402
+ oldItem.unmarkMoving ();
2402
2403
const auto res =
2403
2404
releaseBackToAllocator (oldItem, RemoveContext::kNormal , false );
2404
2405
XDCHECK (res == ReleaseRes::kReleased );
@@ -2437,7 +2438,7 @@ bool CacheAllocator<CacheTrait>::moveForSlabRelease(
2437
2438
// that's identical to this one to replace it. Here we just need to wait
2438
2439
// until all users have dropped the item handles before we can proceed.
2439
2440
startTime = util::getCurrentTimeSec ();
2440
- while (!oldItem.isOnlyExclusive ()) {
2441
+ while (!oldItem.isOnlyMoving ()) {
2441
2442
throttleWith (throttler, [&] {
2442
2443
XLOGF (WARN,
2443
2444
" Spent {} seconds, slab release still waiting for refcount to "
@@ -2491,8 +2492,8 @@ CacheAllocator<CacheTrait>::allocateNewItemForOldItem(const Item& oldItem) {
2491
2492
return {};
2492
2493
}
2493
2494
2494
- // Set up the destination for the move. Since oldChainedItem would have
2495
- // the exclusive bit set , it won't be picked for eviction.
2495
+ // Set up the destination for the move. Since oldChainedItem would be
2496
+ // marked as moving , it won't be picked for eviction.
2496
2497
auto newItemHdl =
2497
2498
allocateChainedItemInternal (parentHandle, oldChainedItem.getSize ());
2498
2499
if (!newItemHdl) {
@@ -2544,7 +2545,7 @@ bool CacheAllocator<CacheTrait>::tryMovingForSlabRelease(
2544
2545
// item is still valid.
2545
2546
const std::string parentKey =
2546
2547
oldItem.asChainedItem ().getParentItem (compressor_).getKey ().str ();
2547
- if (oldItem.isOnlyExclusive ()) {
2548
+ if (oldItem.isOnlyMoving ()) {
2548
2549
// If chained item no longer has a refcount, its parent is already
2549
2550
// being released, so we abort this try to moving.
2550
2551
return false ;
@@ -2574,10 +2575,10 @@ void CacheAllocator<CacheTrait>::evictForSlabRelease(
2574
2575
stats_.numEvictionAttempts .inc ();
2575
2576
2576
2577
// if the item is already in a state where only the exclusive bit is set,
2577
- // nothing needs to be done. We simply need to unmark exclusive bit and free
2578
+ // nothing needs to be done. We simply need to call unmarkMoving and free
2578
2579
// the item.
2579
- if (item.isOnlyExclusive ()) {
2580
- item.unmarkExclusive ();
2580
+ if (item.isOnlyMoving ()) {
2581
+ item.unmarkMoving ();
2581
2582
const auto res =
2582
2583
releaseBackToAllocator (item, RemoveContext::kNormal , false );
2583
2584
XDCHECK (ReleaseRes::kReleased == res);
@@ -2608,7 +2609,7 @@ void CacheAllocator<CacheTrait>::evictForSlabRelease(
2608
2609
stats_.numEvictionSuccesses .inc ();
2609
2610
2610
2611
// we have the last handle. no longer need to hold on to the exclusive bit
2611
- item.unmarkExclusive ();
2612
+ item.unmarkMoving ();
2612
2613
2613
2614
// manually decrement the refcount to call releaseBackToAllocator
2614
2615
const auto ref = decRef (*owningHandle);
@@ -2620,7 +2621,7 @@ void CacheAllocator<CacheTrait>::evictForSlabRelease(
2620
2621
}
2621
2622
2622
2623
if (shutDownInProgress_) {
2623
- item.unmarkExclusive ();
2624
+ item.unmarkMoving ();
2624
2625
allocator_->abortSlabRelease (ctx);
2625
2626
throw exception::SlabReleaseAborted (
2626
2627
folly::sformat (" Slab Release aborted while trying to evict"
@@ -2766,9 +2767,9 @@ CacheAllocator<CacheTrait>::advanceIteratorAndTryEvictChainedItem(
2766
2767
template <typename CacheTrait>
2767
2768
typename CacheAllocator<CacheTrait>::WriteHandle
2768
2769
CacheAllocator<CacheTrait>::evictNormalItemForSlabRelease(Item& item) {
2769
- XDCHECK (item.isExclusive ());
2770
+ XDCHECK (item.isMoving ());
2770
2771
2771
- if (item.isOnlyExclusive ()) {
2772
+ if (item.isOnlyMoving ()) {
2772
2773
return WriteHandle{};
2773
2774
}
2774
2775
@@ -2780,7 +2781,7 @@ CacheAllocator<CacheTrait>::evictNormalItemForSlabRelease(Item& item) {
2780
2781
2781
2782
// We remove the item from both access and mm containers. It doesn't matter
2782
2783
// if someone else calls remove on the item at this moment, the item cannot
2783
- // be freed as long as we have the exclusive bit set .
2784
+ // be freed as long as it's marked for eviction .
2784
2785
auto handle = accessContainer_->removeIf (item, std::move (predicate));
2785
2786
2786
2787
if (!handle) {
@@ -2804,7 +2805,7 @@ CacheAllocator<CacheTrait>::evictNormalItemForSlabRelease(Item& item) {
2804
2805
template <typename CacheTrait>
2805
2806
typename CacheAllocator<CacheTrait>::WriteHandle
2806
2807
CacheAllocator<CacheTrait>::evictChainedItemForSlabRelease(ChainedItem& child) {
2807
- XDCHECK (child.isExclusive ());
2808
+ XDCHECK (child.isMoving ());
2808
2809
2809
2810
// We have the child marked as moving, but dont know anything about the
2810
2811
// state of the parent. Unlike the case of regular eviction where we are
@@ -2826,7 +2827,7 @@ CacheAllocator<CacheTrait>::evictChainedItemForSlabRelease(ChainedItem& child) {
2826
2827
// check if the child is still in mmContainer and the expected parent is
2827
2828
// valid under the chained item lock.
2828
2829
if (expectedParent.getKey () != parentKey || !child.isInMMContainer () ||
2829
- child.isOnlyExclusive () ||
2830
+ child.isOnlyMoving () ||
2830
2831
&expectedParent != &child.getParentItem (compressor_) ||
2831
2832
!expectedParent.isAccessible () || !expectedParent.hasChainedItem ()) {
2832
2833
return {};
@@ -2881,14 +2882,14 @@ CacheAllocator<CacheTrait>::evictChainedItemForSlabRelease(ChainedItem& child) {
2881
2882
2882
2883
// In case someone else had removed this chained item from its parent by now
2883
2884
// So we check again to see if it has been unlinked from its parent
2884
- if (!child.isInMMContainer () || child.isOnlyExclusive ()) {
2885
+ if (!child.isInMMContainer () || child.isOnlyMoving ()) {
2885
2886
return {};
2886
2887
}
2887
2888
2888
2889
// check after removing from the MMContainer that the parent is still not
2889
2890
// being marked as moving. If parent is moving, it will release the child
2890
2891
// item and we will wait for that.
2891
- if (parentHandle->isExclusive ()) {
2892
+ if (parentHandle->isMoving ()) {
2892
2893
return {};
2893
2894
}
2894
2895
@@ -2921,7 +2922,7 @@ bool CacheAllocator<CacheTrait>::removeIfExpired(const ReadHandle& handle) {
2921
2922
}
2922
2923
2923
2924
template <typename CacheTrait>
2924
- bool CacheAllocator<CacheTrait>::markExclusiveForSlabRelease (
2925
+ bool CacheAllocator<CacheTrait>::markMovingForSlabRelease (
2925
2926
const SlabReleaseContext& ctx, void * alloc, util::Throttler& throttler) {
2926
2927
// MemoryAllocator::processAllocForRelease will execute the callback
2927
2928
// if the item is not already free. So there are three outcomes here:
@@ -2940,7 +2941,7 @@ bool CacheAllocator<CacheTrait>::markExclusiveForSlabRelease(
2940
2941
// Since this callback is executed, the item is not yet freed
2941
2942
itemFreed = false ;
2942
2943
Item* item = static_cast <Item*>(memory);
2943
- if (item->markExclusive ()) {
2944
+ if (item->markMoving ()) {
2944
2945
markedMoving = true ;
2945
2946
}
2946
2947
};
0 commit comments