X-Git-Url: https://git.kernel.dk/?a=blobdiff_plain;f=smalloc.c;h=7b30ce704601894c255a2c5b34dc56a547a45dc1;hb=d9dd70f7e3d64ea764f182f152626d895841277c;hp=7e6c4f8f1d9a930725ddc3f6282b5ab2dd74f352;hpb=8e5732e558509fc0f4ccdeb1e4d01ad038aead06;p=fio.git diff --git a/smalloc.c b/smalloc.c index 7e6c4f8f..7b30ce70 100644 --- a/smalloc.c +++ b/smalloc.c @@ -13,19 +13,13 @@ #include "mutex.h" -#undef ENABLE_RESIZE /* define to enable pool resizing */ #define MP_SAFE /* define to made allocator thread safe */ -#define INITIAL_SIZE 1048576 /* new pool size */ -#define MAX_POOLS 32 /* maximum number of pools to setup */ +#define INITIAL_SIZE 32*1048576 /* new pool size */ +#define MAX_POOLS 4 /* maximum number of pools to setup */ unsigned int smalloc_pool_size = INITIAL_SIZE; -#ifdef ENABLE_RESIZE -#define MAX_SIZE 8 * smalloc_pool_size -static unsigned int resize_error; -#endif - struct pool { struct fio_mutex *lock; /* protects this pool */ void *map; /* map of blocks */ @@ -175,51 +169,6 @@ static int compact_pool(struct pool *pool) return !!compacted; } -static int resize_pool(struct pool *pool) -{ -#ifdef ENABLE_RESIZE - unsigned int new_size = pool->size << 1; - struct mem_hdr *hdr, *last_hdr; - void *ptr; - - if (new_size >= MAX_SIZE || resize_error) - return 1; - - if (ftruncate(pool->fd, new_size) < 0) - goto fail; - - ptr = mremap(pool->map, pool->size, new_size, 0); - if (ptr == MAP_FAILED) - goto fail; - - pool->map = ptr; - hdr = pool; - do { - last_hdr = hdr; - } while ((hdr = hdr_nxt(hdr)) != NULL); - - if (hdr_free(last_hdr)) { - last_hdr->size = hdr_size(last_hdr) + new_size - pool_size; - hdr_mark_free(last_hdr); - } else { - struct mem_hdr *nxt; - - nxt = (void *) last_hdr + hdr_size(last_hdr) + sizeof(*hdr); - nxt->size = new_size - pool_size - sizeof(*hdr); - hdr_mark_free(nxt); - } - - pool_room += new_size - pool_size; - pool_size = new_size; - return 0; -fail: - perror("resize"); - resize_error = 1; -#else - return 1; -#endif -} - static int add_pool(struct pool *pool, unsigned int alloc_size) { struct mem_hdr *hdr; @@ -421,20 +370,12 @@ fail: * if we fail to allocate, first compact the entries that we missed. * if that also fails, increase the size of the pool */ - ++did_restart; - if (did_restart <= 1) { + if (++did_restart <= 1) { if (!compact_pool(pool)) { pool->last = pool->map; goto restart; } } - ++did_restart; - if (did_restart <= 2) { - if (!resize_pool(pool)) { - pool->last = pool->map; - goto restart; - } - } pool_unlock(pool); return NULL; }