linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Tetsuo Handa <penguin-kernel@i-love.sakura.ne.jp>
To: linux-mm <linux-mm@kvack.org>
Subject: memcg versus clone(CLONE_VM without CLONE_THREAD)
Date: Tue, 23 Oct 2018 22:05:12 +0900	[thread overview]
Message-ID: <4a36ab60-ab2b-eb54-f5a8-33f969f00e73@i-love.sakura.ne.jp> (raw)

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;
}
----------

             reply	other threads:[~2018-10-23 13:05 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-23 13:05 Tetsuo Handa [this message]
2018-10-23 16:55 ` Michal Hocko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4a36ab60-ab2b-eb54-f5a8-33f969f00e73@i-love.sakura.ne.jp \
    --to=penguin-kernel@i-love.sakura.ne.jp \
    --cc=linux-mm@kvack.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox