Skip to main content
Redhat Developers  Logo
  • Products

    Featured

    • Red Hat Enterprise Linux
      Red Hat Enterprise Linux Icon
    • Red Hat OpenShift AI
      Red Hat OpenShift AI
    • Red Hat Enterprise Linux AI
      Linux icon inside of a brain
    • Image mode for Red Hat Enterprise Linux
      RHEL image mode
    • Red Hat OpenShift
      Openshift icon
    • Red Hat Ansible Automation Platform
      Ansible icon
    • Red Hat Developer Hub
      Developer Hub
    • View All Red Hat Products
    • Linux

      • Red Hat Enterprise Linux
      • Image mode for Red Hat Enterprise Linux
      • Red Hat Universal Base Images (UBI)
    • Java runtimes & frameworks

      • JBoss Enterprise Application Platform
      • Red Hat build of OpenJDK
    • Kubernetes

      • Red Hat OpenShift
      • Microsoft Azure Red Hat OpenShift
      • Red Hat OpenShift Virtualization
      • Red Hat OpenShift Lightspeed
    • Integration & App Connectivity

      • Red Hat Build of Apache Camel
      • Red Hat Service Interconnect
      • Red Hat Connectivity Link
    • AI/ML

      • Red Hat OpenShift AI
      • Red Hat Enterprise Linux AI
    • Automation

      • Red Hat Ansible Automation Platform
      • Red Hat Ansible Lightspeed
    • Developer tools

      • Red Hat Trusted Software Supply Chain
      • Podman Desktop
      • Red Hat OpenShift Dev Spaces
    • Developer Sandbox

      Developer Sandbox
      Try Red Hat products and technologies without setup or configuration fees for 30 days with this shared Openshift and Kubernetes cluster.
    • Try at no cost
  • Technologies

    Featured

    • AI/ML
      AI/ML Icon
    • Linux
      Linux Icon
    • Kubernetes
      Cloud icon
    • Automation
      Automation Icon showing arrows moving in a circle around a gear
    • View All Technologies
    • Programming Languages & Frameworks

      • Java
      • Python
      • JavaScript
    • System Design & Architecture

      • Red Hat architecture and design patterns
      • Microservices
      • Event-Driven Architecture
      • Databases
    • Developer Productivity

      • Developer productivity
      • Developer Tools
      • GitOps
    • Secure Development & Architectures

      • Security
      • Secure coding
    • Platform Engineering

      • DevOps
      • DevSecOps
      • Ansible automation for applications and services
    • Automated Data Processing

      • AI/ML
      • Data Science
      • Apache Kafka on Kubernetes
      • View All Technologies
    • Start exploring in the Developer Sandbox for free

      sandbox graphic
      Try Red Hat's products and technologies without setup or configuration.
    • Try at no cost
  • Learn

    Featured

    • Kubernetes & Cloud Native
      Openshift icon
    • Linux
      Rhel icon
    • Automation
      Ansible cloud icon
    • Java
      Java icon
    • AI/ML
      AI/ML Icon
    • View All Learning Resources

    E-Books

    • GitOps Cookbook
    • Podman in Action
    • Kubernetes Operators
    • The Path to GitOps
    • View All E-books

    Cheat Sheets

    • Linux Commands
    • Bash Commands
    • Git
    • systemd Commands
    • View All Cheat Sheets

    Documentation

    • API Catalog
    • Product Documentation
    • Legacy Documentation
    • Red Hat Learning

      Learning image
      Boost your technical skills to expert-level with the help of interactive lessons offered by various Red Hat Learning programs.
    • Explore Red Hat Learning
  • Developer Sandbox

    Developer Sandbox

    • Access Red Hat’s products and technologies without setup or configuration, and start developing quicker than ever before with our new, no-cost sandbox environments.
    • Explore Developer Sandbox

    Featured Developer Sandbox activities

    • Get started with your Developer Sandbox
    • OpenShift virtualization and application modernization using the Developer Sandbox
    • Explore all Developer Sandbox activities

    Ready to start developing apps?

    • Try at no cost
  • Blog
  • Events
  • Videos

OpenJDK 8u372 to feature cgroup v2 support

