linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Mel Gorman <mel@csn.ul.ie>
To: Andrea Arcangeli <aarcange@redhat.com>
Cc: Christoph Lameter <cl@linux-foundation.org>,
	Adam Litke <agl@us.ibm.com>, Avi Kivity <avi@redhat.com>,
	David Rientjes <rientjes@google.com>,
	KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>,
	Rik van Riel <riel@redhat.com>, Mel Gorman <mel@csn.ul.ie>,
	linux-kernel@vger.kernel.org, linux-mm@kvack.org
Subject: [PATCH 12/12] Do not compact within a preferred zone after a compaction failure
Date: Thu, 18 Feb 2010 18:02:42 +0000	[thread overview]
Message-ID: <1266516162-14154-13-git-send-email-mel@csn.ul.ie> (raw)
In-Reply-To: <1266516162-14154-1-git-send-email-mel@csn.ul.ie>

The fragmentation index may indicate that a failure it due to external
fragmentation, a compaction run complete and an allocation failure still
fail. There are two obvious reasons as to why

  o Page migration cannot move all pages so fragmentation remains
  o A suitable page may exist but watermarks are not met

In the event of compaction and allocation failure, this patch prevents
compaction happening for a short interval. It's only recorded on the
preferred zone but that should be enough coverage. This could have been
implemented similar to the zonelist_cache but the increased size of the
zonelist did not appear to be justified.

Signed-off-by: Mel Gorman <mel@csn.ul.ie>
Acked-by: Rik van Riel <riel@redhat.com>
---
 include/linux/compaction.h |   35 +++++++++++++++++++++++++++++++++++
 include/linux/mmzone.h     |    7 +++++++
 mm/page_alloc.c            |    5 ++++-
 3 files changed, 46 insertions(+), 1 deletions(-)

