Re: [systemd-devel] test program won't stop after hitting MemoryLimit

2016-02-23 Thread Lennart Poettering
On Thu, 18.02.16 07:05, jeremy_f...@dell.com (jeremy_f...@dell.com) wrote:

> Dell - Internal Use - Confidential

Really? You sent this to a public mailing list...

>  Hi All:
> 
> I am trying to test Resource Control of system by setting
> MemoryLimit on my Debian system. Unfortunately it won't work after
> my testing. Maybe I am not configuring right. Please let me know how
> to fix this.

Linux has an overcommiting memory manager. MemoryLimit= operates on
actual memory usage. With malloc() you only allocate address space
however. It basically just gives you an address range and the promise
that keep the memory around should you ever actually store something
in it. In your test program you never do that however, hence it will
never be backed by real memory.

Consider invoking memset() on the memory you allocate, so that it is
actually touched.


Lennart

-- 
Lennart Poettering, Red Hat
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/systemd-devel


[systemd-devel] test program won't stop after hitting MemoryLimit

2016-02-17 Thread Jeremy_Fang
Dell - Internal Use - Confidential
 Hi All:

I am trying to test Resource Control of system by setting MemoryLimit on my 
Debian system. Unfortunately it won't work after my testing. Maybe I am not 
configuring right. Please let me know how to fix this.

Here is info for your reference:

1)  uname  -a
Linux OS10 3.16.7-ckt11 #1 SMP Thu Feb 4 13:32:12 PST 2016 x86_64 GNU/Linux

2)  my test program: keeping allocate 2k memory as shown below:
#include 
#include 

main(int argc, char *argv[])
{
int  size = 0, times = 0;
char *buffer = NULL;

size  = 2000;
times = 1;
while (1) {
printf("size=%d, times=%d\n", size, times);
buffer = malloc(size);
if (buffer == NULL) {
printf("out of memory\n");
break;
}
else  {
 printf("buffer=%p\n", buffer);
}
times++;
sleep(3);
}
}

3)  /lib/systemd/system/limits.slice
[Unit]
Description=Limited resources Slice
DefaultDependencies=no
Before=slices.target

[Slice]
MemoryAccounting=true
MemoryLimit=20K

4)   /lib/system/system/test.service

[Unit]
Description=My Test Service.
DefaultDependencies=no

[Service]
Slice=limits.slice
ExecStart=/tmp/test
KillSignal=SIGKILL
SuccessExitStatus=SIGKILL
FailureAction=reboot-force

# Resource Limitations
LimitCORE=infinity

5)   systemctl daemon-reload
6)  systemctl   restart limits.slice
7)  systemctl  start  test.service

I would like to see test program will be ended after running for a while 
keeping allocating 2K memory with configured MemroyLimit as 20K.
But it seems test program is keep running for a long time and it won't be 
stopped.

Here is the output of systemctl status test.service

test.service - Test Service.
   Loaded: loaded (/lib/systemd/system/test.service; static)
   Active: active (running) since Thu 2016-02-18 06:40:49 UTC; 2min 5s ago
Main PID: 2429 (test)
   CGroup: /limits.slice/test.service
   2429 /tmp/test

Feb 18 06:40:49 OS10 systemd[1]: Started Test Service..

Where does it go wrong or am I missing anything ?
Please help !

Thanks,

Jeremy



___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/systemd-devel