From 2ef0e22c550092d62a21db01fc40cf151e1a2dfc Mon Sep 17 00:00:00 2001 From: Gareth Rees Date: Fri, 11 Apr 2014 21:15:09 +0100 Subject: [PATCH] Default value for mps_key_arena_size makes it easier to create arenas. Copied from Perforce Change: 185472 ServerID: perforce.ravenbrook.com --- mps/code/arenavm.c | 6 +++--- mps/code/config.h | 2 ++ mps/manual/source/topic/arena.rst | 31 ++++++++++++++++--------------- 3 files changed, 21 insertions(+), 18 deletions(-) diff --git a/mps/code/arenavm.c b/mps/code/arenavm.c index 15b79bbed51..81e0684c436 100644 --- a/mps/code/arenavm.c +++ b/mps/code/arenavm.c @@ -480,7 +480,7 @@ ARG_DEFINE_KEY(arena_contracted, Fun); static Res VMArenaInit(Arena *arenaReturn, ArenaClass class, ArgList args) { - Size userSize; /* size requested by user */ + Size userSize = VM_ARENA_SIZE_DEFAULT; /* size requested by user */ Size chunkSize; /* size actually created */ Size vmArenaSize; /* aligned size of VMArenaStruct */ Res res; @@ -495,8 +495,8 @@ static Res VMArenaInit(Arena *arenaReturn, ArenaClass class, ArgList args) AVER(class == VMArenaClassGet()); AVERT(ArgList, args); - ArgRequire(&arg, args, MPS_KEY_ARENA_SIZE); - userSize = arg.val.size; + if (ArgPick(&arg, args, MPS_KEY_ARENA_SIZE)) + userSize = arg.val.size; AVER(userSize > 0); diff --git a/mps/code/config.h b/mps/code/config.h index b781f1da591..0afa66c06bb 100644 --- a/mps/code/config.h +++ b/mps/code/config.h @@ -366,6 +366,8 @@ pool to be very heavily used. */ #define CONTROL_EXTEND_BY 4096 +#define VM_ARENA_SIZE_DEFAULT ((Size)1 << 20) + /* Stack configuration */ diff --git a/mps/manual/source/topic/arena.rst b/mps/manual/source/topic/arena.rst index 5220ece4007..1925117cc84 100644 --- a/mps/manual/source/topic/arena.rst +++ b/mps/manual/source/topic/arena.rst @@ -233,18 +233,18 @@ Virtual memory arenas more efficient. When creating a virtual memory arena, :c:func:`mps_arena_create_k` - requires one :term:`keyword argument`: + accepts one :term:`keyword argument` on all platforms: - * :c:macro:`MPS_KEY_ARENA_SIZE` (type :c:type:`size_t`). is the - initial amount of virtual address space, in :term:`bytes (1)`, - that the arena will reserve (this space is initially reserved so - that the arena can subsequently use it without interference from - other parts of the program, but most of it is not committed, so - it doesn't require any RAM or backing store). The arena may - allocate more virtual address space beyond this initial - reservation as and when it deems it necessary. The MPS is most - efficient if you reserve an address space that is several times - larger than your peak memory usage. + * :c:macro:`MPS_KEY_ARENA_SIZE` (type :c:type:`size_t`, default + 2\ :superscript:`20`) is the initial amount of virtual address + space, in :term:`bytes (1)`, that the arena will reserve (this + space is initially reserved so that the arena can subsequently + use it without interference from other parts of the program, but + most of it is not committed, so it doesn't require any RAM or + backing store). The arena may allocate more virtual address + space beyond this initial reservation as and when it deems it + necessary. The MPS is most efficient if you reserve an address + space that is several times larger than your peak memory usage. .. note:: @@ -252,8 +252,8 @@ Virtual memory arenas more times it has to extend its address space, the less efficient garbage collection will become. - An optional :term:`keyword argument` may be passed, but is - only used on the Windows operating system: + A second optional :term:`keyword argument` may be passed, but it + only has any effect on the Windows operating system: * :c:macro:`MPS_KEY_VMW3_TOP_DOWN` (type :c:type:`mps_bool_t`). If true, the arena will allocate address space starting at the @@ -273,8 +273,9 @@ Virtual memory arenas If the MPS fails to allocate memory for the internal arena structures, :c:func:`mps_arena_create_k` returns - :c:macro:`MPS_RES_MEMORY`. Either ``size`` was far too small or - the operating system refused to provide enough memory. + :c:macro:`MPS_RES_MEMORY`. Either :c:macro:`MPS_KEY_ARENA_SIZE` + was far too small or the operating system refused to provide + enough memory. For example::