linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Nick Piggin <nickpiggin@yahoo.com.au>
To: Andrew Morton <akpm@osdl.org>, Linus Torvalds <torvalds@osdl.org>
Cc: Linux Memory Management <linux-mm@kvack.org>,
	linux-kernel <linux-kernel@vger.kernel.org>
Subject: [RFC][PATCH 2/3] alloc-order watermarks
Date: Sun, 05 Sep 2004 15:46:41 +1000	[thread overview]
Message-ID: <413AA841.1040003@yahoo.com.au> (raw)
In-Reply-To: <413AA7F8.3050706@yahoo.com.au>

[-- Attachment #1: Type: text/plain, Size: 4 bytes --]

2/3

[-- Attachment #2: vm-alloc-order-watermarks.patch --]
[-- Type: text/x-patch, Size: 3849 bytes --]



Move the watermark checking code into a single function. Extend it to account
for the order of the allocation and the number of free pages that could satisfy
such a request.

Signed-off-by: Nick Piggin <nickpiggin@yahoo.com.au>


---

 linux-2.6-npiggin/include/linux/mmzone.h |    2 +
 linux-2.6-npiggin/mm/page_alloc.c        |   57 ++++++++++++++++++++-----------
 2 files changed, 40 insertions(+), 19 deletions(-)

diff -puN mm/page_alloc.c~vm-alloc-order-watermarks mm/page_alloc.c
--- linux-2.6/mm/page_alloc.c~vm-alloc-order-watermarks	2004-09-05 14:55:46.000000000 +1000
+++ linux-2.6-npiggin/mm/page_alloc.c	2004-09-05 15:10:07.000000000 +1000
@@ -676,6 +676,36 @@ buffered_rmqueue(struct zone *zone, int 
 }
 
 /*
+ * Return the number of pages available for order 'order' allocations.
+ */
+int zone_watermark_ok(struct zone *z, int order, unsigned long mark,
+		int alloc_type, int can_try_harder, int gfp_high)
+{
+	unsigned long min = mark, free_pages = z->free_pages;
+	int o;
+
+	if (gfp_high)
+		min -= min / 2;
+	if (can_try_harder)
+		min -= min / 4;
+	min += z->protection[alloc_type];
+
+	if (free_pages < min)
+		return 0;
+	for (o = 0; o < order; o++) {
+		/* At the next order, this order's pages become unavailable */
+		free_pages -= z->free_area[order].nr_free << o;
+
+		/* Require fewer higher order pages to be free */
+		min >>= 1;
+
+		if (free_pages < min + (1 << order) - 1)
+			return 0;
+	}
+	return 1;
+}
+
+/*
  * This is the 'heart' of the zoned buddy allocator.
  *
  * Herein lies the mysterious "incremental min".  That's the
@@ -696,7 +726,6 @@ __alloc_pages(unsigned int gfp_mask, uns
 		struct zonelist *zonelist)
 {
 	const int wait = gfp_mask & __GFP_WAIT;
-	unsigned long min;
 	struct zone **zones, *z;
 	struct page *page;
 	struct reclaim_state reclaim_state;
@@ -732,9 +761,9 @@ __alloc_pages(unsigned int gfp_mask, uns
 
 	/* Go through the zonelist once, looking for a zone with enough free */
 	for (i = 0; (z = zones[i]) != NULL; i++) {
-		min = z->pages_low + (1<<order) + z->protection[alloc_type];
 
-		if (z->free_pages < min)
+		if (!zone_watermark_ok(z, order, z->pages_low,
+				alloc_type, 0, 0))
 			continue;
 
 		if (!cpuset_zone_allowed(z))
@@ -753,14 +782,9 @@ __alloc_pages(unsigned int gfp_mask, uns
 	 * coming from realtime tasks to go deeper into reserves
 	 */
 	for (i = 0; (z = zones[i]) != NULL; i++) {
-		min = z->pages_min;
-		if (gfp_mask & __GFP_HIGH)
-			min /= 2;
-		if (can_try_harder)
-			min -= min / 4;
-		min += (1<<order) + z->protection[alloc_type];
-
-		if (z->free_pages < min)
+		if (!zone_watermark_ok(z, order, z->pages_min,
+				alloc_type, can_try_harder,
+				gfp_mask & __GFP_HIGH))
 			continue;
 
 		if (!cpuset_zone_allowed(z))
@@ -801,14 +825,9 @@ rebalance:
 
 	/* go through the zonelist yet one more time */
 	for (i = 0; (z = zones[i]) != NULL; i++) {
-		min = z->pages_min;
-		if (gfp_mask & __GFP_HIGH)
-			min /= 2;
-		if (can_try_harder)
-			min -= min / 4;
-		min += (1<<order) + z->protection[alloc_type];
-
-		if (z->free_pages < min)
+		if (!zone_watermark_ok(z, order, z->pages_min,
+				alloc_type, can_try_harder,
+				gfp_mask & __GFP_HIGH))
 			continue;
 
 		if (!cpuset_zone_allowed(z))
diff -puN include/linux/mmzone.h~vm-alloc-order-watermarks include/linux/mmzone.h
--- linux-2.6/include/linux/mmzone.h~vm-alloc-order-watermarks	2004-09-05 14:55:46.000000000 +1000
+++ linux-2.6-npiggin/include/linux/mmzone.h	2004-09-05 15:10:07.000000000 +1000
@@ -279,6 +279,8 @@ void get_zone_counts(unsigned long *acti
 			unsigned long *free);
 void build_all_zonelists(void);
 void wakeup_kswapd(struct zone *zone);
+int zone_watermark_ok(struct zone *z, int order, unsigned long mark,
+		int alloc_type, int can_try_harder, int gfp_high);
 
 /*
  * zone_idx() returns 0 for the ZONE_DMA zone, 1 for the ZONE_NORMAL zone, etc.

_

  reply	other threads:[~2004-09-05  5:46 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-09-05  5:44 [RFC][PATCH 0/3] beat kswapd with the proverbial clue-bat Nick Piggin
2004-09-05  5:45 ` [RFC][PATCH 1/3] account free buddy areas Nick Piggin
2004-09-05  5:46   ` Nick Piggin [this message]
2004-09-05  5:47     ` [RFC][PATCH 3/3] teach kswapd about watermarks Nick Piggin
2004-09-05  6:04       ` David S. Miller
2004-09-05  6:20         ` Nick Piggin
2004-09-05  5:50     ` [RFC][PATCH 2/3] alloc-order watermarks Nick Piggin
2004-09-05  6:13   ` [RFC][PATCH 1/3] account free buddy areas Nick Piggin
2004-09-05  6:02 ` [RFC][PATCH 0/3] beat kswapd with the proverbial clue-bat David S. Miller
2004-09-05  6:16   ` Nick Piggin
2004-09-05 10:13     ` Nick Piggin
2004-09-05 17:24       ` Linus Torvalds
2004-09-05 17:36         ` Martin J. Bligh
2004-09-05 17:37         ` Arjan van de Ven
2004-09-05 17:58           ` Linus Torvalds
2004-09-05 18:41             ` Arjan van de Ven
2004-09-06  1:35             ` Nick Piggin
2004-09-15 13:27             ` Jörn Engel
2004-09-15 13:29               ` Arjan van de Ven
2004-09-15 13:34                 ` Jörn Engel
2004-09-15 13:39                   ` Arjan van de Ven
2004-09-15 14:18                     ` Jörn Engel
2004-09-06  1:09         ` Nick Piggin
2004-09-05  6:09 ` Andrew Morton
2004-09-05  6:26   ` Nick Piggin
2004-09-05  6:27   ` Anton Blanchard
2004-09-05 10:09     ` Nick Piggin
2004-09-06  3:33       ` David S. Miller
2004-09-06  8:55         ` Nick Piggin
2004-09-05 16:49 ` Linus Torvalds
2004-09-06  0:54   ` Nick Piggin
2004-09-06  1:49     ` Nick Piggin

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=413AA841.1040003@yahoo.com.au \
    --to=nickpiggin@yahoo.com.au \
    --cc=akpm@osdl.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=torvalds@osdl.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