[Git][ghc/ghc][master] rts: make it possible to change mblock size on 32-bit targets

Marge Bot (@marge-bot) gitlab at gitlab.haskell.org
Tue Feb 14 16:32:56 UTC 2023



Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC


Commits:
1928c7f3 by Cheng Shao at 2023-02-14T11:32:26-05:00
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.

- - - - -


3 changed files:

- rts/sm/GCUtils.c
- rts/sm/HeapAlloc.h
- rts/sm/NonMoving.h


Changes:

=====================================
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;
             }
         }


=====================================
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)


=====================================
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;
 



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/1928c7f3e9dfc13226e8cf786a565d42df6dad41

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/1928c7f3e9dfc13226e8cf786a565d42df6dad41
You're receiving this email because of your account on gitlab.haskell.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20230214/954bead1/attachment-0001.html>


More information about the ghc-commits mailing list