1 // Copyright 2009 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
7 // This is a temporary mcache.go for gccgo.
8 // At some point it will be replaced by the one in the gc runtime package.
12 type mcachelist
struct {
17 // Per-thread (in Go, per-P) cache for small objects.
18 // No locking needed because it is per-thread (per-P).
20 // mcaches are allocated from non-GC'd memory, so any heap pointers
21 // must be specially handled.
25 // The following members are accessed on every malloc,
26 // so they are grouped here for better caching.
27 next_sample
int32 // trigger heap sample after allocating this many bytes
28 local_cachealloc
uintptr // bytes allocated (or freed) from cache since last lock of heap
30 // Allocator cache for tiny objects w/o pointers.
31 // See "Tiny allocator" comment in malloc.go.
33 // tiny points to the beginning of the current tiny block, or
34 // nil if there is no current tiny block.
36 // tiny is a heap pointer. Since mcache is in non-GC'd memory,
37 // we handle it by clearing it in releaseAll during mark
42 // The rest is not accessed on every malloc.
43 alloc
[_NumSizeClasses
]*mspan
// spans to allocate from
44 free
[_NumSizeClasses
]mcachelist
// lists of explicitly freed objects
46 // Local allocator stats, flushed during GC.
47 local_nlookup
uintptr // number of pointer lookups
48 local_largefree
uintptr // bytes freed for large objects (>maxsmallsize)
49 local_nlargefree
uintptr // number of frees for large objects (>maxsmallsize)
50 local_nsmallfree
[_NumSizeClasses
]uintptr // number of frees for small objects (<=maxsmallsize)
65 next
*mspan
// next span in list, or nil if none
66 prev
*mspan
// previous span's next field, or list head's first field if none
68 npages
uintptr // number of pages in span
72 // if sweepgen == h->sweepgen - 2, the span needs sweeping
73 // if sweepgen == h->sweepgen - 1, the span is currently being swept
74 // if sweepgen == h->sweepgen, the span is swept and ready to use
75 // h->sweepgen is incremented by 2 after every GC
79 sizeclass
uint8 // size class
80 incache
bool // being used by an mcache
81 state
uint8 // mspaninuse etc
82 needzero
uint8 // needs to be zeroed before allocation
83 elemsize
uintptr // computed from sizeclass or from npages
84 unusedsince
int64 // first time spotted by gc in mspanfree state
85 npreleased
uintptr // number of pages released to the os
86 limit
uintptr // end of data in span
88 speciallock mutex
// guards specials list
89 specials
*special
// linked list of special records sorted by offset.