Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mempool: improve dump; fix buffer accounting bugs #15403

Merged
merged 2 commits into from Jun 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/common/buffer.cc
Expand Up @@ -1768,7 +1768,7 @@ static std::atomic_flag buffer_debug_lock = ATOMIC_FLAG_INIT;
{
if (append_buffer.unused_tail_length() < prealloc) {
append_buffer = buffer::create(prealloc);
if (_mempool) {
if (_mempool >= 0) {
Copy link
Contributor

@tchaikov tchaikov Jun 1, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, it's -1 by default. and the mem pool index starts at 0. they are enum whose first element is not assigned with a number. maybe we should make this explicit. like

enum pool_index_t {
  P(none),
  DEFINE_MEMORY_POOLS_HELPER(P)
  num_pools        // Must be last.
};

and use mempool_none as the default value for _mempool? so we can compare _mempool with mempool_none instead of the (sort of) magic number?

append_buffer.get_raw()->reassign_to_mempool(_mempool);
}
append_buffer.set_length(0); // unused, so far.
Expand Down Expand Up @@ -1860,6 +1860,9 @@ static std::atomic_flag buffer_debug_lock = ATOMIC_FLAG_INIT;
// make a new append_buffer!
append_buffer = raw_combined::create(CEPH_BUFFER_APPEND_SIZE);
append_buffer.set_length(0); // unused, so far.
if (_mempool >= 0) {
append_buffer.get_raw()->reassign_to_mempool(_mempool);
}
}
append(append_buffer, append_buffer.append(c) - 1, 1); // add segment to the list
}
Expand Down Expand Up @@ -1887,6 +1890,9 @@ static std::atomic_flag buffer_debug_lock = ATOMIC_FLAG_INIT;
sizeof(raw_combined);
append_buffer = raw_combined::create(alen);
append_buffer.set_length(0); // unused, so far.
if (_mempool >= 0) {
append_buffer.get_raw()->reassign_to_mempool(_mempool);
}
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/common/mempool.cc
Expand Up @@ -113,12 +113,14 @@ void mempool::pool_t::dump(ceph::Formatter *f, stats_t *ptotal) const
if (ptotal) {
*ptotal += total;
}
f->dump_object("total", total);
total.dump(f);
if (!by_type.empty()) {
f->open_object_section("by_type");
for (auto &i : by_type) {
f->open_object_section(i.first.c_str());
i.second.dump(f);
f->close_section();
}
f->close_section();
}
}
49 changes: 41 additions & 8 deletions src/test/test_mempool.cc
Expand Up @@ -265,6 +265,18 @@ TEST(mempool, unordered_map)
h[2] = obj(1);
}

TEST(mempool, string_test)
{
mempool::osdmap::string s;
s.reserve(100);
EXPECT_GE(mempool::osdmap::allocated_items(), s.capacity() + 1u); // +1 for zero-byte termination :
for (size_t i = 0; i < 10; ++i) {
s += '1';
s.append(s);
EXPECT_GE(mempool::osdmap::allocated_items(), s.capacity() + 1u);
}
}

TEST(mempool, bufferlist)
{
bufferlist bl;
Expand All @@ -277,16 +289,37 @@ TEST(mempool, bufferlist)
ASSERT_GE(after, before + len);
}

TEST(mempool, string_test)
TEST(mempool, bufferlist_reassign)
{
mempool::osdmap::string s;
s.reserve(100);
EXPECT_GE(mempool::osdmap::allocated_items(), s.capacity() + 1u); // +1 for zero-byte termination :
for (size_t i = 0; i < 10; ++i) {
s += '1';
s.append(s);
EXPECT_GE(mempool::osdmap::allocated_items(), s.capacity() + 1u);
bufferlist bl;
size_t items_before = mempool::buffer_anon::allocated_items();
size_t bytes_before = mempool::buffer_anon::allocated_bytes();
bl.append("fooo");
ASSERT_EQ(items_before + 1, mempool::buffer_anon::allocated_items());
ASSERT_LT(bytes_before, mempool::buffer_anon::allocated_bytes());

// move existing bl
bl.reassign_to_mempool(mempool::mempool_osd);
ASSERT_EQ(items_before, mempool::buffer_anon::allocated_items());
ASSERT_EQ(bytes_before, mempool::buffer_anon::allocated_bytes());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit, could check if mempool::mempool_osd gets the item and bytes number.


// additional appends should go to the same pool
items_before = mempool::osd::allocated_items();
bytes_before = mempool::osd::allocated_bytes();
cout << "anon b " << mempool::buffer_anon::allocated_bytes() << std::endl;
for (unsigned i = 0; i < 1000; ++i) {
bl.append("asdfddddddddddddddddddddddasfdasdfasdfasdfasdfasdf");
}
cout << "anon a " << mempool::buffer_anon::allocated_bytes() << std::endl;
ASSERT_LT(items_before, mempool::osd::allocated_items());
ASSERT_LT(bytes_before, mempool::osd::allocated_bytes());

// try_.. won't
items_before = mempool::osd::allocated_items();
bytes_before = mempool::osd::allocated_bytes();
bl.try_assign_to_mempool(mempool::mempool_bloom_filter);
ASSERT_EQ(items_before, mempool::osd::allocated_items());
ASSERT_EQ(bytes_before, mempool::osd::allocated_bytes());
}

int main(int argc, char **argv)
Expand Down