April 19, 2023
Severin Gehwolf
Related topics:
JavaKubernetes
Related products:
Red Hat build of OpenJDKRed Hat OpenShiftRed Hat Enterprise Linux

Share:

    The control group (cgroup) pseudo filesystem is the key feature enabling resource quotas on containers deployed on Kubernetes. The cgroups filesystem is a Linux kernel feature and comes in one of three forms, depending on the hosts' configuration:

    • cgroup v2, or unified hierarchy
    • cgroup v1, or legacy hierarchy
    • hybrid (basically cgroup v1, but some system services use cgroup v2).

    The state of the art is cgroup v2. With the releases of Red Hat OpenShift 4.12 and Red Hat Enterprise Linux 9, which both feature cgroup v2, it becomes increasingly likely that OpenJDK 8 running in containers runs on a cgroup v2-enabled Linux kernel. Cgroup v1, the current predominant configuration, will become increasingly less frequent in practice as time moves forward.

    OpenJDK 8u372: cgroup v1 and v2 support

    With the release of OpenJDK 8u372 in April 2023, the cgroup v2 support patches present in later JDK releases have been backported to OpenJDK 8. 30 patches in total have been backported so as to bring this feature to OpenJDK 8u. It was added to OpenJDK 8u, a very mature and stable JDK release, under the enhancement exception rule of adapting to new hardware and operating environments.

    Version 8u372 and later will detect the cgroup version in use, v1 or v2, on the host system. Once it detects the version, it looks up the set resource limits via the pseudo filesystem hierarchy and will size its internal resources accordingly. This will ensure that OpenJDK 8 will comply to the set resource limits of containers on cgroup v2 systems, a feature OpenJDK users have grown accustomed to since it was first brought to OpenJDK 8 with the 8u192 release.

    How to see which cgroup version OpenJDK 8u detected

    One easy way to see which cgroup version, if any, OpenJDK 8u detected is by using the -XshowSettings:system Java launcher switch. Example:

    [root@357fec96b37e /]# /opt/jdk8u372/bin/java -XshowSettings:system -version
    Operating System Metrics:
        Provider: cgroupv2
        Effective CPU Count: 3
        CPU Period: 100000us
        CPU Quota: 300000us
        CPU Shares: -1
        List of Processors: N/A
        List of Effective Processors, 4 total: 
        0 1 2 3 
        List of Memory Nodes: N/A
        List of Available Memory Nodes, 1 total: 
        0 
        Memory Limit: 500.00M
        Memory Soft Limit: 0.00K
        Memory & Swap Limit: 500.00M
    
    openjdk version "1.8.0_372-beta"
    OpenJDK Runtime Environment (Temurin)(build 1.8.0_372-beta-202303201451-b05)
    OpenJDK 64-Bit Server VM (Temurin)(build 25.372-b05, mixed mode)

    Another way is to use the -XX:+UnlockDiagnosticVMOptions -XX:+PrintContainerInfo JVM switches in order to see the details of which files are being looked up internally:

    [root@357fec96b37e /]# /opt/jdk8u372/bin/java -XX:+UnlockDiagnosticVMOptions -XX:+PrintContainerInfo -version
    OSContainer::init: Initializing Container Support
    Detected cgroups v2 unified hierarchy
    Path to /cpu.max is /sys/fs/cgroup//cpu.max
    Raw value for CPU quota is: 300000
    CPU Quota is: 300000
    Path to /cpu.max is /sys/fs/cgroup//cpu.max
    CPU Period is: 100000
    Path to /cpu.weight is /sys/fs/cgroup//cpu.weight
    Raw value for CPU Shares is: 100
    CPU Shares is: -1
    CPU Quota count based on quota/period: 3
    OSContainer::active_processor_count: 3
    CgroupSubsystem::active_processor_count (cached): 3
    total physical memory: 5033832448
    Path to /memory.max is /sys/fs/cgroup//memory.max
    Raw value for memory limit is: 524288000
    Memory Limit is: 524288000
    total container memory: 524288000
    total container memory: 524288000
    CgroupSubsystem::active_processor_count (cached): 3
    Path to /cpu.max is /sys/fs/cgroup//cpu.max
    Raw value for CPU quota is: 300000
    CPU Quota is: 300000
    Path to /cpu.max is /sys/fs/cgroup//cpu.max
    CPU Period is: 100000
    Path to /cpu.weight is /sys/fs/cgroup//cpu.weight
    Raw value for CPU Shares is: 100
    CPU Shares is: -1
    CPU Quota count based on quota/period: 3
    OSContainer::active_processor_count: 3
    openjdk version "1.8.0_372-beta"
    OpenJDK Runtime Environment (Temurin)(build 1.8.0_372-beta-202303201451-b05)
    OpenJDK 64-Bit Server VM (Temurin)(build 25.372-b05, mixed mode)

    OpenJDK 8u362 and older: cgroup v1 only

    Older releases of OpenJDK 8u will only be able to detect cgroup v1 systems. Security considerations aside, it's highly encouraged to upgrade to a later release if you are running your containers on recent cloud infrastructure such as OpenShift 4.12. For example, for a 8u362 build of OpenJDK on a cgroup's v2 system, it would look like as if the container detection failed (i.e., no metrics):

    $ ./jdk8u362-b09/bin/java -XshowSettings:system -version
    Operating System Metrics:
        No metrics available for this platform
    openjdk version "1.8.0_362"
    OpenJDK Runtime Environment (Temurin)(build 1.8.0_362-b09)
    OpenJDK 64-Bit Server VM (Temurin)(build 25.362-b09, mixed mode)
    

    Onward to JDK 21

    While it's important to support new computing environments in older JDK releases, the next OpenJDK LTS release, OpenJDK 21, is around the corner and is scheduled to be released in September 2023. JDK 21 includes many more improvements for a better container and cloud experience. So if you are thinking of writing new Java applications, consider targeting JDK 21, and perhaps using Quarkus for the best cloud native experience!

    Looking for more resources? Explore all things Java on Red Hat Developer.

    Last updated: September 19, 2023

    Related Posts

    • Java 17: What’s new in OpenJDK's container awareness

    • Overhauling memory tuning in OpenJDK containers updates

    • The future of Java and OpenJDK updates without Oracle support

    • Migrating from Oracle JDK to OpenJDK on Red Hat Enterprise Linux: What you need to know

    • OpenJDK now available for Windows

    Recent Posts

    • GuideLLM: Evaluate LLM deployments for real-world inference

    • Unleashing multimodal magic with RamaLama

    • Integrate Red Hat AI Inference Server & LangChain in agentic workflows

    • Streamline multi-cloud operations with Ansible and ServiceNow

    • Automate dynamic application security testing with RapiDAST

    What’s up next?

    Quarkus for Spring Developers

    Learn how to optimize Java for today’s compute and runtime demands with Quarkus—a Kubernetes-native platform. Quarkus for Spring Developers introduces Quarkus to Java developers, with a special eye for helping those familiar with Spring’s conventions make a quick and easy transition.

    Get the e-book
    Red Hat Developers logo LinkedIn YouTube Twitter Facebook

    Products

    • Red Hat Enterprise Linux
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform

    Build

    • Developer Sandbox
    • Developer Tools
    • Interactive Tutorials
    • API Catalog

    Quicklinks

    • Learning Resources
    • E-books
    • Cheat Sheets
    • Blog
    • Events
    • Newsletter

    Communicate

    • About us
    • Contact sales
    • Find a partner
    • Report a website issue
    • Site Status Dashboard
    • Report a security problem

    RED HAT DEVELOPER

    Build here. Go anywhere.

    We serve the builders. The problem solvers who create careers with code.

    Join us if you’re a developer, software engineer, web designer, front-end designer, UX designer, computer scientist, architect, tester, product manager, project manager or team lead.

    Sign me up

    Red Hat legal and privacy links

    • About Red Hat
    • Jobs
    • Events
    • Locations
    • Contact Red Hat
    • Red Hat Blog
    • Inclusion at Red Hat
    • Cool Stuff Store
    • Red Hat Summit

    Red Hat legal and privacy links

    • Privacy statement
    • Terms of use
    • All policies and guidelines
    • Digital accessibility

    Report a website issue