summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Rientjes <rientjes@google.com>2014-12-12 16:56:16 -0800
committerJiri Slaby <jslaby@suse.cz>2016-04-21 13:11:52 +0200
commitef2276fc46e695b72d0640dd9e154d3e244dc85b (patch)
treeb09b419b9f5572dcb2fa27add12b42b966217a41
parentf0592d355da50713a25c943a08142363237f1a41 (diff)
downloadlwn-ef2276fc46e695b72d0640dd9e154d3e244dc85b.tar.gz
lwn-ef2276fc46e695b72d0640dd9e154d3e244dc85b.zip
fs, seq_file: fallback to vmalloc instead of oom kill processes
commit 5cec38ac866bfb8775638e71a86e4d8cac30caae upstream. Since commit 058504edd026 ("fs/seq_file: fallback to vmalloc allocation"), seq_buf_alloc() falls back to vmalloc() when the kmalloc() for contiguous memory fails. This was done to address order-4 slab allocations for reading /proc/stat on large machines and noticed because PAGE_ALLOC_COSTLY_ORDER < 4, so there is no infinite loop in the page allocator when allocating new slab for such high-order allocations. Contiguous memory isn't necessary for caller of seq_buf_alloc(), however. Other GFP_KERNEL high-order allocations that are <= PAGE_ALLOC_COSTLY_ORDER will simply loop forever in the page allocator and oom kill processes as a result. We don't want to kill processes so that we can allocate contiguous memory in situations when contiguous memory isn't necessary. This patch does the kmalloc() allocation with __GFP_NORETRY for high-order allocations. This still utilizes memory compaction and direct reclaim in the allocation path, the only difference is that it will fail immediately instead of oom kill processes when out of memory. [akpm@linux-foundation.org: add comment] Signed-off-by: David Rientjes <rientjes@google.com> Cc: Heiko Carstens <heiko.carstens@de.ibm.com> Cc: Christoph Hellwig <hch@infradead.org> Cc: Al Viro <viro@zeniv.linux.org.uk> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Jiri Slaby <jslaby@suse.cz>
-rw-r--r--fs/seq_file.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/fs/seq_file.c b/fs/seq_file.c
index 6e050e26af43..96ae14abce98 100644
--- a/fs/seq_file.c
+++ b/fs/seq_file.c
@@ -36,7 +36,11 @@ static void *seq_buf_alloc(unsigned long size)
{
void *buf;
- buf = kmalloc(size, GFP_KERNEL | __GFP_NOWARN);
+ /*
+ * __GFP_NORETRY to avoid oom-killings with high-order allocations -
+ * it's better to fall back to vmalloc() than to kill things.
+ */
+ buf = kmalloc(size, GFP_KERNEL | __GFP_NORETRY | __GFP_NOWARN);
if (!buf && size > PAGE_SIZE)
buf = vmalloc(size);
return buf;