file: track allocation origin
authorJens Axboe <axboe@kernel.dk>
Wed, 19 Aug 2020 18:04:38 +0000 (12:04 -0600)
committerJens Axboe <axboe@kernel.dk>
Wed, 19 Aug 2020 18:04:38 +0000 (12:04 -0600)
We can't always rely on the engine options for the file, as files
can come from various places. So mark the file as having come from
smalloc/calloc and use that when freeing it.

Signed-off-by: Jens Axboe <axboe@kernel.dk>
file.h
filesetup.c

diff --git a/file.h b/file.h
index 375bbfd33ed805d70f1443ea4308ce1ece746ca6..5e2ef99851a2f33308c4cb96a8bcf7af64923233 100644 (file)
--- a/file.h
+++ b/file.h
@@ -33,6 +33,7 @@ enum fio_file_flags {
        FIO_FILE_partial_mmap   = 1 << 6,       /* can't do full mmap */
        FIO_FILE_axmap          = 1 << 7,       /* uses axmap */
        FIO_FILE_lfsr           = 1 << 8,       /* lfsr is used */
+       FIO_FILE_smalloc        = 1 << 9,       /* smalloc file/file_name */
 };
 
 enum file_lock_mode {
@@ -188,6 +189,7 @@ FILE_FLAG_FNS(hashed);
 FILE_FLAG_FNS(partial_mmap);
 FILE_FLAG_FNS(axmap);
 FILE_FLAG_FNS(lfsr);
+FILE_FLAG_FNS(smalloc);
 #undef FILE_FLAG_FNS
 
 /*
index 49c54b810e0371660aaa794840703ede6e9e5489..a1c60445cc1bb4863ece64c8be935d68f3da91d1 100644 (file)
@@ -1449,7 +1449,6 @@ void close_and_free_files(struct thread_data *td)
 {
        struct fio_file *f;
        unsigned int i;
-       bool use_free = td_ioengine_flagged(td, FIO_NOFILEHASH);
 
        dprint(FD_FILE, "close files\n");
 
@@ -1471,7 +1470,7 @@ void close_and_free_files(struct thread_data *td)
 
                zbd_close_file(f);
 
-               if (use_free)
+               if (!fio_file_smalloc(f))
                        free(f->file_name);
                else
                        sfree(f->file_name);
@@ -1480,7 +1479,7 @@ void close_and_free_files(struct thread_data *td)
                        axmap_free(f->io_axmap);
                        f->io_axmap = NULL;
                }
-               if (use_free)
+               if (!fio_file_smalloc(f))
                        free(f);
                else
                        sfree(f);
@@ -1609,6 +1608,8 @@ static struct fio_file *alloc_new_file(struct thread_data *td)
        f->fd = -1;
        f->shadow_fd = -1;
        fio_file_reset(td, f);
+       if (!td_ioengine_flagged(td, FIO_NOFILEHASH))
+               fio_file_set_smalloc(f);
        return f;
 }