Skip to content

Commit 05a9e4a

Browse files
committed
Fix potential VM map fragmentation regression.
Revert 245ae60 (Support --with-lg-page values larger than actual page size.), because it could cause VM map fragmentation if the kernel grows mmap()ed memory downward. This resolves jemalloc#391.
1 parent 48384dc commit 05a9e4a

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

include/jemalloc/internal/jemalloc_internal.h.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -754,7 +754,7 @@ sa2u(size_t size, size_t alignment)
754754
* Calculate the size of the over-size run that arena_palloc()
755755
* would need to allocate in order to guarantee the alignment.
756756
*/
757-
if (usize + large_pad + alignment <= arena_maxrun)
757+
if (usize + large_pad + alignment - PAGE <= arena_maxrun)
758758
return (usize);
759759
}
760760

@@ -784,7 +784,7 @@ sa2u(size_t size, size_t alignment)
784784
* Calculate the multi-chunk mapping that huge_palloc() would need in
785785
* order to guarantee the alignment.
786786
*/
787-
if (usize + alignment < usize) {
787+
if (usize + alignment - PAGE < usize) {
788788
/* size_t overflow. */
789789
return (0);
790790
}

src/arena.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2687,7 +2687,7 @@ arena_palloc_large(tsdn_t *tsdn, arena_t *arena, size_t usize, size_t alignment,
26872687
return (NULL);
26882688

26892689
alignment = PAGE_CEILING(alignment);
2690-
alloc_size = usize + large_pad + alignment;
2690+
alloc_size = usize + large_pad + alignment - PAGE;
26912691

26922692
malloc_mutex_lock(tsdn, &arena->lock);
26932693
run = arena_run_alloc_large(tsdn, arena, alloc_size, false);

src/chunk_mmap.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ chunk_alloc_mmap_slow(size_t size, size_t alignment, bool *zero, bool *commit)
99
void *ret;
1010
size_t alloc_size;
1111

12-
alloc_size = size + alignment;
12+
alloc_size = size + alignment - PAGE;
1313
/* Beware size_t wrap-around. */
1414
if (alloc_size < size)
1515
return (NULL);

0 commit comments

Comments
 (0)