@@ -1387,7 +1387,7 @@ class CacheAllocator : public CacheBase {
13871387
13881388 private:
13891389 // wrapper around Item's refcount and active handle tracking
1390- FOLLY_ALWAYS_INLINE RefcountWithFlags::incResult incRef (Item& it, bool failIfMoving );
1390+ FOLLY_ALWAYS_INLINE RefcountWithFlags::incResult incRef (Item& it);
13911391 FOLLY_ALWAYS_INLINE RefcountWithFlags::Value decRef (Item& it);
13921392
13931393 // drops the refcount and if needed, frees the allocation back to the memory
@@ -1551,6 +1551,26 @@ class CacheAllocator : public CacheBase {
15511551 WriteHandle allocateChainedItemInternal (const ReadHandle& parent,
15521552 uint32_t size);
15531553
1554+ // Allocate a chained item to a specific tier
1555+ //
1556+ // The resulting chained item does not have a parent item yet
1557+ // and if we fail to link to the chain for any reasoin
1558+ // the chained item will be freed once the handle is dropped.
1559+ //
1560+ // The parent item parameter here is mainly used to find the
1561+ // correct pool to allocate memory for this chained item
1562+ //
1563+ // @param parent parent item
1564+ // @param size the size for the chained allocation
1565+ // @param tid the tier to allocate on
1566+ //
1567+ // @return handle to the chained allocation
1568+ // @throw std::invalid_argument if the size requested is invalid or
1569+ // if the item is invalid
1570+ WriteHandle allocateChainedItemInternalTier (const Item& parent,
1571+ uint32_t size,
1572+ TierId tid);
1573+
15541574 // Given an item and its parentKey, validate that the parentKey
15551575 // corresponds to an item that's the parent of the supplied item.
15561576 //
@@ -1626,19 +1646,17 @@ class CacheAllocator : public CacheBase {
16261646 //
16271647 // @return true If the move was completed, and the containers were updated
16281648 // successfully.
1629- bool moveRegularItemWithSync (Item& oldItem, WriteHandle& newItemHdl);
1649+ bool moveRegularItem (Item& oldItem, WriteHandle& newItemHdl);
16301650
1631- // Moves a regular item to a different slab. This should only be used during
1632- // slab release after the item's exclusive bit has been set. The user supplied
1633- // callback is responsible for copying the contents and fixing the semantics
1634- // of chained item.
1651+ // Moves a chained item to a different memory tier.
16351652 //
1636- // @param oldItem item being moved
1653+ // @param oldItem Reference to the item being moved
16371654 // @param newItemHdl Reference to the handle of the new item being moved into
1655+ // @param parentHandle Reference to the handle of the parent item
16381656 //
16391657 // @return true If the move was completed, and the containers were updated
16401658 // successfully.
1641- bool moveRegularItem (Item & oldItem, WriteHandle& newItemHdl);
1659+ bool moveChainedItem (ChainedItem & oldItem, WriteHandle& newItemHdl, Item& parentItem );
16421660
16431661 // template class for viewAsChainedAllocs that takes either ReadHandle or
16441662 // WriteHandle
@@ -1651,29 +1669,12 @@ class CacheAllocator : public CacheBase {
16511669 template <typename Handle>
16521670 folly::IOBuf convertToIOBufT (Handle& handle);
16531671
1654- // Moves a chained item to a different slab. This should only be used during
1655- // slab release after the item's exclusive bit has been set. The user supplied
1656- // callback is responsible for copying the contents and fixing the semantics
1657- // of chained item.
1658- //
1659- // Note: If we have successfully moved the old item into the new, the
1660- // newItemHdl is reset and no longer usable by the caller.
1661- //
1662- // @param oldItem Reference to the item being moved
1663- // @param newItemHdl Reference to the handle of the new item being
1664- // moved into
1665- //
1666- // @return true If the move was completed, and the containers were updated
1667- // successfully.
1668- bool moveChainedItem (ChainedItem& oldItem, WriteHandle& newItemHdl);
1669-
16701672 // Transfers the chain ownership from parent to newParent. Parent
16711673 // will be unmarked as having chained allocations. Parent will not be null
16721674 // after calling this API.
16731675 //
1674- // Parent and NewParent must be valid handles to items with same key and
1675- // parent must have chained items and parent handle must be the only
1676- // outstanding handle for parent. New parent must be without any chained item
1676+ // NewParent must be valid handles to item with same key as Parent and
1677+ // Parent must have chained items. New parent must be without any chained item
16771678 // handles.
16781679 //
16791680 // Chained item lock for the parent's key needs to be held in exclusive mode.
@@ -1682,7 +1683,7 @@ class CacheAllocator : public CacheBase {
16821683 // @param newParent the new parent for the chain
16831684 //
16841685 // @throw if any of the conditions for parent or newParent are not met.
1685- void transferChainLocked (WriteHandle & parent, WriteHandle& newParent);
1686+ void transferChainLocked (Item & parent, WriteHandle& newParent);
16861687
16871688 // replace a chained item in the existing chain. This needs to be called
16881689 // with the chained item lock held exclusive
@@ -1696,6 +1697,24 @@ class CacheAllocator : public CacheBase {
16961697 WriteHandle newItemHdl,
16971698 const Item& parent);
16981699
1700+ //
1701+ // Performs the actual inplace replace - it is called from
1702+ // moveChainedItem and replaceChainedItemLocked
1703+ // must hold chainedItemLock
1704+ //
1705+ // @param oldItem the item we are replacing in the chain
1706+ // @param newItem the item we are replacing it with
1707+ // @param parent the parent for the chain
1708+ // @param fromMove used to determine if the replaced was called from
1709+ // moveChainedItem - we avoid the handle destructor
1710+ // in this case.
1711+ //
1712+ // @return handle to the oldItem
1713+ void replaceInChainLocked (Item& oldItem,
1714+ WriteHandle& newItemHdl,
1715+ const Item& parent,
1716+ bool fromMove);
1717+
16991718 // Insert an item into MM container. The caller must hold a valid handle for
17001719 // the item.
17011720 //
@@ -1986,7 +2005,7 @@ auto& mmContainer = getMMContainer(tid, pid, cid);
19862005 throw std::runtime_error (" Not supported for chained items" );
19872006 }
19882007
1989- if (candidate->markMoving (true )) {
2008+ if (candidate->markMoving ()) {
19902009 mmContainer.remove (itr);
19912010 candidates.push_back (candidate);
19922011 } else {
@@ -2059,7 +2078,7 @@ auto& mmContainer = getMMContainer(tid, pid, cid);
20592078
20602079 // TODO: only allow it for read-only items?
20612080 // or implement mvcc
2062- if (candidate->markMoving (true )) {
2081+ if (candidate->markMoving ()) {
20632082 // promotions should rarely fail since we already marked moving
20642083 mmContainer.remove (itr);
20652084 candidates.push_back (candidate);
0 commit comments