< prev index next >

src/java.base/linux/classes/jdk/internal/platform/CgroupSubsystemFactory.java

Print this page
@  rev 57586 : Review changes
|
o  rev 57585 : 8231111: Cgroups v2: Rework Metrics in java.base so as to recognize unified hierarchy
|  Reviewed-by: bobv
~
o  rev 56863 : 8231111: Cgroups v2: Rework Metrics in java.base so as to recognize unified hierarchy
|  Reviewed-by: bobv
~

@@ -1,7 +1,7 @@
 /*
- * 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
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.  Oracle designates this

@@ -64,22 +64,33 @@
             }
         } catch (IOException e) {
             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();
         }
 
         // If no controller is enabled, return no metrics.
         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
             String mountPath = null;
             try (Stream<String> lines =
< prev index next >