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 0f7a642..27ddb46 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));
-       if (!du) {
-               log_err("fio: smalloc() pool exhausted\n");
+       if (!du)
                return NULL;
-       }
 
        memset(du, 0, sizeof(*du));
        INIT_FLIST_HEAD(&du->list);
index 317d738..a3bbbb2 100644 (file)
@@ -1319,7 +1319,6 @@ static struct fio_file *alloc_new_file(struct thread_data *td)
 
        f = smalloc(sizeof(*f));
        if (!f) {
-               log_err("fio: smalloc OOM\n");
                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);
-       if (!f->file_name) {
-               log_err("fio: smalloc OOM\n");
+       if (!f->file_name)
                assert(0);
-       }
 
        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) {
-                               log_err("fio: smalloc OOM\n");
+                       if (!__f->file_name)
                                assert(0);
-                       }
 
                        __f->filetype = f->filetype;
                }
diff --git a/flow.c b/flow.c
index e0ac135..42b6dd7 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) {
-                       log_err("fio: smalloc pool exhausted\n");
                        fio_mutex_up(flow_lock);
                        return NULL;
                }
index 3862699..091c161 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);
-       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)
@@ -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));
-       if (!rep) {
-               log_err("fio: smalloc pool too small\n");
+       if (!rep)
                return ENOMEM;
-       }
 
        __fio_mutex_init(&rep->lock, FIO_MUTEX_LOCKED);
        rep->data = NULL;
index 3ca29ff..d038ac6 100644 (file)
--- a/smalloc.c
+++ b/smalloc.c
@@ -450,6 +450,8 @@ void *smalloc(size_t size)
                break;
        } while (1);
 
+       log_err("smalloc: OOM. Consider using --alloc-size to increase the "
+               "shared memory available.\n");
        return NULL;
 }
 
index 013087e..1131400 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));
+       if (!wq->workers)
+               goto err;
 
        for (i = 0; i < wq->max_workers; i++)
                if (start_worker(wq, i, sk_out))