Skip to content

Commit 3634b39

Browse files
committed
HP_MALLOC: Fix computation of PKG stats
Many thanks to 46Labs for supporting this work!
1 parent fc9344a commit 3634b39

File tree

3 files changed

+7
-38
lines changed

3 files changed

+7
-38
lines changed

mem/hp_malloc_dyn.h

Lines changed: 3 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -177,20 +177,10 @@ void __pkg_frag_split(struct hp_block *hpb, struct hp_frag *frag,
177177
n->file=file;
178178
n->func=func;
179179
n->line=line;
180-
#ifndef STATISTICS
181-
hpb->used -= FRAG_OVERHEAD;
182-
hpb->real_used += FRAG_OVERHEAD;
183-
hpb->total_fragments++;
184-
#endif
185180
#endif
186181

187182
hp_frag_attach(hpb, n);
188183
update_stats_pkg_frag_attach(hpb, n);
189-
190-
#if defined(DBG_MALLOC) && !defined(STATISTICS)
191-
hpb->used -= n->size;
192-
hpb->real_used -= n->size + FRAG_OVERHEAD;
193-
#endif
194184
}
195185

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

430-
#ifndef STATISTICS
431-
hpb->used += frag->size;
432-
hpb->real_used += frag->size + FRAG_OVERHEAD;
433-
#endif
434-
435420
/* split the fragment if possible */
436421
#if !defined INLINE_ALLOC && defined DBG_MALLOC
437422
pkg_frag_split_dbg(hpb, frag, size, file, "hp_malloc frag", line);
@@ -848,34 +833,21 @@ void hp_pkg_free(struct hp_block *hpb, void *p,
848833
update_stats_pkg_frag_detach(hpb, next);
849834

850835
#ifdef DBG_MALLOC
851-
#ifndef STATISTICS
852-
hpb->used += next->size;
853-
hpb->real_used += next->size + FRAG_OVERHEAD;
854-
#endif
855836
hpb->used += FRAG_OVERHEAD;
856837
#endif
857838

858839
f->size += next->size + FRAG_OVERHEAD;
859840
update_stats_pkg_frag_merge(hpb);
860-
861-
#if defined(DBG_MALLOC) && !defined(STATISTICS)
862-
hpb->real_used -= FRAG_OVERHEAD;
863-
hpb->total_fragments--;
864-
#endif
865841
}
866842

867843
hp_frag_attach(hpb, f);
868844
update_stats_pkg_frag_attach(hpb, f);
845+
869846
#ifdef DBG_MALLOC
870847
f->file=file;
871848
f->func=func;
872849
f->line=line;
873850
#endif
874-
875-
#if defined(DBG_MALLOC) && !defined(STATISTICS)
876-
hpb->used -= f->size;
877-
hpb->real_used -= f->size + FRAG_OVERHEAD;
878-
#endif
879851
}
880852

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

11181090
#ifdef DBG_MALLOC
1119-
#ifndef STATISTICS
1120-
hpb->used += next->size;
1121-
hpb->real_used += next->size + FRAG_OVERHEAD;
1122-
#endif
11231091
hpb->used += FRAG_OVERHEAD;
11241092
#endif
11251093

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

11281097
/* split the result if necessary */
11291098
if (f->size > size)
@@ -1591,7 +1560,7 @@ void hp_status(struct hp_block *hpb)
15911560
}
15921561
}
15931562

1594-
LM_GEN1(memdump, "TOTAL: %6d free fragments\n", t);
1563+
LM_GEN1(memdump, "TOTAL: %6d/%ld free fragments\n", t, hpb->total_fragments);
15951564
LM_GEN1(memdump, "Fragment overhead: %u\n", (unsigned int)FRAG_OVERHEAD);
15961565
LM_GEN1(memdump, "-----------------------------\n");
15971566
}

mem/hp_malloc_stats.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,9 @@ void hp_init_shm_statistics(struct hp_block *hpb)
179179
update_stat(shm_rused, (long)hpb->real_used);
180180
update_stat(shm_frags, (long)hpb->total_fragments);
181181

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

186187
unsigned long hp_shm_get_used(struct hp_block *hpb)

mem/hp_malloc_stats.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,12 @@ unsigned long hp_rpm_get_frags(struct hp_block *hpb);
7171
#define update_stats_pkg_frag_split(blk, ...) \
7272
do { \
7373
(blk)->used -= FRAG_OVERHEAD; \
74-
(blk)->real_used += FRAG_OVERHEAD; \
7574
(blk)->total_fragments++; \
7675
} while (0)
7776

7877
#define update_stats_pkg_frag_merge(blk, ...) \
7978
do { \
80-
(blk)->real_used -= FRAG_OVERHEAD; \
79+
(blk)->used += FRAG_OVERHEAD; \
8180
(blk)->total_fragments--; \
8281
} while (0)
8382

0 commit comments

Comments
 (0)