diff options
author | Giovanni Campagna <gcampagn@cs.stanford.edu> | 2015-07-17 11:55:49 +0100 |
---|---|---|
committer | Simon Marlow <marlowsd@gmail.com> | 2015-07-22 17:50:02 +0100 |
commit | 0d1a8d09f452977aadef7897aa12a8d41c7a4af0 (patch) | |
tree | 3e8404c7f37c77b67ca913521e6890d6491f4721 /rts/sm/OSMem.h | |
parent | b949c96b4960168a3b399fe14485b24a2167b982 (diff) | |
download | haskell-0d1a8d09f452977aadef7897aa12a8d41c7a4af0.tar.gz |
Two step allocator for 64-bit systems
Summary:
The current OS memory allocator conflates the concepts of allocating
address space and allocating memory, which makes the HEAP_ALLOCED()
implementation excessively complicated (as the only thing it cares
about is address space layout) and slow. Instead, what we want
is to allocate a single insanely large contiguous block of address
space (to make HEAP_ALLOCED() checks fast), and then commit subportions
of that in 1MB blocks as we did before.
This is currently behind a flag, USE_LARGE_ADDRESS_SPACE, that is only enabled for
certain OSes.
Test Plan: validate
Reviewers: simonmar, ezyang, austin
Subscribers: thomie, carter
Differential Revision: https://phabricator.haskell.org/D524
GHC Trac Issues: #9706
Diffstat (limited to 'rts/sm/OSMem.h')
-rw-r--r-- | rts/sm/OSMem.h | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/rts/sm/OSMem.h b/rts/sm/OSMem.h index db704fc78b..9a6ccdd7ec 100644 --- a/rts/sm/OSMem.h +++ b/rts/sm/OSMem.h @@ -20,6 +20,47 @@ W_ getPageSize (void); StgWord64 getPhysicalMemorySize (void); void setExecutable (void *p, W_ len, rtsBool exec); +#ifdef USE_LARGE_ADDRESS_SPACE + +/* + If "large address space" is enabled, we allocate memory in two + steps: first we request some address space, and then we request some + memory in it. This allows us to ask for much more address space that + we will ever need, which keeps everything nice and consecutive. +*/ + +// Reserve the large address space blob, and return the address that +// the OS has chosen for it. It is not safe to access the memory +// pointed to by the return value, until that memory is committed +// using osCommitMemory(). +// +// This function is called once when the block allocator is initialized. +void *osReserveHeapMemory(void); + +// Commit (allocate memory for) a piece of address space, which must +// be within the previously reserved space After this call, it is safe +// to access @p up to @len bytes. +// +// There is no guarantee on the contents of the memory pointed to by +// @p, in particular it must not be assumed to contain all zeros. +void osCommitMemory(void *p, W_ len); + +// Decommit (release backing memory for) a piece of address space, +// which must be within the previously reserve space and must have +// been previously committed After this call, it is again unsafe to +// access @p (up to @len bytes), but there is no guarantee that the +// memory will be released to the system (as far as eg. RSS statistics +// from top are concerned). +void osDecommitMemory(void *p, W_ len); + +// Release the address space previously obtained and undo the effects of +// osReserveHeapMemory +// +// This function is called once, when the block allocator is deinitialized +// before the program terminates. +void osReleaseHeapMemory(void); +#endif + #include "EndPrivate.h" #endif /* SM_OSMEM_H */ |