+ fs-filec-fdtable-avoid-triggering-ooms-from-alloc_fdmem.patch added to -mm tree

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

 



Subject: + fs-filec-fdtable-avoid-triggering-ooms-from-alloc_fdmem.patch added to -mm tree
To: ebiederm@xxxxxxxxxxxx,cwang@xxxxxxxxxxxxxxxx,eric.dumazet@xxxxxxxxx,rientjes@xxxxxxxxxx,stable@xxxxxxxxxxxxxxx
From: akpm@xxxxxxxxxxxxxxxxxxxx
Date: Tue, 04 Feb 2014 15:48:38 -0800


The patch titled
     Subject: fs/file.c:fdtable: avoid triggering OOMs from alloc_fdmem
has been added to the -mm tree.  Its filename is
     fs-filec-fdtable-avoid-triggering-ooms-from-alloc_fdmem.patch

This patch should soon appear at
    http://ozlabs.org/~akpm/mmots/broken-out/fs-filec-fdtable-avoid-triggering-ooms-from-alloc_fdmem.patch
and later at
    http://ozlabs.org/~akpm/mmotm/broken-out/fs-filec-fdtable-avoid-triggering-ooms-from-alloc_fdmem.patch

Before you just go and hit "reply", please:
   a) Consider who else should be cc'ed
   b) Prefer to cc a suitable mailing list as well
   c) Ideally: find the original patch on the mailing list and do a
      reply-to-all to that, adding suitable additional cc's

*** Remember to use Documentation/SubmitChecklist when testing your code ***

The -mm tree is included into linux-next and is updated
there every 3-4 working days

------------------------------------------------------
From: ebiederm@xxxxxxxxxxxx (Eric W. Biederman)
Subject: fs/file.c:fdtable: avoid triggering OOMs from alloc_fdmem

Recently due to a spike in connections per second memcached on 3 separate
boxes triggered the OOM killer from accept.  At the time the OOM killer
was triggered there was 4GB out of 36GB free in zone 1.  The problem was
that alloc_fdtable was allocating an order 3 page (32KiB) to hold a
bitmap, and there was sufficient fragmentation that the largest page
available was 8KiB.

I find the logic that PAGE_ALLOC_COSTLY_ORDER can't fail pretty dubious
but I do agree that order 3 allocations are very likely to succeed.

There are always pathologies where order > 0 allocations can fail when
there are copious amounts of free memory available.  Using the pigeon hole
principle it is easy to show that it requires 1 page more than 50% of the
pages being free to guarantee an order 1 (8KiB) allocation will succeed, 1
page more than 75% of the pages being free to guarantee an order 2 (16KiB)
allocation will succeed and 1 page more than 87.5% of the pages being free
to guarantee an order 3 allocate will succeed.

A server churning memory with a lot of small requests and replies like
memcached is a common case that if anything can will skew the odds against
large pages being available.

Therefore let's not give external applications a practical way to kill
linux server applications, and specify __GFP_NORETRY to the kmalloc in
alloc_fdmem.  Unless I am misreading the code and by the time the code
reaches should_alloc_retry in __alloc_pages_slowpath (where __GFP_NORETRY
becomes signification).  We have already tried everything reasonable to
allocate a page and the only thing left to do is wait.  So not waiting and
falling back to vmalloc immediately seems like the reasonable thing to do
even if there wasn't a chance of triggering the OOM killer.

Signed-off-by: "Eric W. Biederman" <ebiederm@xxxxxxxxxxxx>
Cc: Eric Dumazet <eric.dumazet@xxxxxxxxx>
Acked-by: David Rientjes <rientjes@xxxxxxxxxx>
Cc: Cong Wang <cwang@xxxxxxxxxxxxxxxx>
Cc: <stable@xxxxxxxxxxxxxxx>
Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
---

 fs/file.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff -puN fs/file.c~fs-filec-fdtable-avoid-triggering-ooms-from-alloc_fdmem fs/file.c
--- a/fs/file.c~fs-filec-fdtable-avoid-triggering-ooms-from-alloc_fdmem
+++ a/fs/file.c
@@ -34,7 +34,7 @@ static void *alloc_fdmem(size_t size)
 	 * vmalloc() if the allocation size will be considered "large" by the VM.
 	 */
 	if (size <= (PAGE_SIZE << PAGE_ALLOC_COSTLY_ORDER)) {
-		void *data = kmalloc(size, GFP_KERNEL|__GFP_NOWARN);
+		void *data = kmalloc(size, GFP_KERNEL|__GFP_NOWARN|__GFP_NORETRY);
 		if (data != NULL)
 			return data;
 	}
_

Patches currently in -mm which might be from ebiederm@xxxxxxxxxxxx are

vmcore-prevent-pt_note-p_memsz-overflow-during-header-update.patch
vmcore-prevent-pt_note-p_memsz-overflow-during-header-update-v2.patch
fs-filec-fdtable-avoid-triggering-ooms-from-alloc_fdmem.patch
kernel-audit-fix-non-modular-users-of-module_init-in-core-code.patch

--
To unsubscribe from this list: send the line "unsubscribe stable" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Kernel]     [Kernel Development Newbies]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite Hiking]     [Linux Kernel]     [Linux SCSI]