Skip to content

Commit 9c0f36a

Browse files
authored
split background data eviction between dsa and memcpy using bernoulli distribution (pmem#7)
1 parent 162f342 commit 9c0f36a

File tree

1 file changed

+23
-13
lines changed

1 file changed

+23
-13
lines changed

cachelib/allocator/CacheAllocator.h

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include <optional>
3535
#include <stdexcept>
3636
#include <utility>
37+
#include <random>
3738

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

2222+
std::default_random_engine generator;
2223+
std::bernoulli_distribution distribution(0.5);
2224+
22212225
for (auto index = 0U; index < candidates.size(); index++) {
22222226
XDCHECK_EQ(newItemHandles[index].get(),newItemPtr[index]);
22232227
if (newItemHandles[index].get() != newItemPtr[index]) {
@@ -2232,25 +2236,31 @@ auto& mmContainer = getMMContainer(tid, pid, cid);
22322236
XDCHECK_EQ(newItemHandles[index]->getRefCount(), 1);
22332237
XDCHECK_EQ(candidates[index]->getRefCount(), 0);
22342238

2235-
dml::const_data_view srcView = dml::make_view(
2239+
if (distribution(generator)) {
2240+
dml::const_data_view srcView = dml::make_view(
22362241
reinterpret_cast<uint8_t*>(candidates[index]->getMemory()),
22372242
candidates[index]->getSize());
2238-
dml::data_view dstView = dml::make_view(
2243+
dml::data_view dstView = dml::make_view(
22392244
reinterpret_cast<uint8_t*>(newItemHandles[index]->getMemory()),
22402245
newItemHandles[index]->getSize());
2241-
(*stats_.dsaEvictionSubmits)[tid][pid][cid].inc();
2242-
if (config_.dsaAsync) {
2243-
dmlHandles.emplace_back(
2246+
(*stats_.dsaEvictionSubmits)[tid][pid][cid].inc();
2247+
if (config_.dsaAsync) {
2248+
dmlHandles.emplace_back(
22442249
dml::submit<dml::hardware>(dml::mem_copy, srcView, dstView));
2245-
} else {
2246-
auto dmlHandle =
2247-
dml::submit<dml::hardware>(dml::mem_copy, srcView, dstView);
2248-
auto result = dmlHandle.get();
2249-
if (result.status != dml::status_code::ok) {
2250-
std::string error = dsa_error_string(result);
2251-
throw std::runtime_error(folly::sformat("dml error: {} for item: {}", error, candidates[index]->toString()));
2250+
} else {
2251+
auto dmlHandle = dml::submit<dml::hardware>(dml::mem_copy, srcView, dstView);
2252+
auto result = dmlHandle.get();
2253+
if (result.status != dml::status_code::ok) {
2254+
std::string error = dsa_error_string(result);
2255+
throw std::runtime_error(folly::sformat("dml error: {} for item: {} count {}",
2256+
error, candidates[index]->toString(), (*stats_.dsaEvictionSubmits)[tid][pid][cid].get()));
2257+
}
2258+
XDCHECK_EQ(result.status,dml::status_code::ok);
22522259
}
2253-
XDCHECK_EQ(result.status,dml::status_code::ok);
2260+
} else {
2261+
std::memcpy(newItemHandles[index]->getMemory(),
2262+
candidates[index]->getMemory(),
2263+
candidates[index]->getSize());
22542264
}
22552265
}
22562266
if (config_.dsaAsync) {

0 commit comments

Comments
 (0)