Skip to content

Commit

Permalink
hp malloc: reorder some initializing operations
Browse files Browse the repository at this point in the history
	* hp_mem_warming() fails if anything is allocated before
		(it cannot access the big fragment anymore)
(cherry picked from commit 9f71064)
  • Loading branch information
liviuchircu committed Mar 27, 2014
1 parent 5663e41 commit 8b8ab79
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
6 changes: 6 additions & 0 deletions mem/hp_malloc.c
Expand Up @@ -456,6 +456,12 @@ struct hp_block *hp_malloc_init(char *address, unsigned long size)
qm->free_hash[PEEK_HASH_RR(qm, qm->first_frag->size)].total_no++;
hp_frag_attach(qm, qm->first_frag);

/* if memory warming is on, pre-populate the hash with free fragments */
if (mem_warming_enabled) {
if (shm_mem_warming(qm) != 0)
LM_INFO("skipped memory warming\n");
}

hp_stats_lock = hp_malloc_unsafe(qm, sizeof *hp_stats_lock);
if (!hp_stats_lock) {
LM_ERR("failed to alloc hp statistics lock\n");
Expand Down
23 changes: 9 additions & 14 deletions mem/shm_mem.c
Expand Up @@ -283,20 +283,6 @@ int shm_mem_init_mallocs(void* mempool, unsigned long pool_size)
}

#ifdef HP_MALLOC
/* if memory warming is on, pre-populate the hash with free fragments */
if (mem_warming_enabled) {
if (shm_mem_warming(shm_block) != 0)
LM_INFO("skipped memory warming\n");
}

mem_hash_usage = shm_malloc_unsafe(HP_TOTAL_HASH_SIZE * sizeof *mem_hash_usage);
if (!mem_hash_usage) {
LM_ERR("failed to allocate statistics array\n");
return -1;
}

memset(mem_hash_usage, 0, HP_TOTAL_HASH_SIZE * sizeof *mem_hash_usage);

/* lock_alloc cannot be used yet! */
mem_lock = shm_malloc_unsafe(HP_TOTAL_HASH_SIZE * sizeof *mem_lock);
if (!mem_lock) {
Expand All @@ -311,6 +297,15 @@ int shm_mem_init_mallocs(void* mempool, unsigned long pool_size)
shm_mem_destroy();
return -1;
}

mem_hash_usage = shm_malloc_unsafe(HP_TOTAL_HASH_SIZE * sizeof *mem_hash_usage);
if (!mem_hash_usage) {
LM_ERR("failed to allocate statistics array\n");
return -1;
}

memset(mem_hash_usage, 0, HP_TOTAL_HASH_SIZE * sizeof *mem_hash_usage);

#else
mem_lock = shm_malloc_unsafe(sizeof *mem_lock);
if (!mem_lock) {
Expand Down

0 comments on commit 8b8ab79

Please sign in to comment.