init: re-call sinit() if we change the smallc pool size
authorJens Axboe <axboe@fb.com>
Sun, 25 Sep 2016 19:56:59 +0000 (13:56 -0600)
committerJens Axboe <axboe@fb.com>
Sun, 25 Sep 2016 19:56:59 +0000 (13:56 -0600)
Just adds more pools, but that should be fine at init time.

Signed-off-by: Jens Axboe <axboe@fb.com>
init.c
smalloc.c

diff --git a/init.c b/init.c
index 5482c665c277e5050b89a5759fa9bcd49895fd26..f7cb46d33ee7933bac51a10cad4e40212f456cec 100644 (file)
--- a/init.c
+++ b/init.c
@@ -2309,6 +2309,7 @@ int parse_cmd_line(int argc, char *argv[], int client_type)
                case 'a':
                        smalloc_pool_size = atoi(optarg);
                        smalloc_pool_size <<= 10;
+                       sinit();
                        break;
                case 't':
                        if (check_str_time(optarg, &def_timeout, 1)) {
index 6f647c060e087c198ce9b580cbef72ff03227847..3ca29ff1404579d8be5068ee7b8455218fba6c3c 100644 (file)
--- a/smalloc.c
+++ b/smalloc.c
@@ -26,7 +26,9 @@
 #define SMALLOC_BPL    (SMALLOC_BPB * SMALLOC_BPI)
 
 #define INITIAL_SIZE   16*1024*1024    /* new pool size */
-#define MAX_POOLS      8               /* maximum number of pools to setup */
+#define INITIAL_POOLS  8               /* maximum number of pools to setup */
+
+#define MAX_POOLS      16
 
 #define SMALLOC_PRE_RED                0xdeadbeefU
 #define SMALLOC_POST_RED       0x5aa55aa5U
@@ -149,12 +151,15 @@ static int find_next_zero(int word, int start)
        return ffz(word) + start;
 }
 
-static int add_pool(struct pool *pool, unsigned int alloc_size)
+static bool add_pool(struct pool *pool, unsigned int alloc_size)
 {
        int bitmap_blocks;
        int mmap_flags;
        void *ptr;
 
+       if (nr_pools == MAX_POOLS)
+               return false;
+
 #ifdef SMALLOC_REDZONE
        alloc_size += sizeof(unsigned int);
 #endif
@@ -191,21 +196,22 @@ static int add_pool(struct pool *pool, unsigned int alloc_size)
                goto out_fail;
 
        nr_pools++;
-       return 0;
+       return true;
 out_fail:
        log_err("smalloc: failed adding pool\n");
        if (pool->map)
                munmap(pool->map, pool->mmap_size);
-       return 1;
+       return false;
 }
 
 void sinit(void)
 {
-       int i, ret;
+       bool ret;
+       int i;
 
-       for (i = 0; i < MAX_POOLS; i++) {
-               ret = add_pool(&mp[i], smalloc_pool_size);
-               if (ret)
+       for (i = 0; i < INITIAL_POOLS; i++) {
+               ret = add_pool(&mp[nr_pools], smalloc_pool_size);
+               if (!ret)
                        break;
        }