Skip to content

Commit 327d209

Browse files
authored
Merge pull request ceph#58952 from YiteGu/add-perfcounter-for-blk-discard
blk/kerneldevice: add perfcounter for block async discard Reviewed-by: Igor Fedotov <[email protected]>
2 parents b62699b + f446f4c commit 327d209

File tree

7 files changed

+41
-11
lines changed

7 files changed

+41
-11
lines changed

src/blk/BlockDevice.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,13 +140,13 @@ BlockDevice::device_type_from_name(const std::string& blk_dev_name)
140140

141141
BlockDevice* BlockDevice::create_with_type(block_device_t device_type,
142142
CephContext* cct, const std::string& path, aio_callback_t cb,
143-
void *cbpriv, aio_callback_t d_cb, void *d_cbpriv)
143+
void *cbpriv, aio_callback_t d_cb, void *d_cbpriv, const char* dev_name)
144144
{
145145

146146
switch (device_type) {
147147
#if defined(HAVE_LIBAIO) || defined(HAVE_POSIXAIO)
148148
case block_device_t::aio:
149-
return new KernelDevice(cct, cb, cbpriv, d_cb, d_cbpriv);
149+
return new KernelDevice(cct, cb, cbpriv, d_cb, d_cbpriv, dev_name);
150150
#endif
151151
#if defined(HAVE_SPDK)
152152
case block_device_t::spdk:
@@ -164,7 +164,7 @@ BlockDevice* BlockDevice::create_with_type(block_device_t device_type,
164164

165165
BlockDevice *BlockDevice::create(
166166
CephContext* cct, const string& path, aio_callback_t cb,
167-
void *cbpriv, aio_callback_t d_cb, void *d_cbpriv)
167+
void *cbpriv, aio_callback_t d_cb, void *d_cbpriv, const char* dev_name)
168168
{
169169
const string blk_dev_name = cct->_conf.get_val<string>("bdev_type");
170170
block_device_t device_type = block_device_t::unknown;
@@ -173,7 +173,7 @@ BlockDevice *BlockDevice::create(
173173
} else {
174174
device_type = device_type_from_name(blk_dev_name);
175175
}
176-
return create_with_type(device_type, cct, path, cb, cbpriv, d_cb, d_cbpriv);
176+
return create_with_type(device_type, cct, path, cb, cbpriv, d_cb, d_cbpriv, dev_name);
177177
}
178178

179179
bool BlockDevice::is_valid_io(uint64_t off, uint64_t len) const {

src/blk/BlockDevice.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,8 @@ class BlockDevice {
175175
static block_device_t device_type_from_name(const std::string& blk_dev_name);
176176
static BlockDevice *create_with_type(block_device_t device_type,
177177
CephContext* cct, const std::string& path, aio_callback_t cb,
178-
void *cbpriv, aio_callback_t d_cb, void *d_cbpriv);
178+
void *cbpriv, aio_callback_t d_cb, void *d_cbpriv, const char* dev_name);
179+
179180
protected:
180181
uint64_t size = 0;
181182
uint64_t block_size = 0;
@@ -206,7 +207,8 @@ class BlockDevice {
206207
virtual ~BlockDevice() = default;
207208

208209
static BlockDevice *create(
209-
CephContext* cct, const std::string& path, aio_callback_t cb, void *cbpriv, aio_callback_t d_cb, void *d_cbpriv);
210+
CephContext* cct, const std::string& path, aio_callback_t cb, void *cbpriv, aio_callback_t d_cb,
211+
void *d_cbpriv, const char* dev_name = "");
210212
virtual bool supported_bdev_label() { return true; }
211213
virtual bool is_rotational() { return rotational; }
212214

src/blk/kernel/KernelDevice.cc

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ using ceph::make_timespan;
5959
using ceph::mono_clock;
6060
using ceph::operator <<;
6161

62-
KernelDevice::KernelDevice(CephContext* cct, aio_callback_t cb, void *cbpriv, aio_callback_t d_cb, void *d_cbpriv)
62+
KernelDevice::KernelDevice(CephContext* cct, aio_callback_t cb, void *cbpriv, aio_callback_t d_cb, void *d_cbpriv, const char* dev_name)
6363
: BlockDevice(cct, cb, cbpriv),
6464
aio(false), dio(false),
6565
discard_callback(d_cb),
@@ -89,10 +89,25 @@ KernelDevice::KernelDevice(CephContext* cct, aio_callback_t cb, void *cbpriv, ai
8989
}
9090
io_queue = std::make_unique<aio_queue_t>(iodepth);
9191
}
92+
93+
char name[128];
94+
sprintf(name, "blk-kernel-device-%s", dev_name);
95+
PerfCountersBuilder b(cct, name,
96+
l_blk_kernel_device_first, l_blk_kernel_device_last);
97+
b.set_prio_default(PerfCountersBuilder::PRIO_USEFUL);
98+
b.add_u64_counter(l_blk_kernel_device_discard_op, "discard_op",
99+
"Number of discard ops issued to kernel device");
100+
101+
logger.reset(b.create_perf_counters());
102+
cct->get_perfcounters_collection()->add(logger.get());
92103
}
93104

94105
KernelDevice::~KernelDevice()
95106
{
107+
if (logger) {
108+
cct->get_perfcounters_collection()->remove(logger.get());
109+
logger.reset();
110+
}
96111
cct->_conf.remove_observer(this);
97112
}
98113

@@ -784,6 +799,7 @@ void KernelDevice::_discard_thread(uint64_t tid)
784799
discard_running ++;
785800
l.unlock();
786801
dout(20) << __func__ << " finishing" << dendl;
802+
logger->inc(l_blk_kernel_device_discard_op, discard_processing.size());
787803
for (auto p = discard_processing.begin(); p != discard_processing.end(); ++p) {
788804
_discard(p.get_start(), p.get_len());
789805
}

src/blk/kernel/KernelDevice.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@
2929

3030
#define RW_IO_MAX (INT_MAX & CEPH_PAGE_MASK)
3131

32+
enum {
33+
l_blk_kernel_device_first = 1000,
34+
l_blk_kernel_device_discard_op,
35+
l_blk_kernel_device_last,
36+
};
37+
3238
class KernelDevice : public BlockDevice,
3339
public md_config_obs_t {
3440
protected:
@@ -53,6 +59,7 @@ class KernelDevice : public BlockDevice,
5359
void *discard_callback_priv;
5460
bool aio_stop;
5561
bool discard_stop;
62+
std::unique_ptr<PerfCounters> logger;
5663

5764
ceph::mutex discard_lock = ceph::make_mutex("KernelDevice::discard_lock");
5865
ceph::condition_variable discard_cond;
@@ -119,7 +126,8 @@ class KernelDevice : public BlockDevice,
119126
ceph::unique_leakable_ptr<buffer::raw> create_custom_aligned(size_t len, IOContext* ioc) const;
120127

121128
public:
122-
KernelDevice(CephContext* cct, aio_callback_t cb, void *cbpriv, aio_callback_t d_cb, void *d_cbpriv);
129+
KernelDevice(CephContext* cct, aio_callback_t cb, void *cbpriv, aio_callback_t d_cb,
130+
void *d_cbpriv, const char* dev_name = "");
123131
~KernelDevice();
124132

125133
void aio_submit(IOContext *ioc) override;

src/os/bluestore/BlueFS.cc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,17 +483,21 @@ int BlueFS::add_block_device(unsigned id, const string& path, bool trim,
483483
bluefs_shared_alloc_context_t* _shared_alloc)
484484
{
485485
uint64_t reserved;
486+
string dev_name;
486487
switch(id) {
487488
case BDEV_WAL:
488489
case BDEV_NEWWAL:
489490
reserved = BDEV_LABEL_BLOCK_SIZE;
491+
dev_name = "wal";
490492
break;
491493
case BDEV_DB:
492494
case BDEV_NEWDB:
493495
reserved = SUPER_RESERVED;
496+
dev_name = "db";
494497
break;
495498
case BDEV_SLOW:
496499
reserved = 0;
500+
dev_name = "slow";
497501
break;
498502
default:
499503
ceph_assert(false);
@@ -503,7 +507,7 @@ int BlueFS::add_block_device(unsigned id, const string& path, bool trim,
503507
ceph_assert(id < bdev.size());
504508
ceph_assert(bdev[id] == NULL);
505509
BlockDevice *b = BlockDevice::create(cct, path, NULL, NULL,
506-
discard_cb[id], static_cast<void*>(this));
510+
discard_cb[id], static_cast<void*>(this), dev_name.c_str());
507511
block_reserved[id] = reserved;
508512
if (_shared_alloc) {
509513
b->set_no_exclusive_lock();

src/os/bluestore/BlueFS.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,7 @@ class BlueFS {
737737
}
738738

739739
int add_block_device(unsigned bdev, const std::string& path, bool trim,
740-
bluefs_shared_alloc_context_t* _shared_alloc = nullptr);
740+
bluefs_shared_alloc_context_t* _shared_alloc = nullptr);
741741
bool bdev_support_label(unsigned id);
742742
uint64_t get_block_device_size(unsigned bdev) const;
743743
BlockDevice* get_block_device(unsigned bdev) const;

src/os/bluestore/BlueStore.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6994,7 +6994,7 @@ int BlueStore::_open_bdev(bool create)
69946994
{
69956995
ceph_assert(bdev == NULL);
69966996
string p = path + "/block";
6997-
bdev = BlockDevice::create(cct, p, aio_cb, static_cast<void*>(this), discard_cb, static_cast<void*>(this));
6997+
bdev = BlockDevice::create(cct, p, aio_cb, static_cast<void*>(this), discard_cb, static_cast<void*>(this), "bluestore");
69986998
int r = bdev->open(p);
69996999
if (r < 0)
70007000
goto fail;

0 commit comments

Comments
 (0)