msantos / alcove

Control plane for system processes

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

does it work with systemd?

benoitc opened this issue · comments

Can alcove work with systemd which take the lead on the cgroup folder?

No, unfortunately not yet. Getting cgroups to work with cgmanager and systemd is planned though, I just need to look at how the D-BUS protocol works.

ok. would be good tohqvec it. maybe it could be the base for a good
container or hestration at some point :)
On Thu 18 Jun 2015 at 16:21 Michael Santos notifications@github.com wrote:

No, unfortunately not yet. Getting cgroups to work with cgmanager and
systemd is planned though, I just need to look at how the D-BUS protocol
works.


Reply to this email directly or view it on GitHub
#1 (comment).

cgroups are still going through a lot of change and it seems the single PID writer restriction has been relaxed. Testing on Ubuntu 15.04, the cgroupfs is writeable again and works alongside systemd:

To create the cgroup:

-module(cgex).

-export([
        start/0,
        create/2,                                                                                                                                                                      task/3
    ]).                                                                                                                                                                        
start() ->
    alcove_drv:start_link([{exec, "sudo"}]).

create(Drv, Cgroup) ->
    case alcove_cgroup:supported(Drv) of                                                                                                                                               true ->
            ok = alcove_cgroup:create(Drv, [], Cgroup),                                                                                                                                    {ok,3} = alcove_cgroup:set(Drv, [], <<"memory">>, Cgroup,
                <<"memory.limit_in_bytes">>, <<"16m">>),
            ok;
        false ->
            {error,unsupported}
    end.

task(Drv, Cgroup, Pid) ->
    case alcove_cgroup:set(Drv, [], <<>>, Cgroup, <<"tasks">>, integer_to_list(Pid)) of
        {ok,_} -> ok;
        Err -> Err
    end.

For testing the cgroup:

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <err.h>

    int
main(int argc, char *argv[])
{
    int i = 0;
    size_t n = 1024 * 1024;

    for (i = 0; i < 128; i++) {
        char *p = NULL;
        (void)printf("%d\n", i);
        p = malloc(n);
        if (!p) err(EXIT_FAILURE, "malloc");
        (void)memset(p, 'x', n);
    }

    exit(0);
}

Running the test:

1> {ok,Drv} = cgex:start().
{ok,<0.147.0>}

% Cgroups are nested paths: [<<"path">>, <<"to">>, <<"cgroup">>]
2> Cgroup = [<<"memleak">>].
[<<"memleak">>] 

3> cgex:create(Drv, Cgroup).
ok

4> {ok, Pid} = alcove:fork(Drv, []).
{ok,4616}

5> cgex:task(Drv, Cgroup, Pid).
ok

6> alcove:execvp(Drv, [Pid], "/tmp/memleak", ["/tmp/memleak"]).
ok

7> flush().
Shell got {alcove_event,<0.147.0>,[4616],{termsig,sigkill}}
ok

And dmesg shows the OOM kill ran and killed the process:

[480844.041495] Task in /memleak killed as a result of limit of /memleak
[480844.041508] memory: usage 16384kB, limit 16384kB, failcnt 24
[480844.041509] memory+swap: usage 0kB, limit 9007199254740988kB, failcnt 0
[480844.041510] kmem: usage 0kB, limit 9007199254740988kB, failcnt 0
[480844.041511] Memory cgroup stats for /memleak: cache:0KB rss:16384KB rss_huge:0KB mapped_file:0KB writeback:0KB inactive_anon:0KB active_anon:16376KB inactive_file:0KB active_file:0KB unevictable:0KB
[480844.041525] [ pid ]   uid  tgid total_vm      rss nr_ptes swapents oom_score_adj name
[480844.041621] [ 4616]     0  4616     5168     4361      14        0             0 memleak
[480844.041625] Memory cgroup out of memory: Kill process 4616 (memleak) score 1036 or sacrifice child
[480844.041704] Killed process 4616 (memleak) total-vm:20672kB, anon-rss:16136kB, file-rss:1308kB

On other sytems, there's usually an executable to create the cgroup and put the task inside the cgroup which alcove can call using execvp.