smalloc: limit to 1 pool, and bump size to 16MB
[fio.git] / smalloc.c
index d0f732baee6cc6515e26f554432fae87958c0bf6..67cb7cc11d475b81aef3d53a7eb896eee31504bb 100644 (file)
--- a/smalloc.c
+++ b/smalloc.c
@@ -17,6 +17,7 @@
 #include "arch/arch.h"
 #include "os/os.h"
 #include "smalloc.h"
+#include "log.h"
 
 #define SMALLOC_REDZONE                /* define to detect memory corruption */
 
@@ -24,8 +25,8 @@
 #define SMALLOC_BPI    (sizeof(unsigned int) * 8)
 #define SMALLOC_BPL    (SMALLOC_BPB * SMALLOC_BPI)
 
-#define INITIAL_SIZE   8192*1024       /* new pool size */
-#define MAX_POOLS      128             /* maximum number of pools to setup */
+#define INITIAL_SIZE   16*1024*1024    /* new pool size */
+#define MAX_POOLS      1               /* maximum number of pools to setup */
 
 #define SMALLOC_PRE_RED                0xdeadbeefU
 #define SMALLOC_POST_RED       0x5aa55aa5U
@@ -221,7 +222,7 @@ static int add_pool(struct pool *pool, unsigned int alloc_size)
        nr_pools++;
        return 0;
 out_fail:
-       fprintf(stderr, "smalloc: failed adding pool\n");
+       log_err("smalloc: failed adding pool\n");
        if (pool->map)
                munmap(pool->map, pool->mmap_size);
        return 1;
@@ -283,14 +284,14 @@ static void sfree_check_redzone(struct block_hdr *hdr)
        unsigned int *postred = postred_ptr(hdr);
 
        if (hdr->prered != SMALLOC_PRE_RED) {
-               fprintf(stderr, "smalloc pre redzone destroyed!\n");
-               fprintf(stderr, "  ptr=%p, prered=%x, expected %x\n",
+               log_err("smalloc pre redzone destroyed!\n"
+                       " ptr=%p, prered=%x, expected %x\n",
                                hdr, hdr->prered, SMALLOC_PRE_RED);
                assert(0);
        }
        if (*postred != SMALLOC_POST_RED) {
-               fprintf(stderr, "smalloc post redzone destroyed!\n");
-               fprintf(stderr, "  ptr=%p, postred=%x, expected %x\n",
+               log_err("smalloc post redzone destroyed!\n"
+                       "  ptr=%p, postred=%x, expected %x\n",
                                hdr, *postred, SMALLOC_POST_RED);
                assert(0);
        }
@@ -478,6 +479,17 @@ out:
        return NULL;
 }
 
+void *scalloc(size_t nmemb, size_t size)
+{
+       void *ret;
+
+       ret = smalloc(nmemb * size);
+       if (ret)
+               memset(ret, 0, nmemb * size);
+
+       return ret;
+}
+
 char *smalloc_strdup(const char *str)
 {
        char *ptr;