gracefully handle full /tmp file system
[fio.git] / smalloc.c
index 409998aa8ad5a66ebbc8ac7d2fb620553ac75880..4cd8298eaa004d7a56d861aefcb1373ae7fd7001 100644 (file)
--- a/smalloc.c
+++ b/smalloc.c
 #include <unistd.h>
 #include <sys/types.h>
 #include <limits.h>
+#include <fcntl.h>
 
 #include "mutex.h"
 #include "arch/arch.h"
+#include "os/os.h"
 
 #define SMALLOC_REDZONE                /* define to detect memory corruption */
 
@@ -176,7 +178,7 @@ static int find_next_zero(int word, int start)
 
 static int add_pool(struct pool *pool, unsigned int alloc_size)
 {
-       int fd, bitmap_blocks;
+       int fd, bitmap_blocks, ret;
        char file[] = "/tmp/.fio_smalloc.XXXXXX";
        void *ptr;
 
@@ -200,6 +202,14 @@ static int add_pool(struct pool *pool, unsigned int alloc_size)
        pool->nr_blocks = bitmap_blocks;
        pool->free_blocks = bitmap_blocks * SMALLOC_BPB;
 
+#ifdef FIO_HAVE_FALLOCATE
+       ret = posix_fallocate(fd, 0, alloc_size);
+       if (ret > 0) {
+               fprintf(stderr, "posix_fallocate pool file failed: %s\n", strerror(ret));
+               goto out_unlink;
+       }
+#endif
+
        if (ftruncate(fd, alloc_size) < 0)
                goto out_unlink;