Skip to main content
Topic: cgroupv2 (Read 4611 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Re: cgroupv2

Reply #15
It's simpler in practice than reading about it (although I am using v1 cgroups, I think v2 just has a bit different layout or something) - look in /sys/fs/cgroups, there are directories with files that set limits, and files that can contain the pid number of processes. Subdirs are limited by the parent limits plus the limits defined in their own files. The manager programs change the values in the files and create the directories (you can even do this manually if you know what to do.) So if you configure a manager to set up a 50% CPU directory and put a process in it then it uses 50% of one core until you take it out again. You can limit other resources likewise.

Re: cgroupv2

Reply #16
I use libcgroup-openrc-git. It's a fully working package but I didn't know what I could do with it other than use it myself, as it's an openrc Artix package so might not be suitable for the AUR, especially as I don't have a straight Arch install to test it with, and Artix package guidelines say no git packages.
The patch came from their mailing list, they were very helpful. AFAIK (which may not be that far :D ) it's the best most full featured cgroup manager, and it's not had a release for a few years as cgroup management functionality has been added to systemd leaving other methods as a low priority I suppose. But a lot of useful commits have been added since the last release, so the git version should be better.
Had you also noticed ionice has been broken due to kernel changes? This also breaks btrfs scrub niceness. The recommendation is to use cgroups instead.
Here's the PKGBUILD and associated files (it provides / conflicts with the  libcgroup AUR pkg so it won't cause a problem if you had that installed before):
Code: [Select]
$ cat PKGBUILD 
pkgname=libcgroup-openrc-git
pkgver=r920.62f7665
pkgrel=1
pkgdesc='Library that abstracts the control group file system in Linux, configured for OpenRC, GIT version.'
arch=('i686' 'x86_64')
url='http://libcg.sourceforge.net'
license=(LGPL)
makedepends=('git')
provides=('libcgroup')
conflicts=('libcgroup')
backup=('etc/cgconfig.conf'
        'etc/cgrules.conf'
'etc/cgsnapshot_blacklist.conf')
options=('!libtool')
install=libcgroup.install
source=("git://git.code.sf.net/p/libcg/libcg" "fix-segfault.patch" "libcgroup")
md5sums=('SKIP' 'SKIP' 'SKIP')

pkgver() {
        cd "$srcdir/libcg"
        printf "r%s.%s" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)"
}

prepare() {
    cd ${srcdir}/libcg
    patch --forward --strip=1 --input="${srcdir}/fix-segfault.patch"
#patch --forward --strip=1 --input="fix-segfault.patch"
}

build() {
cd "${srcdir}/libcg"
autoreconf -i
./configure \
--prefix=/usr \
--sysconfdir=/etc \
--localstatedir=/var \
--sbindir=/usr/bin \
--enable-opaque-hierarchy=name=openrc
make
}

package() {
cd "${srcdir}/libcg"
make DESTDIR="${pkgdir}" pkgconfigdir="/usr/lib/pkgconfig" install
install -D -m0644 samples/cgconfig.conf "${pkgdir}/etc/cgconfig.conf"
install -D -m0644 samples/cgrules.conf "${pkgdir}/etc/cgrules.conf"
install -D -m0644 samples/cgsnapshot_blacklist.conf "${pkgdir}/etc/cgsnapshot_blacklist.conf"
        install -D -m0755 ${srcdir}/libcgroup "${pkgdir}/etc/init.d/libcgroup"
install -d -m0755 $pkgdir/etc/cgconfig.d
rm -f ${pkgdir}/usr/lib/security/pam_cgroup.{la,so,so.0}
mv ${pkgdir}/usr/lib/security/pam_cgroup.so.0.0.0 ${pkgdir}/usr/lib/security/pam_cgroup.so
rm -rf ${pkgdir}/etc/rc.d
# Make cgexec setgid cgred
chown root:160 ${pkgdir}/usr/bin/cgexec
chmod 2755 ${pkgdir}/usr/bin/cgexec
#mkdir -p $pkgdir/etc/cgconfig.d
}

$ cat fix-segfault.patch
diff --git a/src/parse.y b/src/parse.y
index 98f7699..e67ad54 100644
--- a/src/parse.y
+++ b/src/parse.y
@@ -45,9 +45,9 @@ int yywrap(void)
        int val;
        struct cgroup_dictionary *values;
 }
-%type <name> ID DEFAULT
+%type <name> ID DEFAULT group_name
 %type <val> mountvalue_conf mount task_namevalue_conf admin_namevalue_conf
-%type <val> admin_conf task_conf task_or_admin group_conf group start group_name
+%type <val> admin_conf task_conf task_or_admin group_conf group start
 %type <val> namespace namespace_conf default default_conf
 %type <values> namevalue_conf
 %type <val> template template_conf

$ cat libcgroup
#!/usr/bin/openrc-run

name="libcgroup"
description="libcgroup daemon - cgrulesengd"
command="/usr/bin/cgrulesengd"
command_args="-s -g cgred"

start_pre() {
                /usr/bin/cgconfigparser -l /etc/cgconfig.conf -s 1664
            }

stop_post() {
                /usr/bin/cgclear -l /etc/cgconfig.conf -e
            }

$ cat libcgroup.install
post_install() {
  getent group cgred &>/dev/null || groupadd -r -g 160 cgred >/dev/null
}

post_upgrade() {
  post_install
}

post_remove() {
  getent group cgred &>/dev/null && groupdel cgred >/dev/null
}


Hi! maybe offtopic but: where i can find the source?

duh now I see. You override https://aur.archlinux.org/cgit/aur.git/tree/PKGBUILD?h=libcgroup right?