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, e.g. cgxset, 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 may change in the future.  It's possible that '-1' or '-2'
  will be required

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

Issues:

* Github Actions doesn't provide a native cgroup v2 system.  This
  makes testing some of the conversions difficult.  At the moment
  I am using unit tests to augment coverage

The changes to libcgroup are available here:
https://github.com/drakenclimber/libcgroup/tree/issues/cgxget

The changes to the libcgroup tests are available here:
https://github.com/drakenclimber/libcgroup-tests/tree/issues/cgxget

Code coverage numbers are at 43.5%:
https://coveralls.io/builds/37485208

Automated test results are here:
https://github.com/drakenclimber/libcgroup/runs/1988981133

Tom Hromatka (9):
  github: Improve code coverage collection
  wrapper.c: Store the version in struct cgroup_controller
  api.c: Remove static from cgroup_copy_controller_values()
  abstraction: Add cgroup_strtol()
  abstraction: Add function to convert from one cgroup version to
    another
  abstraction: Add cpu controller framework
  abstraction-cpu: Add v1_shares_to_v2()
  abstraction-cpu: Add v2_weight_to_v1()
  cgxget: Introduce cgxget

 .github/actions/setup-libcgroup/action.yml   |   2 +
 .github/workflows/continuous-integration.yml |  36 +++-
 src/Makefile.am                              |   2 +-
 src/abstraction-common.c                     |  96 +++++++++
 src/abstraction-common.h                     |  87 ++++++++
 src/api.c                                    |  10 +-
 src/ctrl-cpu.c                               | 212 +++++++++++++++++++
 src/libcgroup-internal.h                     |  25 ++-
 src/libcgroup.map                            |   1 +
 src/tools/Makefile.am                        |   8 +-
 src/tools/cgget.c                            | 115 +++++++++-
 src/wrapper.c                                |  11 +-
 12 files changed, 571 insertions(+), 34 deletions(-)
 create mode 100644 src/abstraction-common.c
 create mode 100644 src/abstraction-common.h
 create mode 100644 src/ctrl-cpu.c

-- 
2.26.2



_______________________________________________
Libcg-devel mailing list
Libcg-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libcg-devel

Reply via email to