Skip to content

Updated check_config with cgroupv2 controllers#41897

Merged
thaJeztah merged 1 commit intomoby:masterfrom
gunadhya:f-Update_check_config
Jul 29, 2021
Merged

Updated check_config with cgroupv2 controllers#41897
thaJeztah merged 1 commit intomoby:masterfrom
gunadhya:f-Update_check_config

Conversation

@gunadhya
Copy link
Contributor

Fixes #41874

- What I did
Added cgroupv2 available controllers and check for CONFIG_CGROUP_BPF in contrib/check-config.sh
- How I did it

  1. Reading the /sys/fs/cgroup/cgroup.controllers file for available controllers
  2. Added a new CheckFlag for CONFIG_CGROUP_BPF to BPF_CGROUP_DEVICE support
    - How to verify it
    Output :
    Ran on Linux 5.4.0-62-generic
    image

- Description for the changelog

Update in contrib/check-config.sh cgroupv2 controllers and CONFIG_CGROUP_BPF

- A picture of a cute animal (not mandatory but encouraged)

@gunadhya gunadhya force-pushed the f-Update_check_config branch 2 times, most recently from d06f3f6 to 8ba4858 Compare January 19, 2021 14:12
@thaJeztah thaJeztah added area/contrib kind/enhancement Enhancements are not bugs or new features but can improve usability or performance. status/2-code-review labels Jan 19, 2021
@thaJeztah
Copy link
Member

Thanks!

@AkihiroSuda @tianon ptal 🤗

Comment on lines 160 to 177
Copy link
Member

Choose a reason for hiding this comment

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

This file (fairly consistently) uses camelCase for variables (and snake_case for functions). I think we should also consider it a failure case if we don't find the referenced file:

Suggested change
cgroupv2_controller_loc="/sys/fs/cgroup/cgroup.controllers"
# Prints available cgroupv2 controllers if the file exists
if test -f "$cgroupv2_controller_loc"; then
mapfile -t cgroupv2_controllers < $cgroupv2_controller_loc
wrap_good "- cgroupv2 controllers" "${cgroupv2_controllers[*]}"
else
echo "$cgroupv2_controller_loc not found."
fi
cgroupv2ControllersFile='/sys/fs/cgroup/cgroup.controllers'
if [ -s "$cgroupv2ControllersFile" ]; then
mapfile -t cgroupv2Controllers < "$cgroupv2ControllersFile"
wrap_good '- cgroupv2 controllers' "${cgroupv2Controllers[*]}"
else
wrap_warning "warning: missing '$cgroupv2ControllersFile'"
fi

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My bad, I'll update the variable names to camelCase and create the warning if the file doesn't exist.

Copy link
Member

Choose a reason for hiding this comment

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

we should confirm that the file contains the following controllers:

  • cpu
  • cpuset
  • memory
  • io
  • pids

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll update it to show if the file has cpu,cpuset,memory,io,pids enabled or missing similar to other checks.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

image
Is this better?

@AkihiroSuda
Copy link
Member

Can we also check existence of freezer?

@gunadhya
Copy link
Contributor Author

gunadhya commented Jan 20, 2021

Can we also check existence of freezer?

@AkihiroSuda
So a check for CONFIG_CGROUP_FREEZER flag already exists here

The doc mentions cgroup.freezer file https://www.kernel.org/doc/html/latest/admin-guide/cgroup-v2.html#core-interface-files.
And when I grep my kernel config is says yes
image

But I don't see the file

image
Do I have to enable this somehow?

@thaJeztah
Copy link
Member

@AkihiroSuda ptal #41897 (comment)

@AkihiroSuda
Copy link
Member

cgroup.freezer only exists in subgroup, not in the top group

@AkihiroSuda AkihiroSuda added the area/cgroup2 cgroup v2 label Jan 23, 2021
@gunadhya
Copy link
Contributor Author

I've made some changes and added a freezer check.
This is what the new output looks like.
image

Copy link
Member

@AkihiroSuda AkihiroSuda left a comment

Choose a reason for hiding this comment

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

Thanks, but could you squash commits

@gunadhya gunadhya force-pushed the f-Update_check_config branch from fb5643d to c155c9f Compare January 25, 2021 05:22
@gunadhya
Copy link
Contributor Author

Thanks, but could you squash commits

Done

@thaJeztah
Copy link
Member

Thanks for updating! @tianon ptal

Comment on lines 160 to 175
Copy link
Member

Choose a reason for hiding this comment

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

