Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 390297 - sys-apps/openrc: CGroups support
Summary: sys-apps/openrc: CGroups support
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: New packages (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: OpenRC Team
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 387433
  Show dependency tree
 
Reported: 2011-11-12 20:32 UTC by Patrick Lauer
Modified: 2012-01-26 09:33 UTC (History)
1 user (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
CGroup patch (002-enable-cgroups.patch,1.11 KB, text/plain)
2011-11-12 20:35 UTC, Patrick Lauer
Details
CGroup Cleanup patch (003-cgroup-cleanup.patch,613 bytes, text/plain)
2011-11-12 20:36 UTC, Patrick Lauer
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Patrick Lauer gentoo-dev 2011-11-12 20:32:09 UTC
Since the cgroup directory is now automounted only this patch (or something equivalent) is needed to automatically create per-initscript CGroup directories


diff --git a/sh/runscript.sh.in b/sh/runscript.sh.in
index 5853212..0122e47 100644
--- a/sh/runscript.sh.in
+++ b/sh/runscript.sh.in
@@ -188,6 +188,16 @@ fi
 # Load any system overrides
 sourcex -e "@SYSCONFDIR@/rc.conf"
 
+# Attach to CGroup - dir existing is enough for us
+if [ -d /sys/fs/cgroup/ ]; then
+       # use the svcname unless overriden in conf.d
+       SVC_CGROUP=${CGROUP:-$RC_SVCNAME}
+       mkdir -p /sys/fs/cgroup/${SVC_CGROUP}
+       # now attach self to cgroup - any children of this process will inherit this
+       echo $$ > /sys/fs/cgroup/${SVC_CGROUP}/tasks
+       # TODO: set res limits from conf.d
+fi
+
 # Apply any ulimit defined
 [ -n "${rc_ulimit:-$RC_ULIMIT}" ] && ulimit ${rc_ulimit:-$RC_ULIMIT}
Comment 1 Patrick Lauer gentoo-dev 2011-11-12 20:35:19 UTC
Created attachment 292315 [details]
CGroup patch
Comment 2 Patrick Lauer gentoo-dev 2011-11-12 20:36:11 UTC
And then you want to clean up when the init script is stopped and the cgroup is empty:

diff --git a/sh/runscript.sh.in b/sh/runscript.sh.in
index 859cfa8..d1f5e95 100644
--- a/sh/runscript.sh.in
+++ b/sh/runscript.sh.in
@@ -280,3 +280,15 @@ while [ -n "$1" ]; do
        eerror "$RC_SVCNAME: unknown function \`$1'"
        exit 1
 done
+
+# CGroup cleanup
+if [ -d /sys/fs/cgroup/ ]; then
+        # use the svcname unless overriden in conf.d
+        SVC_CGROUP=${CGROUP:-$RC_SVCNAME}
+       # reattach ourself to root cgroup 
+       echo $$ > /sys/fs/cgroup//tasks
+       # remove cgroup if empty, will fail if any task attached
+        rmdir  /sys/fs/cgroup//${SVC_CGROUP} 2>/dev/null
+fi
+# need to exit cleanly
+exit 0
Comment 3 Patrick Lauer gentoo-dev 2011-11-12 20:36:35 UTC
Created attachment 292317 [details]
CGroup Cleanup patch
Comment 4 William Hubbs gentoo-dev 2011-11-17 22:39:12 UTC
This has been added in commit 20df56f.
Comment 5 Alon Bar-Lev 2011-11-27 17:15:03 UTC
Do you sure it is working?

the run-script.sh::start() function is overridden by most services, so the cgroup assignment never reached.

At my system only acpid which has no start() in its init.d script is assigned.

I think the run-script.sh:start() additions should go in its own function and be called directly by script main.

Or add a new callback *_pre_internal() and use it:
---
+                               if [ "$(command -v "$1_pre_internal")" = "$1_pre_internal" ]
+                               then
+                                       "$1"_pre_internal || exit $?
+                               fi
                                if [ "$(command -v "$1_pre")" = "$1_pre" ]
                                then
                                        "$1"_pre || exit $?
                                fi
                                "$1" || exit $?
---
Comment 6 Alon Bar-Lev 2011-11-28 10:37:09 UTC
Also, any reason for the change of /sys/fs/cgroup->/sys/fs/cgroup/openrc?
Comment 7 William Hubbs gentoo-dev 2011-11-29 14:59:41 UTC
(In reply to comment #5)
> Do you sure it is working?
> 
> the run-script.sh::start() function is overridden by most services, so the
> cgroup assignment never reached.

Most services should be rewritten to be compliant with openrc's stop/start functions  in runscript.sh. This is being tracked in bug #367793. To see how this should be done, see man runscript.

(In reply to comment #6)
> Also, any reason for the change of /sys/fs/cgroup->/sys/fs/cgroup/openrc?

The kernel documentation states that /sys/fs/cgroup is a tmpfs, then the cgroup file systems are mounted under that. See the examples in /usr/src/linux/Documentation/cgroups/cgroups.txt.
Comment 8 Alon Bar-Lev 2011-11-29 15:04:52 UTC
Thank for your response!

(In reply to comment #7)
> (In reply to comment #5)
> > Do you sure it is working?
> > 
> > the run-script.sh::start() function is overridden by most services, so the
> > cgroup assignment never reached.
> 
> Most services should be rewritten to be compliant with openrc's stop/start
> functions  in runscript.sh. This is being tracked in bug #367793. To see how
> this should be done, see man runscript.

I don't think user should be able to override this even if it implement the start(). If openrc decides that every server leaves in its own cgroup, it should be enforced.
Comment 9 William Hubbs gentoo-dev 2011-11-29 21:57:27 UTC
(In reply to comment #8)
> (In reply to comment #7)
> > (In reply to comment #5)
> > > Do you sure it is working?
> > > 
> > > the run-script.sh::start() function is overridden by most services, so the
> > > cgroup assignment never reached.
> > 
> > Most services should be rewritten to be compliant with openrc's stop/start
> > functions  in runscript.sh. This is being tracked in bug #367793. To see how
> > this should be done, see man runscript.
> 
> I don't think user should be able to override this even if it implement the
> start(). If openrc decides that every server leaves in its own cgroup, it
> should be enforced.

I do not understand what you mean.

Openrc creates a control group which will contain all of the daemons that openrc starts. If a sys admin wants to manipulate control groups, they can use the tools in dev-libs/libcgroup
Comment 10 Alon Bar-Lev 2011-11-29 22:06:43 UTC
(In reply to comment #9)
> I do not understand what you mean.
> 
> Openrc creates a control group which will contain all of the daemons that
> openrc starts. If a sys admin wants to manipulate control groups, they can use
> the tools in dev-libs/libcgroup

Do you say that a init.d script cannot have start() function?
As if it has, it will override runservice.sh start() function and the cgroup assignment will be skipped.
Comment 11 Alon Bar-Lev 2012-01-25 21:26:29 UTC
I see that this was removed [1]

Why?
Any alternative?

[1] http://git.overlays.gentoo.org/gitweb/?p=proj/openrc.git;a=commitdiff;h=ed4605bf9ff63effe0d09811a3e708d5e3a75378
Comment 12 William Hubbs gentoo-dev 2012-01-26 02:25:54 UTC
(In reply to comment #11)
> I see that this was removed [1]
> 
> Why?
> Any alternative?

Actually this is now back, in git, and should be supported in the latest stable (0.9.8.2). The issue at the time I removed it was that I had been unable to determine how to mount a cgroup with no subsystems attached to it.

The part I still need to add is automatically adding the services openrc starts to the openrc control group.
Comment 13 Alon Bar-Lev 2012-01-26 09:33:44 UTC
(In reply to comment #12)
> The part I still need to add is automatically adding the services openrc starts
> to the openrc control group.

This what I referring to.