]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob
c45ad15e5482f9d3942592f14a1c05eb8b2754d7
[thirdparty/kernel/stable-queue.git] /
1 From 66199712e9eef5aede09dbcd9dfff87798a66917 Mon Sep 17 00:00:00 2001
2 From: Mel Gorman <mgorman@suse.de>
3 Date: Thu, 12 Jan 2012 17:19:41 -0800
4 Subject: mm: page allocator: do not call direct reclaim for THP allocations while compaction is deferred
5
6 From: Mel Gorman <mgorman@suse.de>
7
8 commit 66199712e9eef5aede09dbcd9dfff87798a66917 upstream.
9
10 Stable note: Not tracked in Buzilla. This was part of a series that
11 reduced interactivity stalls experienced when THP was enabled.
12
13 If compaction is deferred, direct reclaim is used to try to free enough
14 pages for the allocation to succeed. For small high-orders, this has a
15 reasonable chance of success. However, if the caller has specified
16 __GFP_NO_KSWAPD to limit the disruption to the system, it makes more sense
17 to fail the allocation rather than stall the caller in direct reclaim.
18 This patch skips direct reclaim if compaction is deferred and the caller
19 specifies __GFP_NO_KSWAPD.
20
21 Async compaction only considers a subset of pages so it is possible for
22 compaction to be deferred prematurely and not enter direct reclaim even in
23 cases where it should. To compensate for this, this patch also defers
24 compaction only if sync compaction failed.
25
26 Signed-off-by: Mel Gorman <mgorman@suse.de>
27 Acked-by: Minchan Kim <minchan.kim@gmail.com>
28 Reviewed-by: Rik van Riel<riel@redhat.com>
29 Cc: Andrea Arcangeli <aarcange@redhat.com>
30 Cc: Dave Jones <davej@redhat.com>
31 Cc: Jan Kara <jack@suse.cz>
32 Cc: Andy Isaacson <adi@hexapodia.org>
33 Cc: Nai Xia <nai.xia@gmail.com>
34 Cc: Johannes Weiner <jweiner@redhat.com>
35 Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
36 Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
37 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
38
39 ---
40 mm/page_alloc.c | 45 +++++++++++++++++++++++++++++++++++----------
41 1 file changed, 35 insertions(+), 10 deletions(-)
42
43 --- a/mm/page_alloc.c
44 +++ b/mm/page_alloc.c
45 @@ -1897,14 +1897,20 @@ static struct page *
46 __alloc_pages_direct_compact(gfp_t gfp_mask, unsigned int order,
47 struct zonelist *zonelist, enum zone_type high_zoneidx,
48 nodemask_t *nodemask, int alloc_flags, struct zone *preferred_zone,
49 - int migratetype, unsigned long *did_some_progress,
50 - bool sync_migration)
51 + int migratetype, bool sync_migration,
52 + bool *deferred_compaction,
53 + unsigned long *did_some_progress)
54 {
55 struct page *page;
56
57 - if (!order || compaction_deferred(preferred_zone))
58 + if (!order)
59 return NULL;
60
61 + if (compaction_deferred(preferred_zone)) {
62 + *deferred_compaction = true;
63 + return NULL;
64 + }
65 +
66 current->flags |= PF_MEMALLOC;
67 *did_some_progress = try_to_compact_pages(zonelist, order, gfp_mask,
68 nodemask, sync_migration);
69 @@ -1932,7 +1938,13 @@ __alloc_pages_direct_compact(gfp_t gfp_m
70 * but not enough to satisfy watermarks.
71 */
72 count_vm_event(COMPACTFAIL);
73 - defer_compaction(preferred_zone);
74 +
75 + /*
76 + * As async compaction considers a subset of pageblocks, only
77 + * defer if the failure was a sync compaction failure.
78 + */
79 + if (sync_migration)
80 + defer_compaction(preferred_zone);
81
82 cond_resched();
83 }
84 @@ -1944,8 +1956,9 @@ static inline struct page *
85 __alloc_pages_direct_compact(gfp_t gfp_mask, unsigned int order,
86 struct zonelist *zonelist, enum zone_type high_zoneidx,
87 nodemask_t *nodemask, int alloc_flags, struct zone *preferred_zone,
88 - int migratetype, unsigned long *did_some_progress,
89 - bool sync_migration)
90 + int migratetype, bool sync_migration,
91 + bool *deferred_compaction,
92 + unsigned long *did_some_progress)
93 {
94 return NULL;
95 }
96 @@ -2095,6 +2108,7 @@ __alloc_pages_slowpath(gfp_t gfp_mask, u
97 unsigned long pages_reclaimed = 0;
98 unsigned long did_some_progress;
99 bool sync_migration = false;
100 + bool deferred_compaction = false;
101
102 /*
103 * In the slowpath, we sanity check order to avoid ever trying to
104 @@ -2175,12 +2189,22 @@ rebalance:
105 zonelist, high_zoneidx,
106 nodemask,
107 alloc_flags, preferred_zone,
108 - migratetype, &did_some_progress,
109 - sync_migration);
110 + migratetype, sync_migration,
111 + &deferred_compaction,
112 + &did_some_progress);
113 if (page)
114 goto got_pg;
115 sync_migration = true;
116
117 + /*
118 + * If compaction is deferred for high-order allocations, it is because
119 + * sync compaction recently failed. In this is the case and the caller
120 + * has requested the system not be heavily disrupted, fail the
121 + * allocation now instead of entering direct reclaim
122 + */
123 + if (deferred_compaction && (gfp_mask & __GFP_NO_KSWAPD))
124 + goto nopage;
125 +
126 /* Try direct reclaim and then allocating */
127 page = __alloc_pages_direct_reclaim(gfp_mask, order,
128 zonelist, high_zoneidx,
129 @@ -2243,8 +2267,9 @@ rebalance:
130 zonelist, high_zoneidx,
131 nodemask,
132 alloc_flags, preferred_zone,
133 - migratetype, &did_some_progress,
134 - sync_migration);
135 + migratetype, sync_migration,
136 + &deferred_compaction,
137 + &did_some_progress);
138 if (page)
139 goto got_pg;
140 }