From e9ed219fd8abf55da097236ea63fdb9fb3d98814 Mon Sep 17 00:00:00 2001 From: Nathaniel Filardo Date: Fri, 20 Nov 2020 03:16:07 +0000 Subject: [PATCH] ChunkMap: limit flat pagemap size Presently, our flat pagemap can be configured to take... 32-bit AS 48-bit AS USE_SMALL_CHUNKS 16 KiB 1 GiB default 4 KiB 256 MiB USE_LARGE_CHUNKS 256 B 16 MiB At 1 GiB, we're already past the 512 MiB threshold imposed when src/test/func/memory/memory.cc, when configured to TEST_LIMITED, probes the effect of rlimit. Instead, restrict flat pagemaps to at most 256 MiB of AS by default (override by defining SNMALLOC_MAX_FLATPAGEMAP_SIZE), which forces the USE_SMALL_CHUNKS & 48-bit AS configuration to use the tree-based version. While here, rename USE_FLATPAGEMAP to CHUNKMAP_USE_FLATPAGEMAP. --- src/mem/chunkmap.h | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/src/mem/chunkmap.h b/src/mem/chunkmap.h index 48adbca..8f00992 100644 --- a/src/mem/chunkmap.h +++ b/src/mem/chunkmap.h @@ -56,15 +56,30 @@ namespace snmalloc SUPERSLAB_BITS > CMMediumslab, "Large allocations may be too small"); #ifndef SNMALLOC_MAX_FLATPAGEMAP_SIZE -// Use flat map is under a single node. -# define SNMALLOC_MAX_FLATPAGEMAP_SIZE PAGEMAP_NODE_SIZE +/* + * Unless otherwise specified, use a flat pagemap for the chunkmap (1 byte per + * Superslab-sized and -aligned region of the address space) if either of the + * following hold: + * + * - the platform supports LazyCommit and the flat structure would occupy 256 + * MiB or less. 256 MiB is more than adequate for 32-bit architectures and + * is the size of the flat pagemap for a 48-bit AS with the default chunk + * size or the USE_LARGE_CHUNKS chunksize (that is, configurations other + * than USE_SMALL_CHUNKS). + * + * - the platform does not support LazyCommit but the flat structure would + * occupy less than PAGEMAP_NODE_SIZE (i.e., the backing store for an + * internal tree node in the non-flat pagemap). + */ +# define SNMALLOC_MAX_FLATPAGEMAP_SIZE \ + (pal_supports ? 256ULL * 1024 * 1024 : PAGEMAP_NODE_SIZE) #endif - static constexpr bool USE_FLATPAGEMAP = pal_supports || - (SNMALLOC_MAX_FLATPAGEMAP_SIZE >= - sizeof(FlatPagemap)); + static constexpr bool CHUNKMAP_USE_FLATPAGEMAP = + SNMALLOC_MAX_FLATPAGEMAP_SIZE >= + sizeof(FlatPagemap); using ChunkmapPagemap = std::conditional_t< - USE_FLATPAGEMAP, + CHUNKMAP_USE_FLATPAGEMAP, FlatPagemap, Pagemap>;