From 81b3c86f086cb2340d1c5596202a307487216b21 Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Sun, 25 Sep 2016 14:22:56 -0600 Subject: [PATCH] smalloc: OOM fixups 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 --- diskutil.c | 4 +--- filesetup.c | 9 ++------- flow.c | 1 - server.c | 12 +++++++----- smalloc.c | 2 ++ workqueue.c | 2 ++ 6 files changed, 14 insertions(+), 16 deletions(-) diff --git a/diskutil.c b/diskutil.c index 0f7a6420..27ddb46b 100644 --- a/diskutil.c +++ b/diskutil.c @@ -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); diff --git a/filesetup.c b/filesetup.c index 317d7380..a3bbbb24 100644 --- a/filesetup.c +++ b/filesetup.c @@ -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 e0ac1352..42b6dd75 100644 --- 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; } diff --git a/server.c b/server.c index 38626998..091c1613 100644 --- 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; diff --git a/smalloc.c b/smalloc.c index 3ca29ff1..d038ac64 100644 --- 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; } diff --git a/workqueue.c b/workqueue.c index 013087e1..1131400f 100644 --- a/workqueue.c +++ b/workqueue.c @@ -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)) -- 2.25.1