linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <greg@kroah.com>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	stable@vger.kernel.org,
	Tomasz Stanislawski <t.stanislaws@samsung.com>,
	Kyungmin Park <kyungmin.park@samsung.com>,
	Laura Abbott <lauraa@codeaurora.org>,
	Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>,
	Minchan Kim <minchan@kernel.org>, Mel Gorman <mel@csn.ul.ie>,
	Marek Szyprowski <m.szyprowski@samsung.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Linus Torvalds <torvalds@linux-foundation.org>
Subject: [ 28/48] mm/page_alloc.c: fix watermark check in __zone_watermark_ok()
Date: Tue, 18 Jun 2013 09:17:54 -0700	[thread overview]
Message-ID: <20130618161729.952381255@linuxfoundation.org> (raw)
In-Reply-To: <20130618161725.912524266@linuxfoundation.org>

From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

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

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

From: Tomasz Stanislawski <t.stanislaws@samsung.com>

commit 026b08147923142e925a7d0aaa39038055ae0156 upstream.

The watermark check consists of two sub-checks.  The first one is:

	if (free_pages <= min + lowmem_reserve)
		return false;

The check assures that there is minimal amount of RAM in the zone.  If
CMA is used then the free_pages is reduced by the number of free pages
in CMA prior to the over-mentioned check.

	if (!(alloc_flags & ALLOC_CMA))
		free_pages -= zone_page_state(z, NR_FREE_CMA_PAGES);

This prevents the zone from being drained from pages available for
non-movable allocations.

The second check prevents the zone from getting too fragmented.

	for (o = 0; o < order; o++) {
		free_pages -= z->free_area[o].nr_free << o;
		min >>= 1;
		if (free_pages <= min)
			return false;
	}

The field z->free_area[o].nr_free is equal to the number of free pages
including free CMA pages.  Therefore the CMA pages are subtracted twice.
This may cause a false positive fail of __zone_watermark_ok() if the CMA
area gets strongly fragmented.  In such a case there are many 0-order
free pages located in CMA.  Those pages are subtracted twice therefore
they will quickly drain free_pages during the check against
fragmentation.  The test fails even though there are many free non-cma
pages in the zone.

This patch fixes this issue by subtracting CMA pages only for a purpose of
(free_pages <= min + lowmem_reserve) check.

Laura said:

  We were observing allocation failures of higher order pages (order 5 =
  128K typically) under tight memory conditions resulting in driver
  failure.  The output from the page allocation failure showed plenty of
  free pages of the appropriate order/type/zone and mostly CMA pages in
  the lower orders.

  For full disclosure, we still observed some page allocation failures
  even after applying the patch but the number was drastically reduced and
  those failures were attributed to fragmentation/other system issues.

Signed-off-by: Tomasz Stanislawski <t.stanislaws@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Tested-by: Laura Abbott <lauraa@codeaurora.org>
Cc: Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>
Acked-by: Minchan Kim <minchan@kernel.org>
Cc: Mel Gorman <mel@csn.ul.ie>
Tested-by: Marek Szyprowski <m.szyprowski@samsung.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

