linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	stable@vger.kernel.org, Nikolay Borisov <kernel@kyup.com>,
	Michal Hocko <mhocko@suse.cz>, Hugh Dickins <hughd@google.com>,
	Linus Torvalds <torvalds@linux-foundation.org>
Subject: [PATCH 4.1 78/84] mm, vmscan: Do not wait for page writeback for GFP_NOFS allocations
Date: Fri, 14 Aug 2015 10:42:46 -0700	[thread overview]
Message-ID: <20150814174212.560646350@linuxfoundation.org> (raw)
In-Reply-To: <20150814174210.214822912@linuxfoundation.org>

4.1-stable review patch.  If anyone has any objections, please let me know.

------------------

From: Michal Hocko <mhocko@suse.cz>

commit ecf5fc6e9654cd7a268c782a523f072b2f1959f9 upstream.

Nikolay has reported a hang when a memcg reclaim got stuck with the
following backtrace:

PID: 18308  TASK: ffff883d7c9b0a30  CPU: 1   COMMAND: "rsync"
  #0 __schedule at ffffffff815ab152
  #1 schedule at ffffffff815ab76e
  #2 schedule_timeout at ffffffff815ae5e5
  #3 io_schedule_timeout at ffffffff815aad6a
  #4 bit_wait_io at ffffffff815abfc6
  #5 __wait_on_bit at ffffffff815abda5
  #6 wait_on_page_bit at ffffffff8111fd4f
  #7 shrink_page_list at ffffffff81135445
  #8 shrink_inactive_list at ffffffff81135845
  #9 shrink_lruvec at ffffffff81135ead
 #10 shrink_zone at ffffffff811360c3
 #11 shrink_zones at ffffffff81136eff
 #12 do_try_to_free_pages at ffffffff8113712f
 #13 try_to_free_mem_cgroup_pages at ffffffff811372be
 #14 try_charge at ffffffff81189423
 #15 mem_cgroup_try_charge at ffffffff8118c6f5
 #16 __add_to_page_cache_locked at ffffffff8112137d
 #17 add_to_page_cache_lru at ffffffff81121618
 #18 pagecache_get_page at ffffffff8112170b
 #19 grow_dev_page at ffffffff811c8297
 #20 __getblk_slow at ffffffff811c91d6
 #21 __getblk_gfp at ffffffff811c92c1
 #22 ext4_ext_grow_indepth at ffffffff8124565c
 #23 ext4_ext_create_new_leaf at ffffffff81246ca8
 #24 ext4_ext_insert_extent at ffffffff81246f09
 #25 ext4_ext_map_blocks at ffffffff8124a848
 #26 ext4_map_blocks at ffffffff8121a5b7
 #27 mpage_map_one_extent at ffffffff8121b1fa
 #28 mpage_map_and_submit_extent at ffffffff8121f07b
 #29 ext4_writepages at ffffffff8121f6d5
 #30 do_writepages at ffffffff8112c490
 #31 __filemap_fdatawrite_range at ffffffff81120199
 #32 filemap_flush at ffffffff8112041c
 #33 ext4_alloc_da_blocks at ffffffff81219da1
 #34 ext4_rename at ffffffff81229b91
 #35 ext4_rename2 at ffffffff81229e32
 #36 vfs_rename at ffffffff811a08a5
 #37 SYSC_renameat2 at ffffffff811a3ffc
 #38 sys_renameat2 at ffffffff811a408e
 #39 sys_rename at ffffffff8119e51e
 #40 system_call_fastpath at ffffffff815afa89

Dave Chinner has properly pointed out that this is a deadlock in the
reclaim code because ext4 doesn't submit pages which are marked by
PG_writeback right away.

