library/src/mmap/BP-MMapSlabAllocator.cc
// updates the information in an allocator
updates the information in an allocator
updates the information in an allocator
BP_ERROR_T BP_SlabAllocUpdateInfo(P_BP_MMAP_SLAB_ALLOCATOR allocator, BP_BOOL skip_locks)
{
	if(!allocator)
		return ERR_FAILURE;
	if(skip_locks == BP_FALSE)
		BP_SLAB_TABLE_LOCK_SEM(allocator->lock);
	if(!allocator->entry_count)
	{
		if(skip_locks == BP_FALSE)
			BP_SLAB_TABLE_UNLOCK_SEM(allocator->lock);
		return ERR_FAILURE;
	}
	size_t entries_available                     = 0;
	size_t entries_used                          = 0;
	size_t entries_still_newly_allocated         = 0;
	P_BP_MMAP_SLAB_ENTRY_HDR largest_contiguous_blocks_available    = NULL;
	size_t largest_contiguous_blocks_available_n                    = 0;
	P_BP_MMAP_SLAB_ENTRY_HDR prev_available_slab_entry                  = NULL;
	size_t                   prev_available_slab_entry_adjacent_entry_n = 0;
	P_BP_MMAP_SLAB_ENTRY_HDR last_available_slab_entry                  = NULL;
	size_t                   last_available_slab_entry_adjacent_entry_n = 0;
	size_t group_top_entries_n = 0;
	BP_SLAB_ALLOCATOR_ITER_LOOP_ALL(allocator)
	{
		if(BP_FLAG_IS_SET(allocator->curr_entry->flags, BP_MMAP_SLAB_ENTRY_INFO_IS_GROUP_TOP))
			group_top_entries_n++;
		if(BP_FLAG_IS_SET(allocator->curr_entry->flags, BP_MMAP_SLAB_ENTRY_INFO_IN_USE))
			entries_used++;
		if(BP_FLAG_IS_SET(allocator->curr_entry->flags, BP_MMAP_SLAB_ENTRY_INFO_NEVER_ALLOCATED))
			entries_still_newly_allocated++;
		if(BP_FLAG_IS_SET(allocator->curr_entry->flags, BP_MMAP_SLAB_ENTRY_INFO_AVAILABLE))
		{
			if(!last_available_slab_entry)
			{
				last_available_slab_entry = allocator->curr_entry;
				last_available_slab_entry_adjacent_entry_n = 1;
			}
			else
			{
				last_available_slab_entry_adjacent_entry_n++;
			}
			entries_available++;
		}
		else
		{
			prev_available_slab_entry = last_available_slab_entry;
			prev_available_slab_entry_adjacent_entry_n = last_available_slab_entry_adjacent_entry_n;
		}
		if(prev_available_slab_entry_adjacent_entry_n < last_available_slab_entry_adjacent_entry_n)
		{
			largest_contiguous_blocks_available_n = last_available_slab_entry_adjacent_entry_n;
			largest_contiguous_blocks_available = last_available_slab_entry;
		}
	}
	allocator->entries_available                     = entries_available;
	allocator->entries_used                          = entries_used;
	allocator->entries_still_newly_allocated         = entries_still_newly_allocated;
	allocator->largest_contiguous_blocks_available   = largest_contiguous_blocks_available;
	allocator->largest_contiguous_blocks_available_n = largest_contiguous_blocks_available_n;
	allocator->group_alloc_n                         = group_top_entries_n;
	if(skip_locks == BP_FALSE)
		BP_SLAB_TABLE_UNLOCK_SEM(allocator->lock);
	return ERR_SUCCESS;
}
BP_ERROR_T BP_SlabAllocUpdateInfo ( P_BP_MMAP_SLAB_ALLOCATOR allocator , BP_BOOL skip_locks ) { if ( ! allocator ) return ERR_FAILURE ; if ( skip_locks == BP_FALSE ) BP_SLAB_TABLE_LOCK_SEM ( allocator -> lock ) ; if ( ! allocator -> entry_count ) { if ( skip_locks == BP_FALSE ) BP_SLAB_TABLE_UNLOCK_SEM ( allocator -> lock ) ; return ERR_FAILURE ; } size_t entries_available = 0 ; size_t entries_used = 0 ; size_t entries_still_newly_allocated = 0 ; P_BP_MMAP_SLAB_ENTRY_HDR largest_contiguous_blocks_available = NULL ; size_t largest_contiguous_blocks_available_n = 0 ; P_BP_MMAP_SLAB_ENTRY_HDR prev_available_slab_entry = NULL ; size_t prev_available_slab_entry_adjacent_entry_n = 0 ; P_BP_MMAP_SLAB_ENTRY_HDR last_available_slab_entry = NULL ; size_t last_available_slab_entry_adjacent_entry_n = 0 ; size_t group_top_entries_n = 0 ; BP_SLAB_ALLOCATOR_ITER_LOOP_ALL ( allocator ) { if ( BP_FLAG_IS_SET ( allocator -> curr_entry -> flags , BP_MMAP_SLAB_ENTRY_INFO_IS_GROUP_TOP ) ) group_top_entries_n ++ ; if ( BP_FLAG_IS_SET ( allocator -> curr_entry -> flags , BP_MMAP_SLAB_ENTRY_INFO_IN_USE ) ) entries_used ++ ; if ( BP_FLAG_IS_SET ( allocator -> curr_entry -> flags , BP_MMAP_SLAB_ENTRY_INFO_NEVER_ALLOCATED ) ) entries_still_newly_allocated ++ ; if ( BP_FLAG_IS_SET ( allocator -> curr_entry -> flags , BP_MMAP_SLAB_ENTRY_INFO_AVAILABLE ) ) { if ( ! last_available_slab_entry ) { last_available_slab_entry = allocator -> curr_entry ; last_available_slab_entry_adjacent_entry_n = 1 ; } else { last_available_slab_entry_adjacent_entry_n ++ ; } entries_available ++ ; } else { prev_available_slab_entry = last_available_slab_entry ; prev_available_slab_entry_adjacent_entry_n = last_available_slab_entry_adjacent_entry_n ; } if ( prev_available_slab_entry_adjacent_entry_n < last_available_slab_entry_adjacent_entry_n ) { largest_contiguous_blocks_available_n = last_available_slab_entry_adjacent_entry_n ; largest_contiguous_blocks_available = last_available_slab_entry ; } } allocator -> entries_available = entries_available ; allocator -> entries_used = entries_used ; allocator -> entries_still_newly_allocated = entries_still_newly_allocated ; allocator -> largest_contiguous_blocks_available = largest_contiguous_blocks_available ; allocator -> largest_contiguous_blocks_available_n = largest_contiguous_blocks_available_n ; allocator -> group_alloc_n = group_top_entries_n ; if ( skip_locks == BP_FALSE ) BP_SLAB_TABLE_UNLOCK_SEM ( allocator -> lock ) ; return ERR_SUCCESS ; }
updates the information in an allocator
updates the information in an allocator
// ensure we have an allocator // lock the allocator before display // ensure we have an entry count, if not, exit // return indicating failure // local variables used for calculations // pointer to the largest set of available blocks // prev entry data // last entry data // number of group entries // Iterate through all items in the allocator and run checks on each to determine // the status of our allocator. // count the number of group top entries // count the number of entries used // if the current slab has never been allocated, indicate that here // check if flag is available // if the last available slab entry isn't set, set it // increase the available adjacent count // if the previous largest has less entries than the current set of available entries, then // set the current set of entries as the largest. // set count // set entry // set updated information in the allocator // unlock allocator before exit // return indicating success