Skip to content

Commit

Permalink
memory: count small_pool spans in use
Browse files Browse the repository at this point in the history
This can give a clue as to which object sizes contribute to a memory leak,
from which we can try to guess what is leaked.
  • Loading branch information
avikivity committed Jul 28, 2015
1 parent 53b5a26 commit ce6c5c8
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions core/memory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ class small_pool {
size_t _free_count = 0;
unsigned _min_free;
unsigned _max_free;
unsigned _spans_in_use = 0;
page_list _span_list;
static constexpr unsigned idx_frac_bits = 2;
private:
Expand Down Expand Up @@ -738,6 +739,7 @@ small_pool::add_more_objects() {
}
while (_free_count < goal) {
auto data = reinterpret_cast<char*>(cpu_mem.allocate_large(_span_size));
++_spans_in_use;
auto span = cpu_mem.to_page(data);
for (unsigned i = 0; i < _span_size; ++i) {
span[i].offset_in_span = i;
Expand Down Expand Up @@ -773,6 +775,7 @@ small_pool::trim_free_list() {
if (--span->nr_small_alloc == 0) {
_span_list.erase(cpu_mem.pages, *span);
cpu_mem.free_span(span - cpu_mem.pages, span->span_size);
--_spans_in_use;
}
}
}
Expand Down

0 comments on commit ce6c5c8

Please sign in to comment.