public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@zip.com.au>
To: Linus Torvalds <torvalds@transmeta.com>
Cc: lkml <linux-kernel@vger.kernel.org>
Subject: [patch 8/13] alloc_pages cleanup
Date: Tue, 16 Jul 2002 22:30:00 -0700	[thread overview]
Message-ID: <3D3500D8.B7FD8F73@zip.com.au> (raw)



Cleanup patch from Martin Bligh: convert some loops which want to be
`for' loops into that, and add some commentary.




 page_alloc.c |   44 ++++++++++++++++++++------------------------
 1 files changed, 20 insertions(+), 24 deletions(-)

--- 2.5.26/mm/page_alloc.c~cleanup-alloc_pages	Tue Jul 16 21:46:36 2002
+++ 2.5.26-akpm/mm/page_alloc.c	Tue Jul 16 21:46:36 2002
@@ -323,22 +323,23 @@ balance_classzone(zone_t * classzone, un
 struct page * __alloc_pages(unsigned int gfp_mask, unsigned int order, zonelist_t *zonelist)
 {
 	unsigned long min;
-	zone_t **zone, * classzone;
+	zone_t **zones, *classzone;
 	struct page * page;
-	int freed;
+	int freed, i;
 
 	KERNEL_STAT_ADD(pgalloc, 1<<order);
 
-	zone = zonelist->zones;
-	classzone = *zone;
-	if (classzone == NULL)
+	zones = zonelist->zones;  /* the list of zones suitable for gfp_mask */
+	classzone = zones[0]; 
+	if (classzone == NULL)    /* no zones in the zonelist */
 		return NULL;
+
+	/* Go through the zonelist once, looking for a zone with enough free */
 	min = 1UL << order;
-	for (;;) {
-		zone_t *z = *(zone++);
-		if (!z)
-			break;
+	for (i = 0; zones[i] != NULL; i++) {
+		zone_t *z = zones[i];
 
+		/* the incremental min is allegedly to discourage fallback */
 		min += z->pages_low;
 		if (z->free_pages > min) {
 			page = rmqueue(z, order);
@@ -349,16 +350,15 @@ struct page * __alloc_pages(unsigned int
 
 	classzone->need_balance = 1;
 	mb();
+	/* we're somewhat low on memory, failed to find what we needed */
 	if (waitqueue_active(&kswapd_wait))
 		wake_up_interruptible(&kswapd_wait);
 
-	zone = zonelist->zones;
+	/* Go through the zonelist again, taking __GFP_HIGH into account */
 	min = 1UL << order;
-	for (;;) {
+	for (i = 0; zones[i] != NULL; i++) {
 		unsigned long local_min;
-		zone_t *z = *(zone++);
-		if (!z)
-			break;
+		zone_t *z = zones[i];
 
 		local_min = z->pages_min;
 		if (gfp_mask & __GFP_HIGH)
@@ -375,11 +375,9 @@ struct page * __alloc_pages(unsigned int
 
 rebalance:
 	if (current->flags & (PF_MEMALLOC | PF_MEMDIE)) {
-		zone = zonelist->zones;
-		for (;;) {
-			zone_t *z = *(zone++);
-			if (!z)
-				break;
+		/* go through the zonelist yet again, ignoring mins */
+		for (i = 0; zones[i] != NULL; i++) {
+			zone_t *z = zones[i];
 
 			page = rmqueue(z, order);
 			if (page)
@@ -403,12 +401,10 @@ nopage:
 	if (page)
 		return page;
 
-	zone = zonelist->zones;
+	/* go through the zonelist yet one more time */
 	min = 1UL << order;
-	for (;;) {
-		zone_t *z = *(zone++);
-		if (!z)
-			break;
+	for (i = 0; zones[i] != NULL; i++) {
+		zone_t *z = zones[i];
 
 		min += z->pages_min;
 		if (z->free_pages > min) {

.

                 reply	other threads:[~2002-07-17  5:22 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=3D3500D8.B7FD8F73@zip.com.au \
    --to=akpm@zip.com.au \
    --cc=linux-kernel@vger.kernel.org \
    --cc=torvalds@transmeta.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