---
 mm/page_alloc.c |    6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -1626,6 +1626,7 @@ static bool __zone_watermark_ok(struct z
 	long min = mark;
 	long lowmem_reserve = z->lowmem_reserve[classzone_idx];
 	int o;
+	long free_cma = 0;
 
 	free_pages -= (1 << order) - 1;
 	if (alloc_flags & ALLOC_HIGH)
@@ -1635,9 +1636,10 @@ static bool __zone_watermark_ok(struct z
 #ifdef CONFIG_CMA
 	/* If allocation can't use CMA areas don't use free CMA pages */
 	if (!(alloc_flags & ALLOC_CMA))
-		free_pages -= zone_page_state(z, NR_FREE_CMA_PAGES);
+		free_cma = zone_page_state(z, NR_FREE_CMA_PAGES);
 #endif
-	if (free_pages <= min + lowmem_reserve)
+
+	if (free_pages - free_cma <= min + lowmem_reserve)
 		return false;
 	for (o = 0; o < order; o++) {
 		/* At the next order, this order's pages become unavailable */



  parent reply	other threads:[~2013-06-18 16:18 UTC|newest]

Thread overview: 67+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-06-18 16:17 [ 00/48] 3.9.7-stable review Greg Kroah-Hartman
2013-06-18 16:17 ` [ 01/48] audit: wait_for_auditd() should use TASK_UNINTERRUPTIBLE Greg Kroah-Hartman
2013-06-18 16:17 ` [ 02/48] b43: stop format string leaking into error msgs Greg Kroah-Hartman
2013-06-18 16:17 ` [ 03/48] ACPI / video: Do not bind to device objects with a scan handler Greg Kroah-Hartman
2013-06-18 16:17 ` [ 04/48] libceph: must hold mutex for reset_changed_osds() Greg Kroah-Hartman
2013-06-18 16:17 ` [ 05/48] ceph: add cpu_to_le32() calls when encoding a reconnect capability Greg Kroah-Hartman
2013-06-18 16:17 ` [ 06/48] ceph: ceph_pagelist_append might sleep while atomic Greg Kroah-Hartman
2013-06-18 16:17 ` [ 07/48] rbd: dont destroy ceph_opts in rbd_add() Greg Kroah-Hartman
2013-06-18 16:17 ` [ 08/48] drivers/rtc/rtc-twl.c: fix missing device_init_wakeup() when booted with device tree Greg Kroah-Hartman
2013-06-18 16:17 ` [ 09/48] drm/gma500/psb: Unpin framebuffer on crtc disable Greg Kroah-Hartman
2013-06-18 16:17 ` [ 10/48] drm/gma500/cdv: " Greg Kroah-Hartman
2013-06-18 16:17 ` [ 11/48] Bluetooth: Fix missing length checks for L2CAP signalling PDUs Greg Kroah-Hartman
2013-06-18 16:17 ` [ 12/48] Bluetooth: Fix mgmt handling of power on failures Greg Kroah-Hartman
2013-06-18 16:17 ` [ 13/48] s390/pci: Implement IRQ functions if !PCI Greg Kroah-Hartman
2013-06-18 17:35   ` Ben Hutchings
2013-06-18 17:42     ` Greg Kroah-Hartman
2013-06-18 21:35       ` Ben Hutchings
2013-06-19  7:09     ` Martin Schwidefsky
2013-06-20 19:21     ` Greg Kroah-Hartman
2013-06-18 16:17 ` [ 14/48] ath9k: Disable PowerSave by default Greg Kroah-Hartman
2013-06-18 16:17 ` [ 15/48] Revert "ath9k_hw: Update rx gain initval to improve rx sensitivity" Greg Kroah-Hartman
2013-06-18 16:17 ` [ 16/48] ath9k: Use minstrel rate control by default Greg Kroah-Hartman
2013-06-18 16:17 ` [ 17/48] CPU hotplug: provide a generic helper to disable/enable CPU hotplug Greg Kroah-Hartman
2013-06-18 16:17 ` [ 18/48] reboot: rigrate shutdown/reboot to boot cpu Greg Kroah-Hartman
2013-06-18 16:17 ` [ 19/48] kmsg: honor dmesg_restrict sysctl on /dev/kmsg Greg Kroah-Hartman
2013-06-18 16:17 ` [ 20/48] cciss: fix broken mutex usage in ioctl Greg Kroah-Hartman
2013-06-18 16:17 ` [ 21/48] memcg: dont initialize kmem-cache destroying work for root caches Greg Kroah-Hartman
2013-06-18 16:17 ` [ 22/48] wl12xx: fix minimum required firmware version for wl127x multirole Greg Kroah-Hartman
2013-06-18 16:17 ` [ 23/48] drm/i915: prefer VBT modes for SVDO-LVDS over EDID Greg Kroah-Hartman
2013-06-18 16:17 ` [ 24/48] swap: avoid read_swap_cache_async() race to deadlock while waiting on discard I/O completion Greg Kroah-Hartman
2013-06-18 16:17 ` [ 25/48] md/raid1: consider WRITE as successful only if at least one non-Faulty and non-rebuilding drive completed it Greg Kroah-Hartman
2013-06-18 16:17 ` [ 26/48] md/raid1,5,10: Disable WRITE SAME until a recovery strategy is in place Greg Kroah-Hartman
2013-06-18 16:17 ` [ 27/48] md/raid1,raid10: use freeze_array in place of raise_barrier in various places Greg Kroah-Hartman
2013-06-18 16:17 ` Greg Kroah-Hartman [this message]
2013-06-18 16:17 ` [ 29/48] mm: migration: add migrate_entry_wait_huge() Greg Kroah-Hartman
2013-06-20  9:52   ` Satoru Takeuchi
2013-06-20 17:02     ` Greg Kroah-Hartman
2013-06-21 11:42       ` Satoru Takeuchi
2013-06-21 12:47     ` Michal Hocko
2013-06-21 22:56       ` Satoru Takeuchi
2013-06-22 12:28         ` Satoru Takeuchi
2013-06-27 18:48     ` Naoya Horiguchi
2013-06-18 16:17 ` [ 30/48] x86: Fix adjust_range_size_mask calling position Greg Kroah-Hartman
2013-06-18 16:17 ` [ 31/48] x86: Fix typo in kexec register clearing Greg Kroah-Hartman
2013-06-18 16:17 ` [ 32/48] drm/nv50/disp: force dac power state during load detect Greg Kroah-Hartman
2013-06-18 16:17 ` [ 33/48] drm/nv50/kms: use dac loadval from vbios, where its available Greg Kroah-Hartman
2013-06-18 16:18 ` [ 34/48] libceph: clear messenger auth_retry flag when we authenticate Greg Kroah-Hartman
2013-06-18 16:18 ` [ 35/48] libceph: fix authorizer invalidation Greg Kroah-Hartman
2013-06-18 16:18 ` [ 36/48] libceph: add update_authorizer auth method Greg Kroah-Hartman
2013-06-18 16:18 ` [ 37/48] libceph: wrap auth ops in wrapper functions Greg Kroah-Hartman
2013-06-18 16:18 ` [ 38/48] libceph: wrap auth methods in a mutex Greg Kroah-Hartman
2013-06-18 16:18 ` [ 39/48] Modify UEFI anti-bricking code Greg Kroah-Hartman
2013-06-18 16:18 ` [ 40/48] powerpc: Fix stack overflow crash in resume_kernel when ftracing Greg Kroah-Hartman
2013-06-18 16:18 ` [ 41/48] powerpc: Fix emulation of illegal instructions on PowerNV platform Greg Kroah-Hartman
2013-06-18 16:18 ` [ 42/48] powerpc: Fix missing/delayed calls to irq_work Greg Kroah-Hartman
2013-06-18 16:18 ` [ 43/48] usb: chipidea: fix id change handling Greg Kroah-Hartman
2013-06-18 16:18 ` [ 44/48] USB: pl2303: fix device initialisation at open Greg Kroah-Hartman
2013-06-18 16:18 ` [ 45/48] USB: f81232: " Greg Kroah-Hartman
2013-06-18 16:18 ` [ 46/48] USB: spcp8x5: " Greg Kroah-Hartman
2013-06-18 16:18 ` [ 47/48] tg3: Wait for boot code to finish after power on Greg Kroah-Hartman
2013-06-18 16:18 ` [ 48/48] ARM: Kirkwood: handle mv88f6282 cpu in __kirkwood_variant() Greg Kroah-Hartman
2013-06-18 21:55 ` [ 00/48] 3.9.7-stable review Shuah Khan
2013-06-18 22:11   ` Greg Kroah-Hartman
2013-06-18 22:58 ` Guenter Roeck
2013-06-18 23:26   ` Greg Kroah-Hartman
2013-06-20 10:02 ` Satoru Takeuchi
2013-06-20 17:01   ` 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=20130618161729.952381255@linuxfoundation.org \
    --to=greg@kroah.com \
    --cc=akpm@linux-foundation.org \
    --cc=b.zolnierkie@samsung.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=kyungmin.park@samsung.com \
    --cc=lauraa@codeaurora.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=m.szyprowski@samsung.com \
    --cc=mel@csn.ul.ie \
    --cc=minchan@kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=t.stanislaws@samsung.com \
    --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).