smalloc: OOM fixups
authorJens Axboe <axboe@fb.com>
Sun, 25 Sep 2016 20:22:56 +0000 (14:22 -0600)
committerJens Axboe <axboe@fb.com>
Sun, 25 Sep 2016 20:22:56 +0000 (14:22 -0600)
Warn directly in smalloc() instead of having the callers do it.
Add a hint on how to solve a situation where we run out of
shared memory.

Signed-off-by: Jens Axboe <axboe@fb.com>
diskutil.c
filesetup.c
flow.c
server.c
smalloc.c
workqueue.c

index 0f7a64209b57747139e66705a8fd2f71ebbe4697..27ddb46b7fecdae75114874210ed2ae135d21bd6 100644 (file)
@@ -292,10 +292,8 @@ static struct disk_util *disk_util_add(struct thread_data *td, int majdev,
        dprint(FD_DISKUTIL, "add maj/min %d/%d: %s\n", majdev, mindev, path);
 
        du = smalloc(sizeof(*du));
        dprint(FD_DISKUTIL, "add maj/min %d/%d: %s\n", majdev, mindev, path);
 
        du = smalloc(sizeof(*du));
-       if (!du) {
-               log_err("fio: smalloc() pool exhausted\n");
+       if (!du)
                return NULL;
                return NULL;
-       }
 
        memset(du, 0, sizeof(*du));
        INIT_FLIST_HEAD(&du->list);
 
        memset(du, 0, sizeof(*du));
        INIT_FLIST_HEAD(&du->list);
index 317d738042c1b988fa243535c39dfc6e71d8d260..a3bbbb24dbb2bce44fac7dba270acfde5f30ede6 100644 (file)
@@ -1319,7 +1319,6 @@ static struct fio_file *alloc_new_file(struct thread_data *td)
 
        f = smalloc(sizeof(*f));
        if (!f) {
 
        f = smalloc(sizeof(*f));
        if (!f) {
-               log_err("fio: smalloc OOM\n");
                assert(0);
                return NULL;
        }
                assert(0);
                return NULL;
        }
@@ -1402,10 +1401,8 @@ int add_file(struct thread_data *td, const char *fname, int numjob, int inc)
                f->real_file_size = -1ULL;
 
        f->file_name = smalloc_strdup(file_name);
                f->real_file_size = -1ULL;
 
        f->file_name = smalloc_strdup(file_name);
-       if (!f->file_name) {
-               log_err("fio: smalloc OOM\n");
+       if (!f->file_name)
                assert(0);
                assert(0);
-       }
 
        get_file_type(f);
 
 
        get_file_type(f);
 
@@ -1608,10 +1605,8 @@ void dup_files(struct thread_data *td, struct thread_data *org)
 
                if (f->file_name) {
                        __f->file_name = smalloc_strdup(f->file_name);
 
                if (f->file_name) {
                        __f->file_name = smalloc_strdup(f->file_name);
-                       if (!__f->file_name) {
-                               log_err("fio: smalloc OOM\n");
+                       if (!__f->file_name)
                                assert(0);
                                assert(0);
-                       }
 
                        __f->filetype = f->filetype;
                }
 
                        __f->filetype = f->filetype;
                }
diff --git a/flow.c b/flow.c
index e0ac13521f453ed32f2e1ce2fbcdaeb93e70adcc..42b6dd75adbe63a4bbfc30ae26f5715a149e63d7 100644 (file)
--- a/flow.c
+++ b/flow.c
@@ -58,7 +58,6 @@ static struct fio_flow *flow_get(unsigned int id)
        if (!flow) {
                flow = smalloc(sizeof(*flow));
                if (!flow) {
        if (!flow) {
                flow = smalloc(sizeof(*flow));
                if (!flow) {
-                       log_err("fio: smalloc pool exhausted\n");
                        fio_mutex_up(flow_lock);
                        return NULL;
                }
                        fio_mutex_up(flow_lock);
                        return NULL;
                }
index 38626998f279467695fbb27d161ada37f5adbedd..091c1613662f66b3eec6f609ab782304a4ecc097 100644 (file)
--- a/server.c
+++ b/server.c
@@ -578,8 +578,12 @@ static int fio_net_queue_cmd(uint16_t opcode, void *buf, off_t size,
        struct sk_entry *entry;
 
        entry = fio_net_prep_cmd(opcode, buf, size, tagptr, flags);
        struct sk_entry *entry;
 
        entry = fio_net_prep_cmd(opcode, buf, size, tagptr, flags);
-       fio_net_queue_entry(entry);
-       return 0;
+       if (entry) {
+               fio_net_queue_entry(entry);
+               return 0;
+       }
+
+       return 1;
 }
 
 static int fio_net_send_simple_stack_cmd(int sk, uint16_t opcode, uint64_t tag)
 }
 
 static int fio_net_send_simple_stack_cmd(int sk, uint16_t opcode, uint64_t tag)
@@ -1999,10 +2003,8 @@ int fio_server_get_verify_state(const char *name, int threadnumber,
        dprint(FD_NET, "server: request verify state\n");
 
        rep = smalloc(sizeof(*rep));
        dprint(FD_NET, "server: request verify state\n");
 
        rep = smalloc(sizeof(*rep));
-       if (!rep) {
-               log_err("fio: smalloc pool too small\n");
+       if (!rep)
                return ENOMEM;
                return ENOMEM;
-       }
 
        __fio_mutex_init(&rep->lock, FIO_MUTEX_LOCKED);
        rep->data = NULL;
 
        __fio_mutex_init(&rep->lock, FIO_MUTEX_LOCKED);
        rep->data = NULL;
index 3ca29ff1404579d8be5068ee7b8455218fba6c3c..d038ac64ccfb8dedbe2801ed3630dafbb121b97c 100644 (file)
--- a/smalloc.c
+++ b/smalloc.c
@@ -450,6 +450,8 @@ void *smalloc(size_t size)
                break;
        } while (1);
 
                break;
        } while (1);
 
+       log_err("smalloc: OOM. Consider using --alloc-size to increase the "
+               "shared memory available.\n");
        return NULL;
 }
 
        return NULL;
 }
 
index 013087e10561128bfb6f51b03abc32f63a9d3964..1131400fd23a5acc8479c813fef0135c4987cf30 100644 (file)
@@ -323,6 +323,8 @@ int workqueue_init(struct thread_data *td, struct workqueue *wq,
                goto err;
 
        wq->workers = smalloc(wq->max_workers * sizeof(struct submit_worker));
                goto err;
 
        wq->workers = smalloc(wq->max_workers * sizeof(struct submit_worker));
+       if (!wq->workers)
+               goto err;
 
        for (i = 0; i < wq->max_workers; i++)
                if (start_worker(wq, i, sk_out))
 
        for (i = 0; i < wq->max_workers; i++)
                if (start_worker(wq, i, sk_out))