summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCheng Shao <terrorjack@type.dance>2023-02-06 17:37:14 +0000
committerMarge Bot <ben+marge-bot@smart-cactus.org>2023-02-14 11:32:26 -0500
commit1928c7f3e9dfc13226e8cf786a565d42df6dad41 (patch)
treed8f9ec7ba6ff78a1a6e6e67d27f408a565969a92
parent9fb4ca89bff9873e5f6a6849fa22a349c94deaae (diff)
downloadhaskell-1928c7f3e9dfc13226e8cf786a565d42df6dad41.tar.gz
rts: make it possible to change mblock size on 32-bit targets
The MBLOCK_SHIFT macro must be the single source of truth for defining the mblock size, and changing it should only affect performance, not correctness. This patch makes it truly possible to reconfigure mblock size, at least on 32-bit targets, by fixing places which implicitly relied on the previous MBLOCK_SHIFT constant. Fixes #22901.
-rw-r--r--rts/sm/GCUtils.c7
-rw-r--r--rts/sm/HeapAlloc.h3
-rw-r--r--rts/sm/NonMoving.h2
3 files changed, 9 insertions, 3 deletions
diff --git a/rts/sm/GCUtils.c b/rts/sm/GCUtils.c
index 9d57bf7d9e..86b95e1fd8 100644
--- a/rts/sm/GCUtils.c
+++ b/rts/sm/GCUtils.c
@@ -350,7 +350,12 @@ alloc_todo_block (gen_workspace *ws, uint32_t size)
bd = gct->free_blocks;
gct->free_blocks = bd->link;
} else {
- allocBlocks_sync(16, &bd);
+ // We allocate in chunks of at most 16 blocks, use one
+ // block to satisfy the allocation request and place
+ // the rest on `gct->free_blocks` for future use.
+ StgWord chunk_size = 16;
+ StgWord n_blocks = stg_min(chunk_size, 1 << (MBLOCK_SHIFT - BLOCK_SHIFT - 1));
+ allocBlocks_sync(n_blocks, &bd);
gct->free_blocks = bd->link;
}
}
diff --git a/rts/sm/HeapAlloc.h b/rts/sm/HeapAlloc.h
index 58aae1119d..f91795529d 100644
--- a/rts/sm/HeapAlloc.h
+++ b/rts/sm/HeapAlloc.h
@@ -63,8 +63,7 @@ extern struct mblock_address_range mblock_address_space;
#elif SIZEOF_VOID_P == 4
extern StgWord8 mblock_map[];
-/* On a 32-bit machine a 4KB table is always sufficient */
-# define MBLOCK_MAP_SIZE 4096
+# define MBLOCK_MAP_SIZE (1 << (32 - MBLOCK_SHIFT))
# define MBLOCK_MAP_ENTRY(p) ((StgWord)(p) >> MBLOCK_SHIFT)
# define HEAP_ALLOCED(p) mblock_map[MBLOCK_MAP_ENTRY(p)]
# define HEAP_ALLOCED_GC(p) HEAP_ALLOCED(p)
diff --git a/rts/sm/NonMoving.h b/rts/sm/NonMoving.h
index 1f0f68fac6..d88a203dcb 100644
--- a/rts/sm/NonMoving.h
+++ b/rts/sm/NonMoving.h
@@ -29,6 +29,8 @@
GHC_STATIC_ASSERT(NONMOVING_SEGMENT_SIZE % BLOCK_SIZE == 0, "non-moving segment size must be multiple of block size");
+GHC_STATIC_ASSERT(NONMOVING_SEGMENT_BLOCKS * 2 <= BLOCKS_PER_MBLOCK, "non-moving segment size must not exceed half of mblock size");
+
// The index of a block within a segment
typedef uint16_t nonmoving_block_idx;