Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1240525

Re: Can't we use timeout based OOM warning/killing?

From Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Newsgroups linux.kernel
Subject Re: Can't we use timeout based OOM warning/killing?
Date 2015-10-06 17:00 +0200
Message-ID <qgBSH-PD-19@gated-at.bofh.it> (permalink)
References <qcxDX-5PG-19@gated-at.bofh.it> <qcDT3-6vz-9@gated-at.bofh.it> <qdJjH-4wk-7@gated-at.bofh.it> <qf7N0-3r7-13@gated-at.bofh.it> <qfob7-1Mk-5@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


Tetsuo Handa wrote:
> Sorry. This was my misunderstanding. But I still think that we need to be
> prepared for cases where zapping OOM victim's mm approach fails.
> ( http://lkml.kernel.org/r/201509242050.EHE95837.FVFOOtMQHLJOFS@I-love.SAKURA.ne.jp )

I tested whether it is easy/difficult to make zapping OOM victim's mm
approach fail. The result seems that not difficult to make it fail.

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

static int reader(void *unused)
{
	char c;
	int fd = open("/proc/self/cmdline", O_RDONLY);
	while (pread(fd, &c, 1, 0) == 1);
	return 0;
}

static int writer(void *unused)
{
	const int fd = open("/proc/self/exe", O_RDONLY);
	static void *ptr[10000];
	int i;
	sleep(2);
	while (1) {
		for (i = 0; i < 10000; i++)
			ptr[i] = mmap(NULL, 4096, PROT_READ, MAP_PRIVATE, fd,
				      0);
		for (i = 0; i < 10000; i++)
			munmap(ptr[i], 4096);
	}
	return 0;
}

int main(int argc, char *argv[])
{
	int zero_fd = open("/dev/zero", O_RDONLY);
	char *buf = NULL;
	unsigned long size = 0;
	int i;
	for (size = 1048576; size < 512UL * (1 << 30); size <<= 1) {
		char *cp = realloc(buf, size);
		if (!cp) {
			size >>= 1;
			break;
		}
		buf = cp;
	}
	for (i = 0; i < 100; i++) {
		clone(reader, malloc(1024) + 1024, CLONE_THREAD | CLONE_SIGHAND | CLONE_VM,
		      NULL);
	}
	clone(writer, malloc(1024) + 1024, CLONE_THREAD | CLONE_SIGHAND | CLONE_VM, NULL);
	read(zero_fd, buf, size); /* Will cause OOM due to overcommit */
	return * (char *) NULL; /* Kill all threads. */
}
---------- Reproducer end ----------

(I wrote this program for trying to mimic a trouble that a customer's system
 hung up with a lot of ps processes blocked at reading /proc/pid/ entries
 due to unkillable down_read(&mm->mmap_sem) in __access_remote_vm(). Though
 I couldn't identify what function was holding the mmap_sem for writing...)

Uptime > 429 of http://I-love.SAKURA.ne.jp/tmp/serial-20151006.txt.xz showed
a OOM livelock that

  (1) thread group leader is blocked at down_read(&mm->mmap_sem) in exit_mm()
      called from do_exit().

  (2) writer thread is blocked at down_write(&mm->mmap_sem) in vm_mmap_pgoff()
      called from SyS_mmap_pgoff() called from SyS_mmap().

  (3) many reader threads are blocking the writer thread because of
      down_read(&mm->mmap_sem) called from proc_pid_cmdline_read().

  (4) while the thread group leader is blocked at down_read(&mm->mmap_sem),
      some of the reader threads are trying to allocate memory via page fault.

So, zapping the first OOM victim's mm might fail by chance.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Back to linux.kernel | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Re: Can't we use timeout based OOM warning/killing? Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp> - 2015-10-06 17:00 +0200
  Re: Can't we use timeout based OOM warning/killing? Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp> - 2015-10-12 08:50 +0200
    Silent hang up caused by pages being not scanned? Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp> - 2015-10-12 17:30 +0200
      Re: Silent hang up caused by pages being not scanned? Linus Torvalds <torvalds@linux-foundation.org> - 2015-10-12 23:30 +0200
        Re: Silent hang up caused by pages being not scanned? Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp> - 2015-10-13 14:30 +0200
          Re: Silent hang up caused by pages being not scanned? Linus Torvalds <torvalds@linux-foundation.org> - 2015-10-13 18:40 +0200
            Re: Silent hang up caused by pages being not scanned? Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp> - 2015-10-14 14:30 +0200
            Re: Silent hang up caused by pages being not scanned? Michal Hocko <mhocko@kernel.org> - 2015-10-15 15:20 +0200
              Re: Silent hang up caused by pages being not scanned? Michal Hocko <mhocko@kernel.org> - 2015-10-16 18:00 +0200
                Re: Silent hang up caused by pages being not scanned? Linus Torvalds <torvalds@linux-foundation.org> - 2015-10-16 20:40 +0200
                Re: Silent hang up caused by pages being not scanned? Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp> - 2015-10-16 20:50 +0200
      Re: Silent hang up caused by pages being not scanned? Michal Hocko <mhocko@kernel.org> - 2015-10-13 15:40 +0200
        Re: Silent hang up caused by pages being not scanned? Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp> - 2015-10-13 18:20 +0200
          Re: Silent hang up caused by pages being not scanned? Michal Hocko <mhocko@kernel.org> - 2015-10-14 15:30 +0200
            Re: Silent hang up caused by pages being not scanned? Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp> - 2015-10-14 16:40 +0200
              Re: Silent hang up caused by pages being not scanned? Michal Hocko <mhocko@kernel.org> - 2015-10-14 17:00 +0200
                Re: Silent hang up caused by pages being not scanned? Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp> - 2015-10-14 17:10 +0200

csiph-web