Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
c0c90d2
Run centos and debian workflows on push and PR
igchor Nov 2, 2021
dbe3fda
Adds createPutToken and switches findEviction
byrnedj Feb 4, 2023
9afcd64
Add memory usage statistics for allocation classes
igchor Jul 6, 2022
eca7d8c
Initial multi-tier support implementation
igchor Sep 28, 2021
664da8d
AC stats multi-tier
byrnedj Jan 17, 2023
3b7bb0c
Tests and fix tier sizing
byrnedj Feb 8, 2023
58e825b
This is the additional multi-tier support needed
guptask Nov 14, 2022
9fc705f
Rolling average alloc latency
guptask Jul 21, 2022
ce0e38a
Rolling average class latency
guptask Jul 21, 2022
e0a8006
MM2Q promotion iterator
byrnedj Aug 9, 2022
bcb2ae2
Multi-tier allocator patch
byrnedj Feb 7, 2023
d4cf1d4
basic multi-tier test based on numa bindings
igchor Dec 30, 2021
6d2fbef
Aadding new configs to hit_ratio/graph_cache_leader_fobj
vinser52 Jan 27, 2022
5bfa1ff
Background data movement for the tiers
byrnedj Oct 21, 2022
1593291
dummy change to trigger container image rebuild
guptask Mar 28, 2023
a171f38
Updated the docker gcc version to 12 (#83)
guptask May 9, 2023
35a17e4
NUMA bindigs support for private memory (#82)
vinser52 May 17, 2023
46d168c
Do not run cachelib-centos-8-5 on PRs (#85)
igchor Jun 6, 2023
7d06531
Add option to insert items to first free tier (#87)
igchor Jun 8, 2023
1521efe
Chained item movement between tiers - sync on the parent item (#84)
byrnedj Jun 28, 2023
3328e4e
edit dockerfile
byrnedj Jul 24, 2023
3c87c49
Track latency of per item eviction/promotion between memory tiers
guptask Jul 28, 2023
795f85b
Update dependencies (#95)
igchor Aug 23, 2023
96d948f
enable DTO build without memcpy changes to cachebench
byrnedj Feb 28, 2024
47d5034
Bckground eviction for multi-tier
byrnedj Feb 28, 2024
efea480
no online eviction option patch
byrnedj Feb 28, 2024
ebfca17
fixes cmake in latest test removal (upstream test build fails - need …
byrnedj May 20, 2024
52618b5
fixes commit for now (should drop once https://github.com/facebook/Ca…
byrnedj May 28, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
MM2Q promotion iterator
-----------------------

Hot queue iterator for 2Q. Will start at Hot queue and move to Warm queue if hot queue is exhausted. Useful for promotion semantics if using 2Q replacement. rebased on to develop and added some tests.
  • Loading branch information
byrnedj committed May 20, 2024
commit e0a80066f62e94431f43ebba0071db3a5d85df0f
14 changes: 14 additions & 0 deletions cachelib/allocator/MM2Q.h
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,11 @@ class MM2Q {
// Iterator passed as parameter.
template <typename F>
void withEvictionIterator(F&& f);

// Execute provided function under container lock. Function gets
// iterator passed as parameter.
template <typename F>
void withPromotionIterator(F&& f);

// Execute provided function under container lock.
template <typename F>
Expand Down Expand Up @@ -921,6 +926,15 @@ void MM2Q::Container<T, HookPtr>::withEvictionIterator(F&& fun) {
}
}

// returns the head of the hot queue for promotion
template <typename T, MM2Q::Hook<T> T::*HookPtr>
template <typename F>
void
MM2Q::Container<T, HookPtr>::withPromotionIterator(F&& fun) {
lruMutex_->lock_combine([this, &fun]() {
fun(LockedIterator{LockHolder{}, lru_.begin(LruType::Hot)});
});
}
template <typename T, MM2Q::Hook<T> T::*HookPtr>
template <typename F>
void MM2Q::Container<T, HookPtr>::withContainerLock(F&& fun) {
Expand Down
4 changes: 4 additions & 0 deletions cachelib/allocator/datastruct/DList.h
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,10 @@ class DList {
curr_ = dir_ == Direction::FROM_HEAD ? dlist_->head_ : dlist_->tail_;
}

Direction getDirection() noexcept {
return dir_;
}

protected:
void goForward() noexcept;
void goBackward() noexcept;
Expand Down
72 changes: 62 additions & 10 deletions cachelib/allocator/datastruct/MultiDList.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,18 @@ class MultiDList {
}

explicit Iterator(const MultiDList<T, HookPtr>& mlist,
size_t listIdx) noexcept
size_t listIdx, bool head) noexcept
: currIter_(mlist.lists_[mlist.lists_.size() - 1]->rbegin()),
mlist_(mlist) {
XDCHECK_LT(listIdx, mlist.lists_.size());
initToValidRBeginFrom(listIdx);
if (head) {
initToValidBeginFrom(listIdx);
} else {
initToValidRBeginFrom(listIdx);
}
// We should either point to an element or the end() iterator
// which has an invalid index_.
XDCHECK(index_ == kInvalidIndex || currIter_.get() != nullptr);
XDCHECK(index_ == kInvalidIndex || index_ == mlist.lists_.size() || currIter_.get() != nullptr);
}
virtual ~Iterator() = default;

Expand Down Expand Up @@ -167,6 +171,9 @@ class MultiDList {

// reset iterator to the beginning of a speicific queue
void initToValidRBeginFrom(size_t listIdx) noexcept;

// reset iterator to the head of a specific queue
void initToValidBeginFrom(size_t listIdx) noexcept;

// Index of current list
size_t index_{0};
Expand All @@ -182,6 +189,9 @@ class MultiDList {

// provides an iterator starting from the tail of a specific list.
Iterator rbegin(size_t idx) const;

// provides an iterator starting from the head of a specific list.
Iterator begin(size_t idx) const;

// Iterator to compare against for the end.
Iterator rend() const noexcept;
Expand All @@ -201,12 +211,26 @@ void MultiDList<T, HookPtr>::Iterator::goForward() noexcept {
}
// Move iterator forward
++currIter_;
// If we land at the rend of this list, move to the previous list.
while (index_ != kInvalidIndex &&
currIter_ == mlist_.lists_[index_]->rend()) {
--index_;
if (index_ != kInvalidIndex) {
currIter_ = mlist_.lists_[index_]->rbegin();

if (currIter_.getDirection() == DListIterator::Direction::FROM_HEAD) {
// If we land at the rend of this list, move to the previous list.
while (index_ != kInvalidIndex && index_ != mlist_.lists_.size() &&
currIter_ == mlist_.lists_[index_]->end()) {
++index_;
if (index_ != kInvalidIndex && index_ != mlist_.lists_.size()) {
currIter_ = mlist_.lists_[index_]->begin();
} else {
return;
}
}
} else {
// If we land at the rend of this list, move to the previous list.
while (index_ != kInvalidIndex &&
currIter_ == mlist_.lists_[index_]->rend()) {
--index_;
if (index_ != kInvalidIndex) {
currIter_ = mlist_.lists_[index_]->rbegin();
}
}
}
}
Expand Down Expand Up @@ -247,6 +271,25 @@ void MultiDList<T, HookPtr>::Iterator::initToValidRBeginFrom(
: mlist_.lists_[index_]->rbegin();
}

template <typename T, DListHook<T> T::*HookPtr>
void MultiDList<T, HookPtr>::Iterator::initToValidBeginFrom(
size_t listIdx) noexcept {
// Find the first non-empty list.
index_ = listIdx;
while (index_ != mlist_.lists_.size() &&
mlist_.lists_[index_]->size() == 0) {
++index_;
}
if (index_ == mlist_.lists_.size()) {
//we reached the end - we should get set to
//invalid index
index_ = std::numeric_limits<size_t>::max();
}
currIter_ = index_ == std::numeric_limits<size_t>::max()
? mlist_.lists_[0]->begin()
: mlist_.lists_[index_]->begin();
}

template <typename T, DListHook<T> T::*HookPtr>
typename MultiDList<T, HookPtr>::Iterator&
MultiDList<T, HookPtr>::Iterator::operator++() noexcept {
Expand All @@ -273,7 +316,16 @@ typename MultiDList<T, HookPtr>::Iterator MultiDList<T, HookPtr>::rbegin(
if (listIdx >= lists_.size()) {
throw std::invalid_argument("Invalid list index for MultiDList iterator.");
}
return MultiDList<T, HookPtr>::Iterator(*this, listIdx);
return MultiDList<T, HookPtr>::Iterator(*this, listIdx, false);
}

template <typename T, DListHook<T> T::*HookPtr>
typename MultiDList<T, HookPtr>::Iterator MultiDList<T, HookPtr>::begin(
size_t listIdx) const {
if (listIdx >= lists_.size()) {
throw std::invalid_argument("Invalid list index for MultiDList iterator.");
}
return MultiDList<T, HookPtr>::Iterator(*this, listIdx, true);
}

template <typename T, DListHook<T> T::*HookPtr>
Expand Down
33 changes: 33 additions & 0 deletions cachelib/allocator/tests/MM2QTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,19 @@ void MMTypeTest<MMType>::testIterate(std::vector<std::unique_ptr<Node>>& nodes,
}
}

template <typename MMType>
void MMTypeTest<MMType>::testIterateHot(std::vector<std::unique_ptr<Node>>& nodes,
Container& c) {
auto it = nodes.rbegin();
c.withPromotionIterator([&it,&c](auto &&it2q) {
while (it2q && c.isHot(*it2q)) {
ASSERT_EQ(it2q->getId(), (*it)->getId());
++it2q;
++it;
}
});
}

template <typename MMType>
void MMTypeTest<MMType>::testMatch(std::string expected,
MMTypeTest<MMType>::Container& c) {
Expand All @@ -238,6 +251,23 @@ void MMTypeTest<MMType>::testMatch(std::string expected,
ASSERT_EQ(expected, actual);
}

template <typename MMType>
void MMTypeTest<MMType>::testMatchHot(std::string expected,
MMTypeTest<MMType>::Container& c) {
int index = -1;
std::string actual;
c.withPromotionIterator([&c,&actual,&index](auto &&it2q) {
while (it2q) {
++index;
actual += folly::stringPrintf(
"%d:%s, ", it2q->getId(),
(c.isHot(*it2q) ? "H" : (c.isCold(*it2q) ? "C" : "W")));
++it2q;
}
});
ASSERT_EQ(expected, actual);
}

TEST_F(MM2QTest, DetailedTest) {
MM2Q::Config config;
config.lruRefreshTime = 0;
Expand All @@ -259,8 +289,11 @@ TEST_F(MM2QTest, DetailedTest) {
}

testIterate(nodes, c);
testIterateHot(nodes, c);

testMatch("0:C, 1:C, 2:C, 3:C, 4:H, 5:H, ", c);
testMatchHot("5:H, 4:H, 3:C, 2:C, 1:C, 0:C, ", c);

// Move 3 to top of the hot cache
c.recordAccess(*(nodes[4]), AccessMode::kRead);
testMatch("0:C, 1:C, 2:C, 3:C, 5:H, 4:H, ", c);
Expand Down