backend: ensure that server side releases/frees shm segment on exit
We were leaking one for every job run.
Signed-off-by: Jens Axboe <axboe@kernel.dk>
diff --git a/fio.h b/fio.h
index 393f381..6a7bd03 100644
--- a/fio.h
+++ b/fio.h
@@ -445,6 +445,7 @@
extern void fio_unpin_memory(void);
extern int __must_check allocate_io_mem(struct thread_data *);
extern void free_io_mem(struct thread_data *);
+extern void free_threads_shm(void);
/*
* Reset stats after ramp time completes
diff --git a/init.c b/init.c
index a04198f..cf105a3 100644
--- a/init.c
+++ b/init.c
@@ -207,7 +207,7 @@
},
};
-static void free_shm(void)
+void free_threads_shm(void)
{
struct shmid_ds sbuf;
@@ -215,11 +215,19 @@
void *tp = threads;
threads = NULL;
+ shmdt(tp);
+ shmctl(shm_id, IPC_RMID, &sbuf);
+ shm_id = -1;
+ }
+}
+
+void free_shm(void)
+{
+ if (threads) {
file_hash_exit();
flow_exit();
fio_debug_jobp = NULL;
- shmdt(tp);
- shmctl(shm_id, IPC_RMID, &sbuf);
+ free_threads_shm();
}
scleanup();
diff --git a/server.c b/server.c
index 8b91d26..c859ad7 100644
--- a/server.c
+++ b/server.c
@@ -550,6 +550,7 @@
}
ret = fio_backend();
+ free_threads_shm();
_exit(ret);
}