diff options
| author | Russ Cox <rsc@golang.org> | 2015-02-19 13:38:46 -0500 |
|---|---|---|
| committer | Russ Cox <rsc@golang.org> | 2015-02-19 20:17:01 +0000 |
| commit | 484f801ff4125d86f8c4072f070611afea9c79f7 (patch) | |
| tree | 6609ead9e0e6dabd5565800a5c5f80a89211ef75 /src/runtime/mfixalloc.go | |
| parent | d384545a4580cf1f6990efee5f0047ec60f4258d (diff) | |
| download | go-484f801ff4125d86f8c4072f070611afea9c79f7.tar.xz | |
runtime: reorganize memory code
Move code from malloc1.go, malloc2.go, mem.go, mgc0.go into
appropriate locations.
Factor mgc.go into mgc.go, mgcmark.go, mgcsweep.go, mstats.go.
A lot of this code was in certain files because the right place was in
a C file but it was written in Go, or vice versa. This is one step toward
making things actually well-organized again.
Change-Id: I6741deb88a7cfb1c17ffe0bcca3989e10207968f
Reviewed-on: https://go-review.googlesource.com/5300
Reviewed-by: Austin Clements <austin@google.com>
Reviewed-by: Rick Hudson <rlh@golang.org>
Diffstat (limited to 'src/runtime/mfixalloc.go')
| -rw-r--r-- | src/runtime/mfixalloc.go | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/runtime/mfixalloc.go b/src/runtime/mfixalloc.go index 3934a9e439..c1106b6281 100644 --- a/src/runtime/mfixalloc.go +++ b/src/runtime/mfixalloc.go @@ -10,6 +10,34 @@ package runtime import "unsafe" +// FixAlloc is a simple free-list allocator for fixed size objects. +// Malloc uses a FixAlloc wrapped around sysAlloc to manages its +// MCache and MSpan objects. +// +// Memory returned by FixAlloc_Alloc is not zeroed. +// The caller is responsible for locking around FixAlloc calls. +// Callers can keep state in the object but the first word is +// smashed by freeing and reallocating. +type fixalloc struct { + size uintptr + first unsafe.Pointer // go func(unsafe.pointer, unsafe.pointer); f(arg, p) called first time p is returned + arg unsafe.Pointer + list *mlink + chunk *byte + nchunk uint32 + inuse uintptr // in-use bytes now + stat *uint64 +} + +// A generic linked list of blocks. (Typically the block is bigger than sizeof(MLink).) +// Since assignments to mlink.next will result in a write barrier being preformed +// this can not be used by some of the internal GC structures. For example when +// the sweeper is placing an unmarked object on the free list it does not want the +// write barrier to be called since that could result in the object being reachable. +type mlink struct { + next *mlink +} + // Initialize f to allocate objects of the given size, // using the allocator to obtain chunks of memory. func fixAlloc_Init(f *fixalloc, size uintptr, first func(unsafe.Pointer, unsafe.Pointer), arg unsafe.Pointer, stat *uint64) { |
