@@ -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
@@ -1545,6 +1545,26 @@ class CacheAllocator : public CacheBase {
15451545 WriteHandle allocateChainedItemInternal (const ReadHandle& parent,
15461546 uint32_t size);
15471547
1548+ // Allocate a chained item to a specific tier
1549+ //
1550+ // The resulting chained item does not have a parent item yet
1551+ // and if we fail to link to the chain for any reasoin
1552+ // the chained item will be freed once the handle is dropped.
1553+ //
1554+ // The parent item parameter here is mainly used to find the
1555+ // correct pool to allocate memory for this chained item
1556+ //
1557+ // @param parent parent item
1558+ // @param size the size for the chained allocation
1559+ // @param tid the tier to allocate on
1560+ //
1561+ // @return handle to the chained allocation
1562+ // @throw std::invalid_argument if the size requested is invalid or
1563+ // if the item is invalid
1564+ WriteHandle allocateChainedItemInternalTier (const Item& parent,
1565+ uint32_t size,
1566+ TierId tid);
1567+
15481568 // Given an item and its parentKey, validate that the parentKey
15491569 // corresponds to an item that's the parent of the supplied item.
15501570 //
@@ -1620,19 +1640,17 @@ class CacheAllocator : public CacheBase {
16201640 //
16211641 // @return true If the move was completed, and the containers were updated
16221642 // successfully.
1623- bool moveRegularItemWithSync (Item& oldItem, WriteHandle& newItemHdl);
1643+ bool moveRegularItem (Item& oldItem, WriteHandle& newItemHdl);
16241644
1625- // Moves a regular item to a different slab. This should only be used during
1626- // slab release after the item's exclusive bit has been set. The user supplied
1627- // callback is responsible for copying the contents and fixing the semantics
1628- // of chained item.
1645+ // Moves a chained item to a different memory tier.
16291646 //
1630- // @param oldItem item being moved
1647+ // @param oldItem Reference to the item being moved
16311648 // @param newItemHdl Reference to the handle of the new item being moved into
1649+ // @param parentHandle Reference to the handle of the parent item
16321650 //
16331651 // @return true If the move was completed, and the containers were updated
16341652 // successfully.
1635- bool moveRegularItem (Item & oldItem, WriteHandle& newItemHdl);
1653+ bool moveChainedItem (ChainedItem & oldItem, WriteHandle& newItemHdl, Item& parentItem );
16361654
16371655 // template class for viewAsChainedAllocs that takes either ReadHandle or
16381656 // WriteHandle
@@ -1645,29 +1663,12 @@ class CacheAllocator : public CacheBase {
16451663 template <typename Handle>
16461664 folly::IOBuf convertToIOBufT (Handle& handle);
16471665
1648- // Moves a chained item to a different slab. This should only be used during
1649- // slab release after the item's exclusive bit has been set. The user supplied
1650- // callback is responsible for copying the contents and fixing the semantics
1651- // of chained item.
1652- //
1653- // Note: If we have successfully moved the old item into the new, the
1654- // newItemHdl is reset and no longer usable by the caller.
1655- //
1656- // @param oldItem Reference to the item being moved
1657- // @param newItemHdl Reference to the handle of the new item being
1658- // moved into
1659- //
1660- // @return true If the move was completed, and the containers were updated
1661- // successfully.
1662- bool moveChainedItem (ChainedItem& oldItem, WriteHandle& newItemHdl);
1663-
16641666 // Transfers the chain ownership from parent to newParent. Parent
16651667 // will be unmarked as having chained allocations. Parent will not be null
16661668 // after calling this API.
16671669 //
1668- // Parent and NewParent must be valid handles to items with same key and
1669- // parent must have chained items and parent handle must be the only
1670- // outstanding handle for parent. New parent must be without any chained item
1670+ // NewParent must be valid handles to item with same key as Parent and
1671+ // Parent must have chained items. New parent must be without any chained item
16711672 // handles.
16721673 //
16731674 // Chained item lock for the parent's key needs to be held in exclusive mode.
@@ -1676,7 +1677,7 @@ class CacheAllocator : public CacheBase {
16761677 // @param newParent the new parent for the chain
16771678 //
16781679 // @throw if any of the conditions for parent or newParent are not met.
1679- void transferChainLocked (WriteHandle & parent, WriteHandle& newParent);
1680+ void transferChainLocked (Item & parent, WriteHandle& newParent);
16801681
16811682 // replace a chained item in the existing chain. This needs to be called
16821683 // with the chained item lock held exclusive
@@ -1690,6 +1691,24 @@ class CacheAllocator : public CacheBase {
16901691 WriteHandle newItemHdl,
16911692 const Item& parent);
16921693
1694+ //
1695+ // Performs the actual inplace replace - it is called from
1696+ // moveChainedItem and replaceChainedItemLocked
1697+ // must hold chainedItemLock
1698+ //
1699+ // @param oldItem the item we are replacing in the chain
1700+ // @param newItem the item we are replacing it with
1701+ // @param parent the parent for the chain
1702+ // @param fromMove used to determine if the replaced was called from
1703+ // moveChainedItem - we avoid the handle destructor
1704+ // in this case.
1705+ //
1706+ // @return handle to the oldItem
1707+ void replaceInChainLocked (Item& oldItem,
1708+ WriteHandle& newItemHdl,
1709+ const Item& parent,
1710+ bool fromMove);
1711+
16931712 // Insert an item into MM container. The caller must hold a valid handle for
16941713 // the item.
16951714 //
@@ -1980,7 +1999,7 @@ auto& mmContainer = getMMContainer(tid, pid, cid);
19801999 throw std::runtime_error (" Not supported for chained items" );
19812000 }
19822001
1983- if (candidate->markMoving (true )) {
2002+ if (candidate->markMoving ()) {
19842003 mmContainer.remove (itr);
19852004 candidates.push_back (candidate);
19862005 } else {
@@ -2053,7 +2072,7 @@ auto& mmContainer = getMMContainer(tid, pid, cid);
20532072
20542073 // TODO: only allow it for read-only items?
20552074 // or implement mvcc
2056- if (candidate->markMoving (true )) {
2075+ if (candidate->markMoving ()) {
20572076 // promotions should rarely fail since we already marked moving
20582077 mmContainer.remove (itr);
20592078 candidates.push_back (candidate);
0 commit comments