RFR: 8271195: Use largest available large page size smaller than LargePageSizeInBytes when available [v11]

Swati Sharma duke at openjdk.java.net
Fri Mar 11 17:42:51 UTC 2022


On Mon, 7 Mar 2022 12:08:48 GMT, Thomas Schatzl <tschatzl at openjdk.org> wrote:

>> Swati Sharma has updated the pull request incrementally with one additional commit since the last revision:
>> 
>>   8271195: Resolved the comments.
>
> Please drop the test.
> 
> The test is not able to distinguish failures from problems with the VM logic and other processes spuriously allocating enough large pages to make this test fail afaict. That's just a too annoying failure to debug. We can look into the test in a separate CR.
> 
> I kept the other comments I had for reference.

Hello @tschatzl,

All your comments have been incorporated, and also created a minimal test case as per @albertnetymk suggestion to test a point scenario.
Please suggest if the test changes looks good or should we add the below point test case.

Thanks,
Swati

------------------------------------------------------------------------------------------------
/*
 * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 * or visit www.oracle.com if you need additional information or have any
 * questions.
 */

package runtime.os;

/* @test
 * @bug 8271195
 * @summary Use largest available large page size smaller than LargePageSizeInBytes when available.
 * @requires os.family == "linux"
 * @requires os.arch == "amd64" | os.arch == "x86_64"
 * @requires vm.bits == 64
 * @requires vm.gc != "Z"
 * @library /test/lib
 * @run main/othervm runtime.os.TestExplicitPageAllocation
 */

import jdk.test.lib.process.ProcessTools;
import jdk.test.lib.process.OutputAnalyzer;
import jdk.test.lib.Utils;
import java.util.regex.Pattern;
import java.util.regex.Matcher;
import java.util.List;
import java.io.*;
import java.util.Scanner;

public class TestExplicitPageAllocation {

    private static final String HUGE_PAGES_1G = "/sys/kernel/mm/hugepages/hugepages-1048576kB/free_hugepages";
    private static final String HUGE_PAGES_2M = "/sys/kernel/mm/hugepages/hugepages-2048kB/free_hugepages";
    private static final int HEAP_SIZE_IN_KB = 2 * 1024 * 1024;
    private static final int CODE_CACHE_SIZE_IN_KB = 256 * 1024;
    private static final Pattern HEAP_PATTERN = Pattern.compile("Heap:");
    private static final Pattern PAGE_SIZE_PATTERN = Pattern.compile(".*page_size=([^ ]+).*");
    private static final Pattern HUGEPAGE_PATTERN = Pattern.compile(".*hugepages-([^ ]+).*kB");

    public static void main(String args[]) throws Exception {
        int pageCount1G = -1, pageCount2M = -1;
        try {
            pageCount1G = readPageCount(HUGE_PAGES_1G, "1G");
            pageCount2M = readPageCount(HUGE_PAGES_2M, "2M");
        } catch (Exception e) {
            System.out.println("Setup Exception " + e);
        }
        if (pageCount1G < 2 && pageCount2M >= ((HEAP_SIZE_IN_KB + CODE_CACHE_SIZE_IN_KB) / (2 * 1024))) {
            testCase();
        }
    }

    public static int readPageCount(String filename, String pageSize) throws Exception {
        BufferedReader d = new BufferedReader(new FileReader(filename));
        int pageCount = Integer.parseInt(d.readLine());
        if (pageCount == 0) {
            System.out.println("No pages configured for " + pageSize);
        }
        return pageCount;
    }

    private static boolean checkOutput(OutputAnalyzer out, String pageSize) {
        List<String> lines = out.asLines();
        for (int i = 0; i < lines.size(); ++i) {
            String line = lines.get(i);
            System.out.println(line);
            if (HEAP_PATTERN.matcher(line).find()) {
                Matcher trace = PAGE_SIZE_PATTERN.matcher(line);
                trace.find();
                String tracePageSize = trace.group(1);
                if (pageSize.equals(tracePageSize)) {
                    return true;
                }
            }
        }
        return false;
    }

    public static void testCase() throws Exception {
        ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-Xlog:pagesize",
                                                                  "-XX:ReservedCodeCacheSize=" + CODE_CACHE_SIZE_IN_KB + "k",
                                                                  "-XX:InitialCodeCacheSize=160k",
                                                                  "-XX:LargePageSizeInBytes=1g",
                                                                  "-XX:+UseParallelGC",
                                                                  "-XX:+UseLargePages",
                                                                  "-Xmx" + HEAP_SIZE_IN_KB + "k",
                                                                  "-Xms" + HEAP_SIZE_IN_KB + "k",
                                                                  "-version");
        OutputAnalyzer output = new OutputAnalyzer(pb.start());
        output.shouldHaveExitValue(0);
        if (checkOutput(output, "2M")) {
            System.out.println("TestCase Passed for pagesize: 1G, allocated pagesize: 2M");
        } else {
            throw new AssertionError("TestCase Failed for 2M page allocation");
        }
    }
}

-------------

PR: https://git.openjdk.java.net/jdk/pull/7326



More information about the hotspot-gc-dev mailing list