RFR: 8245543: Cgroups: Incorrect detection logic on some systems (still reproducible)

Boris Ulasevich bulasevich at openjdk.java.net
Sun Oct 4 18:17:38 UTC 2020


On Fri, 2 Oct 2020 16:34:49 GMT, Severin Gehwolf <sgehwolf at openjdk.org> wrote:

> An issue similar to [JDK-8239559](https://bugs.openjdk.java.net/browse/JDK-8239559) has been discovered. On the
> affected system, `/proc/self/mountinfo` contains a line such as this one:
> 
> 35 26 0:26 / /sys/fs/cgroup/systemd rw,nosuid,nodev,noexec,relatime - cgroup systemd rw,name=systemd
>  
> 
> Note that `/proc/cgroups` looks like this:
> 
> #subsys_name	hierarchy	num_cgroups	enabled
> cpuset	0	1	1
> cpu	0	1	1
> cpuacct	0	1	1
> blkio	0	1	1
> memory	0	1	1
> devices	0	1	1
> freezer	0	1	1
> net_cls	0	1	1
> perf_event	0	1	1
> net_prio	0	1	1
> hugetlb	0	1	1
> pids	0	1	1
> 
> This is in fact a cgroups v1 system with systemd put into a separate namespace via FS type `cgroup`. That mountinfo
> line confuses the cgroups version detection heuristic. It only looked whether or not there is **any** entry in
> mountinfo of FS-type `cgroup` . That's wrong. A better heuristic would be looking at controllers we care about: `cpu`,
> `cpuacct`, `memory`, `cpuset` for hotspot and some more for the Java side. The proposed fix on the hotspot side is to
> set `any_cgroup_mounts_found` to true only if one of those controllers show up in mountinfo. Otherwise, we know it's
> cgroup v2 due to the zero hierarchy ids.  For the Java side the proposal is to add some parsing for mountinfo lines and
> look for `cgroup` FS-type lines which aren't also mounted purely for systemd.
> **Testing**
> 
>  - [x] Linux x86_64 container tests on cgroup v1 (fastdebug)
>  - [x] Linux x86_64 container tests on cgroup v2 (fastdebug)
>  - [x] Added regression test which fails prior the patch and passes after
>  - [ ] Submit testing (still running)

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

> 70:      *  Pattern explanation:
> 71:      *
> 72:      *  /`````\    /`````\    /`````\    /```````\    /```````\    /```\ (8) /```````\     (10) + (11)

Alternatively, consider the inline comment:

    private static final Pattern MOUNTINFO_PATTERN = Pattern.compile(
        "^[^\\s]+\\s+[^\\s]+\\s+[^\\s]+\\s+" +  // (1) + (2) + (3)
        "([^\\s]+)\\s+([^\\s]+)\\s+"         +  // (4) + (5) - group 1,2: mount point, mount options
        "[^-]+-\\s+"    +                       // (6) + (7) + (8)
        "([^\\s]+)\\s+" +                       // (9) - group 3: fstype
        ".*$");                                 // (10) + (11)

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

> 78:      */
> 79:     private static final Pattern MOUNTINFO_PATTERN =
> 80:
> Pattern.compile("^[^\\s]+\\s+[^\\s]+\\s+[^\\s]+\\s+([^\\s]+)\\s+([^\\s]+)\\s+[^-]+-\\s+([^\\s]+)\\s+.*$");

Only group_3 = fstype is used in the pattern, right?

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

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


More information about the serviceability-dev mailing list