Skip to content

Commit

Permalink
Merge pull request ceph#34537 from ideepika/wip-bluestore-mem-tracking
Browse files Browse the repository at this point in the history
os/bluestore: mempool split for finer granularity

Reviewed-by: Josh Durgin <[email protected]>
Reviewed-by: Mark Nelson <[email protected]>
Reviewed-by: Adam Kupczyk <[email protected]>
  • Loading branch information
jdurgin authored Jul 15, 2020
2 parents 1e6364f + 6a50c85 commit 6983798
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 31 deletions.
10 changes: 9 additions & 1 deletion src/include/mempool.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,20 @@ namespace mempool {
f(bluestore_alloc) \
f(bluestore_cache_data) \
f(bluestore_cache_onode) \
f(bluestore_cache_meta) \
f(bluestore_cache_other) \
f(bluestore_Buffer) \
f(bluestore_Extent) \
f(bluestore_Blob) \
f(bluestore_SharedBlob) \
f(bluestore_inline_bl) \
f(bluestore_fsck) \
f(bluestore_txc) \
f(bluestore_writing_deferred) \
f(bluestore_writing_deferred) \
f(bluestore_writing) \
f(bluefs) \
f(bluefs_file_reader) \
f(bluefs_file_writer) \
f(buffer_anon) \
f(buffer_meta) \
f(osd) \
Expand Down
10 changes: 7 additions & 3 deletions src/os/bluestore/BlueFS.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ using ceph::Formatter;

MEMPOOL_DEFINE_OBJECT_FACTORY(BlueFS::File, bluefs_file, bluefs);
MEMPOOL_DEFINE_OBJECT_FACTORY(BlueFS::Dir, bluefs_dir, bluefs);
MEMPOOL_DEFINE_OBJECT_FACTORY(BlueFS::FileWriter, bluefs_file_writer, bluefs);
MEMPOOL_DEFINE_OBJECT_FACTORY(BlueFS::FileWriter, bluefs_file_writer, bluefs_file_writer);
MEMPOOL_DEFINE_OBJECT_FACTORY(BlueFS::FileReaderBuffer,
bluefs_file_reader_buffer, bluefs);
MEMPOOL_DEFINE_OBJECT_FACTORY(BlueFS::FileReader, bluefs_file_reader, bluefs);
bluefs_file_reader_buffer, bluefs_file_reader);
MEMPOOL_DEFINE_OBJECT_FACTORY(BlueFS::FileReader, bluefs_file_reader, bluefs_file_reader);
MEMPOOL_DEFINE_OBJECT_FACTORY(BlueFS::FileLock, bluefs_file_lock, bluefs);

