Skip to content

Commit 7c12483

Browse files
committed
Fix lg_chunk clamping for config_cache_oblivious.
Fix lg_chunk clamping to take into account cache-oblivious large allocation. This regression only resulted in incorrect behavior if !config_fill (false unless --disable-fill specified) and config_cache_oblivious (true unless --disable-cache-oblivious specified). This regression was introduced by 8a03cf0 (Implement cache index randomization for large allocations.), which was first released in 4.0.0. This resolves jemalloc#555.
1 parent 1027a26 commit 7c12483

File tree

2 files changed

+12
-16
lines changed

2 files changed

+12
-16
lines changed

src/arena.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2710,6 +2710,7 @@ arena_malloc_hard(tsdn_t *tsdn, arena_t *arena, size_t size, szind_t ind,
27102710
return (arena_malloc_small(tsdn, arena, ind, zero));
27112711
if (likely(size <= large_maxclass))
27122712
return (arena_malloc_large(tsdn, arena, ind, zero));
2713+
assert(index2size(ind) >= chunksize);
27132714
return (huge_malloc(tsdn, arena, index2size(ind), zero));
27142715
}
27152716

@@ -3806,15 +3807,8 @@ arena_boot(void)
38063807
arena_maxrun = chunksize - (map_bias << LG_PAGE);
38073808
assert(arena_maxrun > 0);
38083809
large_maxclass = index2size(size2index(chunksize)-1);
3809-
if (large_maxclass > arena_maxrun) {
3810-
/*
3811-
* For small chunk sizes it's possible for there to be fewer
3812-
* non-header pages available than are necessary to serve the
3813-
* size classes just below chunksize.
3814-
*/
3815-
large_maxclass = arena_maxrun;
3816-
}
38173810
assert(large_maxclass > 0);
3811+
assert(large_maxclass + large_pad <= arena_maxrun);
38183812
nlclasses = size2index(large_maxclass) - size2index(SMALL_MAXCLASS);
38193813
nhclasses = NSIZES - nlclasses - NBINS;
38203814

src/jemalloc.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1136,16 +1136,18 @@ malloc_conf_init(void)
11361136

11371137
CONF_HANDLE_BOOL(opt_abort, "abort", true)
11381138
/*
1139-
* Chunks always require at least one header page,
1140-
* as many as 2^(LG_SIZE_CLASS_GROUP+1) data pages, and
1141-
* possibly an additional page in the presence of
1142-
* redzones. In order to simplify options processing,
1143-
* use a conservative bound that accommodates all these
1144-
* constraints.
1139+
* Chunks always require at least one header page, as
1140+
* many as 2^(LG_SIZE_CLASS_GROUP+1) data pages (plus an
1141+
* additional page in the presence of cache-oblivious
1142+
* large), and possibly an additional page in the
1143+
* presence of redzones. In order to simplify options
1144+
* processing, use a conservative bound that
1145+
* accommodates all these constraints.
11451146
*/
11461147
CONF_HANDLE_SIZE_T(opt_lg_chunk, "lg_chunk", LG_PAGE +
1147-
LG_SIZE_CLASS_GROUP + (config_fill ? 2 : 1),
1148-
(sizeof(size_t) << 3) - 1, yes, yes, true)
1148+
LG_SIZE_CLASS_GROUP + 1 + (config_cache_oblivious ||
1149+
config_fill ? 1 : 0), (sizeof(size_t) << 3) - 1,
1150+
yes, yes, true)
11491151
if (strncmp("dss", k, klen) == 0) {
11501152
int i;
11511153
bool match = false;

0 commit comments

Comments
 (0)