[PATCH 03 of 16] prevent oom deadlocks during read/write operations

Andrea Arcangeli
2007-06-08T20:06:36Z

# HG changeset patch
# User Andrea Arcangeli <andrea@suse.de>
# Date 1181332960 -7200
# Node ID 532a5f712848ee75d827bfe233b9364a709e1fc1
# Parent d64cb81222748354bf5b16258197217465f35aeb
prevent oom deadlocks during read/write operations

We need to react to SIGKILL during read/write with huge buffers or it
becomes too easy to prevent a SIGKILLED task to run do_exit promptly
after it has been selected for oom-killage.

Signed-off-by: Andrea Arcangeli <andrea@suse.de>

diff --git a/mm/filemap.c b/mm/filemap.c
--- a/mm/filemap.c
+++ b/mm/filemap.c
@@ -894,6 +894,13 @@ void do_generic_mapping_read(struct addr
struct page *page;
unsigned long nr, ret;

+ if (unlikely(sigismember(&current->pending.signal, SIGKILL)))
+ /*
+ * Must not hang almost forever in D state in presence of sigkill
+ * and lots of ram/swap (think during OOM).
+ */
+ break;
+
/* nr is the maximum number of bytes to copy from this page */
nr = PAGE_CACHE_SIZE;
if (index >= end_index) {
@@ -2105,6 +2112,13 @@ generic_file_buffered_write(struct kiocb
unsigned long index;
unsigned long offset;
size_t copied;
+
+ if (unlikely(sigismember(&current->pending.signal, SIGKILL)))
+ /*
+ * Must not hang almost forever in D state in presence of sigkill
+ * and lots of ram/swap (think during OOM).
+ */
+ break;

offset = (pos & (PAGE_CACHE_SIZE -1)); /* Within page */
index = pos >> PAGE_CACHE_SHIFT;