Split mutex.c and .h each into three files
[fio.git] / smalloc.c
index 3ca29ff1404579d8be5068ee7b8455218fba6c3c..cab7132511b1729b152278f119d300c83f54b5d2 100644 (file)
--- a/smalloc.c
+++ b/smalloc.c
@@ -13,6 +13,7 @@
 #include <limits.h>
 #include <fcntl.h>
 
+#include "fio.h"
 #include "mutex.h"
 #include "arch/arch.h"
 #include "os/os.h"
@@ -188,7 +189,7 @@ static bool add_pool(struct pool *pool, unsigned int alloc_size)
                goto out_fail;
 
        pool->map = ptr;
-       pool->bitmap = (void *) ptr + (pool->nr_blocks * SMALLOC_BPL);
+       pool->bitmap = (unsigned int *)((char *) ptr + (pool->nr_blocks * SMALLOC_BPL));
        memset(pool->bitmap, 0, bitmap_blocks * sizeof(unsigned int));
 
        pool->lock = fio_mutex_init(FIO_MUTEX_UNLOCKED);
@@ -248,7 +249,7 @@ static void *postred_ptr(struct block_hdr *hdr)
        uintptr_t ptr;
 
        ptr = (uintptr_t) hdr + hdr->size - sizeof(unsigned int);
-       ptr = (ptr + int_mask) & ~int_mask;
+       ptr = (uintptr_t) PTR_ALIGN(ptr, int_mask);
 
        return (void *) ptr;
 }
@@ -450,6 +451,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;
 }