[Devel] Re: No limitation in physical memory in cgroups

KAMEZAWA Hiroyuki kamezawa.hiroyu at jp.fujitsu.com
Thu May 21 00:15:56 PDT 2009


On Thu, 21 May 2009 14:47:17 +0800
anqin <anqin.qin at gmail.com> wrote:

> > I wonder....
> >
> > max_usage_in_bytes is not _reseted_ when you specified limit.
> > Then, please set limit before attaching task.
> >
> > Sane sequence is.
> > 1. mount
> > 2. mkdir
> > 3. set limit
> > 4. attach.
> >
> >
> 
> I have tried again the experiment based on the above rules,
> but I get the same result.
> 
> Again, my operations are as follows: (I have prepared three shell, #1,
> #2 and #3)
> 
> a) In shell #1, prepare a bash :
> 
> # bash
> # echo $$
> 11026
> 
> b) In shell #2, prepare the memory control via cgroupfs:
> 
> # mount -t cgroup cgroup /mnt/mycgrp2
> # cd /mn/mycgrp2
> # mkdir mycontainer2
> # cd mycontainer2
> # echo 0 > cpuset.mems
> # echo 0-1 > cpuset.cpus
> # echo 350000 > memory.limit_in_bytes
> 
> # cat memory.usage_in_bytes
> 0
> # cat memory.max_usage_in_bytes
> 0
> # cat memory.limit_in_bytes
> 352256
> 
> # echo 11026 > tasks
> # cat tasks
> 11026
> 
> 
> c) In Shell #1, run a memory consumer (in which, malloc() is called
> to allocate memory and not free until program is existed) to allocate
> 500M memory:
> 
> 
> # ./memconsume  500
> Begin allocate block ... OK
> allocate No.2 block ... OK
> ...
> 
> d) In Shell #3, run the top and see the memory consumption of memconsume:
> 
> # ps -ef | grep memconsume
> root     11667 11647  0 00:40 pts/0    00:00:00 ./memconsume 500
> root     11671 10536  0 00:56 pts/2    00:00:00 grep memconsume
> # top -p 11667
> 
> e) In Sehll #2, I cat the usage_in_bytes to see the ascending
> change of memory:
> 
> # cat memory.usage_in_bytes
> 143360
> # cat memory.usage_in_bytes
> 159744
> # cat memory.usage_in_bytes
> 233472
> ...
> # cat memory.usage_in_bytes   //<--  hit the max limited value
> 352256
> # cat memory.usage_in_bytes
> 258048
> # cat memory.usage_in_bytes
> 282624
> ...
> # cat memory.usage_in_bytes   // <--  hit the max limited value
> 348160
> # cat memory.usage_in_bytes
> 122880
> ...
> 
Ok, them, usage_in_bytes doesn't exceed limit. As expected.



> On the other hand, the top shown in Shell #3 that the virtual
> memory is growing up to 450M, but RES is fluctuating between
> 615 and 497 and the %MEM always shows 0.2  and 0.3 in the whole
> experiment.
> 
Ok.

> Does the phenomena conform with the behaviors of memroy cgroups?
> Currently, the memory cgroups can not kill the processes or limit
> their further allocation of memory when the processes call for more
> memory, right?
> 
right. memcg doesn't prevent malloc or mmap. but controls usage of "physical"
memory.

> Maybe, something wrong in my test codes. The following is the
> code of memconsume.c
> 




> ------------------------  memconsume.c ----------------------------
> 
> #include <stdio.h>
> #include <stdlib.h>
> #include <unistd.h>
> 
> int main(int argc, char *argv[])
> {
> 	int i, t_total;
> 	char *p = NULL;
> 
> 	if (argc != 2) {
> 		printf("Usage: %s  number (block = 1M) \n", argv[0]);
> 		return -1;
> 	}
> 
> 	i = t_total = 0;
> 
> 	t_total = atoi(argv[1]);
> 	if (t_total == 0) {
> 		printf("Usage: %s number (kb) \n", argv[0]);
> 		printf("\t- number is integer (kb)\n");
> 		return -1;
> 	}
> 
> 	printf("Begin allocate memory ...");
> 
> 	while (1) {
> 		p = NULL;
> 		p = (char *) malloc(1024 * 1024);
> 		if (p) {
> 			printf("OK\n");
> 			i++;
> 			if (i >= t_total)
> 				break;
> 		} else
> 			printf("fail\n");
> 		sleep(1);
> 		printf("allocate No.%d block ...", i + 1);
> 	}

You need to call memset() or some to use "physical" memory by page fault.
malloc just allocates virtual address. (and this program will start to use
swap.)


BTW, Try
# echo 300M > .../memory.memsw.limit_in_bytes 
If you config CGROUP_MEM_RES_CTRL_SWAP. You can limit mem+swap usage.

Thanks,
-Kame

> 
> 
> 	printf("End the consumption, total memory = %d * 1024 * 1024 bytes\n",  i);
> 	return 0;
> }
> 
> 
> ------------------------------------------------------------------------------
> 
> Thanks again,
> 
> Anqin
> 

_______________________________________________
Containers mailing list
Containers at lists.linux-foundation.org
https://lists.linux-foundation.org/mailman/listinfo/containers




More information about the Devel mailing list