]> git.kaiwu.me - njs.git/commitdiff
NXT_DEBUG_MEMORY macro.
authorValentin Bartenev <vbart@nginx.com>
Thu, 8 Dec 2016 16:29:40 +0000 (19:29 +0300)
committerValentin Bartenev <vbart@nginx.com>
Thu, 8 Dec 2016 16:29:40 +0000 (19:29 +0300)
It allows to turn off accumulation of small pool allocations into a big
preallocated chunk of memory.  This is useful for debugging memory access
with sanitizer, since such accumulation can cover buffer overruns from
being detected.

nxt/nxt_mem_cache_pool.c

index fcf68280dc3b18113752898c359dc75c47e1be33..f1cbd546c9823012eff68d3558bfea83aaaa5b8a 100644 (file)
@@ -124,12 +124,14 @@ struct nxt_mem_cache_pool_s {
 
 
 static nxt_uint_t nxt_mem_cache_shift(nxt_uint_t n);
+#if !(NXT_DEBUG_MEMORY)
 static void *nxt_mem_cache_alloc_small(nxt_mem_cache_pool_t *pool, size_t size);
 static nxt_uint_t nxt_mem_cache_alloc_chunk(u_char *map, nxt_uint_t size);
 static nxt_mem_cache_page_t *
     nxt_mem_cache_alloc_page(nxt_mem_cache_pool_t *pool);
 static nxt_mem_cache_block_t *
     nxt_mem_cache_alloc_cluster(nxt_mem_cache_pool_t *pool);
+#endif
 static void *nxt_mem_cache_alloc_large(nxt_mem_cache_pool_t *pool,
     size_t alignment, size_t size);
 static intptr_t nxt_mem_cache_rbtree_compare(nxt_rbtree_node_t *node1,
@@ -302,10 +304,14 @@ nxt_mem_cache_alloc(nxt_mem_cache_pool_t *pool, size_t size)
         pool->proto->trace(pool->trace, "mem cache alloc: %zd", size);
     }
 
+#if !(NXT_DEBUG_MEMORY)
+
     if (size <= pool->page_size) {
         return nxt_mem_cache_alloc_small(pool, size);
     }
 
+#endif
+
     return nxt_mem_cache_alloc_large(pool, NXT_MAX_ALIGNMENT, size);
 }
 
@@ -337,6 +343,8 @@ nxt_mem_cache_align(nxt_mem_cache_pool_t *pool, size_t alignment, size_t size)
 
     if (nxt_fast_path((alignment - 1) & alignment) == 0) {
 
+#if !(NXT_DEBUG_MEMORY)
+
         if (size <= pool->page_size && alignment <= pool->page_alignment) {
             size = nxt_max(size, alignment);
 
@@ -345,6 +353,8 @@ nxt_mem_cache_align(nxt_mem_cache_pool_t *pool, size_t alignment, size_t size)
             }
         }
 
+#endif
+
         return nxt_mem_cache_alloc_large(pool, alignment, size);
     }
 
@@ -367,6 +377,8 @@ nxt_mem_cache_zalign(nxt_mem_cache_pool_t *pool, size_t alignment, size_t size)
 }
 
 
+#if !(NXT_DEBUG_MEMORY)
+
 static void *
 nxt_mem_cache_alloc_small(nxt_mem_cache_pool_t *pool, size_t size)
 {
@@ -549,6 +561,8 @@ nxt_mem_cache_alloc_cluster(nxt_mem_cache_pool_t *pool)
     return cluster;
 }
 
+#endif
+
 
 static void *
 nxt_mem_cache_alloc_large(nxt_mem_cache_pool_t *pool, size_t alignment,