[Git][ghc/ghc][master] rts: add -xr option to control two step allocator reserved space size
Marge Bot (@marge-bot)
gitlab at gitlab.haskell.org
Wed Mar 6 02:46:22 UTC 2024
Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC
Commits:
21e3f325 by Cheng Shao at 2024-03-05T21:45:52-05:00
rts: add -xr option to control two step allocator reserved space size
This patch adds a -xr RTS option to control the size of virtual memory
address space reserved by the two step allocator on a 64-bit platform,
see added documentation for explanation. Closes #24498.
- - - - -
6 changed files:
- docs/users_guide/9.10.1-notes.rst
- docs/users_guide/runtime_control.rst
- rts/RtsFlags.c
- rts/include/rts/Flags.h
- rts/sm/MBlock.c
- testsuite/tests/rts/all.T
Changes:
=====================================
docs/users_guide/9.10.1-notes.rst
=====================================
@@ -232,6 +232,11 @@ Runtime system
- Add a :rts-flag:`--no-automatic-time-samples` flag which stops time profiling samples being automatically started on
startup. Time profiling can be controlled manually using functions in ``GHC.Profiling``.
+- Add a :rts-flag:`-xr ⟨size⟩` which controls the size of virtual
+ memory address space reserved by the two step allocator on a 64-bit
+ platform. The default size is now 1T on aarch64 as well. See
+ :ghc-ticket:`24498`.
+
``base`` library
~~~~~~~~~~~~~~~~
=====================================
docs/users_guide/runtime_control.rst
=====================================
@@ -368,6 +368,18 @@ Miscellaneous RTS options
thread can execute its exception handlers. The ``-xq`` controls the
size of this additional quota.
+.. rts-flag:: -xr ⟨size⟩
+
+ :default: 1T
+
+ This option controls the size of virtual memory address space
+ reserved by the two step allocator on a 64-bit platform. It can be
+ useful in scenarios where even reserving a large address range
+ without committing can be expensive (e.g. WSL1), or when you
+ actually have enough physical memory and want to support a Haskell
+ heap larger than 1T. ``-xr`` is a no-op if GHC is configured with
+ ``--disable-large-address-space`` or if the platform is 32-bit.
+
.. _rts-options-gc:
RTS options to control the garbage collector
=====================================
rts/RtsFlags.c
=====================================
@@ -186,6 +186,9 @@ void initRtsFlagsDefaults(void)
RtsFlags.GcFlags.ringBell = false;
RtsFlags.GcFlags.longGCSync = 0; /* detection turned off */
+ // 1 TBytes
+ RtsFlags.GcFlags.addressSpaceSize = (StgWord64)1 << 40;
+
RtsFlags.DebugFlags.scheduler = false;
RtsFlags.DebugFlags.interpreter = false;
RtsFlags.DebugFlags.weak = false;
@@ -552,6 +555,11 @@ usage_text[] = {
" -xq The allocation limit given to a thread after it receives",
" an AllocationLimitExceeded exception. (default: 100k)",
"",
+#if defined(USE_LARGE_ADDRESS_SPACE)
+" -xr The size of virtual memory address space reserved by the",
+" two step allocator (default: 1T)",
+"",
+#endif
" -Mgrace=<n>",
" The amount of allocation after the program receives a",
" HeapOverflow exception before the exception is thrown again, if",
@@ -1820,6 +1828,12 @@ error = true;
/ BLOCK_SIZE;
break;
+ case 'r':
+ OPTION_UNSAFE;
+ RtsFlags.GcFlags.addressSpaceSize
+ = decodeSize(rts_argv[arg], 3, MBLOCK_SIZE, HS_WORD64_MAX);
+ break;
+
default:
OPTION_SAFE;
errorBelch("unknown RTS option: %s",rts_argv[arg]);
@@ -2118,7 +2132,9 @@ decodeSize(const char *flag, uint32_t offset, StgWord64 min, StgWord64 max)
m = atof(s);
c = s[strlen(s)-1];
- if (c == 'g' || c == 'G')
+ if (c == 't' || c == 'T')
+ m *= (StgWord64)1024*1024*1024*1024;
+ else if (c == 'g' || c == 'G')
m *= 1024*1024*1024;
else if (c == 'm' || c == 'M')
m *= 1024*1024;
@@ -2737,4 +2753,3 @@ doingErasProfiling( void )
|| RtsFlags.ProfFlags.eraSelector != 0);
}
#endif /* PROFILING */
-
=====================================
rts/include/rts/Flags.h
=====================================
@@ -89,6 +89,8 @@ typedef struct _GC_FLAGS {
bool numa; /* Use NUMA */
StgWord numaMask;
+
+ StgWord64 addressSpaceSize; /* large address space size in bytes */
} GC_FLAGS;
/* See Note [Synchronization of flags and base APIs] */
=====================================
rts/sm/MBlock.c
=====================================
@@ -659,20 +659,14 @@ initMBlocks(void)
#if defined(USE_LARGE_ADDRESS_SPACE)
{
- W_ size;
-#if defined(aarch64_HOST_ARCH)
- size = (W_)1 << 38; // 1/4 TByte
-#else
- size = (W_)1 << 40; // 1 TByte
-#endif
void *startAddress = NULL;
if (RtsFlags.GcFlags.heapBase) {
startAddress = (void*) RtsFlags.GcFlags.heapBase;
}
- void *addr = osReserveHeapMemory(startAddress, &size);
+ void *addr = osReserveHeapMemory(startAddress, &RtsFlags.GcFlags.addressSpaceSize);
mblock_address_space.begin = (W_)addr;
- mblock_address_space.end = (W_)addr + size;
+ mblock_address_space.end = (W_)addr + RtsFlags.GcFlags.addressSpaceSize;
mblock_high_watermark = (W_)addr;
}
#elif SIZEOF_VOID_P == 8
=====================================
testsuite/tests/rts/all.T
=====================================
@@ -3,7 +3,7 @@ test('testblockalloc',
compile_and_run, [''])
test('testmblockalloc',
- [c_src, only_ways(['normal','threaded1']), extra_run_opts('+RTS -I0'),
+ [c_src, only_ways(['normal','threaded1']), extra_run_opts('+RTS -I0 -xr0.125T'),
when(arch('wasm32'), skip)], # MBlocks can't be freed on wasm32, see Note [Megablock allocator on wasm] in rts
compile_and_run, [''])
# -I0 is important: the idle GC will run the memory leak detector,
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/21e3f3250e88640087a1a60bee2cc113bf04509f
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/21e3f3250e88640087a1a60bee2cc113bf04509f
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/20240305/3f3a74d3/attachment-0001.html>
More information about the ghc-commits
mailing list