summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason Evans <je@fb.com>2011-08-12 05:51:00 (GMT)
committerJason Evans <je@fb.com>2011-08-12 06:00:25 (GMT)
commit183ba50c1940a95080f6cf890ae4ae40200301e7 (patch)
tree68d6b43339b4e47d1cf4d517779210041bfa9110
parent0cdd42eb3204cdd2646561c90ec202716cd3c344 (diff)
downloadjemalloc-183ba50c1940a95080f6cf890ae4ae40200301e7.zip
jemalloc-183ba50c1940a95080f6cf890ae4ae40200301e7.tar.gz
jemalloc-183ba50c1940a95080f6cf890ae4ae40200301e7.tar.bz2
Fix two prof-related bugs in rallocm().
Properly handle boundary conditions for sampled region promotion in rallocm(). Prior to this fix, some combinations of 'size' and 'extra' values could cause erroneous behavior. Additionally, size class recording for promoted regions was incorrect.
-rw-r--r--src/arena.c1
-rw-r--r--src/jemalloc.c13
2 files changed, 11 insertions, 3 deletions
diff --git a/src/arena.c b/src/arena.c
index e00dccc..e749c1d 100644
--- a/src/arena.c
+++ b/src/arena.c
@@ -1657,6 +1657,7 @@ arena_prof_promoted(const void *ptr, size_t size)
assert(ptr != NULL);
assert(CHUNK_ADDR2BASE(ptr) != ptr);
assert(isalloc(ptr) == PAGE_SIZE);
+ assert(size <= small_maxclass);
chunk = (arena_chunk_t *)CHUNK_ADDR2BASE(ptr);
pageind = ((uintptr_t)ptr - (uintptr_t)chunk) >> PAGE_SHIFT;
diff --git a/src/jemalloc.c b/src/jemalloc.c
index e287516..afba0e1 100644
--- a/src/jemalloc.c
+++ b/src/jemalloc.c
@@ -1670,15 +1670,22 @@ JEMALLOC_P(rallocm)(void **ptr, size_t *rsize, size_t size, size_t extra,
old_ctx = prof_ctx_get(p);
if ((cnt = prof_alloc_prep(max_usize)) == NULL)
goto OOM;
- if (prof_promote && (uintptr_t)cnt != (uintptr_t)1U && max_usize
- <= small_maxclass) {
+ /*
+ * Use minimum usize to determine whether promotion may happen.
+ */
+ if (prof_promote && (uintptr_t)cnt != (uintptr_t)1U
+ && ((alignment == 0) ? s2u(size) : sa2u(size,
+ alignment, NULL)) <= small_maxclass) {
q = iralloc(p, small_maxclass+1, (small_maxclass+1 >=
size+extra) ? 0 : size+extra - (small_maxclass+1),
alignment, zero, no_move);
if (q == NULL)
goto ERR;
usize = isalloc(q);
- arena_prof_promoted(q, usize);
+ if (max_usize < PAGE_SIZE) {
+ usize = max_usize;
+ arena_prof_promoted(q, usize);
+ }
} else {
q = iralloc(p, size, extra, alignment, zero, no_move);
if (q == NULL)