On Mon, 23 May 2022 22:11:47 GMT, Ioi Lam <ik...@openjdk.org> wrote:

> This PR fixes a bug found on an Ubuntu host that's mostly running with 
> cgroupv2, but there's a controller (freezer) that is mounted in cgroupv1 mode.
> 
> The container support code in the VM and JDK checks if we have simultaneously 
> mounted v1 and v2 containers. If so, we revert to "hybrid" mode (which is 
> essentially v1).
> 
> However, the "hybrid checks" only considers the following controllers that 
> Java cares about:
> 
> - cpu
> - cpuacct
> - cpuset
> - blkio
> - memory
> - pids
> 
> If only "freezer" is mounted in v1 mode, Java will start in V2 mode. Later, 
> when `setCgroupV2Path()` sees the first line in /proc/self/cgroup, it runs 
> into the assert.
> 
> 
> $ cat /proc/self/cgroup
> 1:freezer:/
> 0::/user.slice/user-1001.slice/session-85.scope
> 
> 
> The fix is simple -- when we get to `setCgroupV2Path()`, we have already 
> decided that the system has not mounted any v1 controllers that we care 
> about, so we should just ignore all the v1 controllers (which has a non-empty 
> name).

src/java.base/linux/classes/jdk/internal/platform/CgroupSubsystemFactory.java 
line 155:

> 153:                 // There are some controllers (such as freezer) that 
> Java doesn't
> 154:                 // care about. Just ignore them. These are not 
> considered in the
> 155:                 // anyCgroupsV1Controller/anyCgroupsV1Controller checks.

It's not clear why this `default` is necessary. Could we just add the comment 
like so:


// Intentional fall-through. There are controllers (such as freezer) that
// Java doesn't care about. Just ignore them. Only listed controllers are
// considered in the anyCgroupsV1Controller/anyCgroupsV2Controller checks.

src/java.base/linux/classes/jdk/internal/platform/CgroupSubsystemFactory.java 
line 229:

> 227:         String name = tokens[1];
> 228:         if (!name.equals("")) {
> 229:             // This is probably a v1 controller that we have ignored 
> (e.g., freezer)

Could we add an assertion that the controller isn't in the `infos` map?

           if (!name.equals("")) {
            // This must be a v1 controller that we have ignored (e.g., freezer)
            assert infos.get(name) == null;
            return;
         }

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

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

Reply via email to