]> git.saurik.com Git - redis.git/blobdiff - deps/jemalloc/src/huge.c
Merge pull request #208 from jbergstroem/jemalloc-2.2.5
[redis.git] / deps / jemalloc / src / huge.c
index ac3f3a0d848070ef9a1337bf0d4746e3532906ae..a4f9b054ed5924f0185bc8ed959ae30bc02fdaee 100644 (file)
@@ -110,12 +110,12 @@ huge_palloc(size_t size, size_t alignment, bool zero)
        if (offset == 0) {
                /* Trim trailing space. */
                chunk_dealloc((void *)((uintptr_t)ret + chunk_size), alloc_size
        if (offset == 0) {
                /* Trim trailing space. */
                chunk_dealloc((void *)((uintptr_t)ret + chunk_size), alloc_size
-                   - chunk_size);
+                   - chunk_size, true);
        } else {
                size_t trailsize;
 
                /* Trim leading space. */
        } else {
                size_t trailsize;
 
                /* Trim leading space. */
-               chunk_dealloc(ret, alignment - offset);
+               chunk_dealloc(ret, alignment - offset, true);
 
                ret = (void *)((uintptr_t)ret + (alignment - offset));
 
 
                ret = (void *)((uintptr_t)ret + (alignment - offset));
 
@@ -124,7 +124,7 @@ huge_palloc(size_t size, size_t alignment, bool zero)
                    /* Trim trailing space. */
                    assert(trailsize < alloc_size);
                    chunk_dealloc((void *)((uintptr_t)ret + chunk_size),
                    /* Trim trailing space. */
                    assert(trailsize < alloc_size);
                    chunk_dealloc((void *)((uintptr_t)ret + chunk_size),
-                       trailsize);
+                       trailsize, true);
                }
        }
 
                }
        }
 
@@ -234,6 +234,13 @@ huge_ralloc(void *ptr, size_t oldsize, size_t size, size_t extra,
            ) {
                size_t newsize = huge_salloc(ret);
 
            ) {
                size_t newsize = huge_salloc(ret);
 
+               /*
+                * Remove ptr from the tree of huge allocations before
+                * performing the remap operation, in order to avoid the
+                * possibility of another thread acquiring that mapping before
+                * this one removes it from the tree.
+                */
+               huge_dalloc(ptr, false);
                if (mremap(ptr, oldsize, newsize, MREMAP_MAYMOVE|MREMAP_FIXED,
                    ret) == MAP_FAILED) {
                        /*
                if (mremap(ptr, oldsize, newsize, MREMAP_MAYMOVE|MREMAP_FIXED,
                    ret) == MAP_FAILED) {
                        /*
@@ -253,9 +260,8 @@ huge_ralloc(void *ptr, size_t oldsize, size_t size, size_t extra,
                        if (opt_abort)
                                abort();
                        memcpy(ret, ptr, copysize);
                        if (opt_abort)
                                abort();
                        memcpy(ret, ptr, copysize);
-                       idalloc(ptr);
-               } else
-                       huge_dalloc(ptr, false);
+                       chunk_dealloc_mmap(ptr, oldsize);
+               }
        } else
 #endif
        {
        } else
 #endif
        {
@@ -295,9 +301,10 @@ huge_dalloc(void *ptr, bool unmap)
                        memset(node->addr, 0x5a, node->size);
 #endif
 #endif
                        memset(node->addr, 0x5a, node->size);
 #endif
 #endif
-               chunk_dealloc(node->addr, node->size);
        }
 
        }
 
+       chunk_dealloc(node->addr, node->size, unmap);
+
        base_node_dealloc(node);
 }
 
        base_node_dealloc(node);
 }