[systemd-devel] test program won't stop after hitting MemoryLimit
Jeremy_Fang at dell.com
Jeremy_Fang at dell.com
Thu Feb 18 07:05:45 UTC 2016
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 <stdio.h>
#include <stdlib.h>
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/systemd-devel/attachments/20160218/6ef5b1f6/attachment.html>
More information about the systemd-devel
mailing list