diff --git a/include/linux/compaction.h b/include/linux/compaction.h
index 1cf95e2..8b1471b 100644
--- a/include/linux/compaction.h
+++ b/include/linux/compaction.h
@@ -13,6 +13,32 @@ extern int sysctl_compaction_handler(struct ctl_table *table, int write,
 extern int fragmentation_index(struct zone *zone, unsigned int order);
 extern unsigned long try_to_compact_pages(struct zonelist *zonelist,
 			int order, gfp_t gfp_mask, nodemask_t *mask);
+
+/* defer_compaction - Do not compact within a zone until a given time */
+static inline void defer_compaction(struct zone *zone, unsigned long resume)
+{
+	/*
+	 * This function is called when compaction fails to result in a page
+	 * allocation success. This is somewhat unsatisfactory as the failure
+	 * to compact has nothing to do with time and everything to do with
+	 * the requested order, the number of free pages and watermarks. How
+	 * to wait on that is more unclear, but the answer would apply to
+	 * other areas where the VM waits based on time.
+	 */
+	zone->compact_resume = resume;
+}
+
+static inline int compaction_deferred(struct zone *zone)
+{
+	/* init once if necessary */
+	if (unlikely(!zone->compact_resume)) {
+		zone->compact_resume = jiffies;
+		return 0;
+	}
+
+	return time_before(jiffies, zone->compact_resume);
+}
+
 #else
 static inline unsigned long try_to_compact_pages(struct zonelist *zonelist,
 			int order, gfp_t gfp_mask, nodemask_t *nodemask)
@@ -20,6 +46,15 @@ static inline unsigned long try_to_compact_pages(struct zonelist *zonelist,
 	return COMPACT_INCOMPLETE;
 }
 
+static inline void defer_compaction(struct zone *zone, unsigned long resume)
+{
+}
+
+static inline int compaction_deferred(struct zone *zone)
+{
+	return 1;
+}
+
 #endif /* CONFIG_COMPACTION */
 
 #if defined(CONFIG_COMPACTION) && defined(CONFIG_SYSFS) && defined(CONFIG_NUMA)
diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
index 30fe668..31fb38b 100644
--- a/include/linux/mmzone.h
+++ b/include/linux/mmzone.h
@@ -328,6 +328,13 @@ struct zone {
 	unsigned long		*pageblock_flags;
 #endif /* CONFIG_SPARSEMEM */
 
+#ifdef CONFIG_COMPACTION
+	/*
+	 * If a compaction fails, do not try compaction again until
+	 * jiffies is after the value of compact_resume
+	 */
+	unsigned long		compact_resume;
+#endif
 
 	ZONE_PADDING(_pad1_)
 
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 1910b8b..7021c68 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -1730,7 +1730,7 @@ __alloc_pages_direct_reclaim(gfp_t gfp_mask, unsigned int order,
 	cond_resched();
 
 	/* Try memory compaction for high-order allocations before reclaim */
-	if (order) {
+	if (order && !compaction_deferred(preferred_zone)) {
 		*did_some_progress = try_to_compact_pages(zonelist,
 						order, gfp_mask, nodemask);
 		if (*did_some_progress != COMPACT_INCOMPLETE) {
@@ -1750,6 +1750,9 @@ __alloc_pages_direct_reclaim(gfp_t gfp_mask, unsigned int order,
 			 */
 			count_vm_event(COMPACTFAIL);
 
+			/* On failure, avoid compaction for a short time. */
+			defer_compaction(preferred_zone, jiffies + HZ/50);
+
 			cond_resched();
 		}
 	}
-- 
1.6.5

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

      parent reply	other threads:[~2010-02-18 18:02 UTC|newest]

Thread overview: 51+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-02-18 18:02 [PATCH 0/12] Memory Compaction v3 Mel Gorman
2010-02-18 18:02 ` [PATCH 01/12] mm,migration: Take a reference to the anon_vma before migrating Mel Gorman
2010-02-19  0:12   ` KAMEZAWA Hiroyuki
2010-02-19 13:59     ` Mel Gorman
2010-02-19 16:43   ` Rik van Riel
2010-02-18 18:02 ` [PATCH 02/12] mm,migration: Do not try to migrate unmapped anonymous pages Mel Gorman
2010-02-19 16:45   ` Rik van Riel
2010-02-18 18:02 ` [PATCH 03/12] mm: Share the anon_vma ref counts between KSM and page migration Mel Gorman
2010-02-19  0:18   ` KAMEZAWA Hiroyuki
2010-02-19 14:05     ` Mel Gorman
2010-02-19 15:01       ` Christoph Lameter
2010-02-20  3:48       ` KAMEZAWA Hiroyuki
2010-02-20  9:32         ` Mel Gorman
2010-02-19  5:09   ` Minchan Kim
2010-02-19 21:42   ` Rik van Riel
2010-02-19 21:58     ` Mel Gorman
2010-02-20  0:16       ` Rik van Riel
2010-02-20  9:29         ` Mel Gorman
2010-02-18 18:02 ` [PATCH 04/12] mm: Document /proc/pagetypeinfo Mel Gorman
2010-02-19  1:36   ` Minchan Kim
2010-02-19 21:42   ` Rik van Riel
2010-02-18 18:02 ` [PATCH 05/12] Allow CONFIG_MIGRATION to be set without CONFIG_NUMA or memory hot-remove Mel Gorman
2010-02-19  0:21   ` KAMEZAWA Hiroyuki
2010-02-19 14:09     ` Mel Gorman
2010-02-18 18:02 ` [PATCH 06/12] Export unusable free space index via /proc/pagetypeinfo Mel Gorman
2010-02-19  1:35   ` Minchan Kim
2010-02-19 21:46   ` Rik van Riel
2010-02-18 18:02 ` [PATCH 07/12] Export fragmentation " Mel Gorman
2010-02-19  1:59   ` Minchan Kim
2010-02-20  0:16   ` Rik van Riel
2010-02-18 18:02 ` [PATCH 08/12] Memory compaction core Mel Gorman
2010-02-19  0:37   ` KAMEZAWA Hiroyuki
2010-02-19 14:15     ` Mel Gorman
2010-02-18 18:02 ` [PATCH 09/12] Add /proc trigger for memory compaction Mel Gorman
2010-02-19  0:43   ` KAMEZAWA Hiroyuki
2010-02-19 14:16     ` Mel Gorman
2010-02-20  3:53       ` KAMEZAWA Hiroyuki
2010-02-19  2:26   ` Minchan Kim
2010-02-18 18:02 ` [PATCH 10/12] Add /sys trigger for per-node " Mel Gorman
2010-02-19 14:53   ` Greg KH
2010-02-19 15:28     ` Mel Gorman
2010-02-19 15:31       ` Greg KH
2010-02-19 15:51         ` Mel Gorman
2010-02-19 15:52           ` Mel Gorman
2010-02-19 16:02             ` Greg KH
2010-02-18 18:02 ` [PATCH 11/12] Direct compact when a high-order allocation fails Mel Gorman
2010-02-19  0:51   ` KAMEZAWA Hiroyuki
2010-02-19 14:19     ` Mel Gorman
2010-02-19  2:41   ` Minchan Kim
2010-02-19 14:25     ` Mel Gorman
2010-02-18 18:02 ` Mel Gorman [this message]

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=1266516162-14154-13-git-send-email-mel@csn.ul.ie \
    --to=mel@csn.ul.ie \
    --cc=aarcange@redhat.com \
    --cc=agl@us.ibm.com \
    --cc=avi@redhat.com \
    --cc=cl@linux-foundation.org \
    --cc=kosaki.motohiro@jp.fujitsu.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=riel@redhat.com \
    --cc=rientjes@google.com \
    /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).