This patchset is the first of several to add a cgroup v1/v2
abstraction layer to libcgroup. It adds the underlying framework,
and a simple conversion - cpu.shares to cpu.weight and vice versa.
Adding additional conversions is straightforward. Support for
additional libcgroup tools is also planned.
Why an abstraction layer?
As enterprise systems slowly transition from cgroup v1 to cgroup
v2, higher-level applications (e.g. databases) are in a difficult
position. These applications have very long lifespans and may
run on a wide variety of systems (both in age and capability.)
Providing a library that can abstract away the cgroup v1/v2
differences will allow these applications to seamlessly work on
vastly disparate systems.
Key requirements of the abstraction layer:
* A user shall be able to specify either cgroup v1 or v2
settings/values as input parameters
* The abstraction layer shall translate these requested
settings/values into the proper "on-disk" cgroup version
* When data is returned to the user, it shall be returned in the
same version originally specified by the user
* If the version is unspecified, the abstraction layer may
translate the request or may not. This is an optional feature
and subject to change. It's possible that '-1' or '-2' will be
required in the future
Examples:
On a cgroup v2 system where cpu.weight is set to 200:
$ ./cgxget -2 -nr cpu.weight foo
cpu.weight: 200
$ ./src/tools/cgxget -1 -nr cpu.shares foo
cpu.shares: 2048
# As outlined above, failure to provide either -1 or -2
# is a best-effort behavior and is not guaranteed to
# succeed
$ ./cgxget -nr cpu.weight foo
cpu.weight: 200
$ ./cgxget -nr cpu.shares foo
variable file read failed No such file or directory
On a cgroup v1 system where cpu.shares is set to 512:
$ ./cgxget -1 -nr cpu.shares bar
cpu.shares: 512
$ ./cgxget -2 -nr cpu.weight bar
cpu.weight: 50
# As outlined above, failure to provide either -1 or -2
# is a best-effort behavior and is not guaranteed to
# succeed
$ ./cgxget -nr cpu.shares bar
cpu.shares: 512
$ ./cgxget -nr cpu.weight bar
variable file read failed No such file or directory
Why the name cgxget?
I'm open to suggestions here, but I like cgx(get|set|...) for
a few reasons:
* It's easy to tab complete and see the various cgroup abstraction
layer commands that are supported
* I considered cgget2, but I was afraid that it could be
misconstrued as a cgroup v2-only utility
What's next?
Much like the work to add cgroup v2 support, the abstraction
layer will be added in steps. I have created a github issue [1]
to track the progress. Comments, patches, and testing are always
welcome.
[1] https://github.com/libcgroup/libcgroup/issues/24
The changes to libcgroup are available here:
https://github.com/drakenclimber/libcgroup/tree/issues/cgxget4
The changes to the libcgroup tests are available here:
https://github.com/drakenclimber/libcgroup-tests/tree/issues/cgxget4
Overal code coverage increased 1.7% to 51.7%. Code coverage of
src/abstraction-common.c is at 75.8%:
https://coveralls.io/builds/41251128
Automated tests are passing and the results are here:
https://github.com/drakenclimber/libcgroup/runs/3030300300
Tom Hromatka (9):
wrapper.c: Store the version in struct cgroup_controller
api.c: Remove static from cgroup_copy_controller_values()
abstraction: Add cgroup_strtol()
abstraction: Add mapping tables
abstraction: Add integer conversion function
abstraction: Add function to convert from one cgroup version to
another
abstraction-map: Add cpu.shares <-> cpu.weight mapping
cgxget: Introduce cgxget
cgxset: Introduce cgxset
src/Makefile.am | 2 +-
src/abstraction-common.c | 213 +++++++++++++++++++++++++++++++++++++++
src/abstraction-common.h | 81 +++++++++++++++
src/abstraction-map.c | 44 ++++++++
src/abstraction-map.h | 52 ++++++++++
src/api.c | 10 +-
src/libcgroup-internal.h | 25 +++--
src/libcgroup.map | 4 +
src/tools/Makefile.am | 12 ++-
src/tools/cgconfig.c | 7 ++
src/tools/cgget.c | 115 +++++++++++++++++++--
src/tools/cgset.c | 47 +++++++++
src/wrapper.c | 11 +-
13 files changed, 595 insertions(+), 28 deletions(-)
create mode 100644 src/abstraction-common.c
create mode 100644 src/abstraction-common.h
create mode 100644 src/abstraction-map.c
create mode 100644 src/abstraction-map.h
--
2.25.1
_______________________________________________
Libcg-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/libcg-devel