static void wal_discard_cb(void *priv, void* priv2) {
Expand Down Expand Up @@ -1957,6 +1957,7 @@ int64_t BlueFS::_read_random(
logger->inc(l_bluefs_read_random_bytes, len);

std::shared_lock s_lock(h->lock);
buf->bl.reassign_to_mempool(mempool::mempool_bluefs_file_reader);
while (len > 0) {
if (off < buf->bl_off || off >= buf->get_buf_end()) {
s_lock.unlock();
Expand Down Expand Up @@ -2057,6 +2058,7 @@ int64_t BlueFS::_read(
if (off < buf->bl_off || off >= buf->get_buf_end()) {
s_lock.unlock();
std::unique_lock u_lock(h->lock);
buf->bl.reassign_to_mempool(mempool::mempool_bluefs_file_reader);
if (off < buf->bl_off || off >= buf->get_buf_end()) {
// if precondition hasn't changed during locking upgrade.
buf->bl.clear();
Expand Down Expand Up @@ -2115,6 +2117,7 @@ int64_t BlueFS::_read(
ret += r;
buf->pos += r;
}

dout(20) << __func__ << " got " << ret << dendl;
ceph_assert(!outbl || (int)outbl->length() == ret);
--h->file->num_reading;
Expand Down Expand Up @@ -3377,6 +3380,7 @@ BlueFS::FileWriter *BlueFS::_create_writer(FileRef f)
void BlueFS::_close_writer(FileWriter *h)
{
dout(10) << __func__ << " " << h << " type " << h->writer_type << dendl;
h->buffer.reassign_to_mempool(mempool::mempool_bluefs_file_writer);
for (unsigned i=0; i<MAX_BDEV; ++i) {
if (bdev[i]) {
if (h->iocv[i]) {
Expand Down
28 changes: 14 additions & 14 deletions src/os/bluestore/BlueStore.cc
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,13 @@ MEMPOOL_DEFINE_OBJECT_FACTORY(BlueStore::Onode, bluestore_onode,

// bluestore_cache_other
MEMPOOL_DEFINE_OBJECT_FACTORY(BlueStore::Buffer, bluestore_buffer,
bluestore_cache_other);
bluestore_Buffer);
MEMPOOL_DEFINE_OBJECT_FACTORY(BlueStore::Extent, bluestore_extent,
bluestore_cache_other);
bluestore_Extent);
MEMPOOL_DEFINE_OBJECT_FACTORY(BlueStore::Blob, bluestore_blob,
bluestore_cache_other);
bluestore_Blob);
MEMPOOL_DEFINE_OBJECT_FACTORY(BlueStore::SharedBlob, bluestore_shared_blob,
bluestore_cache_other);
bluestore_SharedBlob);

// bluestore_txc
MEMPOOL_DEFINE_OBJECT_FACTORY(BlueStore::TransContext, bluestore_transcontext,
Expand Down Expand Up @@ -1646,7 +1646,7 @@ void BlueStore::OnodeSpace::rename(
OnodeRef& oldo,
const ghobject_t& old_oid,
const ghobject_t& new_oid,
const mempool::bluestore_cache_other::string& new_okey)
const mempool::bluestore_cache_meta::string& new_okey)
{
std::lock_guard l(cache->lock);
ldout(cache->cct, 30) << __func__ << " " << old_oid << " -> " << new_oid
Expand Down Expand Up @@ -2235,7 +2235,7 @@ void BlueStore::ExtentMap::update(KeyValueDB::Transaction t,
unsigned n;
// we need to encode inline_bl to measure encoded length
bool never_happen = encode_some(0, OBJECT_MAX_SIZE, inline_bl, &n);
inline_bl.reassign_to_mempool(mempool::mempool_bluestore_cache_other);
inline_bl.reassign_to_mempool(mempool::mempool_bluestore_inline_bl);
ceph_assert(!never_happen);
size_t len = inline_bl.length();
dout(20) << __func__ << " inline shard " << len << " bytes from " << n
Expand Down Expand Up @@ -3292,7 +3292,7 @@ BlueStore::Onode* BlueStore::Onode::decode(
auto p = v.front().begin_deep();
on->onode.decode(p);
for (auto& i : on->onode.attrs) {
i.second.reassign_to_mempool(mempool::mempool_bluestore_cache_other);
i.second.reassign_to_mempool(mempool::mempool_bluestore_cache_data);
}

// initialize extent_map
Expand All @@ -3301,7 +3301,7 @@ BlueStore::Onode* BlueStore::Onode::decode(
denc(on->extent_map.inline_bl, p);
on->extent_map.decode_some(on->extent_map.inline_bl);
on->extent_map.inline_bl.reassign_to_mempool(
mempool::mempool_bluestore_cache_other);
mempool::mempool_bluestore_cache_data);
}
else {
on->extent_map.init_shards(false, false);
Expand Down Expand Up @@ -10416,7 +10416,7 @@ int BlueStore::getattr(
int r;
{
std::shared_lock l(c->lock);
mempool::bluestore_cache_other::string k(name);
mempool::bluestore_cache_meta::string k(name);

OnodeRef o = c->get_onode(oid, false);
if (!o || !o->exists) {
Expand Down Expand Up @@ -14687,10 +14687,10 @@ int BlueStore::_setattr(TransContext *txc,
if (val.is_partial()) {
auto& b = o->onode.attrs[name.c_str()] = bufferptr(val.c_str(),
val.length());
b.reassign_to_mempool(mempool::mempool_bluestore_cache_other);
b.reassign_to_mempool(mempool::mempool_bluestore_cache_data);
} else {
auto& b = o->onode.attrs[name.c_str()] = val;
b.reassign_to_mempool(mempool::mempool_bluestore_cache_other);
b.reassign_to_mempool(mempool::mempool_bluestore_cache_data);
}
txc->write_onode(o);
dout(10) << __func__ << " " << c->cid << " " << o->oid
Expand All @@ -14713,10 +14713,10 @@ int BlueStore::_setattrs(TransContext *txc,
if (p->second.is_partial()) {
auto& b = o->onode.attrs[p->first.c_str()] =
bufferptr(p->second.c_str(), p->second.length());
b.reassign_to_mempool(mempool::mempool_bluestore_cache_other);
b.reassign_to_mempool(mempool::mempool_bluestore_cache_data);
} else {
auto& b = o->onode.attrs[p->first.c_str()] = p->second;
b.reassign_to_mempool(mempool::mempool_bluestore_cache_other);
b.reassign_to_mempool(mempool::mempool_bluestore_cache_data);
}
}
txc->write_onode(o);
Expand Down Expand Up @@ -15128,7 +15128,7 @@ int BlueStore::_rename(TransContext *txc,
<< new_oid << dendl;
int r;
ghobject_t old_oid = oldo->oid;
mempool::bluestore_cache_other::string new_okey;
mempool::bluestore_cache_meta::string new_okey;

if (newo) {
if (newo->exists) {
Expand Down
26 changes: 16 additions & 10 deletions src/os/bluestore/BlueStore.h
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ class BlueStore : public ObjectStore,
boost::intrusive::list_member_hook<>,
&Buffer::state_item> > state_list_t;

mempool::bluestore_cache_other::map<uint32_t, std::unique_ptr<Buffer>>
mempool::bluestore_cache_meta::map<uint32_t, std::unique_ptr<Buffer>>
buffer_map;

// we use a bare intrusive list here instead of std::map because
Expand Down Expand Up @@ -474,7 +474,7 @@ class BlueStore : public ObjectStore,

// we use a bare pointer because we don't want to affect the ref
// count
mempool::bluestore_cache_other::unordered_map<uint64_t,SharedBlob*> sb_map;
mempool::bluestore_cache_meta::unordered_map<uint64_t,SharedBlob*> sb_map;

SharedBlobRef lookup(uint64_t sbid) {
std::lock_guard l(lock);
Expand Down Expand Up @@ -689,7 +689,7 @@ class BlueStore : public ObjectStore,
#endif
};
typedef boost::intrusive_ptr<Blob> BlobRef;
typedef mempool::bluestore_cache_other::map<int,BlobRef> blob_map_t;
typedef mempool::bluestore_cache_meta::map<int,BlobRef> blob_map_t;

/// a logical extent, pointing to (some portion of) a blob
typedef boost::intrusive::set_base_hook<boost::intrusive::optimize_size<true> > ExtentBase; //making an alias to avoid build warnings
Expand Down Expand Up @@ -797,7 +797,7 @@ class BlueStore : public ObjectStore,
bool loaded = false; ///< true if shard is loaded
bool dirty = false; ///< true if shard is dirty and needs reencoding
};
mempool::bluestore_cache_other::vector<Shard> shards; ///< shards
mempool::bluestore_cache_meta::vector<Shard> shards; ///< shards

ceph::buffer::list inline_bl; ///< cached encoded map, if unsharded; empty=>dirty

Expand Down Expand Up @@ -1064,7 +1064,7 @@ class BlueStore : public ObjectStore,
ghobject_t oid;

/// key under PREFIX_OBJ where we are stored
mempool::bluestore_cache_other::string key;
mempool::bluestore_cache_meta::string key;

boost::intrusive::list_member_hook<> lru_item;

Expand All @@ -1086,7 +1086,7 @@ class BlueStore : public ObjectStore,
ceph::condition_variable flush_cond; ///< wait here for uncommitted txns

Onode(Collection *c, const ghobject_t& o,
const mempool::bluestore_cache_other::string& k)
const mempool::bluestore_cache_meta::string& k)
: nref(0),
c(c),
oid(o),
Expand Down Expand Up @@ -1288,7 +1288,7 @@ class BlueStore : public ObjectStore,

private:
/// forward lookups
mempool::bluestore_cache_other::unordered_map<ghobject_t,OnodeRef> onode_map;
mempool::bluestore_cache_meta::unordered_map<ghobject_t,OnodeRef> onode_map;

friend struct Collection; // for split_cache()

Expand All @@ -1304,7 +1304,7 @@ class BlueStore : public ObjectStore,
OnodeRef lookup(const ghobject_t& o);
void rename(OnodeRef& o, const ghobject_t& old_oid,
const ghobject_t& new_oid,
const mempool::bluestore_cache_other::string& new_okey);
const mempool::bluestore_cache_meta::string& new_okey);
void clear();
bool empty();

Expand Down Expand Up @@ -2211,8 +2211,14 @@ class BlueStore : public ObjectStore,
MetaCache(BlueStore *s) : MempoolCache(s) {};

virtual uint64_t _get_used_bytes() const {
return mempool::bluestore_cache_other::allocated_bytes() +
mempool::bluestore_cache_onode::allocated_bytes();
return mempool::bluestore_Buffer::allocated_bytes() +
mempool::bluestore_Blob::allocated_bytes() +
mempool::bluestore_Extent::allocated_bytes() +
mempool::bluestore_cache_meta::allocated_bytes() +
mempool::bluestore_cache_other::allocated_bytes() +
mempool::bluestore_cache_onode::allocated_bytes() +
mempool::bluestore_SharedBlob::allocated_bytes() +
mempool::bluestore_inline_bl::allocated_bytes();
}

virtual std::string get_cache_name() const {
Expand Down
3 changes: 2 additions & 1 deletion src/os/bluestore/bluestore_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -936,7 +936,8 @@ std::ostream& operator<<(std::ostream& out, const bluestore_shared_blob_t& o);
struct bluestore_onode_t {
uint64_t nid = 0; ///< numeric id (locally unique)
uint64_t size = 0; ///< object size
std::map<mempool::bluestore_cache_other::string, ceph::buffer::ptr> attrs; ///< attrs
// FIXME: bufferptr does not have a mempool
std::map<mempool::bluestore_cache_meta::string, ceph::buffer::ptr> attrs;

struct shard_info {
uint32_t offset = 0; ///< logical offset for start of shard
Expand Down
7 changes: 5 additions & 2 deletions src/test/objectstore/store_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6438,15 +6438,18 @@ TEST_P(StoreTestSpecificAUSize, TooManyBlobsTest) {
#if defined(WITH_BLUESTORE)
void get_mempool_stats(uint64_t* total_bytes, uint64_t* total_items)
{
uint64_t meta_allocated = mempool::bluestore_cache_meta::allocated_bytes();
uint64_t onode_allocated = mempool::bluestore_cache_onode::allocated_bytes();
uint64_t other_allocated = mempool::bluestore_cache_other::allocated_bytes();

uint64_t meta_items = mempool::bluestore_cache_meta::allocated_items();
uint64_t onode_items = mempool::bluestore_cache_onode::allocated_items();
uint64_t other_items = mempool::bluestore_cache_other::allocated_items();
cout << "onode(" << onode_allocated << "/" << onode_items
cout << "meta(" << meta_allocated << "/" << meta_items
<< ") onode(" << onode_allocated << "/" << onode_items
<< ") other(" << other_allocated << "/" << other_items
<< ")" << std::endl;
*total_bytes = onode_allocated + other_allocated;
*total_bytes = meta_allocated + onode_allocated + other_allocated;
*total_items = onode_items;
}

Expand Down

0 comments on commit 6983798

Please sign in to comment.