Skip to content

Commit

Permalink
HP_MALLOC: Fix computation of PKG stats
Browse files Browse the repository at this point in the history
Many thanks to 46Labs for supporting this work!
  • Loading branch information
liviuchircu committed Apr 3, 2020
1 parent fc9344a commit 3634b39
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 38 deletions.
37 changes: 3 additions & 34 deletions mem/hp_malloc_dyn.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,20 +177,10 @@ void __pkg_frag_split(struct hp_block *hpb, struct hp_frag *frag,
n->file=file;
n->func=func;
n->line=line;
#ifndef STATISTICS
hpb->used -= FRAG_OVERHEAD;
hpb->real_used += FRAG_OVERHEAD;
hpb->total_fragments++;
#endif
#endif

hp_frag_attach(hpb, n);
update_stats_pkg_frag_attach(hpb, n);

#if defined(DBG_MALLOC) && !defined(STATISTICS)
hpb->used -= n->size;
hpb->real_used -= n->size + FRAG_OVERHEAD;
#endif
}

#if !defined INLINE_ALLOC && defined DBG_MALLOC
Expand Down Expand Up @@ -427,11 +417,6 @@ void *hp_pkg_malloc(struct hp_block *hpb, unsigned long size,
hp_frag_detach(hpb, frag);
update_stats_pkg_frag_detach(hpb, frag);

#ifndef STATISTICS
hpb->used += frag->size;
hpb->real_used += frag->size + FRAG_OVERHEAD;
#endif

/* split the fragment if possible */
#if !defined INLINE_ALLOC && defined DBG_MALLOC
pkg_frag_split_dbg(hpb, frag, size, file, "hp_malloc frag", line);
Expand Down Expand Up @@ -848,34 +833,21 @@ void hp_pkg_free(struct hp_block *hpb, void *p,
update_stats_pkg_frag_detach(hpb, next);

#ifdef DBG_MALLOC
#ifndef STATISTICS
hpb->used += next->size;
hpb->real_used += next->size + FRAG_OVERHEAD;
#endif
hpb->used += FRAG_OVERHEAD;
#endif

f->size += next->size + FRAG_OVERHEAD;
update_stats_pkg_frag_merge(hpb);

#if defined(DBG_MALLOC) && !defined(STATISTICS)
hpb->real_used -= FRAG_OVERHEAD;
hpb->total_fragments--;
#endif
}

hp_frag_attach(hpb, f);
update_stats_pkg_frag_attach(hpb, f);

#ifdef DBG_MALLOC
f->file=file;
f->func=func;
f->line=line;
#endif

#if defined(DBG_MALLOC) && !defined(STATISTICS)
hpb->used -= f->size;
hpb->real_used -= f->size + FRAG_OVERHEAD;
#endif
}

#if !defined INLINE_ALLOC && defined DBG_MALLOC
Expand Down Expand Up @@ -1116,14 +1088,11 @@ void *hp_pkg_realloc(struct hp_block *hpb, void *p, unsigned long size,
update_stats_pkg_frag_detach(hpb, next);

#ifdef DBG_MALLOC
#ifndef STATISTICS
hpb->used += next->size;
hpb->real_used += next->size + FRAG_OVERHEAD;
#endif
hpb->used += FRAG_OVERHEAD;
#endif

f->size += next->size + FRAG_OVERHEAD;
update_stats_pkg_frag_merge(hpb);

/* split the result if necessary */
if (f->size > size)
Expand Down Expand Up @@ -1591,7 +1560,7 @@ void hp_status(struct hp_block *hpb)
}
}

LM_GEN1(memdump, "TOTAL: %6d free fragments\n", t);
LM_GEN1(memdump, "TOTAL: %6d/%ld free fragments\n", t, hpb->total_fragments);
LM_GEN1(memdump, "Fragment overhead: %u\n", (unsigned int)FRAG_OVERHEAD);
LM_GEN1(memdump, "-----------------------------\n");
}
Expand Down
5 changes: 3 additions & 2 deletions mem/hp_malloc_stats.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,9 @@ void hp_init_shm_statistics(struct hp_block *hpb)
update_stat(shm_rused, (long)hpb->real_used);
update_stat(shm_frags, (long)hpb->total_fragments);

LM_DBG("initializing atomic shm statistics: "
"[ us: %ld | rus: %ld | frags: %ld ]\n", hpb->used, hpb->real_used, hpb->total_fragments);
LM_INFO("initialized atomic shm statistics: "
"[ us: %ld | rus: %ld | frags: %ld ]\n", hpb->used, hpb->real_used,
hpb->total_fragments);
}

unsigned long hp_shm_get_used(struct hp_block *hpb)
Expand Down
3 changes: 1 addition & 2 deletions mem/hp_malloc_stats.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,12 @@ unsigned long hp_rpm_get_frags(struct hp_block *hpb);
#define update_stats_pkg_frag_split(blk, ...) \
do { \
(blk)->used -= FRAG_OVERHEAD; \
(blk)->real_used += FRAG_OVERHEAD; \
(blk)->total_fragments++; \
} while (0)

#define update_stats_pkg_frag_merge(blk, ...) \
do { \
(blk)->real_used -= FRAG_OVERHEAD; \
(blk)->used += FRAG_OVERHEAD; \
(blk)->total_fragments--; \
} while (0)

Expand Down

0 comments on commit 3634b39

Please sign in to comment.