@@ -43,7 +43,9 @@ typedef struct MPIDU_genq_private_pool {
4343 MPIDU_genq_free_fn free_fn ;
4444
4545 intptr_t num_blocks ;
46- intptr_t max_num_blocks ;
46+ intptr_t max_num_blocks ; /* as cells are alloc'ed, the pool may grow up to max_num_blocks.
47+ * NOTE: MPIDU_genq_private_pool_force_alloc_cell may increase max_num_blocks */
48+ intptr_t min_num_blocks ; /* as cells are freed, the pool may shrink back to min_num_blocks */
4749 cell_block_s * cell_blocks ;
4850 cell_block_s * free_blocks_head ;
4951 cell_block_s * free_blocks_tail ;
@@ -69,8 +71,10 @@ int MPIDU_genq_private_pool_create(intptr_t cell_size, intptr_t num_cells_in_blo
6971 if (max_num_cells == 0 ) {
7072 /* 0 means unlimited */
7173 pool_obj -> max_num_blocks = 0 ;
74+ pool_obj -> min_num_blocks = 1 ;
7275 } else {
7376 pool_obj -> max_num_blocks = max_num_cells / num_cells_in_block ;
77+ pool_obj -> min_num_blocks = pool_obj -> max_num_blocks ;
7478 }
7579
7680 pool_obj -> malloc_fn = malloc_fn ;
@@ -278,9 +282,9 @@ int MPIDU_genq_private_pool_free_cell(MPIDU_genq_private_pool_t pool, void *cell
278282 if (block -> num_used_cells == pool_obj -> num_cells_in_block - 1 ) {
279283 append_free_blocks (pool_obj , block );
280284 } else if (block -> num_used_cells == 0 ) {
281- /* Avoid frequent re-allocation by preserving the last block .
285+ /* Avoid frequent re-allocation by preserving a minimum number of blocks .
282286 * All blocks will be freed when the pool is destroyed */
283- if (pool_obj -> num_blocks > 1 && pool_obj -> max_num_blocks == 0 ) {
287+ if (pool_obj -> num_blocks > pool_obj -> min_num_blocks ) {
284288 remove_free_blocks (pool_obj , block );
285289 DL_DELETE (pool_obj -> cell_blocks , block );
286290 cell_block_free (pool_obj , block );
0 commit comments