]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: fix scavenging tests for pallocChunkBytes huge pages and larger
authorMichael Anthony Knyszek <mknyszek@google.com>
Tue, 20 Oct 2020 12:57:14 +0000 (12:57 +0000)
committerMichael Knyszek <mknyszek@google.com>
Tue, 20 Oct 2020 15:19:09 +0000 (15:19 +0000)
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 <mknyszek@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
Trust: Michael Knyszek <mknyszek@google.com>

src/runtime/mgcscavenge_test.go

index 7f619b1e7db933350257a1cc62d6b5dbf716b8a9..250343077ff84737ac31d5d7b56108903d13cf66 100644 (file)
@@ -235,26 +235,43 @@ func TestPallocDataFindScavengeCandidate(t *testing.T) {
        if PhysHugePageSize > uintptr(PageSize) {
                // Check hugepage preserving behavior.
                bits := uint(PhysHugePageSize / uintptr(PageSize))
-               tests["PreserveHugePageBottom"] = test{
-                       alloc: []BitRange{{bits + 2, PallocChunkPages - (bits + 2)}},
-                       min:   1,
-                       max:   3, // Make it so that max would have us try to break the huge page.
-                       want:  BitRange{0, bits + 2},
-               }
-               if 3*bits < PallocChunkPages {
-                       // We need at least 3 huge pages in a chunk for this test to make sense.
-                       tests["PreserveHugePageMiddle"] = test{
-                               alloc: []BitRange{{0, bits - 10}, {2*bits + 10, PallocChunkPages - (2*bits + 10)}},
+               if bits < PallocChunkPages {
+                       tests["PreserveHugePageBottom"] = test{
+                               alloc: []BitRange{{bits + 2, PallocChunkPages - (bits + 2)}},
                                min:   1,
-                               max:   12, // Make it so that max would have us try to break the huge page.
-                               want:  BitRange{bits, bits + 10},
+                               max:   3, // Make it so that max would have us try to break the huge page.
+                               want:  BitRange{0, bits + 2},
+                       }
+                       if 3*bits < PallocChunkPages {
+                               // We need at least 3 huge pages in a chunk for this test to make sense.
+                               tests["PreserveHugePageMiddle"] = test{
+                                       alloc: []BitRange{{0, bits - 10}, {2*bits + 10, PallocChunkPages - (2*bits + 10)}},
+                                       min:   1,
+                                       max:   12, // Make it so that max would have us try to break the huge page.
+                                       want:  BitRange{bits, bits + 10},
+                               }
+                       }
+                       tests["PreserveHugePageTop"] = test{
+                               alloc: []BitRange{{0, PallocChunkPages - bits}},
+                               min:   1,
+                               max:   1, // Even one page would break a huge page in this case.
+                               want:  BitRange{PallocChunkPages - bits, bits},
+                       }
+               } else if bits == PallocChunkPages {
+                       tests["PreserveHugePageAll"] = test{
+                               min:  1,
+                               max:  1, // Even one page would break a huge page in this case.
+                               want: BitRange{0, PallocChunkPages},
+                       }
+               } else {
+                       // The huge page size is greater than pallocChunkPages, so it should
+                       // be effectively disabled. There's no way we can possible scavenge
+                       // a huge page out of this bitmap chunk.
+                       tests["PreserveHugePageNone"] = test{
+                               min:  1,
+                               max:  1,
+                               want: BitRange{PallocChunkPages - 1, 1},
                        }
-               }
-               tests["PreserveHugePageTop"] = test{
-                       alloc: []BitRange{{0, PallocChunkPages - bits}},
-                       min:   1,
-                       max:   1, // Even one page would break a huge page in this case.
-                       want:  BitRange{PallocChunkPages - bits, bits},
                }
        }
        for name, v := range tests {