@@ -121,13 +121,17 @@ func TestPallocDataFindScavengeCandidate(t *testing.T) {
121
121
max : PallocChunkPages ,
122
122
want : BitRange {41 , 1 },
123
123
},
124
- "MultiMin1" : {
125
- alloc : []BitRange {{0 , 63 }, {65 , 20 }, {87 , PallocChunkPages - 87 }},
124
+ }
125
+ if PallocChunkPages >= 512 {
126
+ // avoid constant overflow when PallocChunkPages is small
127
+ var pallocChunkPages uint = PallocChunkPages
128
+ tests ["MultiMin1" ] = test {
129
+ alloc : []BitRange {{0 , 63 }, {65 , 20 }, {87 , pallocChunkPages - 87 }},
126
130
scavenged : []BitRange {{86 , 1 }},
127
131
min : 1 ,
128
132
max : PallocChunkPages ,
129
133
want : BitRange {85 , 1 },
130
- },
134
+ }
131
135
}
132
136
// Try out different page minimums.
133
137
for m := uintptr (1 ); m <= 64 ; m *= 2 {
@@ -162,25 +166,27 @@ func TestPallocDataFindScavengeCandidate(t *testing.T) {
162
166
max : PallocChunkPages ,
163
167
want : BitRange {PallocChunkPages - uint (m ), uint (m )},
164
168
}
165
- tests ["Straddle64" + suffix ] = test {
166
- alloc : []BitRange {{0 , 64 - uint (m )}, {64 + uint (m ), PallocChunkPages - (64 + uint (m ))}},
167
- min : m ,
168
- max : 2 * m ,
169
- want : BitRange {64 - uint (m ), 2 * uint (m )},
170
- }
171
- tests ["BottomEdge64WithFull" + suffix ] = test {
172
- alloc : []BitRange {{64 , 64 }, {128 + 3 * uint (m ), PallocChunkPages - (128 + 3 * uint (m ))}},
173
- scavenged : []BitRange {{1 , 10 }},
174
- min : m ,
175
- max : 3 * m ,
176
- want : BitRange {128 , 3 * uint (m )},
177
- }
178
- tests ["BottomEdge64WithPocket" + suffix ] = test {
179
- alloc : []BitRange {{64 , 62 }, {127 , 1 }, {128 + 3 * uint (m ), PallocChunkPages - (128 + 3 * uint (m ))}},
180
- scavenged : []BitRange {{1 , 10 }},
181
- min : m ,
182
- max : 3 * m ,
183
- want : BitRange {128 , 3 * uint (m )},
169
+ if PallocChunkPages >= 512 {
170
+ tests ["Straddle64" + suffix ] = test {
171
+ alloc : []BitRange {{0 , 64 - uint (m )}, {64 + uint (m ), PallocChunkPages - (64 + uint (m ))}},
172
+ min : m ,
173
+ max : 2 * m ,
174
+ want : BitRange {64 - uint (m ), 2 * uint (m )},
175
+ }
176
+ tests ["BottomEdge64WithFull" + suffix ] = test {
177
+ alloc : []BitRange {{64 , 64 }, {128 + 3 * uint (m ), PallocChunkPages - (128 + 3 * uint (m ))}},
178
+ scavenged : []BitRange {{1 , 10 }},
179
+ min : m ,
180
+ max : 3 * m ,
181
+ want : BitRange {128 , 3 * uint (m )},
182
+ }
183
+ tests ["BottomEdge64WithPocket" + suffix ] = test {
184
+ alloc : []BitRange {{64 , 62 }, {127 , 1 }, {128 + 3 * uint (m ), PallocChunkPages - (128 + 3 * uint (m ))}},
185
+ scavenged : []BitRange {{1 , 10 }},
186
+ min : m ,
187
+ max : 3 * m ,
188
+ want : BitRange {128 , 3 * uint (m )},
189
+ }
184
190
}
185
191
tests ["Max0" + suffix ] = test {
186
192
scavenged : []BitRange {{0 , PallocChunkPages - uint (m )}},
@@ -204,23 +210,29 @@ func TestPallocDataFindScavengeCandidate(t *testing.T) {
204
210
}
205
211
}
206
212
if m > 1 {
207
- tests ["MaxUnaligned" + suffix ] = test {
208
- scavenged : []BitRange {{0 , PallocChunkPages - uint (m * 2 - 1 )}},
209
- min : m ,
210
- max : m - 2 ,
211
- want : BitRange {PallocChunkPages - uint (m ), uint (m )},
212
- }
213
- tests ["SkipSmall" + suffix ] = test {
214
- alloc : []BitRange {{0 , 64 - uint (m )}, {64 , 5 }, {70 , 11 }, {82 , PallocChunkPages - 82 }},
215
- min : m ,
216
- max : m ,
217
- want : BitRange {64 - uint (m ), uint (m )},
213
+ if PallocChunkPages >= m * 2 {
214
+ tests ["MaxUnaligned" + suffix ] = test {
215
+ scavenged : []BitRange {{0 , PallocChunkPages - uint (m * 2 - 1 )}},
216
+ min : m ,
217
+ max : m - 2 ,
218
+ want : BitRange {PallocChunkPages - uint (m ), uint (m )},
219
+ }
218
220
}
219
- tests ["SkipMisaligned" + suffix ] = test {
220
- alloc : []BitRange {{0 , 64 - uint (m )}, {64 , 63 }, {127 + uint (m ), PallocChunkPages - (127 + uint (m ))}},
221
- min : m ,
222
- max : m ,
223
- want : BitRange {64 - uint (m ), uint (m )},
221
+ if PallocChunkPages >= 512 {
222
+ // avoid constant overflow when PallocChunkPages is small
223
+ var PallocChunkPages uint = PallocChunkPages
224
+ tests ["SkipSmall" + suffix ] = test {
225
+ alloc : []BitRange {{0 , 64 - uint (m )}, {64 , 5 }, {70 , 11 }, {82 , PallocChunkPages - 82 }},
226
+ min : m ,
227
+ max : m ,
228
+ want : BitRange {64 - uint (m ), uint (m )},
229
+ }
230
+ tests ["SkipMisaligned" + suffix ] = test {
231
+ alloc : []BitRange {{0 , 64 - uint (m )}, {64 , 63 }, {127 + uint (m ), PallocChunkPages - (127 + uint (m ))}},
232
+ min : m ,
233
+ max : m ,
234
+ want : BitRange {64 - uint (m ), uint (m )},
235
+ }
224
236
}
225
237
tests ["MaxLessThan" + suffix ] = test {
226
238
scavenged : []BitRange {{0 , PallocChunkPages - uint (m )}},
@@ -641,7 +653,7 @@ func TestScavengeIndex(t *testing.T) {
641
653
mark func (markFunc )
642
654
find func (findFunc )
643
655
}
644
- for _ , test := range []testCase {
656
+ tests := []testCase {
645
657
{
646
658
name : "Uninitialized" ,
647
659
mark : func (_ markFunc ) {},
@@ -692,26 +704,6 @@ func TestScavengeIndex(t *testing.T) {
692
704
find (BaseChunkIdx , PallocChunkPages - 1 )
693
705
},
694
706
},
695
- {
696
- name : "TwoChunks" ,
697
- mark : func (mark markFunc ) {
698
- mark (PageBase (BaseChunkIdx , 128 ), PageBase (BaseChunkIdx + 1 , 128 ))
699
- },
700
- find : func (find findFunc ) {
701
- find (BaseChunkIdx + 1 , 127 )
702
- find (BaseChunkIdx , PallocChunkPages - 1 )
703
- },
704
- },
705
- {
706
- name : "TwoChunksOffset" ,
707
- mark : func (mark markFunc ) {
708
- mark (PageBase (BaseChunkIdx + 7 , 128 ), PageBase (BaseChunkIdx + 8 , 129 ))
709
- },
710
- find : func (find findFunc ) {
711
- find (BaseChunkIdx + 8 , 128 )
712
- find (BaseChunkIdx + 7 , PallocChunkPages - 1 )
713
- },
714
- },
715
707
{
716
708
name : "SevenChunksOffset" ,
717
709
mark : func (mark markFunc ) {
@@ -793,7 +785,32 @@ func TestScavengeIndex(t *testing.T) {
793
785
}
794
786
},
795
787
},
796
- } {
788
+ }
789
+ if PallocChunkPages >= 512 {
790
+ tests = append (tests ,
791
+ testCase {
792
+ name : "TwoChunks" ,
793
+ mark : func (mark markFunc ) {
794
+ mark (PageBase (BaseChunkIdx , 128 ), PageBase (BaseChunkIdx + 1 , 128 ))
795
+ },
796
+ find : func (find findFunc ) {
797
+ find (BaseChunkIdx + 1 , 127 )
798
+ find (BaseChunkIdx , PallocChunkPages - 1 )
799
+ },
800
+ },
801
+ testCase {
802
+ name : "TwoChunksOffset" ,
803
+ mark : func (mark markFunc ) {
804
+ mark (PageBase (BaseChunkIdx + 7 , 128 ), PageBase (BaseChunkIdx + 8 , 129 ))
805
+ },
806
+ find : func (find findFunc ) {
807
+ find (BaseChunkIdx + 8 , 128 )
808
+ find (BaseChunkIdx + 7 , PallocChunkPages - 1 )
809
+ },
810
+ },
811
+ )
812
+ }
813
+ for _ , test := range tests {
797
814
test := test
798
815
t .Run ("Bg/" + test .name , func (t * testing.T ) {
799
816
mark , find , nextGen := setup (t , false )
@@ -830,8 +847,10 @@ func TestScavengeIndex(t *testing.T) {
830
847
}
831
848
832
849
func TestScavChunkDataPack (t * testing.T ) {
833
- if ! CheckPackScavChunkData (1918237402 , 512 , 512 , 0b11 ) {
834
- t .Error ("failed pack/unpack check for scavChunkData 1" )
850
+ if PallocChunkPages >= 512 {
851
+ if ! CheckPackScavChunkData (1918237402 , 512 , 512 , 0b11 ) {
852
+ t .Error ("failed pack/unpack check for scavChunkData 1" )
853
+ }
835
854
}
836
855
if ! CheckPackScavChunkData (^ uint32 (0 ), 12 , 0 , 0b00 ) {
837
856
t .Error ("failed pack/unpack check for scavChunkData 2" )
0 commit comments