More malloc reduction - remove excessive bilink allocations...
PATCH 1/1 More malloc reduction - remove excessive bilink allocations...
From: Alan D. Brunelle <[email protected]>
Reduce amount of allocations done for bilinks.
Used to do 1-for-1 allocations of bilinks for traces processed, we now have reduced this to the largest tree size left (thousands instead of millions of allocs for a moderately sized file).
This data set used to result in :
malloc/free: 11,241,958 allocs, 11,241,958 frees, 440,381,362 bytes allocated.
It is now:
malloc/free: 41,076 allocs, 41,076 frees, 9,272,450 bytes allocated.
Signed-off-by Alan D. Brunelle <[email protected]>
---
btt/bt_timeline.c | 2 ++ btt/globals.h | 3 ++- btt/inlines.h | 25 ++++++++++++++++++++++--- 3 files changed, 26 insertions(+), 4 deletions(-)
btt/bt_timeline.c +2 -0
@@ -39,6 +39,7 @@ time_t genesis, last_vtrace;LIST_HEAD (all_devs);LIST_HEAD (all_procs);LIST_HEAD (free_ios); +LIST_HEAD (free_bilinks);LIST_HEAD (rmhd);LIST_HEAD (retries);__u64 q_histo[N_HIST_BKTS ], d_histo[N_HIST_BKTS ];
@@ -89,6 +90,7 @@ int main(int argc, char *argv[])dip_exit ();pip_exit ();io_free_all (); +bilink_free_all ();region_exit (&all_regions);free (input_name);
btt/globals.h +2 -1
@@ -190,6 +190,7 @@ struct bilink {struct list_head down_head, up_head;struct io *diop, *uiop; }; +#define bilink_free_head down_head/* bt_timeline.c */
@@ -205,7 +206,7 @@ extern struct list_head all_devs, all_procs, retries, rmhd;extern struct avgs_info all_avgs;extern __u64 last_q, next_retry_check;extern struct region_info all_regions; -extern struct list_head free_ios; +extern struct list_head free_ios, free_bilinks;extern __u64 iostat_interval, iostat_last_stamp;extern time_t genesis, last_vtrace;extern double t_astart, t_aend;
btt/inlines.h +22 -3
@@ -127,7 +127,7 @@ static inline struct io *io_alloc(void)struct io *iop;if (!list_empty (&free_ios)) { - iop = list_entry(free_ios.next, struct io, f_head); + iop = list_entry(free_ios.prev, struct io, f_head);LIST_DEL (&iop->f_head);# if defined(COUNT_IOS )
@@ -406,12 +406,31 @@ static inline int type2c(enum iop_type type)static inline void bilink_free (struct bilink *blp) { -free (blp); +list_add_tail (&blp->bilink_free_head, &free_bilinks); +} + +static inline void bilink_free_all (void ) +{ +struct bilink *blp; +struct list_head *p, *q; + +list_for_each_safe (p, q, &free_bilinks) { + blp = list_entry(p, struct bilink, bilink_free_head); +free (blp); + } }static inline struct bilink *bilink_alloc (struct io *diop,struct io *uiop) { -struct bilink *blp =malloc (sizeof (*blp)); +struct bilink *blp; + +if (!list_empty (&free_bilinks)) { + blp = list_entry(free_bilinks.prev, struct bilink, + bilink_free_head); +LIST_DEL (&blp->bilink_free_head); + } +else + blp =malloc (sizeof (*blp)); blp->diop = diop; blp->uiop = uiop;