1 From 72853e2991a2702ae93aaf889ac7db743a415dd3 Mon Sep 17 00:00:00 2001
2 From: Mel Gorman <mel@csn.ul.ie>
3 Date: Thu, 9 Sep 2010 16:38:16 -0700
4 Subject: mm: page allocator: update free page counters after pages are placed on the free list
6 From: Mel Gorman <mel@csn.ul.ie>
8 commit 72853e2991a2702ae93aaf889ac7db743a415dd3 upstream.
10 When allocating a page, the system uses NR_FREE_PAGES counters to
11 determine if watermarks would remain intact after the allocation was made.
12 This check is made without interrupts disabled or the zone lock held and
13 so is race-prone by nature. Unfortunately, when pages are being freed in
14 batch, the counters are updated before the pages are added on the list.
15 During this window, the counters are misleading as the pages do not exist
16 yet. When under significant pressure on systems with large numbers of
17 CPUs, it's possible for processes to make progress even though they should
18 have been stalled. This is particularly problematic if a number of the
19 processes are using GFP_ATOMIC as the min watermark can be accidentally
20 breached and in extreme cases, the system can livelock.
22 This patch updates the counters after the pages have been added to the
23 list. This makes the allocator more cautious with respect to preserving
24 the watermarks and mitigates livelock possibilities.
26 [akpm@linux-foundation.org: avoid modifying incoming args]
27 Signed-off-by: Mel Gorman <mel@csn.ul.ie>
28 Reviewed-by: Rik van Riel <riel@redhat.com>
29 Reviewed-by: Minchan Kim <minchan.kim@gmail.com>
30 Reviewed-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
31 Reviewed-by: Christoph Lameter <cl@linux.com>
32 Reviewed-by: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
33 Acked-by: Johannes Weiner <hannes@cmpxchg.org>
34 Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
35 Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
36 Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
39 mm/page_alloc.c | 9 +++++----
40 1 file changed, 5 insertions(+), 4 deletions(-)
44 @@ -588,13 +588,13 @@ static void free_pcppages_bulk(struct zo
48 + int to_free = count;
50 spin_lock(&zone->lock);
51 zone->all_unreclaimable = 0;
52 zone->pages_scanned = 0;
54 - __mod_zone_page_state(zone, NR_FREE_PAGES, count);
58 struct list_head *list;
60 @@ -619,8 +619,9 @@ static void free_pcppages_bulk(struct zo
61 /* MIGRATE_MOVABLE list may include MIGRATE_RESERVEs */
62 __free_one_page(page, zone, 0, page_private(page));
63 trace_mm_page_pcpu_drain(page, 0, page_private(page));
64 - } while (--count && --batch_free && !list_empty(list));
65 + } while (--to_free && --batch_free && !list_empty(list));
67 + __mod_zone_page_state(zone, NR_FREE_PAGES, count);
68 spin_unlock(&zone->lock);
71 @@ -631,8 +632,8 @@ static void free_one_page(struct zone *z
72 zone->all_unreclaimable = 0;
73 zone->pages_scanned = 0;
75 - __mod_zone_page_state(zone, NR_FREE_PAGES, 1 << order);
76 __free_one_page(page, zone, order, migratetype);
77 + __mod_zone_page_state(zone, NR_FREE_PAGES, 1 << order);
78 spin_unlock(&zone->lock);