Skip to content
Permalink
Browse files

OPS-6: HP_MALLOC / F_MALLOC - remove redundant logic

There is no need for a separate frag->is_free field, as this task is
already achieved by the optimally managed frag->prev field in both
allocators.
  • Loading branch information
liviuchircu committed Mar 15, 2019
1 parent 4adb1bb commit 572f0df73ea9f70ee9fcb85206312a9be25c7a00
Showing with 7 additions and 49 deletions.
  1. +1 −6 mem/f_malloc.c
  2. +2 −6 mem/f_malloc.h
  3. +2 −13 mem/f_malloc_dyn.h
  4. +1 −6 mem/hp_malloc.c
  5. +0 −3 mem/hp_malloc.h
  6. +1 −15 mem/hp_malloc_dyn.h
@@ -154,11 +154,6 @@ static inline void fm_insert_free(struct fm_block* qm, struct fm_frag* frag)
if( *f )
(*f)->prev = &(frag->u.nxt_free);

#if (defined DBG_MALLOC) || (defined SHM_EXTRA_STATS)
/* mark fragment as "free" */
frag->is_free = 1;
#endif

*f=frag;
qm->free_hash[hash].no++;

@@ -276,7 +271,7 @@ void fm_stats_core_init(struct fm_block *fm, int core_index)
struct fm_frag *f;

for (f=fm->first_frag; (char *)f < (char *)fm->last_frag; f=FRAG_NEXT(f))
if (!f->is_free)
if (!frag_is_free(f))
f->statistic_index = core_index;
}

@@ -74,17 +74,13 @@ struct fm_frag {
unsigned long check;
#endif

#define FM_FRAG_OVERHEAD (sizeof(struct fm_frag))

#if (defined DBG_MALLOC) || (defined SHM_EXTRA_STATS)
char is_free;
#endif

#ifdef SHM_EXTRA_STATS
unsigned long statistic_index;
#endif
};

#define FM_FRAG_OVERHEAD (sizeof(struct fm_frag))

struct fm_frag_lnk {
struct fm_frag* first;
unsigned long no;
@@ -147,14 +147,8 @@ void* fm_malloc(struct fm_block* qm, unsigned long size,
qm->used += FRAG_OVERHEAD;
#endif

if( frag->size >size ) {
#if (defined DBG_MALLOC) || (defined SHM_EXTRA_STATS)
/* mark it as "busy" */
frag->is_free = 0;
#endif

if (frag->size >size)
goto solved;
}

n = FRAG_NEXT(frag);
}
@@ -178,11 +172,6 @@ void* fm_malloc(struct fm_block* qm, unsigned long size,

fm_remove_free(qm,frag);

#if (defined DBG_MALLOC) || (defined SHM_EXTRA_STATS)
/* mark it as "busy" */
frag->is_free = 0;
#endif

/*see if we'll use full frag, or we'll split it in 2*/

#if !defined INLINE_ALLOC && defined DBG_MALLOC
@@ -464,7 +453,7 @@ void fm_status(struct fm_block* qm)
dbg_ht_init(allocd);

for (f=qm->first_frag; (char*)f<(char*)qm->last_frag; f=FRAG_NEXT(f))
if (!f->is_free)
if (!frag_is_free(f))
if (dbg_ht_update(allocd, f->file, f->func, f->line, f->size) < 0) {
LM_ERR("Unable to update alloc'ed. memory summary\n");
dbg_ht_free(allocd);
@@ -201,11 +201,6 @@ static inline void hp_frag_attach(struct hp_block *hpb, struct hp_frag *frag)
if (*f)
(*f)->prev = &(frag->u.nxt_free);

/* mark fragment as "free" */
#if (defined DBG_MALLOC) || (defined SHM_EXTRA_STATS)
frag->is_free = 1;
#endif

*f = frag;

#ifdef HP_MALLOC_FAST_STATS
@@ -626,7 +621,7 @@ void hp_stats_core_init(struct hp_block *hp, int core_index)
struct hp_frag *f;

for (f=hp->first_frag; (char*)f<(char*)hp->last_frag; f=FRAG_NEXT(f))
if (!f->is_free)
if (!frag_is_free(f))
f->statistic_index = core_index;
}
#endif
@@ -94,9 +94,6 @@ struct hp_frag {
unsigned long line;
#endif

#if (defined DBG_MALLOC) || (defined SHM_EXTRA_STATS)
char is_free;
#endif
#ifdef SHM_EXTRA_STATS
unsigned long statistic_index;
#endif
@@ -337,10 +337,6 @@ void *hp_pkg_malloc(struct hp_block *hpb, unsigned long size,
hp_frag_detach(hpb, frag);
update_stats_pkg_frag_detach(hpb, frag);

#if (defined DBG_MALLOC) || (defined SHM_EXTRA_STATS)
/* mark fragment as "busy" */
frag->is_free = 0;
#endif
#ifndef STATISTICS
hpb->used += frag->size;
hpb->real_used += frag->size + FRAG_OVERHEAD;
@@ -450,11 +446,6 @@ void *hp_shm_malloc_unsafe(struct hp_block *hpb, unsigned long size,
hpb->real_used += frag->size + FRAG_OVERHEAD;
}

#if (defined DBG_MALLOC) || (defined SHM_EXTRA_STATS)
/* mark it as "busy" */
frag->is_free = 0;
#endif

/* split the fragment if possible */
#if !defined INLINE_ALLOC && defined DBG_MALLOC
shm_frag_split_unsafe_dbg(hpb, frag, size, file, "hp_malloc frag", line);
@@ -568,11 +559,6 @@ void *hp_shm_malloc(struct hp_block *hpb, unsigned long size,
hpb->real_used += (frag)->size + FRAG_OVERHEAD;
#endif

#if (defined DBG_MALLOC) || (defined SHM_EXTRA_STATS)
/* mark fragment as "busy" */
frag->is_free = 0;
#endif

#if !defined INLINE_ALLOC && defined DBG_MALLOC
/* split the fragment if possible */
shm_frag_split_dbg(hpb, frag, size, hash, file, "hp_malloc frag", line);
@@ -1052,7 +1038,7 @@ void hp_status(struct hp_block *hpb)
dbg_ht_init(allocd);

for (f=hpb->first_frag; (char*)f<(char*)hpb->last_frag; f=FRAG_NEXT(f))
if (!f->is_free)
if (!frag_is_free(f))
if (dbg_ht_update(allocd, f->file, f->func, f->line, f->size) < 0) {
LM_ERR("Unable to update alloc'ed. memory summary\n");
dbg_ht_free(allocd);

0 comments on commit 572f0df

Please sign in to comment.
You can’t perform that action at this time.