Exemple #1
0
/*
 * heap_get_bestfit_block --
 *	extracts a memory block of equal size index
 */
int
heap_get_bestfit_block(PMEMobjpool *pop, struct bucket *b,
	struct memory_block *m)
{
	if (bucket_lock(b) != 0)
		return EAGAIN;

	int i;
	uint32_t units = m->size_idx;
	for (i = 0; i < MAX_BUCKET_REFILL; ++i) {
		if (bucket_get_rm_block_bestfit(b, m) != 0)
			heap_ensure_bucket_filled(pop, b, 1);
		else
			break;
	}

	if (i == MAX_BUCKET_REFILL) {
		bucket_unlock(b);
		return ENOMEM;
	}

	if (units != m->size_idx)
		heap_recycle_block(pop, b, m, units);

	bucket_unlock(b);

	return 0;
}
Exemple #2
0
/*
 * heap_get_exact_block --
 *	extracts exactly this memory block and cuts it accordingly
 */
int
heap_get_exact_block(PMEMobjpool *pop, struct bucket *b,
	struct memory_block *m, uint32_t units)
{
	if (bucket_lock(b) != 0)
		return EAGAIN;

	if (bucket_get_rm_block_exact(b, *m) != 0)
		return ENOMEM;

	if (units != m->size_idx)
		heap_recycle_block(pop, b, m, units);

	bucket_unlock(b);

	return 0;
}
Exemple #3
0
/*
 * heap_get_bestfit_block --
 *	extracts a memory block of equal size index
 */
int
heap_get_bestfit_block(struct palloc_heap *heap, struct bucket *b,
	struct memory_block *m)
{
	uint32_t units = m->size_idx;

	while (b->c_ops->get_rm_bestfit(b->container, m) != 0) {
		if (b->aclass->type == CLASS_HUGE) {
			if (heap_ensure_huge_bucket_filled(heap) != 0)
				return ENOMEM;
		} else {
			if (heap_ensure_run_bucket_filled(heap, b, units) != 0)
				return ENOMEM;
		}
	}

	ASSERT(m->size_idx >= units);

	if (units != m->size_idx)
		heap_recycle_block(heap, b, m, units);

	return 0;
}