diff options
| author | Michael Anthony Knyszek <mknyszek@google.com> | 2022-03-15 00:23:26 +0000 |
|---|---|---|
| committer | Michael Knyszek <mknyszek@google.com> | 2022-03-31 20:02:55 +0000 |
| commit | f990b0f1e80cf6152219b4d3f9a397899e8d6d40 (patch) | |
| tree | 022a41c828dbfeef63248342c6a3d08b94fa7dc0 /src/runtime/malloc.go | |
| parent | 4a56ba1c453927256f231a8bcef316bb4b3aa68a (diff) | |
| download | go-f990b0f1e80cf6152219b4d3f9a397899e8d6d40.tar.xz | |
runtime: add wrappers for sys* functions and consolidate docs
This change lifts all non-platform-specific code out of sys* functions
for each platform up into wrappers, and moves documentation about the OS
virtual memory abstraction layer from malloc.go to mem.go, which
contains those wrappers.
Change-Id: Ie803e4447403eaafc508b34b53a1a47d6cee9388
Reviewed-on: https://go-review.googlesource.com/c/go/+/393398
Reviewed-by: Austin Clements <austin@google.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
Trust: Michael Knyszek <mknyszek@google.com>
Diffstat (limited to 'src/runtime/malloc.go')
| -rw-r--r-- | src/runtime/malloc.go | 69 |
1 files changed, 0 insertions, 69 deletions
diff --git a/src/runtime/malloc.go b/src/runtime/malloc.go index a22bef821a..a00878a11c 100644 --- a/src/runtime/malloc.go +++ b/src/runtime/malloc.go @@ -354,75 +354,6 @@ var ( physHugePageShift uint ) -// OS memory management abstraction layer -// -// Regions of the address space managed by the runtime may be in one of four -// states at any given time: -// 1) None - Unreserved and unmapped, the default state of any region. -// 2) Reserved - Owned by the runtime, but accessing it would cause a fault. -// Does not count against the process' memory footprint. -// 3) Prepared - Reserved, intended not to be backed by physical memory (though -// an OS may implement this lazily). Can transition efficiently to -// Ready. Accessing memory in such a region is undefined (may -// fault, may give back unexpected zeroes, etc.). -// 4) Ready - may be accessed safely. -// -// This set of states is more than is strictly necessary to support all the -// currently supported platforms. One could get by with just None, Reserved, and -// Ready. However, the Prepared state gives us flexibility for performance -// purposes. For example, on POSIX-y operating systems, Reserved is usually a -// private anonymous mmap'd region with PROT_NONE set, and to transition -// to Ready would require setting PROT_READ|PROT_WRITE. However the -// underspecification of Prepared lets us use just MADV_FREE to transition from -// Ready to Prepared. Thus with the Prepared state we can set the permission -// bits just once early on, we can efficiently tell the OS that it's free to -// take pages away from us when we don't strictly need them. -// -// For each OS there is a common set of helpers defined that transition -// memory regions between these states. The helpers are as follows: -// -// sysAlloc transitions an OS-chosen region of memory from None to Ready. -// More specifically, it obtains a large chunk of zeroed memory from the -// operating system, typically on the order of a hundred kilobytes -// or a megabyte. This memory is always immediately available for use. -// -// sysFree transitions a memory region from any state to None. Therefore, it -// returns memory unconditionally. It is used if an out-of-memory error has been -// detected midway through an allocation or to carve out an aligned section of -// the address space. It is okay if sysFree is a no-op only if sysReserve always -// returns a memory region aligned to the heap allocator's alignment -// restrictions. -// -// sysReserve transitions a memory region from None to Reserved. It reserves -// address space in such a way that it would cause a fatal fault upon access -// (either via permissions or not committing the memory). Such a reservation is -// thus never backed by physical memory. -// If the pointer passed to it is non-nil, the caller wants the -// reservation there, but sysReserve can still choose another -// location if that one is unavailable. -// NOTE: sysReserve returns OS-aligned memory, but the heap allocator -// may use larger alignment, so the caller must be careful to realign the -// memory obtained by sysReserve. -// -// sysMap transitions a memory region from Reserved to Prepared. It ensures the -// memory region can be efficiently transitioned to Ready. -// -// sysUsed transitions a memory region from Prepared to Ready. It notifies the -// operating system that the memory region is needed and ensures that the region -// may be safely accessed. This is typically a no-op on systems that don't have -// an explicit commit step and hard over-commit limits, but is critical on -// Windows, for example. -// -// sysUnused transitions a memory region from Ready to Prepared. It notifies the -// operating system that the physical pages backing this memory region are no -// longer needed and can be reused for other purposes. The contents of a -// sysUnused memory region are considered forfeit and the region must not be -// accessed again until sysUsed is called. -// -// sysFault transitions a memory region from Ready or Prepared to Reserved. It -// marks a region such that it will always fault if accessed. Used only for -// debugging the runtime. - func mallocinit() { if class_to_size[_TinySizeClass] != _TinySize { throw("bad TinySizeClass") |
