@@ -1394,7 +1394,7 @@ class CacheAllocator : public CacheBase {
1394
1394
1395
1395
private:
1396
1396
// wrapper around Item's refcount and active handle tracking
1397
- FOLLY_ALWAYS_INLINE RefcountWithFlags::incResult incRef (Item& it, bool failIfMoving );
1397
+ FOLLY_ALWAYS_INLINE RefcountWithFlags::incResult incRef (Item& it);
1398
1398
FOLLY_ALWAYS_INLINE RefcountWithFlags::Value decRef (Item& it);
1399
1399
1400
1400
// drops the refcount and if needed, frees the allocation back to the memory
@@ -1552,6 +1552,26 @@ class CacheAllocator : public CacheBase {
1552
1552
WriteHandle allocateChainedItemInternal (const ReadHandle& parent,
1553
1553
uint32_t size);
1554
1554
1555
+ // Allocate a chained item to a specific tier
1556
+ //
1557
+ // The resulting chained item does not have a parent item yet
1558
+ // and if we fail to link to the chain for any reasoin
1559
+ // the chained item will be freed once the handle is dropped.
1560
+ //
1561
+ // The parent item parameter here is mainly used to find the
1562
+ // correct pool to allocate memory for this chained item
1563
+ //
1564
+ // @param parent parent item
1565
+ // @param size the size for the chained allocation
1566
+ // @param tid the tier to allocate on
1567
+ //
1568
+ // @return handle to the chained allocation
1569
+ // @throw std::invalid_argument if the size requested is invalid or
1570
+ // if the item is invalid
1571
+ WriteHandle allocateChainedItemInternalTier (const Item& parent,
1572
+ uint32_t size,
1573
+ TierId tid);
1574
+
1555
1575
// Given an item and its parentKey, validate that the parentKey
1556
1576
// corresponds to an item that's the parent of the supplied item.
1557
1577
//
@@ -1632,19 +1652,17 @@ class CacheAllocator : public CacheBase {
1632
1652
//
1633
1653
// @return true If the move was completed, and the containers were updated
1634
1654
// successfully.
1635
- bool moveRegularItemWithSync (Item& oldItem, WriteHandle& newItemHdl);
1655
+ bool moveRegularItem (Item& oldItem, WriteHandle& newItemHdl);
1636
1656
1637
- // Moves a regular item to a different slab. This should only be used during
1638
- // slab release after the item's exclusive bit has been set. The user supplied
1639
- // callback is responsible for copying the contents and fixing the semantics
1640
- // of chained item.
1657
+ // Moves a chained item to a different memory tier.
1641
1658
//
1642
- // @param oldItem item being moved
1659
+ // @param oldItem Reference to the item being moved
1643
1660
// @param newItemHdl Reference to the handle of the new item being moved into
1661
+ // @param parentHandle Reference to the handle of the parent item
1644
1662
//
1645
1663
// @return true If the move was completed, and the containers were updated
1646
1664
// successfully.
1647
- bool moveRegularItem (Item & oldItem, WriteHandle& newItemHdl);
1665
+ bool moveChainedItem (ChainedItem & oldItem, WriteHandle& newItemHdl, Item& parentItem );
1648
1666
1649
1667
// template class for viewAsChainedAllocs that takes either ReadHandle or
1650
1668
// WriteHandle
@@ -1657,29 +1675,12 @@ class CacheAllocator : public CacheBase {
1657
1675
template <typename Handle>
1658
1676
folly::IOBuf convertToIOBufT (Handle& handle);
1659
1677
1660
- // Moves a chained item to a different slab. This should only be used during
1661
- // slab release after the item's exclusive bit has been set. The user supplied
1662
- // callback is responsible for copying the contents and fixing the semantics
1663
- // of chained item.
1664
- //
1665
- // Note: If we have successfully moved the old item into the new, the
1666
- // newItemHdl is reset and no longer usable by the caller.
1667
- //
1668
- // @param oldItem Reference to the item being moved
1669
- // @param newItemHdl Reference to the handle of the new item being
1670
- // moved into
1671
- //
1672
- // @return true If the move was completed, and the containers were updated
1673
- // successfully.
1674
- bool moveChainedItem (ChainedItem& oldItem, WriteHandle& newItemHdl);
1675
-
1676
1678
// Transfers the chain ownership from parent to newParent. Parent
1677
1679
// will be unmarked as having chained allocations. Parent will not be null
1678
1680
// after calling this API.
1679
1681
//
1680
- // Parent and NewParent must be valid handles to items with same key and
1681
- // parent must have chained items and parent handle must be the only
1682
- // outstanding handle for parent. New parent must be without any chained item
1682
+ // NewParent must be valid handles to item with same key as Parent and
1683
+ // Parent must have chained items. New parent must be without any chained item
1683
1684
// handles.
1684
1685
//
1685
1686
// Chained item lock for the parent's key needs to be held in exclusive mode.
@@ -1688,7 +1689,7 @@ class CacheAllocator : public CacheBase {
1688
1689
// @param newParent the new parent for the chain
1689
1690
//
1690
1691
// @throw if any of the conditions for parent or newParent are not met.
1691
- void transferChainLocked (WriteHandle & parent, WriteHandle& newParent);
1692
+ void transferChainLocked (Item & parent, WriteHandle& newParent);
1692
1693
1693
1694
// replace a chained item in the existing chain. This needs to be called
1694
1695
// with the chained item lock held exclusive
@@ -1702,6 +1703,24 @@ class CacheAllocator : public CacheBase {
1702
1703
WriteHandle newItemHdl,
1703
1704
const Item& parent);
1704
1705
1706
+ //
1707
+ // Performs the actual inplace replace - it is called from
1708
+ // moveChainedItem and replaceChainedItemLocked
1709
+ // must hold chainedItemLock
1710
+ //
1711
+ // @param oldItem the item we are replacing in the chain
1712
+ // @param newItem the item we are replacing it with
1713
+ // @param parent the parent for the chain
1714
+ // @param fromMove used to determine if the replaced was called from
1715
+ // moveChainedItem - we avoid the handle destructor
1716
+ // in this case.
1717
+ //
1718
+ // @return handle to the oldItem
1719
+ void replaceInChainLocked (Item& oldItem,
1720
+ WriteHandle& newItemHdl,
1721
+ const Item& parent,
1722
+ bool fromMove);
1723
+
1705
1724
// Insert an item into MM container. The caller must hold a valid handle for
1706
1725
// the item.
1707
1726
//
@@ -2016,7 +2035,7 @@ auto& mmContainer = getMMContainer(tid, pid, cid);
2016
2035
throw std::runtime_error (" Not supported for chained items" );
2017
2036
}
2018
2037
2019
- if (candidate->markMoving (true )) {
2038
+ if (candidate->markMoving ()) {
2020
2039
mmContainer.remove (itr);
2021
2040
candidates.push_back (candidate);
2022
2041
} else {
@@ -2089,7 +2108,7 @@ auto& mmContainer = getMMContainer(tid, pid, cid);
2089
2108
2090
2109
// TODO: only allow it for read-only items?
2091
2110
// or implement mvcc
2092
- if (candidate->markMoving (true )) {
2111
+ if (candidate->markMoving ()) {
2093
2112
// promotions should rarely fail since we already marked moving
2094
2113
mmContainer.remove (itr);
2095
2114
candidates.push_back (candidate);
0 commit comments