summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJens Axboe <axboe@fb.com>2015-03-03 15:13:17 -0700
committerMohamad Ayyash <mkayyash@google.com>2015-03-06 17:58:35 -0800
commitd19a46fedbf054bc58a47738ae5d54704653f24b (patch)
tree4aff5d4015637f18f8cb0731d4b12990516334e1
parenteb433fd28ce3ce814fabfb945bf330faf3193f1d (diff)
downloadfio-d19a46fedbf054bc58a47738ae5d54704653f24b.tar.gz
smalloc: bump initial size to 8 pools
Commit 23bd40f944b7 shrank our pool size from 128 pools at 8MB max, to one static 16MB pool. Christian reports: "For our tests with about 250k files we found the smalloc pool being depleted. Now for us values of 3-4 would be enough, but since it is a compile time switch I'd like to make it safe for everybody and set 8." Bump the pool alloc to 8 pools again, retaining the 16MB size. That's still substantially less than before, but should be enough for most cases. Allocate the pools at init time, to avoid the issue that the original commit fixed. Also fix a bug where we failed to iterate some pools when restarting the allocation scan, resulting in less-than-optimal exhaustion of all pools before smalloc() gave up and returned NULL. Signed-off-by: Jens Axboe <axboe@fb.com>
-rw-r--r--smalloc.c35
1 files changed, 20 insertions, 15 deletions
diff --git a/smalloc.c b/smalloc.c
index 66f9ec0d..b460d657 100644
--- a/smalloc.c
+++ b/smalloc.c
@@ -26,7 +26,7 @@
#define SMALLOC_BPL (SMALLOC_BPB * SMALLOC_BPI)
#define INITIAL_SIZE 16*1024*1024 /* new pool size */
-#define MAX_POOLS 1 /* maximum number of pools to setup */
+#define MAX_POOLS 8 /* maximum number of pools to setup */
#define SMALLOC_PRE_RED 0xdeadbeefU
#define SMALLOC_POST_RED 0x5aa55aa5U
@@ -230,11 +230,21 @@ out_fail:
void sinit(void)
{
- int ret;
+ int i, ret;
lock = fio_rwlock_init();
- ret = add_pool(&mp[0], INITIAL_SIZE);
- assert(!ret);
+
+ for (i = 0; i < MAX_POOLS; i++) {
+ ret = add_pool(&mp[i], INITIAL_SIZE);
+ if (ret)
+ break;
+ }
+
+ /*
+ * If we added at least one pool, we should be OK for most
+ * cases.
+ */
+ assert(i);
}
static void cleanup_pool(struct pool *pool)
@@ -442,16 +452,17 @@ static void *smalloc_pool(struct pool *pool, size_t size)
void *smalloc(size_t size)
{
- unsigned int i;
+ unsigned int i, end_pool;
if (size != (unsigned int) size)
return NULL;
global_write_lock();
i = last_pool;
+ end_pool = nr_pools;
do {
- for (; i < nr_pools; i++) {
+ for (; i < end_pool; i++) {
void *ptr = smalloc_pool(&mp[i], size);
if (ptr) {
@@ -461,20 +472,14 @@ void *smalloc(size_t size)
}
}
if (last_pool) {
- last_pool = 0;
+ end_pool = last_pool;
+ last_pool = i = 0;
continue;
}
- if (nr_pools + 1 > MAX_POOLS)
- break;
- else {
- i = nr_pools;
- if (add_pool(&mp[nr_pools], size))
- goto out;
- }
+ break;
} while (1);
-out:
global_write_unlock();
return NULL;
}