All of lore.kernel.org
 help / color / mirror / Atom feed
From: Robert Millan <rmh@aybabtu.com>
To: The development of GRUB 2 <grub-devel@gnu.org>
Cc: Marcin Kurek <morgoth6@gmail.com>
Subject: [PATCH] fix memory management on efika/pegasos
Date: Sun, 30 Sep 2007 22:10:35 +0200	[thread overview]
Message-ID: <20070930201035.GA12468@thorin> (raw)
In-Reply-To: <20070801182716.GA12782@aragorn>

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


Finally, I think I got this right now.  My efika boots and all the other
setups should be happy as well.  Please, review/test this and report.

-- 
Robert Millan

<GPLv2> I know my rights; I want my phone call!
<DRM> What use is a phone call, if you are unable to speak?
(as seen on /.)

[-- Attachment #2: efika.diff --]
[-- Type: text/x-diff, Size: 2670 bytes --]

2007-09-30  Robert Millan  <rmh@aybabtu.com>

	* kern/powerpc/ieee1275/init.c: Rename HEAP_LIMIT to HEAP_MAX_ADDR,
	and make it easier to figure out.
	Add HEAP_MIN_SIZE and HEAP_MAX_ADDR definitions.
	(grub_claim_heap): Use HEAP_MAX_ADDR rather than taking a parameter.
	Do not avoid claiming a region above HEAP_MAX_ADDR if that would
	leave us with less than HEAP_MIN_SIZE total heap.
	Avoid our total amount of heap to surpass HEAP_MAX_SIZE.

diff -ur grub2/kern/powerpc/ieee1275/init.c grub2.efika/kern/powerpc/ieee1275/init.c
--- grub2/kern/powerpc/ieee1275/init.c	2007-07-22 01:32:27.000000000 +0200
+++ grub2.efika/kern/powerpc/ieee1275/init.c	2007-09-30 21:54:19.000000000 +0200
@@ -33,7 +33,15 @@
 #include <grub/ieee1275/ofdisk.h>
 #include <grub/ieee1275/ieee1275.h>
 
-#define HEAP_LIMIT (4<<20) /* 4 MiB */
+/* The minimal heap size we can live with. */
+#define HEAP_MIN_SIZE		(unsigned long) (2 * 1024 * 1024)
+
+/* The maximum heap size we're going to claim */
+#define HEAP_MAX_SIZE		(unsigned long) (4 * 1024 * 1024)
+
+/* If possible, we will avoid claiming heap above this address, because it
+   seems to cause relocation problems with OSes that link at 4 MiB */
+#define HEAP_MAX_ADDR		(unsigned long) (4 * 1024 * 1024)
 
 extern char _start[];
 extern char _end[];
@@ -113,16 +121,24 @@
 }
 
 /* Claim some available memory in the first /memory node. */
-static void grub_claim_heap (unsigned long heaplimit)
+static void grub_claim_heap ()
 {
+  unsigned long total = 0;
+
   auto int heap_init (grub_uint64_t addr, grub_uint64_t len);
   int heap_init (grub_uint64_t addr, grub_uint64_t len)
   {
     len -= 1; /* Required for some firmware.  */
 
-    /* Don't claim anything above `heaplimit'.  */
-    if (addr + len > heaplimit)
-      len = heaplimit - addr;
+    /* Never exceed HEAP_MAX_SIZE  */
+    if (total + len > HEAP_MAX_SIZE)
+      len = HEAP_MAX_SIZE - total;
+
+    /* Avoid claiming anything above HEAP_MAX_ADDR, if possible. */
+    if ((addr < HEAP_MAX_ADDR) &&				/* if it's too late, don't bother */
+        (addr + len > HEAP_MAX_ADDR) &&				/* if it wasn't available anyway, don't bother */
+        (total + (HEAP_MAX_ADDR - addr) > HEAP_MIN_SIZE))	/* only limit ourselves when we can afford to */
+       len = HEAP_MAX_ADDR - addr;
 
     if (len)
       {
@@ -134,6 +150,10 @@
 	grub_mm_init_region ((void *) (grub_addr_t) addr, len);
       }
 
+    total += len;
+    if (total >= HEAP_MAX_SIZE)
+      return 1;
+
     return 0;
   }
 
@@ -147,7 +167,7 @@
   int actual;
 
   grub_console_init ();
-  grub_claim_heap (HEAP_LIMIT);
+  grub_claim_heap ();
   grub_ofdisk_init ();
 
   /* Process commandline.  */

  reply	other threads:[~2007-09-30 20:11 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-07-02 18:16 another regression on Efika Robert Millan
2007-07-02 21:14 ` Robert Millan
2007-07-04 16:18 ` Hollis Blanchard
2007-07-10 10:04   ` Jordi Mallach
2007-07-10 14:08     ` memory management issue (Re: another regression on Efika) Robert Millan
2007-07-10 20:32       ` Hollis Blanchard
2007-07-13 22:08         ` Robert Millan
2007-07-24 19:59           ` Robert Millan
2007-07-25 17:51             ` Hollis Blanchard
2007-07-25 20:08               ` Robert Millan
2007-07-25 23:25                 ` Hollis Blanchard
2007-07-27  8:05                   ` Robert Millan
     [not found]                     ` <20070727103310.GA1539@powerlinux.fr>
2007-07-27 19:15                       ` Robert Millan
2007-07-29 19:30                         ` Robert Millan
2007-07-30 20:11                           ` [PATCH] efika memory issues Robert Millan
2007-07-30 22:35                             ` Hollis Blanchard
2007-07-31 14:38                               ` Robert Millan
2007-07-31 15:55                                 ` Hollis Blanchard
2007-07-31 19:42                                   ` Robert Millan
2007-08-01 17:34                                     ` Hollis Blanchard
2007-08-01 18:27                                       ` Robert Millan
2007-09-30 20:10                                         ` Robert Millan [this message]
2007-10-01 18:18                                           ` [PATCH] fix memory management on efika/pegasos Marcin Kurek
2007-10-01 22:25                                           ` Marcin Kurek
2007-10-02 19:42                                             ` Robert Millan
2007-10-03 23:38                                               ` Marcin Kurek
2007-10-04 20:47                                                 ` Robert Millan
2007-07-10 14:10     ` OF disk naming scheme (Re: another regression on Efika) Robert Millan
2007-07-10 19:26       ` Jordi Mallach
2007-07-13 22:16         ` Robert Millan
2007-07-22  9:33           ` Robert Millan
2007-07-22 14:37             ` Marco Gerards
2007-07-22 20:25               ` Robert Millan
2007-08-12 14:56                 ` proposed solution using "ofpathname -a" (Re: OF disk naming scheme) Robert Millan
2007-08-05 10:03 ` updated regression diff (Re: another regression on Efika) Robert Millan

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=20070930201035.GA12468@thorin \
    --to=rmh@aybabtu.com \
    --cc=grub-devel@gnu.org \
    --cc=morgoth6@gmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.