Skip to content

Commit 6a73cc4

Browse files
committed
chore(tiered): minor fixes + expose buffer allocation type stats
Signed-off-by: Roman Gershman <[email protected]>
1 parent 1dfb604 commit 6a73cc4

File tree

8 files changed

+38
-17
lines changed

8 files changed

+38
-17
lines changed

src/server/common.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,13 +258,15 @@ bool ParseDouble(string_view src, double* value) {
258258
#define ADD(x) (x) += o.x
259259

260260
TieredStats& TieredStats::operator+=(const TieredStats& o) {
261-
static_assert(sizeof(TieredStats) == 96);
261+
static_assert(sizeof(TieredStats) == 112);
262262

263263
ADD(total_stashes);
264264
ADD(total_fetches);
265265
ADD(total_cancels);
266266
ADD(total_deletes);
267267
ADD(total_defrags);
268+
ADD(total_heap_buf_allocs);
269+
ADD(total_registered_buf_allocs);
268270

269271
ADD(allocated_bytes);
270272
ADD(capacity_bytes);

src/server/common.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ struct TieredStats {
6666
size_t total_cancels = 0;
6767
size_t total_deletes = 0;
6868
size_t total_defrags = 0;
69+
size_t total_registered_buf_allocs = 0;
70+
size_t total_heap_buf_allocs = 0;
6971

7072
size_t allocated_bytes = 0;
7173
size_t capacity_bytes = 0;

src/server/debugcmd.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class DebugCmd {
1717
struct PopulateOptions {
1818
uint64_t total_count = 0;
1919
std::string_view prefix{"key"};
20-
uint32_t val_size = 0;
20+
uint32_t val_size = 16;
2121
bool populate_random_values = false;
2222
std::string_view type{"STRING"};
2323
uint32_t elements = 1;

src/server/server_family.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2175,7 +2175,8 @@ void ServerFamily::Info(CmdArgList args, ConnectionContext* cntx) {
21752175
append("tiered_total_fetches", m.tiered_stats.total_fetches);
21762176
append("tiered_total_cancels", m.tiered_stats.total_cancels);
21772177
append("tiered_total_deletes", m.tiered_stats.total_deletes);
2178-
append("tiered_total_deletes", m.tiered_stats.total_defrags);
2178+
append("tiered_heap_buf_allocations", m.tiered_stats.total_heap_buf_allocs);
2179+
append("tiered_registered_buf_allocations", m.tiered_stats.total_registered_buf_allocs);
21792180

21802181
append("tiered_allocated_bytes", m.tiered_stats.allocated_bytes);
21812182
append("tiered_capacity_bytes", m.tiered_stats.capacity_bytes);

src/server/tiered_storage.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,8 @@ TieredStats TieredStorage::GetStats() const {
331331
stats.pending_stash_cnt = op_stats.pending_stash_cnt;
332332
stats.allocated_bytes = op_stats.disk_stats.allocated_bytes;
333333
stats.capacity_bytes = op_stats.disk_stats.capacity_bytes;
334+
stats.total_heap_buf_allocs = op_stats.disk_stats.heap_buf_alloc_count;
335+
stats.total_registered_buf_allocs = op_stats.disk_stats.registered_buf_alloc_count;
334336
}
335337

336338
{ // SmallBins stats

src/server/tiering/disk_storage.cc

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
using namespace ::dfly::tiering::literals;
1717

18-
ABSL_FLAG(bool, backing_file_direct, false, "If true uses O_DIRECT to open backing files");
18+
ABSL_FLAG(bool, backing_file_direct, true, "If true uses O_DIRECT to open backing files");
1919

2020
ABSL_FLAG(uint64_t, registered_buffer_size, 512_KB,
2121
"Size of registered buffer for IoUring fixed read/writes");
@@ -39,16 +39,6 @@ void DestroyTmpBuf(UringBuf buf) {
3939
::operator delete[](buf.bytes.data(), std::align_val_t(kPageSize));
4040
}
4141

42-
UringBuf PrepareBuf(size_t size) {
43-
DCHECK_EQ(ProactorBase::me()->GetKind(), ProactorBase::IOURING);
44-
auto* up = static_cast<UringProactor*>(ProactorBase::me());
45-
46-
if (auto borrowed = up->RequestBuffer(size); borrowed)
47-
return *borrowed;
48-
else
49-
return AllocateTmpBuf(size);
50-
}
51-
5242
void ReturnBuf(UringBuf buf) {
5343
DCHECK_EQ(ProactorBase::me()->GetKind(), ProactorBase::IOURING);
5444
auto* up = static_cast<UringProactor*>(ProactorBase::me());
@@ -103,6 +93,8 @@ std::error_code DiskStorage::Open(std::string_view path) {
10393

10494
void DiskStorage::Close() {
10595
using namespace std::chrono_literals;
96+
97+
// TODO: to fix this polling.
10698
while (pending_ops_ > 0 || grow_pending_)
10799
util::ThisFiber::SleepFor(10ms);
108100

@@ -175,7 +167,7 @@ std::error_code DiskStorage::Stash(io::Bytes bytes, StashCb cb) {
175167
}
176168

177169
DiskStorage::Stats DiskStorage::GetStats() const {
178-
return {alloc_.allocated_bytes(), alloc_.capacity()};
170+
return {alloc_.allocated_bytes(), alloc_.capacity(), heap_buf_alloc_cnt_, reg_buf_alloc_cnt_};
179171
}
180172

181173
std::error_code DiskStorage::Grow(off_t grow_size) {
@@ -196,4 +188,16 @@ std::error_code DiskStorage::Grow(off_t grow_size) {
196188
return {};
197189
}
198190

191+
UringBuf DiskStorage::PrepareBuf(size_t size) {
192+
DCHECK_EQ(ProactorBase::me()->GetKind(), ProactorBase::IOURING);
193+
auto* up = static_cast<UringProactor*>(ProactorBase::me());
194+
195+
if (auto borrowed = up->RequestBuffer(size); borrowed) {
196+
++reg_buf_alloc_cnt_;
197+
return *borrowed;
198+
}
199+
++heap_buf_alloc_cnt_;
200+
return AllocateTmpBuf(size);
201+
}
202+
199203
} // namespace dfly::tiering

src/server/tiering/disk_storage.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "server/tiering/common.h"
1111
#include "server/tiering/external_alloc.h"
1212
#include "util/fibers/uring_file.h"
13+
#include "util/fibers/uring_proactor.h" // for UringBuf
1314

1415
namespace dfly::tiering {
1516

@@ -19,6 +20,8 @@ class DiskStorage {
1920
struct Stats {
2021
size_t allocated_bytes = 0;
2122
size_t capacity_bytes = 0;
23+
uint64_t heap_buf_alloc_count = 0;
24+
uint64_t registered_buf_alloc_count = 0;
2225
};
2326

2427
using ReadCb = std::function<void(std::string_view, std::error_code)>;
@@ -45,10 +48,14 @@ class DiskStorage {
4548

4649
private:
4750
std::error_code Grow(off_t grow_size);
51+
util::fb2::UringBuf PrepareBuf(size_t len);
4852

49-
private:
5053
off_t size_, max_size_;
5154
size_t pending_ops_ = 0; // number of ongoing ops for safe shutdown
55+
56+
// how many times we allocate registered/heap buffers.
57+
uint64_t heap_buf_alloc_cnt_ = 0, reg_buf_alloc_cnt_ = 0;
58+
5259
bool grow_pending_ = false;
5360
std::unique_ptr<util::fb2::LinuxFile> backing_file_;
5461

src/server/tiering/small_bins.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ SmallBins::FilledBin SmallBins::FlushBin() {
3939
out.resize(current_bin_bytes_ + 2);
4040

4141
BinId id = ++last_bin_id_;
42+
DVLOG(1) << "FlushBin " << id;
4243
auto& pending_set = pending_bins_[id];
4344

4445
char* data = out.data();
@@ -73,8 +74,10 @@ SmallBins::FilledBin SmallBins::FlushBin() {
7374
}
7475

7576
SmallBins::KeySegmentList SmallBins::ReportStashed(BinId id, DiskSegment segment) {
77+
DVLOG(1) << "ReportStashed " << id;
78+
7679
auto key_list = pending_bins_.extract(id);
77-
DCHECK_GT(key_list.mapped().size(), 0u);
80+
DCHECK_GT(key_list.mapped().size(), 0u) << id;
7881

7982
uint16_t bytes = 0;
8083
SmallBins::KeySegmentList list;

0 commit comments

Comments
 (0)