Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
}
static int mask_cmp(unsigned int *map, unsigned int mask)
}
static int mask_cmp(unsigned int *map, unsigned int mask)
void *ptr;
int fd, bitmap_blocks;
void *ptr;
int fd, bitmap_blocks;
- printf("add pool %u\n", alloc_size);
-
strcpy(pool->file, "/tmp/.fio_smalloc.XXXXXX");
fd = mkstemp(pool->file);
if (fd < 0)
strcpy(pool->file, "/tmp/.fio_smalloc.XXXXXX");
fd = mkstemp(pool->file);
if (fd < 0)
static void sfree_pool(struct pool *pool, void *ptr)
{
struct block_hdr *hdr;
static void sfree_pool(struct pool *pool, void *ptr)
{
struct block_hdr *hdr;
- unsigned int nr_blocks, i, idx;
unsigned long offset;
if (!ptr)
unsigned long offset;
if (!ptr)
assert(ptr_valid(pool, ptr));
assert(ptr_valid(pool, ptr));
- nr_blocks = (hdr->size + SMALLOC_BPB - 1) / SMALLOC_BPB;
sfree_check_redzone(hdr);
offset = ptr - pool->map;
sfree_check_redzone(hdr);
offset = ptr - pool->map;
idx = (offset % SMALLOC_BPL) / SMALLOC_BPB;
pool_lock(pool);
idx = (offset % SMALLOC_BPL) / SMALLOC_BPB;
pool_lock(pool);
- clear_blocks(&pool->bitmap[i], idx, nr_blocks);
+ clear_blocks(&pool->bitmap[i], idx, size_to_blocks(hdr->size));
if (i < pool->next_non_full)
pool->next_non_full = i;
if (i < pool->next_non_full)
pool->next_non_full = i;
- pool->free_blocks += nr_blocks;
+ pool->free_blocks += size_to_blocks(hdr->size);
+static inline unsigned int size_to_blocks(unsigned int size)
+{
+ return (size + SMALLOC_BPB - 1) / SMALLOC_BPB;
+}
+
static void *__smalloc_pool(struct pool *pool, unsigned int size)
{
unsigned int nr_blocks;
static void *__smalloc_pool(struct pool *pool, unsigned int size)
{
unsigned int nr_blocks;
unsigned int last_idx;
void *ret = NULL;
unsigned int last_idx;
void *ret = NULL;
- nr_blocks = (size + SMALLOC_BPB - 1) / SMALLOC_BPB;
-
+
+ nr_blocks = size_to_blocks(size);
if (nr_blocks > pool->free_blocks)
goto fail;
if (nr_blocks > pool->free_blocks)
goto fail;