]> Cypherpunks.ru repositories - gostls13.git/blob - src/runtime/msize_allocheaders.go
runtime: implement experiment to replace heap bitmap with alloc headers
[gostls13.git] / src / runtime / msize_allocheaders.go
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.
4
5 //go:build goexperiment.allocheaders
6
7 // Malloc small size classes.
8 //
9 // See malloc.go for overview.
10 // See also mksizeclasses.go for how we decide what size classes to use.
11
12 package runtime
13
14 // Returns size of the memory block that mallocgc will allocate if you ask for the size,
15 // minus any inline space for metadata.
16 func roundupsize(size uintptr, noscan bool) (reqSize uintptr) {
17         reqSize = size
18         if reqSize <= maxSmallSize-mallocHeaderSize {
19                 // Small object.
20                 if !noscan && reqSize > minSizeForMallocHeader { // !noscan && !heapBitsInSpan(reqSize)
21                         reqSize += mallocHeaderSize
22                 }
23                 // (reqSize - size) is either mallocHeaderSize or 0. We need to subtract mallocHeaderSize
24                 // from the result if we have one, since mallocgc will add it back in.
25                 if reqSize <= smallSizeMax-8 {
26                         return uintptr(class_to_size[size_to_class8[divRoundUp(reqSize, smallSizeDiv)]]) - (reqSize - size)
27                 }
28                 return uintptr(class_to_size[size_to_class128[divRoundUp(reqSize-smallSizeMax, largeSizeDiv)]]) - (reqSize - size)
29         }
30         // Large object. Align reqSize up to the next page. Check for overflow.
31         reqSize += pageSize - 1
32         if reqSize < size {
33                 return size
34         }
35         return reqSize &^ (pageSize - 1)
36 }