Skip to content

Fix Linux cgroup2 initialization - #6984

Merged
babsingh merged 1 commit into
eclipse-omr:masterfrom
janvrany:pr/fix-groups2-initialization
May 11, 2023
Merged

Fix Linux cgroup2 initialization#6984
babsingh merged 1 commit into
eclipse-omr:masterfrom
janvrany:pr/fix-groups2-initialization

Conversation

@janvrany

Copy link
Copy Markdown
Contributor

This commit fixes a subtle bug in cgroup2 initialization, namely in populateCgroupEntryListV2().

Consider a system with only memory control group enabled. Then the cgroup.controllers for the process's cgroup2 would contain string memory followed by newline (\n). See Linux kernel source, file kernel/cgroup/cgroup.c, function cgroup_print_ss_mask() 1.

The code that iterates over cgroups listed only considers space as a separator:

separator = strchr(cursor, ' ');
if (NULL != separator) {
    *separator = '\0';
}

So the last (an in our example also the first) cgroup name (pointed to by cursor) contains the \n as the end, therefore the strcmp comparison fails:

...
   && (0 == strcmp(cursor, supportedSubsystems[i].name))
...

(since we're comparing 'memory\n' with just 'memory'). In other words, the last controller in controllers file is always "missed" by OMR.

This went unnoticed probably because most linux systems used have more (all?) controller enabled, so likely the last one was some that OMR is not interested in (such as pids, for example). However, if there's only one controller enabled, it is "missed" and OMR falsely reports CGroups2 are unavailable. This actually happened on RISC-V board running custom, stripped down kernel.

This commit fixes the problem by stripping the newline.

@babsingh babsingh left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Functionally, LGTM.

Minor formatting nitpicks. The unprocessed markdown syntax in the commit message should be removed.

Comment thread port/unix/omrsysinfo.c Outdated
This commit fixes a subtle bug in cgroup2 initialization, namely in
populateCgroupEntryListV2().

Consider a system with only memory control group enabled. Then the
cgroup.controllers for the process's cgroup2 would contain string
memory followed by newline (\n). See Linux kernel source, file
kernel/cgroup/cgroup.c, function cgroup_print_ss_mask() [1].

The code that iterates over cgroups listed only considers
space as a separator:

    separator = strchr(cursor, ' ');
	if (NULL != separator) {
	    *separator = '\0';
	}

So the last (an in our example also the first) cgroup name (pointed to
by cursor) contains the \n as the end, therefore the strcmp
comparison fails:

    ...
       && (0 == strcmp(cursor, supportedSubsystems[i].name))
    ...

(since we're comparing 'memory\n' with just 'memory'). In other words,
the last controller in controllers file is always "missed" by OMR.

This went unnoticed probably because most linux systems used have
more (all?) controller enabled, so likely the last one was some that OMR
is not interested in (such as pids, for example). However, if there's
only one controller enabled, it is "missed" and OMR falsely reports
CGroups2 are unavailable. This actually happened on RISC-V board running
custom, stripped down kernel.

This commit fixes the problem by stripping the newline.

[1]: https://github.com/torvalds/linux/blob/197b6b60ae7bc51dd0814953c562833143b292aa/kernel/cgroup/cgroup.c#L3005
@janvrany
janvrany force-pushed the pr/fix-groups2-initialization branch from 3b52179 to b544b75 Compare May 10, 2023 22:19
@janvrany

Copy link
Copy Markdown
Contributor Author

Thanks @babsingh! b544b75 should address your comments (hope I did not miss anything),

@babsingh

Copy link
Copy Markdown
Contributor

jenkins build all

@babsingh babsingh left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks for fixing this issue.

Just saw your message on OMR slack; was on vacation earlier; otherwise, would have helped.

@janvrany

Copy link
Copy Markdown
Contributor Author

Thanks for reviewing!
Just to let you know, RISC-V build will not finish as the build node is dead (we're working on it, but...) I have tested the change locally for RISC-V both using QEMU (as cross job does) and on real hardware.

@babsingh
babsingh merged commit 779c51b into eclipse-omr:master May 11, 2023
@janvrany
janvrany deleted the pr/fix-groups2-initialization branch May 11, 2023 07:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants