--- old/src/java.base/linux/classes/jdk/internal/platform/CgroupSubsystemFactory.java 2020-01-09 20:39:13.332139460 +0100 +++ new/src/java.base/linux/classes/jdk/internal/platform/CgroupSubsystemFactory.java 2020-01-09 20:39:13.193139314 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, Red Hat Inc. + * Copyright (c) 2020, Red Hat Inc. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -66,10 +66,14 @@ return null; } - // For cgroups v1 all controllers need to have non-null hierarchy id + // For cgroups v1 all controllers need to have non-zero hierarchy id boolean isCgroupsV2 = true; boolean anyControllersEnabled = false; + boolean anyCgroupsV2Controller = false; + boolean anyCgroupsV1Controller = false; for (CgroupInfo info: infos.values()) { + anyCgroupsV1Controller = anyCgroupsV1Controller || info.getHierarchyId() != 0; + anyCgroupsV2Controller = anyCgroupsV2Controller || info.getHierarchyId() == 0; isCgroupsV2 = isCgroupsV2 && info.getHierarchyId() == 0; anyControllersEnabled = anyControllersEnabled || info.isEnabled(); } @@ -78,6 +82,13 @@ if (!anyControllersEnabled) { return null; } + // Warn about mixed cgroups v1 and cgroups v2 controllers. The code is + // not ready to deal with that on a per-controller basis. Return no metrics + // in that case + if (anyCgroupsV1Controller && anyCgroupsV2Controller) { + System.err.println("Warning: Mixed cgroupv1 and cgroupv2 not supported. Metrics disabled."); + return null; + } if (isCgroupsV2) { // read mountinfo so as to determine root mount path