The heuristic was introduced by commit e62e384e9da8 ("memcg: prevent OOM
with too many dirty pages") and it was applied only when may_enter_fs
was specified.  The code has been changed by c3b94f44fcb0 ("memcg:
further prevent OOM with too many dirty pages") which has removed the
__GFP_FS restriction with a reasoning that we do not get into the fs
code.  But this is not sufficient apparently because the fs doesn't
necessarily submit pages marked PG_writeback for IO right away.

ext4_bio_write_page calls io_submit_add_bh but that doesn't necessarily
submit the bio.  Instead it tries to map more pages into the bio and
mpage_map_one_extent might trigger memcg charge which might end up
waiting on a page which is marked PG_writeback but hasn't been submitted
yet so we would end up waiting for something that never finishes.

Fix this issue by replacing __GFP_IO by may_enter_fs check (for case 2)
before we go to wait on the writeback.  The page fault path, which is
the only path that triggers memcg oom killer since 3.12, shouldn't
require GFP_NOFS and so we shouldn't reintroduce the premature OOM
killer issue which was originally addressed by the heuristic.

As per David Chinner the xfs is doing similar thing since 2.6.15 already
so ext4 is not the only affected filesystem.  Moreover he notes:

: For example: IO completion might require unwritten extent conversion
: which executes filesystem transactions and GFP_NOFS allocations. The
: writeback flag on the pages can not be cleared until unwritten
: extent conversion completes. Hence memory reclaim cannot wait on
: page writeback to complete in GFP_NOFS context because it is not
: safe to do so, memcg reclaim or otherwise.

Cc: stable@vger.kernel.org # 3.9+
[tytso@mit.edu: corrected the control flow]
Fixes: c3b94f44fcb0 ("memcg: further prevent OOM with too many dirty pages")
Reported-by: Nikolay Borisov <kernel@kyup.com>
Signed-off-by: Michal Hocko <mhocko@suse.cz>
Signed-off-by: Hugh Dickins <hughd@google.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>


---
 mm/vmscan.c |   14 +++++---------
 1 file changed, 5 insertions(+), 9 deletions(-)

--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -937,21 +937,17 @@ static unsigned long shrink_page_list(st
 		 *
 		 * 2) Global reclaim encounters a page, memcg encounters a
 		 *    page that is not marked for immediate reclaim or
-		 *    the caller does not have __GFP_IO. In this case mark
+		 *    the caller does not have __GFP_FS (or __GFP_IO if it's
+		 *    simply going to swap, not to fs). In this case mark
 		 *    the page for immediate reclaim and continue scanning.
 		 *
-		 *    __GFP_IO is checked  because a loop driver thread might
+		 *    Require may_enter_fs because we would wait on fs, which
+		 *    may not have submitted IO yet. And the loop driver might
 		 *    enter reclaim, and deadlock if it waits on a page for
 		 *    which it is needed to do the write (loop masks off
 		 *    __GFP_IO|__GFP_FS for this reason); but more thought
 		 *    would probably show more reasons.
 		 *
-		 *    Don't require __GFP_FS, since we're not going into the
-		 *    FS, just waiting on its writeback completion. Worryingly,
-		 *    ext4 gfs2 and xfs allocate pages with
-		 *    grab_cache_page_write_begin(,,AOP_FLAG_NOFS), so testing
-		 *    may_enter_fs here is liable to OOM on them.
-		 *
 		 * 3) memcg encounters a page that is not already marked
 		 *    PageReclaim. memcg does not have any dirty pages
 		 *    throttling so we could easily OOM just because too many
@@ -968,7 +964,7 @@ static unsigned long shrink_page_list(st
 
 			/* Case 2 above */
 			} else if (global_reclaim(sc) ||
-			    !PageReclaim(page) || !(sc->gfp_mask & __GFP_IO)) {
+			    !PageReclaim(page) || !may_enter_fs) {
 				/*
 				 * This is slightly racy - end_page_writeback()
 				 * might have just cleared PageReclaim, then



  parent reply	other threads:[~2015-08-14 17:49 UTC|newest]

Thread overview: 83+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-14 17:41 [PATCH 4.1 00/84] 4.1.6-stable review Greg Kroah-Hartman
2015-08-14 17:41 ` [PATCH 4.1 01/84] MIPS: unaligned: Fix build error on big endian R6 kernels Greg Kroah-Hartman
2015-08-14 17:41 ` [PATCH 4.1 02/84] MIPS: Replace add and sub instructions in relocate_kernel.S with addiu Greg Kroah-Hartman
2015-08-14 17:41 ` [PATCH 4.1 03/84] MIPS: Malta: Dont reinitialise RTC Greg Kroah-Hartman
2015-08-14 17:41 ` [PATCH 4.1 04/84] MIPS: Fix sched_getaffinity with MT FPAFF enabled Greg Kroah-Hartman
2015-08-14 17:41 ` [PATCH 4.1 05/84] MIPS: Export get_c0_perfcount_int() Greg Kroah-Hartman
2015-08-14 17:41 ` [PATCH 4.1 06/84] MIPS: do_mcheck: Fix kernel code dump with EVA Greg Kroah-Hartman
2015-08-14 17:41 ` [PATCH 4.1 07/84] MIPS: show_stack: Fix stack trace " Greg Kroah-Hartman
2015-08-14 17:41 ` [PATCH 4.1 09/84] MIPS: Flush RPS on kernel entry " Greg Kroah-Hartman
2015-08-14 17:41 ` [PATCH 4.1 10/84] MIPS: Make set_pte() SMP safe Greg Kroah-Hartman
2015-08-14 17:41 ` [PATCH 4.1 11/84] fsnotify: fix oops in fsnotify_clear_marks_by_group_flags() Greg Kroah-Hartman
2015-08-14 17:41 ` [PATCH 4.1 12/84] drm/i915: Declare the swizzling unknown for L-shaped configurations Greg Kroah-Hartman
2015-08-14 17:41 ` [PATCH 4.1 14/84] drm/radeon: rework audio detect (v4) Greg Kroah-Hartman
2015-08-14 17:41 ` [PATCH 4.1 15/84] drm/radeon/combios: add some validation of lvds values Greg Kroah-Hartman
2015-08-14 17:41 ` [PATCH 4.1 16/84] drm/dp-mst: Remove debug WARN_ON Greg Kroah-Hartman
2015-08-14 17:41 ` [PATCH 4.1 17/84] ipr: Fix locking for unit attention handling Greg Kroah-Hartman
2015-08-14 17:41 ` [PATCH 4.1 18/84] ipr: Fix incorrect trace indexing Greg Kroah-Hartman
2015-08-14 17:41 ` [PATCH 4.1 19/84] ipr: Fix invalid array indexing for HRRQ Greg Kroah-Hartman
2015-08-14 17:41 ` [PATCH 4.1 20/84] Bluetooth: Fix NULL pointer dereference in smp_conn_security Greg Kroah-Hartman
2015-08-14 17:41 ` [PATCH 4.1 21/84] dmaengine: pl330: Fix overflow when reporting residue in memcpy Greg Kroah-Hartman
2015-08-14 17:41 ` [PATCH 4.1 22/84] dmaengine: pl330: Really fix choppy sound because of wrong residue calculation Greg Kroah-Hartman
2015-08-14 17:41 ` [PATCH 4.1 24/84] drivers/usb: Delete XHCI command timer if necessary Greg Kroah-Hartman
2015-08-14 17:41 ` [PATCH 4.1 25/84] USB: sierra: add 1199:68AB device ID Greg Kroah-Hartman
2015-08-14 17:41 ` [PATCH 4.1 26/84] usb: udc: core: add device_del() call to error pathway Greg Kroah-Hartman
2015-08-14 17:41 ` [PATCH 4.1 27/84] usb: chipidea: ehci_init_driver is intended to call one time Greg Kroah-Hartman
2015-08-14 17:41 ` [PATCH 4.1 28/84] phy: twl4030-usb: make runtime pm more reliable Greg Kroah-Hartman
2015-08-14 17:41 ` [PATCH 4.1 29/84] md: use kzalloc() when bitmap is disabled Greg Kroah-Hartman
2015-08-14 17:41 ` [PATCH 4.1 30/84] ath10k: fix qca61x4 hw2.1 support Greg Kroah-Hartman
2015-08-14 17:41 ` [PATCH 4.1 31/84] x86/asm/entry/64: Remove pointless jump to irq_return Greg Kroah-Hartman
2015-08-14 17:42 ` [PATCH 4.1 32/84] x86/nmi: Enable nested do_nmi() handling for 64-bit kernels Greg Kroah-Hartman
2015-08-14 17:42 ` [PATCH 4.1 33/84] x86/nmi/64: Remove asm code that saves CR2 Greg Kroah-Hartman
2015-08-14 17:42 ` [PATCH 4.1 34/84] x86/nmi/64: Switch stacks on userspace NMI entry Greg Kroah-Hartman
2015-08-14 17:42 ` [PATCH 4.1 35/84] x86/nmi/64: Improve nested NMI comments Greg Kroah-Hartman
2015-08-14 17:42 ` [PATCH 4.1 36/84] x86/nmi/64: Reorder nested NMI checks Greg Kroah-Hartman
2015-08-14 17:42 ` [PATCH 4.1 37/84] x86/nmi/64: Use DF to avoid userspace RSP confusing nested NMI detection Greg Kroah-Hartman
2015-08-14 17:42 ` [PATCH 4.1 38/84] dmaengine: at_xdmac: fix transfer data width in at_xdmac_prep_slave_sg() Greg Kroah-Hartman
2015-08-14 17:42 ` [PATCH 4.1 39/84] crypto: nx - Fixing NX data alignment with nx_sg list Greg Kroah-Hartman
2015-08-14 17:42 ` [PATCH 4.1 40/84] crypto: nx - Fixing SHA update bug Greg Kroah-Hartman
2015-08-14 17:42 ` [PATCH 4.1 41/84] crypto: nx - Fix reentrancy bugs Greg Kroah-Hartman
2015-08-14 17:42 ` [PATCH 4.1 42/84] [PATCH] sparc64: Fix userspace FPU register corruptions Greg Kroah-Hartman
2015-08-14 17:42 ` [PATCH 4.1 43/84] clk: keystone: add support for post divider register for main pll Greg Kroah-Hartman
2015-08-14 17:42 ` [PATCH 4.1 44/84] ARM: dts: keystone: fix dt bindings to use post div register for mainpll Greg Kroah-Hartman
2015-08-14 17:42 ` [PATCH 4.1 45/84] ASoC: Intel: Get correct usage_count value to load firmware Greg Kroah-Hartman
2015-08-14 17:42 ` [PATCH 4.1 46/84] ASoC: ssm4567: Keep TDM_BCLKS in ssm4567_set_dai_fmt Greg Kroah-Hartman
2015-08-14 17:42 ` [PATCH 4.1 47/84] ASoC: pcm1681: Fix setting de-emphasis sampling rate selection Greg Kroah-Hartman
2015-08-14 17:42 ` [PATCH 4.1 48/84] ASoC: dapm: Lock during userspace access Greg Kroah-Hartman
2015-08-14 17:42 ` [PATCH 4.1 49/84] ASoC: dapm: Dont add prefix to widget stream name Greg Kroah-Hartman
2015-08-14 17:42 ` [PATCH 4.1 50/84] x86/xen: Probe target addresses in set_aliased_prot() before the hypercall Greg Kroah-Hartman
2015-08-14 17:42 ` [PATCH 4.1 52/84] hwrng: core - correct error check of kthread_run call Greg Kroah-Hartman
2015-08-14 17:42 ` [PATCH 4.1 53/84] crypto: qat - Fix invalid synchronization between register/unregister sym algs Greg Kroah-Hartman
2015-08-14 17:42 ` [PATCH 4.1 54/84] crypto: ixp4xx - Remove bogus BUG_ON on scattered dst buffer Greg Kroah-Hartman
2015-08-14 17:42 ` [PATCH 4.1 55/84] rbd: fix copyup completion race Greg Kroah-Hartman
2015-08-14 17:42 ` [PATCH 4.1 56/84] ARM: dts: i.MX35: Fix can support Greg Kroah-Hartman
2015-08-14 17:42 ` [PATCH 4.1 57/84] ARM: OMAP2+: hwmod: Fix _wait_target_ready() for hwmods without sysc Greg Kroah-Hartman
2015-08-14 17:42 ` [PATCH 4.1 58/84] ALSA: hda - fix cs4210_spdif_automute() Greg Kroah-Hartman
2015-08-14 17:42 ` [PATCH 4.1 59/84] ALSA: hda - one Dell machine needs the headphone white noise fixup Greg Kroah-Hartman
2015-08-14 17:42 ` [PATCH 4.1 60/84] ALSA: fireworks/firewire-lib: add support for recent firmware quirk Greg Kroah-Hartman
2015-08-14 17:42 ` [PATCH 4.1 61/84] hwmon: (nct7904) Export I2C module alias information Greg Kroah-Hartman
2015-08-14 17:42 ` [PATCH 4.1 63/84] ipc: modify message queue accounting to not take kernel data structures into account Greg Kroah-Hartman
2015-08-14 17:42 ` [PATCH 4.1 64/84] ocfs2: fix BUG in ocfs2_downconvert_thread_do_work() Greg Kroah-Hartman
2015-08-14 17:42 ` [PATCH 4.1 65/84] ocfs2: fix shift left overflow Greg Kroah-Hartman
2015-08-14 17:42 ` [PATCH 4.1 66/84] nfsd: Drop BUG_ON and ignore SECLABEL on absent filesystem Greg Kroah-Hartman
2015-08-14 17:42 ` [PATCH 4.1 67/84] PCI: Restore PCI_MSIX_FLAGS_BIRMASK definition Greg Kroah-Hartman
2015-08-14 17:42 ` [PATCH 4.1 68/84] md/raid1: extend spinlock to protect raid1_end_read_request against inconsistencies Greg Kroah-Hartman
2015-08-14 17:42 ` [PATCH 4.1 69/84] dm: fix dm_merge_bvec regression on 32 bit systems Greg Kroah-Hartman
2015-08-14 17:42 ` [PATCH 4.1 70/84] staging: vt6655: vnt_bss_info_changed check conf->beacon_rate is not NULL Greg Kroah-Hartman
2015-08-14 17:42 ` [PATCH 4.1 71/84] staging: lustre: Include unaligned.h instead of access_ok.h Greg Kroah-Hartman
2015-08-14 17:42 ` [PATCH 4.1 72/84] usb: gadget: f_uac2: fix calculation of uac2->p_interval Greg Kroah-Hartman
2015-08-14 17:42 ` [PATCH 4.1 73/84] USB: qcserial/option: make AT URCs work for Sierra Wireless MC7305/MC7355 Greg Kroah-Hartman
2015-08-14 17:42 ` [PATCH 4.1 75/84] mtd: nand: Fix NAND_USE_BOUNCE_BUFFER flag conflict Greg Kroah-Hartman
2015-08-14 17:42 ` [PATCH 4.1 76/84] Input: alps - only Dell laptops have separate button bits for v2 dualpoint sticks Greg Kroah-Hartman
2015-08-14 17:42 ` [PATCH 4.1 77/84] thermal: exynos: Disable the regulator on probe failure Greg Kroah-Hartman
2015-08-14 17:42 ` Greg Kroah-Hartman [this message]
2015-08-14 17:42 ` [PATCH 4.1 79/84] signalfd: fix information leak in signalfd_copyinfo Greg Kroah-Hartman
2015-08-14 17:42 ` [PATCH 4.1 80/84] signal: fix information leak in copy_siginfo_to_user Greg Kroah-Hartman
2015-08-14 17:42 ` [PATCH 4.1 81/84] signal: fix information leak in copy_siginfo_from_user32 Greg Kroah-Hartman
2015-08-14 17:42 ` [PATCH 4.1 82/84] kvm: x86: fix kvm_apic_has_events to check for NULL pointer Greg Kroah-Hartman
2015-08-14 17:42 ` [PATCH 4.1 83/84] nfsd: refactor nfs4_preprocess_stateid_op Greg Kroah-Hartman
2015-08-14 17:42 ` [PATCH 4.1 84/84] nfsd: do nfs4_check_fh in nfs4_check_file instead of nfs4_check_olstateid Greg Kroah-Hartman
2015-08-15  0:10 ` [PATCH 4.1 00/84] 4.1.6-stable review Shuah Khan
2015-08-15  0:46   ` Greg Kroah-Hartman
2015-08-15 15:21 ` Guenter Roeck
2015-08-15 16:40   ` Greg Kroah-Hartman

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=20150814174212.560646350@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=hughd@google.com \
    --cc=kernel@kyup.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mhocko@suse.cz \
    --cc=stable@vger.kernel.org \
    --cc=torvalds@linux-foundation.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;
as well as URLs for NNTP newsgroup(s).