linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Rik van Riel <H.H.vanRiel@fys.ruu.nl>
To: Linus Torvalds <torvalds@transmeta.com>
Cc: "Stephen C. Tweedie" <sct@dcs.ed.ac.uk>,
	linux-mm <linux-mm@kvack.org>,
	linux-kernel <linux-kernel@vger.rutgers.edu>
Subject: [PATCH] free_memory_available() fix
Date: Tue, 3 Mar 1998 00:10:18 +0100 (MET)	[thread overview]
Message-ID: <Pine.LNX.3.91.980303000549.3788A-100000@mirkwood.dummy.home> (raw)

Hi there,

Here's the patch to free_memory_available() in mm/page_alloc.c.

The comment above the source code should give you enough
info to get started on my algoritm...

Please verify it, I've only compiled it :-(, but it
should be correct nevertheless... (just remember to
read it first).

The patch is against 2.1.89-pre2, but judging from the
posts to linux-kernel, it should apply to newer versions
without a hitch.

Rik.
+-----------------------------+------------------------------+
| For Linux mm-patches, go to | "I'm busy managing memory.." |
| my homepage (via LinuxHQ).  | H.H.vanRiel@fys.ruu.nl       |
| ...submissions welcome...   | http://www.fys.ruu.nl/~riel/ |
+-----------------------------+------------------------------+

-----------------------> cut here <------------------------------

--- page_alloc.pre89-2	Mon Mar  2 23:32:16 1998
+++ page_alloc.c	Tue Mar  3 00:03:48 1998
@@ -108,22 +108,51 @@
  * but this had better return false if any reasonable "get_free_page()"
  * allocation could currently fail..
  *
- * Right now we just require that the highest memory order should
- * have at least two entries. Whether this makes sense or not
- * under real load is to be tested, but it also gives us some
- * guarantee about memory fragmentation (essentially, it means
- * that there should be at least two large areas available).
+ * Currently we approve of the following situations:
+ * - the highest memory order has two entries
+ * - the highest memory order has one free entry and:
+ *	- the next-highest memory order has two free entries
+ * - the highest memory order has one free entry and:
+ *	- the next-highest memory order has one free entry
+ *	- the next-next-highest memory order has two free entries
+ *
+ * [previously, there had to be two entries of the highest memory
+ *  order, but this lead to problems on large-memory machines.]
  */
 int free_memory_available(void)
 {
-	int retval;
+	int retval = 0;
 	unsigned long flags;
-	struct free_area_struct * last = free_area + NR_MEM_LISTS - 1;
+	struct free_area_struct * biggest = free_area + NR_MEM_LISTS - 1;
+	struct free_area_struct * bigger = free_area + NR_MEM_LISTS - 2;
+	struct free_area_struct * big = free_area + NR_MEM_LISTS - 3;
 
 	spin_lock_irqsave(&page_alloc_lock, flags);
-	retval =  (last->next != memory_head(last)) && (last->next->next != memory_head(last));
+	if (biggest->next != memory_head(biggest)) {
+		retval = 4;
+		if (biggest->next->next != memory_head(biggest))
+			retval += 4;
+	} else {
+	/* we want at least one free area of the 'biggest' size */
+		goto out;
+	}
+	if (bigger->next != memory_head(bigger)) {
+		retval += 2;
+		if (bigger->next->next != memory_head(bigger))
+			retval += 2;
+	} else {
+	/* if we have only one free area of the 'biggest' size, we also
+	 * want one of the 'bigger' size */
+		goto out;
+	}
+	if (big->next != memory_head(big)) {
+		retval += 1;
+		if (big->next->next != memory_head(big))
+			retval += 1;
+	}
+out:
 	spin_unlock_irqrestore(&page_alloc_lock, flags);
-	return retval;
+	return retval > 7;
 }
 
 static inline void free_pages_ok(unsigned long map_nr, unsigned long order)

                 reply	other threads:[~1998-03-02 23:20 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=Pine.LNX.3.91.980303000549.3788A-100000@mirkwood.dummy.home \
    --to=h.h.vanriel@fys.ruu.nl \
    --cc=linux-kernel@vger.rutgers.edu \
    --cc=linux-mm@kvack.org \
    --cc=sct@dcs.ed.ac.uk \
    --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