/* * bucket_tree_get_rm_block_bestfit -- (internal) removes and returns the * best-fit memory block for size */ static int bucket_tree_get_rm_block_bestfit(struct block_container *bc, struct memory_block *m) { uint64_t key = CHUNK_KEY_PACK(m->zone_id, m->chunk_id, m->block_off, m->size_idx); struct block_container_ctree *c = (struct block_container_ctree *)bc; if ((key = ctree_remove(c->tree, key, 0)) == 0) return ENOMEM; m->chunk_id = CHUNK_KEY_GET_CHUNK_ID(key); m->zone_id = CHUNK_KEY_GET_ZONE_ID(key); m->block_off = CHUNK_KEY_GET_BLOCK_OFF(key); m->size_idx = CHUNK_KEY_GET_SIZE_IDX(key); return 0; }
/* * bucket_insert_block -- inserts a new memory block into the container */ int bucket_insert_block(PMEMobjpool *pop, struct bucket *b, struct memory_block m) { ASSERT(m.chunk_id < MAX_CHUNK); ASSERT(m.zone_id < UINT16_MAX); ASSERT(m.size_idx != 0); #ifdef USE_VG_MEMCHECK if (On_valgrind) { size_t rsize = m.size_idx * bucket_unit_size(b); void *block_data = heap_get_block_data(pop, m); VALGRIND_DO_MAKE_MEM_NOACCESS(pop, block_data, rsize); } #endif uint64_t key = CHUNK_KEY_PACK(m.zone_id, m.chunk_id, m.block_off, m.size_idx); return ctree_insert(b->tree, key, 0); }