Sorry for the delay -- this needs a rebase, but I think we can also simplify this a bit (and make sure it's still POSIX compatible, per #42410, which the mapfile-based implementation is not) with something like the following:

Suggested change
cgroupv2ControllerFile="/sys/fs/cgroup/cgroup.controllers"
# Prints available cgroupv2 controllers if the file exists
if test -f "$cgroupv2ControllerFile"; then
mapfile -t cgroupv2Controllers < $cgroupv2ControllerFile
echo "- cgroupv2 controllers:"
controllersv2=($cgroupv2Controllers)
[[ " ${controllersv2[@]} " =~ " io " ]] && wrap_good " - IO" "available" || wrap_bad " - IO" "missing"
[[ " ${controllersv2[@]} " =~ " cpu " ]] && wrap_good " - CPU" "available" || wrap_bad " - CPU" "missing"
[[ " ${controllersv2[@]} " =~ " cpuset " ]] && wrap_good " - CPUSET" "available" || wrap_bad " - CPUSET" "missing"
[[ " ${controllersv2[@]} " =~ " pids " ]] && wrap_good " - PIDs" "available" || wrap_bad " - PIDs" "missing"
[[ " ${controllersv2[@]} " =~ " memory " ]] && wrap_good " - MEMORY" "available" || wrap_bad " - MEMORY" "missing"
else
echo wrap_warning "warning: missing '$cgroupv2ControllerFile'"
fi
#check if cgroup.freeze exists in subdir
[ -n "$(find /sys/fs/cgroup -type f -name "cgroup.freeze" 2> /dev/null)" ] && wrap_good '- cgroupv2 freezer' 'available' || wrap_bad '- cgroupv2 freezer' 'missing'
cgroupv2ControllerFile='/sys/fs/cgroup/cgroup.controllers'
if [ -f "$cgroupv2ControllerFile" ]; then
echo ' Controllers:'
for controller in cpu cpuset io memory pids; do
if grep -qE '(^| )'"$controller"'($| )' "$cgroupv2ControllerFile"; then
echo " - $(wrap_good "$controller" 'available')"
else
echo " - $(wrap_bad "$controller" 'missing')"
fi
done
else
wrap_bad "$cgroupv2ControllerFile" 'nonexistent??'
fi

I'm also not wild about the unbounded find /sys/fs/cgroup -- I think if we can't find a better way to check whether the cgroup freezer is available then we should probably just leave a TODO comment instead (or not worry about it -- can any of these actually be usefully disabled?). 😕 😞

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, That makes sense. I'll rebase and update the checks for controllers in POSIX. As for the freezer check I'm not sure if we can disable it. I'll have to read about it. I can try to find a better way to do the check or I'll update it with aTODO. Is that okay?

@thaJeztah
Copy link
Member

@gunadhya could you rebase, and have a look at @tianon's suggestion?

@gunadhya
Copy link
Contributor Author

gunadhya commented Jul 7, 2021

@thaJeztah @tianon Sorry for the late response. I'll get right on it.

@gunadhya gunadhya force-pushed the f-Update_check_config branch from c155c9f to a3e3d37 Compare July 8, 2021 15:43
@thaJeztah
Copy link
Member

@tianon PR was updated, PTAL (thanks @gunadhya!)

Copy link
Member

@tianon tianon left a comment

Choose a reason for hiding this comment

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

Just two really minor nits but otherwise this LGTM! Thank you! 🎉

(I'm happy to push these changes myself if you'd rather or if that'd be helpful for you. 👍)

Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
#TODO check if cgroup.freeze exists in subdir
# TODO find an efficient way to check if cgroup.freeze exists in subdir

Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
echo "$(wrap_good 'cgroup hierarchy' 'cgroupv2')"
wrap_good 'cgroup hierarchy' 'cgroupv2'

Signed-off-by: gunadhya <6939749+gunadhya@users.noreply.github.com>

Added cgroupv2 controller check

Modified comment
@gunadhya gunadhya force-pushed the f-Update_check_config branch from a3e3d37 to aff02db Compare July 9, 2021 03:55
@gunadhya
Copy link
Contributor Author

gunadhya commented Jul 9, 2021

@tianon I've updated the pr with new changes.

Copy link
Member

@tianon tianon left a comment

Choose a reason for hiding this comment

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

👍🥳

Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!!

perhaps we should create a tracking issue for the todo (in case someone wants to work on that)

@thaJeztah thaJeztah merged commit 39a9d03 into moby:master Jul 29, 2021
@thaJeztah thaJeztah added this to the 21.xx milestone Oct 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/cgroup2 cgroup v2 area/contrib kind/enhancement Enhancements are not bugs or new features but can improve usability or performance. status/4-merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

contrib/check-config.sh: verify available cgroup v2 controllers

4 participants