Skip to content

Commit 05f5ae7

Browse files
committed
runtime: fix scavenging tests for pallocChunkBytes huge pages and larger
Currently the scavenging tests implicitly assume that the system huge page size is always strictly less than 4 MiB, or pallocChunkBytes. This leads to failures on systems with huge pages of this size, and larger. Filter out those tests on such platforms and add a test for the 4 MiB case. The scavenger is already equipped to handle this case. Huge page sizes > 4 MiB are effectively ignored, so also add a test case to ensure that happens. Unfortunately we can't actually run these tests in our CI because they require the platform to provide the right huge page size, but we really should just parameterize this value so we can test it (there's a TODO about this already). Fixes #42053. Change-Id: Ia576cbf67e178a14a178a893967efbed27d6eb17 Reviewed-on: https://go-review.googlesource.com/c/go/+/263837 Run-TryBot: Michael Knyszek <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Keith Randall <[email protected]> Trust: Michael Knyszek <[email protected]>
1 parent 0bf507e commit 05f5ae7

File tree

1 file changed

+35
-18
lines changed

1 file changed

+35
-18
lines changed

src/runtime/mgcscavenge_test.go

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -235,26 +235,43 @@ func TestPallocDataFindScavengeCandidate(t *testing.T) {
235235
if PhysHugePageSize > uintptr(PageSize) {
236236
// Check hugepage preserving behavior.
237237
bits := uint(PhysHugePageSize / uintptr(PageSize))
238-
tests["PreserveHugePageBottom"] = test{
239-
alloc: []BitRange{{bits + 2, PallocChunkPages - (bits + 2)}},
240-
min: 1,
241-
max: 3, // Make it so that max would have us try to break the huge page.
242-
want: BitRange{0, bits + 2},
243-
}
244-
if 3*bits < PallocChunkPages {
245-
// We need at least 3 huge pages in a chunk for this test to make sense.
246-
tests["PreserveHugePageMiddle"] = test{
247-
alloc: []BitRange{{0, bits - 10}, {2*bits + 10, PallocChunkPages - (2*bits + 10)}},
238+
if bits < PallocChunkPages {
239+
tests["PreserveHugePageBottom"] = test{
240+
alloc: []BitRange{{bits + 2, PallocChunkPages - (bits + 2)}},
248241
min: 1,
249-
max: 12, // Make it so that max would have us try to break the huge page.
250-
want: BitRange{bits, bits + 10},
242+
max: 3, // Make it so that max would have us try to break the huge page.
243+
want: BitRange{0, bits + 2},
244+
}
245+
if 3*bits < PallocChunkPages {
246+
// We need at least 3 huge pages in a chunk for this test to make sense.
247+
tests["PreserveHugePageMiddle"] = test{
248+
alloc: []BitRange{{0, bits - 10}, {2*bits + 10, PallocChunkPages - (2*bits + 10)}},
249+
min: 1,
250+
max: 12, // Make it so that max would have us try to break the huge page.
251+
want: BitRange{bits, bits + 10},
252+
}
253+
}
254+
tests["PreserveHugePageTop"] = test{
255+
alloc: []BitRange{{0, PallocChunkPages - bits}},
256+
min: 1,
257+
max: 1, // Even one page would break a huge page in this case.
258+
want: BitRange{PallocChunkPages - bits, bits},
259+
}
260+
} else if bits == PallocChunkPages {
261+
tests["PreserveHugePageAll"] = test{
262+
min: 1,
263+
max: 1, // Even one page would break a huge page in this case.
264+
want: BitRange{0, PallocChunkPages},
265+
}
266+
} else {
267+
// The huge page size is greater than pallocChunkPages, so it should
268+
// be effectively disabled. There's no way we can possible scavenge
269+
// a huge page out of this bitmap chunk.
270+
tests["PreserveHugePageNone"] = test{
271+
min: 1,
272+
max: 1,
273+
want: BitRange{PallocChunkPages - 1, 1},
251274
}
252-
}
253-
tests["PreserveHugePageTop"] = test{
254-
alloc: []BitRange{{0, PallocChunkPages - bits}},
255-
min: 1,
256-
max: 1, // Even one page would break a huge page in this case.
257-
want: BitRange{PallocChunkPages - bits, bits},
258275
}
259276
}
260277
for name, v := range tests {

0 commit comments

Comments
 (0)