< prev index next >

src/java.base/linux/classes/jdk/internal/platform/cgroupv1/CgroupV1Subsystem.java

Print this page
@  rev 57446 : Review changes
|
o  rev 57445 : 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
~


  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package jdk.internal.platform.cgroupv1;
  27 
  28 import java.io.IOException;
  29 import java.nio.file.Path;
  30 import java.nio.file.Paths;
  31 import java.util.stream.Stream;
  32 
  33 import jdk.internal.platform.CgroupSubsystem;
  34 import jdk.internal.platform.CgroupSubsystemController;
  35 import jdk.internal.platform.CgroupUtil;

  36 
  37 public class CgroupV1Subsystem implements CgroupSubsystem {
  38     private CgroupV1MemorySubSystemController memory;
  39     private CgroupV1SubsystemController cpu;
  40     private CgroupV1SubsystemController cpuacct;
  41     private CgroupV1SubsystemController cpuset;
  42     private CgroupV1SubsystemController blkio;
  43     private boolean activeSubSystems;
  44 
  45     private static final CgroupV1Subsystem INSTANCE = initSubSystem();
  46 
  47     private static final String PROVIDER_NAME = "cgroupv1";
  48 
  49     private CgroupV1Subsystem() {
  50         activeSubSystems = false;
  51     }
  52 
  53     public static CgroupV1Subsystem getInstance() {
  54         return INSTANCE;
  55     }


 302         return CgroupSubsystemController.getLongEntry(cpuacct, "cpuacct.stat", "system");
 303     }
 304 
 305 
 306     /*****************************************************************
 307      * CPU Subsystem
 308      ****************************************************************/
 309 
 310 
 311     public long getCpuPeriod() {
 312         return getLongValue(cpu, "cpu.cfs_period_us");
 313     }
 314 
 315     public long getCpuQuota() {
 316         return getLongValue(cpu, "cpu.cfs_quota_us");
 317     }
 318 
 319     public long getCpuShares() {
 320         long retval = getLongValue(cpu, "cpu.shares");
 321         if (retval == 0 || retval == 1024)
 322             return -1;
 323         else
 324             return retval;
 325     }
 326 
 327     public long getCpuNumPeriods() {
 328         return CgroupSubsystemController.getLongEntry(cpu, "cpu.stat", "nr_periods");
 329     }
 330 
 331     public long getCpuNumThrottled() {
 332         return CgroupSubsystemController.getLongEntry(cpu, "cpu.stat", "nr_throttled");
 333     }
 334 
 335     public long getCpuThrottledTime() {
 336         return CgroupSubsystemController.getLongEntry(cpu, "cpu.stat", "throttled_time");
 337     }
 338 
 339     public long getEffectiveCpuCount() {
 340         return Runtime.getRuntime().availableProcessors();
 341     }
 342 


 348     public int[] getCpuSetCpus() {
 349         return CgroupSubsystemController.stringRangeToIntArray(CgroupSubsystemController.getStringValue(cpuset, "cpuset.cpus"));
 350     }
 351 
 352     public int[] getEffectiveCpuSetCpus() {
 353         return CgroupSubsystemController.stringRangeToIntArray(CgroupSubsystemController.getStringValue(cpuset, "cpuset.effective_cpus"));
 354     }
 355 
 356     public int[] getCpuSetMems() {
 357         return CgroupSubsystemController.stringRangeToIntArray(CgroupSubsystemController.getStringValue(cpuset, "cpuset.mems"));
 358     }
 359 
 360     public int[] getEffectiveCpuSetMems() {
 361         return CgroupSubsystemController.stringRangeToIntArray(CgroupSubsystemController.getStringValue(cpuset, "cpuset.effective_mems"));
 362     }
 363 
 364     public double getCpuSetMemoryPressure() {
 365         return CgroupSubsystemController.getDoubleValue(cpuset, "cpuset.memory_pressure");
 366     }
 367 
 368     public boolean isCpuSetMemoryPressureEnabled() {
 369         long val = getLongValue(cpuset, "cpuset.memory_pressure_enabled");
 370         return (val == 1);
 371     }
 372 
 373 
 374     /*****************************************************************
 375      * Memory Subsystem
 376      ****************************************************************/
 377 
 378 
 379     public long getMemoryFailCount() {
 380         return getLongValue(memory, "memory.failcnt");
 381     }
 382 
 383     public long getMemoryLimit() {
 384         long retval = getLongValue(memory, "memory.limit_in_bytes");
 385         if (retval > CgroupV1SubsystemController.UNLIMITED_MIN) {
 386             if (memory.isHierarchical()) {
 387                 // memory.limit_in_bytes returned unlimited, attempt
 388                 // hierarchical memory limit


 456                 // memory.memsw.limit_in_bytes returned unlimited, attempt
 457                 // hierarchical memory limit
 458                 String match = "hierarchical_memsw_limit";
 459                 retval = CgroupSubsystemController.getLongValueMatchingLine(memory,
 460                                                             "memory.stat",
 461                                                             match,
 462                                                             CgroupV1Subsystem::convertHierachicalLimitLine);
 463             }
 464         }
 465         return CgroupV1SubsystemController.longValOrUnlimited(retval);
 466     }
 467 
 468     public long getMemoryAndSwapMaxUsage() {
 469         return getLongValue(memory, "memory.memsw.max_usage_in_bytes");
 470     }
 471 
 472     public long getMemoryAndSwapUsage() {
 473         return getLongValue(memory, "memory.memsw.usage_in_bytes");
 474     }
 475 
 476     public boolean isMemoryOOMKillEnabled() {
 477         long val = CgroupSubsystemController.getLongEntry(memory, "memory.oom_control", "oom_kill_disable");
 478         return (val == 0);
 479     }
 480 
 481     public long getMemorySoftLimit() {
 482         return CgroupV1SubsystemController.longValOrUnlimited(getLongValue(memory, "memory.soft_limit_in_bytes"));
 483     }
 484 
 485 
 486     /*****************************************************************
 487      * BlKIO Subsystem
 488      ****************************************************************/
 489 
 490 
 491     public long getBlkIOServiceCount() {
 492         return CgroupSubsystemController.getLongEntry(blkio, "blkio.throttle.io_service_bytes", "Total");
 493     }
 494 
 495     public long getBlkIOServiced() {
 496         return CgroupSubsystemController.getLongEntry(blkio, "blkio.throttle.io_serviced", "Total");


  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package jdk.internal.platform.cgroupv1;
  27 
  28 import java.io.IOException;
  29 import java.nio.file.Path;
  30 import java.nio.file.Paths;
  31 import java.util.stream.Stream;
  32 
  33 import jdk.internal.platform.CgroupSubsystem;
  34 import jdk.internal.platform.CgroupSubsystemController;
  35 import jdk.internal.platform.CgroupUtil;
  36 import jdk.internal.platform.Metrics;
  37 
  38 public class CgroupV1Subsystem implements CgroupSubsystem {
  39     private CgroupV1MemorySubSystemController memory;
  40     private CgroupV1SubsystemController cpu;
  41     private CgroupV1SubsystemController cpuacct;
  42     private CgroupV1SubsystemController cpuset;
  43     private CgroupV1SubsystemController blkio;
  44     private boolean activeSubSystems;
  45 
  46     private static final CgroupV1Subsystem INSTANCE = initSubSystem();
  47 
  48     private static final String PROVIDER_NAME = "cgroupv1";
  49 
  50     private CgroupV1Subsystem() {
  51         activeSubSystems = false;
  52     }
  53 
  54     public static CgroupV1Subsystem getInstance() {
  55         return INSTANCE;
  56     }


 303         return CgroupSubsystemController.getLongEntry(cpuacct, "cpuacct.stat", "system");
 304     }
 305 
 306 
 307     /*****************************************************************
 308      * CPU Subsystem
 309      ****************************************************************/
 310 
 311 
 312     public long getCpuPeriod() {
 313         return getLongValue(cpu, "cpu.cfs_period_us");
 314     }
 315 
 316     public long getCpuQuota() {
 317         return getLongValue(cpu, "cpu.cfs_quota_us");
 318     }
 319 
 320     public long getCpuShares() {
 321         long retval = getLongValue(cpu, "cpu.shares");
 322         if (retval == 0 || retval == 1024)
 323             return Metrics.LONG_RETVAL_UNLIMITED;
 324         else
 325             return retval;
 326     }
 327 
 328     public long getCpuNumPeriods() {
 329         return CgroupSubsystemController.getLongEntry(cpu, "cpu.stat", "nr_periods");
 330     }
 331 
 332     public long getCpuNumThrottled() {
 333         return CgroupSubsystemController.getLongEntry(cpu, "cpu.stat", "nr_throttled");
 334     }
 335 
 336     public long getCpuThrottledTime() {
 337         return CgroupSubsystemController.getLongEntry(cpu, "cpu.stat", "throttled_time");
 338     }
 339 
 340     public long getEffectiveCpuCount() {
 341         return Runtime.getRuntime().availableProcessors();
 342     }
 343 


 349     public int[] getCpuSetCpus() {
 350         return CgroupSubsystemController.stringRangeToIntArray(CgroupSubsystemController.getStringValue(cpuset, "cpuset.cpus"));
 351     }
 352 
 353     public int[] getEffectiveCpuSetCpus() {
 354         return CgroupSubsystemController.stringRangeToIntArray(CgroupSubsystemController.getStringValue(cpuset, "cpuset.effective_cpus"));
 355     }
 356 
 357     public int[] getCpuSetMems() {
 358         return CgroupSubsystemController.stringRangeToIntArray(CgroupSubsystemController.getStringValue(cpuset, "cpuset.mems"));
 359     }
 360 
 361     public int[] getEffectiveCpuSetMems() {
 362         return CgroupSubsystemController.stringRangeToIntArray(CgroupSubsystemController.getStringValue(cpuset, "cpuset.effective_mems"));
 363     }
 364 
 365     public double getCpuSetMemoryPressure() {
 366         return CgroupSubsystemController.getDoubleValue(cpuset, "cpuset.memory_pressure");
 367     }
 368 
 369     public Boolean isCpuSetMemoryPressureEnabled() {
 370         long val = getLongValue(cpuset, "cpuset.memory_pressure_enabled");
 371         return (val == 1);
 372     }
 373 
 374 
 375     /*****************************************************************
 376      * Memory Subsystem
 377      ****************************************************************/
 378 
 379 
 380     public long getMemoryFailCount() {
 381         return getLongValue(memory, "memory.failcnt");
 382     }
 383 
 384     public long getMemoryLimit() {
 385         long retval = getLongValue(memory, "memory.limit_in_bytes");
 386         if (retval > CgroupV1SubsystemController.UNLIMITED_MIN) {
 387             if (memory.isHierarchical()) {
 388                 // memory.limit_in_bytes returned unlimited, attempt
 389                 // hierarchical memory limit


 457                 // memory.memsw.limit_in_bytes returned unlimited, attempt
 458                 // hierarchical memory limit
 459                 String match = "hierarchical_memsw_limit";
 460                 retval = CgroupSubsystemController.getLongValueMatchingLine(memory,
 461                                                             "memory.stat",
 462                                                             match,
 463                                                             CgroupV1Subsystem::convertHierachicalLimitLine);
 464             }
 465         }
 466         return CgroupV1SubsystemController.longValOrUnlimited(retval);
 467     }
 468 
 469     public long getMemoryAndSwapMaxUsage() {
 470         return getLongValue(memory, "memory.memsw.max_usage_in_bytes");
 471     }
 472 
 473     public long getMemoryAndSwapUsage() {
 474         return getLongValue(memory, "memory.memsw.usage_in_bytes");
 475     }
 476 
 477     public Boolean isMemoryOOMKillEnabled() {
 478         long val = CgroupSubsystemController.getLongEntry(memory, "memory.oom_control", "oom_kill_disable");
 479         return (val == 0);
 480     }
 481 
 482     public long getMemorySoftLimit() {
 483         return CgroupV1SubsystemController.longValOrUnlimited(getLongValue(memory, "memory.soft_limit_in_bytes"));
 484     }
 485 
 486 
 487     /*****************************************************************
 488      * BlKIO Subsystem
 489      ****************************************************************/
 490 
 491 
 492     public long getBlkIOServiceCount() {
 493         return CgroupSubsystemController.getLongEntry(blkio, "blkio.throttle.io_service_bytes", "Total");
 494     }
 495 
 496     public long getBlkIOServiced() {
 497         return CgroupSubsystemController.getLongEntry(blkio, "blkio.throttle.io_serviced", "Total");
< prev index next >