Implements cgroupsv2

Currently, Cinder only does cgroups v1. Let's use the cgroups
v2 command line, when it's available in /sys. This avoids
having to boot with compatibility kernel command line options:

systemd.unified_cgroup_hierarchy=false
systemd.legacy_systemd_cgroup_controller=false

and just work as expected, provided cgroup-tools >= 2.0.0 is
installed in the system.

Change-Id: Ifdfcd480b72727ec182d5a6954c706f365247edc
This commit is contained in:
Thomas Goirand 2025-01-06 16:38:53 +01:00
parent 962fe29e77
commit d41586a115
2 changed files with 25 additions and 4 deletions

View File

@ -18,6 +18,8 @@
Helpers for cgroup related routines.
"""
import os.path
from oslo_concurrency import processutils
import cinder.privsep
@ -25,11 +27,25 @@ import cinder.privsep
@cinder.privsep.sys_admin_pctxt.entrypoint
def cgroup_create(name):
processutils.execute('cgcreate', '-g', 'blkio:%s' % name)
# If this path exists, it means we have support for cgroups v2
if os.path.isfile('/sys/fs/cgroup/cgroup.controllers'):
# cgroups v2 doesn't support io, but blkio instead.
processutils.execute('cgcreate', '-g', 'io:%s' % name)
else:
processutils.execute('cgcreate', '-g', 'blkio:%s' % name)
@cinder.privsep.sys_admin_pctxt.entrypoint
def cgroup_limit(name, rw, dev, bps):
processutils.execute('cgset', '-r',
'blkio.throttle.%s_bps_device=%s %d' % (rw, dev, bps),
name)
if os.path.isfile('/sys/fs/cgroup/cgroup.controllers'):
if rw == 'read':
cgset_arg = 'rbps'
else:
cgset_arg = 'wbps'
processutils.execute('cgset', '-r',
'io.max=%s %s=%s' % (dev, cgset_arg, bps), name)
else:
processutils.execute('cgset', '-r',
'blkio.throttle.%s_bps_device=%s %d' % (rw, dev,
bps),
name)

View File

@ -0,0 +1,5 @@
---
features:
- |
Cinder now supports setting-up cgroups with the cgroups v2 API, which is
used when doing migration of block device with the LVM backend.