<font size=2 face="sans-serif">Hi Rami,</font>
<br>
<br><font size=2 face="sans-serif">I have looked at the example code in
your slides and wrote something similar to handle the OoM condition and
it seems to work fine. Thank you for that.</font>
<br>
<br><font size=2 face="sans-serif">Since it would be even better for me
to avoid playing with OoM, I explored another option for monitoring memory
usage: keeping the OoM killer enabled and using the "memory threshold"
feature (see below) to get notified when a group's memory usage exceeds
the limit.</font>
<br>
<br><font size=2 face="sans-serif">First, my C code for monitoring the
memory usage looked like this (running as a separate process): </font>
<br>
<br><font size=2 face="sans-serif">// Assuming that initial memory usage
is below the threshold </font>
<br><font size=2 face="sans-serif"> while(1)</font>
<br><font size=2 face="sans-serif"> {</font>
<br><font size=2 face="sans-serif"> if (read(efd, &counter,
sizeof(uint64_t)) != sizeof(uint64_t)) die("read eventfd");</font>
<br><font size=2 face="sans-serif"> printf("Event
received: memory usage ABOVE limit\n");</font>
<br><font size=2 face="sans-serif"> if (read(efd, &counter,
sizeof(uint64_t)) != sizeof(uint64_t)) die("read eventfd");</font>
<br><font size=2 face="sans-serif"> printf("Event
received: memory usage BELOW limit\n");</font>
<br><font size=2 face="sans-serif"> }</font>
<br><font size=2 face="sans-serif"> </font>
<br><font size=2 face="sans-serif">Then I thought: what happens if mem
usage crosses the threshold more than once between 2 consecutive calls
to read() ? (a scenario that cannot be formally excluded).</font>
<br><font size=2 face="sans-serif">I realised that in this situation the
"counter" value returned by read() would contain the number of
occurrences crossing events. </font>
<br><font size=2 face="sans-serif">So for example if, between 2 calls to
read(), the memory usage goes beyond then below the threshold, the value
of "counter" after the 2nd read will be 2.</font>
<br>
<br><font size=2 face="sans-serif">I ended up using this counter behaviour
to determine if the current usage is below or beyond the limit:</font>
<br>
<br><font size=2 face="sans-serif">counter = 0;</font>
<br><font size=2 face="sans-serif">above_mem_limit = 0;</font>
<br>
<br><font size=2 face="sans-serif">while(1)</font>
<br><font size=2 face="sans-serif"> {</font>
<br><font size=2 face="sans-serif"> if (read(efd, &counter,
sizeof(uint64_t)) != sizeof(uint64_t)) die("read eventfd");</font>
<br><font size=2 face="sans-serif"> if(counter%2) above_mem_limit
= !above_mem_limit;</font>
<br><font size=2 face="sans-serif"> printf("Event received!
(counter=%d), above_mem_limit=%d\n", counter, above_mem_limit);</font>
<br><font size=2 face="sans-serif"> }</font>
<br>
<br><font size=2 face="sans-serif">My question: I have never seen this
"event counter" behaviour documented anywhere. The cgroups docs
and forums do not say anything about the 64bit value returned by the read()
call. Do you think one can safely rely on this to count the number
of crossing events ?</font>
<br>
<br><font size=2 face="sans-serif">Thanks and Regards,</font>
<br><font size=2 face="sans-serif">Hedi</font>
<br>
<br><font size=2 face="sans-serif">----</font>
<br>
<br><font size=2 face="sans-serif">From </font><a href=https://www.kernel.org/doc/Documentation/cgroups/memory.txt:><font size=2 face="sans-serif">https://www.kernel.org/doc/Documentation/cgroups/memory.txt:</font></a>
<br>
<br><tt><font size=3>9. Memory thresholds<br>
<br>
Memory cgroup implements memory thresholds using the cgroups notification<br>
API (see cgroups.txt). It allows to register multiple memory and memsw<br>
thresholds and gets notifications when it crosses.<br>
<br>
To register a threshold, an application must:<br>
- create an eventfd using eventfd(2);<br>
- open memory.usage_in_bytes or memory.memsw.usage_in_bytes;<br>
- write string like "<event_fd> <fd of memory.usage_in_bytes>
<threshold>" to<br>
cgroup.event_control.<br>
<br>
Application will be notified through eventfd when memory usage crosses<br>
threshold in any direction.<br>
<br>
It's applicable for root and non-root cgroup.<br>
</font></tt>
<br><font size=2 face="sans-serif">----</font>
<br><font size=2 face="sans-serif">Best Regard,</font>
<br><font size=2 face="sans-serif">Hedi</font>
<br>
<br>
<br>
<br><font size=1 color=#5f5f5f face="sans-serif">From:
</font><font size=1 face="sans-serif">Hedi Boufaied/NCE/AMADEUS</font>
<br><font size=1 color=#5f5f5f face="sans-serif">To:
</font><font size=1 face="sans-serif">Rami Rosen <roszenrami@gmail.com>@AMAEXTMAIL_MUC,
</font>
<br><font size=1 color=#5f5f5f face="sans-serif">Cc:
</font><font size=1 face="sans-serif">kernelnewbies <kernelnewbies@kernelnewbies.org></font>
<br><font size=1 color=#5f5f5f face="sans-serif">Date:
</font><font size=1 face="sans-serif">22/04/2014 13:12</font>
<br><font size=1 color=#5f5f5f face="sans-serif">Subject:
</font><font size=1 face="sans-serif">Re: cgroups:
cannot write on file memory.oom_control</font>
<br>
<hr noshade>
<br>
<br><font size=2 face="sans-serif">Hi Rami,</font>
<br>
<br><font size=2 face="sans-serif">Thank you for the advice. Yes, I will
try using the event handler.</font>
<br>
<br><font size=2 face="sans-serif">Best Regards,</font>
<br><font size=2 face="sans-serif">Hedi</font>
<br>
<br>
<br>
<br>
<br><font size=1 color=#5f5f5f face="sans-serif">From:
</font><font size=1 face="sans-serif">Rami Rosen <roszenrami@gmail.com></font>
<br><font size=1 color=#5f5f5f face="sans-serif">To:
</font><font size=1 face="sans-serif">Hedi Boufaied <hedi.boufaied@amadeus.com>,
</font>
<br><font size=1 color=#5f5f5f face="sans-serif">Cc:
</font><font size=1 face="sans-serif">kernelnewbies <kernelnewbies@kernelnewbies.org></font>
<br><font size=1 color=#5f5f5f face="sans-serif">Date:
</font><font size=1 face="sans-serif">18/04/2014 22:38</font>
<br><font size=1 color=#5f5f5f face="sans-serif">Subject:
</font><font size=1 face="sans-serif">Re: cgroups:
cannot write on file memory.oom_control</font>
<br><font size=1 color=#5f5f5f face="sans-serif">Sent by:
</font><font size=1 face="sans-serif">kernelnewbies-bounces@kernelnewbies.org</font>
<br>
<hr noshade>
<br>
<br>
<br><font size=3>Hi Hedi,<br>
Well, you can use disabling oom in conjunction with event handler.
Thus, you can free memory by changing memory setting of other cgroups when
an oom occurs in a specific cgroup, and avoid having an oops in that cgroup.<br>
You can see an example of using event handler in conjunction with disabling
the oom killer in <br>
"Namespaces and cgroups in linux", in slides 101/102, see:</font><font size=3 color=blue><u><br>
</u></font><a href=http://ramirose.wix.com/ramirosen><font size=3 color=blue><u>http://ramirose.wix.com/ramirosen</u></font></a>
<p><font size=3>A shameless plug - I wrote this presentation of 121 slides
about namespaces and cgroups.</font>
<p><font size=3>Regards,<br>
Rami Rosen</font>
<p><font size=3>בתאריך 17 באפר 2014 11:24, "Hedi Boufaied"
<</font><a href=mailto:hedi.boufaied@amadeus.com><font size=3 color=blue><u>hedi.boufaied@amadeus.com</u></font></a><font size=3>>
כתב:</font>
<br><font size=3 face="sans-serif">Hi Rami,</font><font size=3> <br>
</font><font size=3 face="sans-serif"><br>
Thanks a lot for your sequence. I followed it and it does work.</font><font size=3>
</font><font size=3 face="sans-serif"><br>
I now see my process paused in sleep state instead of getting killed when
the cgroup reaches OoO.</font><font size=3> <br>
</font><font size=3 face="sans-serif"><br>
This being said:</font><font size=3> </font><font size=3 face="sans-serif"><br>
* I do not really understand why the use_hierarchy option needs to be disabled
in order to allow disabling of the oom killer...</font><font size=3> </font><font size=3 face="sans-serif"><br>
* I'm not sure that disabling the OoO killer is safe/reliable enough: in
some of the trials I made, I saw other processes (xterms) not part of the
OoO cgroup getting completely stuck and I had to reboot my machine...</font><font size=3>
<br>
</font><font size=3 face="sans-serif"><br>
Best Regards,</font><font size=3> </font><font size=3 face="sans-serif"><br>
Hedi</font><font size=3> <br>
<br>
<br>
</font><font size=1 color=#5f5f5f face="sans-serif"><br>
From: </font><font size=1 face="sans-serif">Rami
Rosen <</font><a href=mailto:roszenrami@gmail.com target=_blank><font size=1 color=blue face="sans-serif"><u>roszenrami@gmail.com</u></font></a><font size=1 face="sans-serif">></font><font size=3>
</font><font size=1 color=#5f5f5f face="sans-serif"><br>
To: </font><font size=1 face="sans-serif">Hedi
Boufaied <</font><a href=mailto:hedi.boufaied@amadeus.com target=_blank><font size=1 color=blue face="sans-serif"><u>hedi.boufaied@amadeus.com</u></font></a><font size=1 face="sans-serif">>,
</font><font size=1 color=#5f5f5f face="sans-serif"><br>
Cc: </font><font size=1 face="sans-serif">kernelnewbies
<</font><a href=mailto:kernelnewbies@kernelnewbies.org target=_blank><font size=1 color=blue face="sans-serif"><u>kernelnewbies@kernelnewbies.org</u></font></a><font size=1 face="sans-serif">></font><font size=3>
</font><font size=1 color=#5f5f5f face="sans-serif"><br>
Date: </font><font size=1 face="sans-serif">15/04/2014
15:39</font><font size=3> </font><font size=1 color=#5f5f5f face="sans-serif"><br>
Subject: </font><font size=1 face="sans-serif">Re:
cgroups: cannot write on file memory.oom_control</font><font size=3> <br>
</font>
<hr noshade><font size=3><br>
<br>
</font><tt><font size=3><br>
Hi, Hedi,<br>
<br>
This sequence works for me:<br>
<br>
echo 0 > /sys/fs/cgroup/memory/memory.use_hierarchy<br>
<br>
mkdir /sys/fs/cgroup/memory/0<br>
<br>
Then, the following two commands changes the value of oom_kill_disable:<br>
<br>
echo 1 > /sys/fs/cgroup/memory/0/memory.oom_control<br>
<br>
echo 0 > /sys/fs/cgroup/memory/0/memory.oom_control<br>
<br>
<br>
For more info, please look for the text about enabling/disabling<br>
use_hierarchy in section 6,</font></tt><font size=3 color=blue><u><br>
</u></font><a href="http://lxr.free-electrons.com/source/Documentation/cgroups/memory.txt" target=_blank><tt><font size=3 color=blue><u>http://lxr.free-electrons.com/source/Documentation/cgroups/memory.txt</u></font></tt></a><tt><font size=3>.<br>
<br>
Regards,<br>
Rami Rosen</font></tt><font size=3 color=blue><u><br>
</u></font><a href=http://ramirose.wix.com/ramirosen target=_blank><tt><font size=3 color=blue><u>http://ramirose.wix.com/ramirosen</u></font></tt></a><tt><font size=3><br>
<br>
<br>
<br>
On Mon, Apr 14, 2014 at 12:22 PM, Hedi Boufaied<br>
<</font></tt><a href=mailto:hedi.boufaied@amadeus.com target=_blank><tt><font size=3 color=blue><u>hedi.boufaied@amadeus.com</u></font></tt></a><tt><font size=3>>
wrote:<br>
> Hi everyone,<br>
><br>
> I am working with cgroups on OpenSuse (over VirtualBox) and I cannot
disable<br>
> the OOM killer by writing to the file memory.oom_control:<br>
><br>
>> echo 1 > memory.oom_control<br>
>> -bash: echo: write error: Invalid argument<br>
><br>
> I can change the memory limit and several other settings by writing
to the<br>
> appropriate files (like memory.limit_in_bytes) but I could never write
to<br>
> file memory.oom_control although I am root.<br>
><br>
> I saw someone posted a similar issue a few days ago but there was
no<br>
> reply...<br>
><br>
> I have copied below the sequence of command I am using. Any idea what
could<br>
> be the issue ?<br>
><br>
> Thanks in advance for your help!<br>
><br>
> Hedi<br>
><br>
><br>
> ----<br>
><br>
> /sys/fs> su - root<br>
><br>
> /sys/fs> cd cgroup<br>
><br>
> /sys/fs/cgroup> cgcreate -g memory:/mygroup<br>
><br>
> /sys/fs/cgroup> cd memory/mygroup<br>
><br>
> /sys/fs/cgroup/memory/mygroup> echo 32M > memory.limit_in_bytes<br>
><br>
> /sys/fs/cgroup/memory/mygroup> cat memory.limit_in_bytes<br>
> 33554432<br>
><br>
> /sys/fs/cgroup/memory/mygroup> echo 1 > memory.oom_control<br>
> -bash: echo: write error: Invalid argument<br>
><br>
> /sys/fs/cgroup/memory/mygroup> cat memory.oom_control<br>
> oom_kill_disable 0<br>
> under_oom 0<br>
><br>
> ---<br>
> _______________________________________________<br>
> Kernelnewbies mailing list<br>
> </font></tt><a href=mailto:Kernelnewbies@kernelnewbies.org target=_blank><tt><font size=3 color=blue><u>Kernelnewbies@kernelnewbies.org</u></font></tt></a><tt><font size=3><br>
> </font></tt><a href=http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies target=_blank><tt><font size=3 color=blue><u>http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies</u></font></tt></a><tt><font size=3><br>
></font></tt><font size=3><br>
</font><tt><font size=2>_______________________________________________<br>
Kernelnewbies mailing list<br>
Kernelnewbies@kernelnewbies.org<br>
</font></tt><a href=http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies><tt><font size=2>http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies</font></tt></a><tt><font size=2><br>
</font></tt>
<br>