@@ -1387,7 +1387,7 @@ class CacheAllocator : public CacheBase {
1387
1387
1388
1388
private:
1389
1389
// 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);
1391
1391
FOLLY_ALWAYS_INLINE RefcountWithFlags::Value decRef (Item& it);
1392
1392
1393
1393
// drops the refcount and if needed, frees the allocation back to the memory
@@ -1551,6 +1551,26 @@ class CacheAllocator : public CacheBase {
1551
1551
WriteHandle allocateChainedItemInternal (const ReadHandle& parent,
1552
1552
uint32_t size);
1553
1553
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
+
1554
1574
// Given an item and its parentKey, validate that the parentKey
1555
1575
// corresponds to an item that's the parent of the supplied item.
1556
1576
//
@@ -1626,19 +1646,17 @@ class CacheAllocator : public CacheBase {
1626
1646
//
1627
1647
// @return true If the move was completed, and the containers were updated
1628
1648
// successfully.
1629
- bool moveRegularItemWithSync (Item& oldItem, WriteHandle& newItemHdl);
1649
+ bool moveRegularItem (Item& oldItem, WriteHandle& newItemHdl);
1630
1650
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.
1635
1652
//
1636
- // @param oldItem item being moved
1653
+ // @param oldItem Reference to the item being moved
1637
1654
// @param newItemHdl Reference to the handle of the new item being moved into
1655
+ // @param parentHandle Reference to the handle of the parent item
1638
1656
//
1639
1657
// @return true If the move was completed, and the containers were updated
1640
1658
// successfully.
1641
- bool moveRegularItem (Item & oldItem, WriteHandle& newItemHdl);
1659
+ bool moveChainedItem (ChainedItem & oldItem, WriteHandle& newItemHdl, Item& parentItem );
1642
1660
1643
1661
// template class for viewAsChainedAllocs that takes either ReadHandle or
1644
1662
// WriteHandle
@@ -1651,29 +1669,12 @@ class CacheAllocator : public CacheBase {
1651
1669
template <typename Handle >
1652
1670
folly::IOBuf convertToIOBufT (Handle & handle);
1653
1671
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
-
1670
1672
// Transfers the chain ownership from parent to newParent. Parent
1671
1673
// will be unmarked as having chained allocations. Parent will not be null
1672
1674
// after calling this API.
1673
1675
//
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
1677
1678
// handles.
1678
1679
//
1679
1680
// Chained item lock for the parent's key needs to be held in exclusive mode.
@@ -1682,7 +1683,7 @@ class CacheAllocator : public CacheBase {
1682
1683
// @param newParent the new parent for the chain
1683
1684
//
1684
1685
// @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);
1686
1687
1687
1688
// replace a chained item in the existing chain. This needs to be called
1688
1689
// with the chained item lock held exclusive
@@ -1696,6 +1697,24 @@ class CacheAllocator : public CacheBase {
1696
1697
WriteHandle newItemHdl,
1697
1698
const Item& parent);
1698
1699
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
+
1699
1718
// Insert an item into MM container. The caller must hold a valid handle for
1700
1719
// the item.
1701
1720
//
@@ -1986,7 +2005,7 @@ auto& mmContainer = getMMContainer(tid, pid, cid);
1986
2005
throw std::runtime_error (" Not supported for chained items" );
1987
2006
}
1988
2007
1989
- if (candidate->markMoving (true )) {
2008
+ if (candidate->markMoving ()) {
1990
2009
mmContainer.remove (itr);
1991
2010
candidates.push_back (candidate);
1992
2011
} else {
@@ -2059,7 +2078,7 @@ auto& mmContainer = getMMContainer(tid, pid, cid);
2059
2078
2060
2079
// TODO: only allow it for read-only items?
2061
2080
// or implement mvcc
2062
- if (candidate->markMoving (true )) {
2081
+ if (candidate->markMoving ()) {
2063
2082
// promotions should rarely fail since we already marked moving
2064
2083
mmContainer.remove (itr);
2065
2084
candidates.push_back (candidate);
0 commit comments