Skip to content

Commit

Permalink
add MPK support for stats retrieval functions
Browse files Browse the repository at this point in the history
  • Loading branch information
thestinger committed Oct 6, 2020
1 parent 0bf18b7 commit 2bb1c39
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions h_malloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1774,6 +1774,8 @@ EXPORT struct mallinfo h_mallinfo(void) {
return info;
}

thread_unseal_metadata();

struct region_allocator *ra = ro.region_allocator;
mutex_lock(&ra->lock);
info.hblkhd += ra->allocated;
Expand All @@ -1793,6 +1795,8 @@ EXPORT struct mallinfo h_mallinfo(void) {

info.fordblks = info.hblkhd - info.uordblks;
info.usmblks = info.hblkhd;

thread_seal_metadata();
#endif

return info;
Expand All @@ -1810,6 +1814,8 @@ EXPORT int h_malloc_info(int options, UNUSED FILE *fp) {

#if CONFIG_STATS
if (is_init()) {
thread_unseal_metadata();

for (unsigned arena = 0; arena < N_ARENA; arena++) {
fprintf(fp, "<heap nr=\"%u\">", arena);

Expand Down Expand Up @@ -1844,6 +1850,8 @@ EXPORT int h_malloc_info(int options, UNUSED FILE *fp) {
fprintf(fp, "<heap nr=\"%u\">", N_ARENA);
fprintf(fp, "<allocated_large>%zu</allocated_large>", region_allocated);
fputs("</heap>", fp);

thread_seal_metadata();
}
#endif

Expand Down Expand Up @@ -1878,6 +1886,8 @@ EXPORT struct mallinfo h_mallinfo_arena_info(UNUSED size_t arena) {
return info;
}

thread_unseal_metadata();

if (arena < N_ARENA) {
for (unsigned class = 0; class < N_SIZE_CLASSES; class++) {
struct size_class *c = &ro.size_class_metadata[arena][class];
Expand All @@ -1895,6 +1905,8 @@ EXPORT struct mallinfo h_mallinfo_arena_info(UNUSED size_t arena) {
info.uordblks = ra->allocated;
mutex_unlock(&ra->lock);
}

thread_seal_metadata();
#endif

return info;
Expand All @@ -1915,13 +1927,17 @@ EXPORT struct mallinfo h_mallinfo_bin_info(UNUSED size_t arena, UNUSED size_t bi
}

if (arena < N_ARENA && bin < N_SIZE_CLASSES) {
thread_seal_metadata();

struct size_class *c = &ro.size_class_metadata[arena][bin];

mutex_lock(&c->lock);
info.ordblks = c->allocated;
info.uordblks = c->nmalloc;
info.fordblks = c->ndalloc;
mutex_unlock(&c->lock);

thread_unseal_metadata();
}
#endif

Expand Down

0 comments on commit 2bb1c39

Please sign in to comment.