Skip to content

Commit

Permalink
split background data eviction between dsa and memcpy using bernoulli…
Browse files Browse the repository at this point in the history
… distribution
  • Loading branch information
guptask committed May 8, 2023
1 parent 162f342 commit 1cf2437
Showing 1 changed file with 23 additions and 13 deletions.
36 changes: 23 additions & 13 deletions cachelib/allocator/CacheAllocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include <optional>
#include <stdexcept>
#include <utility>
#include <random>

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion"
Expand Down Expand Up @@ -2218,6 +2219,9 @@ auto& mmContainer = getMMContainer(tid, pid, cid);
std::allocator<dml::byte_t>>>();
//dmlHandles.reserve(validHandleCnt);

std::default_random_engine generator;
std::bernoulli_distribution distribution(0.5);

for (auto index = 0U; index < candidates.size(); index++) {
XDCHECK_EQ(newItemHandles[index].get(),newItemPtr[index]);
if (newItemHandles[index].get() != newItemPtr[index]) {
Expand All @@ -2232,25 +2236,31 @@ auto& mmContainer = getMMContainer(tid, pid, cid);
XDCHECK_EQ(newItemHandles[index]->getRefCount(), 1);
XDCHECK_EQ(candidates[index]->getRefCount(), 0);

dml::const_data_view srcView = dml::make_view(
if (distribution(generator)) {
dml::const_data_view srcView = dml::make_view(
reinterpret_cast<uint8_t*>(candidates[index]->getMemory()),
candidates[index]->getSize());
dml::data_view dstView = dml::make_view(
dml::data_view dstView = dml::make_view(
reinterpret_cast<uint8_t*>(newItemHandles[index]->getMemory()),
newItemHandles[index]->getSize());
(*stats_.dsaEvictionSubmits)[tid][pid][cid].inc();
if (config_.dsaAsync) {
dmlHandles.emplace_back(
(*stats_.dsaEvictionSubmits)[tid][pid][cid].inc();
if (config_.dsaAsync) {
dmlHandles.emplace_back(
dml::submit<dml::hardware>(dml::mem_copy, srcView, dstView));
} else {
auto dmlHandle =
dml::submit<dml::hardware>(dml::mem_copy, srcView, dstView);
auto result = dmlHandle.get();
if (result.status != dml::status_code::ok) {
std::string error = dsa_error_string(result);
throw std::runtime_error(folly::sformat("dml error: {} for item: {}", error, candidates[index]->toString()));
} else {
auto dmlHandle = dml::submit<dml::hardware>(dml::mem_copy, srcView, dstView);
auto result = dmlHandle.get();
if (result.status != dml::status_code::ok) {
std::string error = dsa_error_string(result);
throw std::runtime_error(folly::sformat("dml error: {} for item: {} count {}",
error, candidates[index]->toString(), (*stats_.dsaEvictionSubmits)[tid][pid][cid].get()));
}
XDCHECK_EQ(result.status,dml::status_code::ok);
}
XDCHECK_EQ(result.status,dml::status_code::ok);
} else {
std::memcpy(newItemHandles[index]->getMemory(),
candidates[index]->getMemory(),
candidates[index]->getSize());
}
}
if (config_.dsaAsync) {
Expand Down

0 comments on commit 1cf2437

Please sign in to comment.