Fix Linux cgroup2 initialization - #6984
Merged
babsingh merged 1 commit intoMay 11, 2023
Merged
Conversation
janvrany
requested review from
babsingh,
charliegracie and
youngar
as code owners
May 10, 2023 21:48
babsingh
reviewed
May 10, 2023
babsingh
left a comment
Contributor
There was a problem hiding this comment.
Functionally, LGTM.
Minor formatting nitpicks. The unprocessed markdown syntax in the commit message should be removed.
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
force-pushed
the
pr/fix-groups2-initialization
branch
from
May 10, 2023 22:19
3b52179 to
b544b75
Compare
Contributor
Author
Contributor
|
jenkins build all |
babsingh
approved these changes
May 10, 2023
babsingh
left a comment
Contributor
There was a problem hiding this comment.
LGTM. Thanks for fixing this issue.
Just saw your message on OMR slack; was on vacation earlier; otherwise, would have helped.
Contributor
Author
|
Thanks for reviewing! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This commit fixes a subtle bug in cgroup2 initialization, namely in
populateCgroupEntryListV2().Consider a system with only
memorycontrol group enabled. Then thecgroup.controllersfor the process's cgroup2 would contain stringmemoryfollowed by newline (\n). See Linux kernel source, filekernel/cgroup/cgroup.c, functioncgroup_print_ss_mask()1.The code that iterates over cgroups listed only considers space as a separator:
So the last (an in our example also the first) cgroup name (pointed to by
cursor) contains the\nas the end, therefore thestrcmpcomparison fails:(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.