memcg versus clone(CLONE_VM without CLONE_THREAD)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I noticed that memcg OOM event does not trigger as expected when a thread
group ID assigned by clone(CLONE_VM without CLONE_THREAD) is specified.
A bit of surprise because what the "tasks" file says is not what the
limitation is applied to...

----------
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sched.h>
#include <unistd.h>

static int memory_eater(void *unused) {
	FILE *fp;
	const unsigned long size = 1048576 * 200;
	char *buf = malloc(size);
	mkdir("/sys/fs/cgroup/memory/test1", 0755);
	fp = fopen("/sys/fs/cgroup/memory/test1/memory.limit_in_bytes", "w");
	fprintf(fp, "%lu\n", size / 2);
	fclose(fp);
	fp = fopen("/sys/fs/cgroup/memory/test1/tasks", "w");
	fprintf(fp, "%u\n", getpid());
	fclose(fp);
	fp = fopen("/dev/zero", "r");
	fread(buf, 1, size, fp);
	fclose(fp);
	return 0;
}

int main(int argc, char *argv[])
{
	if (clone(memory_eater, malloc(8192) + 8192,
		  /*CLONE_SIGHAND | CLONE_THREAD | */CLONE_VM, NULL) == -1)
		return 1;
	while (1)
		pause();
	return 0;
}
----------




[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Bugtraq]     [Linux OMAP]     [Linux MIPS]     [eCos]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux