OLD | NEW |
1 // Copyright 2009 The Go Authors. All rights reserved. | 1 // Copyright 2009 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 // Malloc small size classes. | 5 // Malloc small size classes. |
6 // | 6 // |
7 // See malloc.h for overview. | 7 // See malloc.h for overview. |
8 // | 8 // |
9 // The size classes are chosen so that rounding an allocation | 9 // The size classes are chosen so that rounding an allocation |
10 // request up to the next size class wastes at most 12.5% (1.125x). | 10 // request up to the next size class wastes at most 12.5% (1.125x). |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 // Initialize the runtime·class_to_size table (and choose class sizes in
the process). | 71 // Initialize the runtime·class_to_size table (and choose class sizes in
the process). |
72 runtime·class_to_size[0] = 0; | 72 runtime·class_to_size[0] = 0; |
73 sizeclass = 1; // 0 means no class | 73 sizeclass = 1; // 0 means no class |
74 align = 8; | 74 align = 8; |
75 for(size = align; size <= MaxSmallSize; size += align) { | 75 for(size = align; size <= MaxSmallSize; size += align) { |
76 if((size&(size-1)) == 0) { // bump alignment once in a whil
e | 76 if((size&(size-1)) == 0) { // bump alignment once in a whil
e |
77 if(size >= 2048) | 77 if(size >= 2048) |
78 align = 256; | 78 align = 256; |
79 else if(size >= 128) | 79 else if(size >= 128) |
80 align = size / 8; | 80 align = size / 8; |
81 » » » else if(size >= 16) | 81 » » » else if(size >= 32) |
82 align = 16; // required for x86 SSE instruct
ions, if we want to use them | 82 align = 16; // required for x86 SSE instruct
ions, if we want to use them |
83 } | 83 } |
84 if((align&(align-1)) != 0) | 84 if((align&(align-1)) != 0) |
85 runtime·throw("InitSizes - bug"); | 85 runtime·throw("InitSizes - bug"); |
86 | 86 |
87 // Make the allocnpages big enough that | 87 // Make the allocnpages big enough that |
88 // the leftover is less than 1/8 of the total, | 88 // the leftover is less than 1/8 of the total, |
89 // so wasted space is at most 12.5%. | 89 // so wasted space is at most 12.5%. |
90 allocsize = PageSize; | 90 allocsize = PageSize; |
91 while(allocsize%size > allocsize/8) | 91 while(allocsize%size > allocsize/8) |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 if(size < MaxSmallSize) { | 175 if(size < MaxSmallSize) { |
176 if(size <= 1024-8) | 176 if(size <= 1024-8) |
177 return runtime·class_to_size[runtime·size_to_class8[(siz
e+7)>>3]]; | 177 return runtime·class_to_size[runtime·size_to_class8[(siz
e+7)>>3]]; |
178 else | 178 else |
179 return runtime·class_to_size[runtime·size_to_class128[(s
ize-1024+127) >> 7]]; | 179 return runtime·class_to_size[runtime·size_to_class128[(s
ize-1024+127) >> 7]]; |
180 } | 180 } |
181 if(size + PageSize < size) | 181 if(size + PageSize < size) |
182 return size; | 182 return size; |
183 return ROUND(size, PageSize); | 183 return ROUND(size, PageSize); |
184 } | 184 } |
OLD | NEW |