From d41586a115aabf01a756f6ee6ef58a813f87b546 Mon Sep 17 00:00:00 2001 From: Thomas Goirand Date: Mon, 6 Jan 2025 16:38:53 +0100 Subject: [PATCH] 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 --- cinder/privsep/cgroup.py | 24 +++++++++++++++---- .../notes/cgroupsv2-75476a8e1ea88b5f.yaml | 5 ++++ 2 files changed, 25 insertions(+), 4 deletions(-) create mode 100644 releasenotes/notes/cgroupsv2-75476a8e1ea88b5f.yaml diff --git a/cinder/privsep/cgroup.py b/cinder/privsep/cgroup.py index 15d47e0cf69..dcc384acab5 100644 --- a/cinder/privsep/cgroup.py +++ b/cinder/privsep/cgroup.py @@ -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) diff --git a/releasenotes/notes/cgroupsv2-75476a8e1ea88b5f.yaml b/releasenotes/notes/cgroupsv2-75476a8e1ea88b5f.yaml new file mode 100644 index 00000000000..a0bb5c85601 --- /dev/null +++ b/releasenotes/notes/cgroupsv2-75476a8e1ea88b5f.yaml @@ -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.