kernel/mem_pool.c
/**
 *
 * @brief Defragment the specified memory pool block sets
 *
 * Reassembles any quad-blocks that are entirely unused into larger blocks
 * (to the extent permitted).
 *
 * @param pool memory pool descriptor
 * @param start_block_set_index index of smallest block set to defragment
 * @param last_block_set_index index of largest block set to defragment
 *
 * @return N/A
 */
@brief Defragment the specified memory pool block sets
Reassembles any quad-blocks that are entirely unused into larger blocks
(to the extent permitted).

@param pool memory pool descriptor
@param start_block_set_index index of smallest block set to defragment
@param last_block_set_index index of largest block set to defragment

@return N/A
@brief Defragment the specified memory pool block sets Reassembles any quad - blocks that are entirely unused into larger blocks ( to the extent permitted ) . @param pool memory pool descriptor @param start_block_set_index index of smallest block set to defragment @param last_block_set_index index of largest block set to defragment @return N / A
static void defrag(struct k_mem_pool *pool,
		   int start_block_set_index, int last_block_set_index)
{
	u32_t i;
	u32_t k;
	int j;
	struct k_mem_pool_quad_block *quad_block;
	for (j = start_block_set_index; j > last_block_set_index; j--) {
		quad_block = pool->block_set[j].quad_block;
		i = 0;
		do {
			if (quad_block[i].mem_blocks == NULL) {
				break;
			}
			if (quad_block[i].mem_status == _QUAD_BLOCK_AVAILABLE) {
				free_existing_block(
					quad_block[i].mem_blocks, pool, j - 1);
				k = i;
				while (((k+1) !=
					pool->block_set[j].nr_of_entries) &&
				       (quad_block[k + 1].mem_blocks != NULL)) {
					k++;
				}
				quad_block[i].mem_blocks =
					quad_block[k].mem_blocks;
				quad_block[i].mem_status =
					quad_block[k].mem_status;
				quad_block[k].mem_blocks = NULL;
			} else {
				i++;
			}
		} while (i < pool->block_set[j].nr_of_entries);
	}
}
static void defrag ( struct k_mem_pool * pool , int start_block_set_index , int last_block_set_index ) { u32_t i ; u32_t k ; int j ; struct k_mem_pool_quad_block * quad_block ; for ( j = start_block_set_index ; j > last_block_set_index ; j -- ) { quad_block = pool -> block_set [ j ] . quad_block ; i = 0 ; do { if ( quad_block [ i ] . mem_blocks == NULL ) { break ; } if ( quad_block [ i ] . mem_status == _QUAD_BLOCK_AVAILABLE ) { free_existing_block ( quad_block [ i ] . mem_blocks , pool , j - 1 ) ; k = i ; while ( ( ( k + 1 ) != pool -> block_set [ j ] . nr_of_entries ) && ( quad_block [ k + 1 ] . mem_blocks != NULL ) ) { k ++ ; } quad_block [ i ] . mem_blocks = quad_block [ k ] . mem_blocks ; quad_block [ i ] . mem_status = quad_block [ k ] . mem_status ; quad_block [ k ] . mem_blocks = NULL ; } else { i ++ ; } } while ( i < pool -> block_set [ j ] . nr_of_entries ) ; } }
@brief Defragment the specified memory pool block sets
 Reassembles any quad-blocks that are entirely unused into larger blocks
 (to the extent permitted).
@brief Defragment the specified memory pool block sets Reassembles any quad - blocks that are entirely unused into larger blocks ( to the extent permitted ) .
/* process block sets from smallest to largest permitted sizes */ /* block set is done if no more quad-blocks exist */ /* reassemble current quad-block, if possible */ /*
				 * mark the corresponding block in next larger
				 * block set as free
				 */ /*
				 * delete the quad-block from this block set
				 * by replacing it with the last quad-block
				 *
				 * (algorithm works even when the deleted
				 * quad-block is the last quad_block)
				 */ /* loop & process replacement quad_block[i] */ /* block set is done if at end of quad-block array */