backend: ensure that server side releases/frees shm segment on exit
authorJens Axboe <axboe@kernel.dk>
Wed, 28 Mar 2012 10:22:40 +0000 (12:22 +0200)
committerJens Axboe <axboe@kernel.dk>
Wed, 28 Mar 2012 10:22:40 +0000 (12:22 +0200)
We were leaking one for every job run.

Signed-off-by: Jens Axboe <axboe@kernel.dk>
fio.h
init.c
server.c

diff --git a/fio.h b/fio.h
index 393f381d249cdcdd542f9fe57da373511af6204b..6a7bd03ca92fa00d84719551cdfc673712a80511 100644 (file)
--- a/fio.h
+++ b/fio.h
@@ -445,6 +445,7 @@ extern int __must_check fio_pin_memory(void);
 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 a04198f3e08c77a02a3d2286c350091106e9b086..cf105a358824f0a7c0061108583ea48b5ae23b00 100644 (file)
--- a/init.c
+++ b/init.c
@@ -207,7 +207,7 @@ static struct option l_opts[FIO_NR_OPTIONS] = {
        },
 };
 
-static void free_shm(void)
+void free_threads_shm(void)
 {
        struct shmid_ds sbuf;
 
@@ -215,11 +215,19 @@ static void free_shm(void)
                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();
index 8b91d26fe328c6577af7a4eace788dd8cb2bc16d..c859ad7277d471742fd7eae0c1ea574a106970c5 100644 (file)
--- a/server.c
+++ b/server.c
@@ -550,6 +550,7 @@ static int handle_run_cmd(struct fio_net_cmd *cmd)
        }
 
        ret = fio_backend();
+       free_threads_shm();
        _exit(ret);
 }