[SeaBIOS] [PATCH v3 2/2] malloc: use large ZoneHigh when there is enough memory

Gerd Hoffmann posted 2 patches 7 months ago
There is a newer version of this series
[SeaBIOS] [PATCH v3 2/2] malloc: use large ZoneHigh when there is enough memory
Posted by Gerd Hoffmann 7 months ago
In case there is enough memory installed use a large ZoneHigh.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 src/config.h | 3 ++-
 src/malloc.c | 4 +++-
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/src/config.h b/src/config.h
index 93c8dbc2d530..9abe355b6c47 100644
--- a/src/config.h
+++ b/src/config.h
@@ -17,7 +17,8 @@
 // Maximum number of map entries in the e820 map
 #define BUILD_MAX_E820 32
 // Space to reserve in high-memory for tables
-#define BUILD_MAX_HIGHTABLE (256*1024)
+#define BUILD_MIN_HIGHTABLE (256*1024)
+#define BUILD_MAX_HIGHTABLE (16*1024*1024)
 // Largest supported externaly facing drive id
 #define BUILD_MAX_EXTDRIVE 16
 // Number of bytes the smbios may be and still live in the f-segment
diff --git a/src/malloc.c b/src/malloc.c
index 7fa50a85595b..967e000f51ba 100644
--- a/src/malloc.c
+++ b/src/malloc.c
@@ -423,7 +423,7 @@ malloc_preinit(void)
 
     // Populate temp high ram
     u32 highram_start = 0;
-    u32 highram_size = BUILD_MAX_HIGHTABLE;
+    u32 highram_size = BUILD_MIN_HIGHTABLE;
     int i;
     for (i=e820_count-1; i>=0; i--) {
         struct e820entry *en = &e820_list[i];
@@ -434,6 +434,8 @@ malloc_preinit(void)
             continue;
         u32 s = en->start, e = end;
         if (!highram_start) {
+            if (e - s > BUILD_MAX_HIGHTABLE * 16)
+                highram_size = BUILD_MAX_HIGHTABLE;
             u32 newe = ALIGN_DOWN(e - highram_size, MALLOC_MIN_ALIGN);
             if (newe <= e && newe >= s) {
                 highram_start = newe;
-- 
2.35.1

_______________________________________________
SeaBIOS mailing list -- seabios@seabios.org
To unsubscribe send an email to seabios-leave@seabios.org
[SeaBIOS] Re: [PATCH v3 2/2] malloc: use large ZoneHigh when there is enough memory
Posted by Kevin O'Connor 7 months ago
On Tue, Apr 26, 2022 at 10:56:42AM +0200, Gerd Hoffmann wrote:
> In case there is enough memory installed use a large ZoneHigh.
> 
> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
> ---
>  src/config.h | 3 ++-
>  src/malloc.c | 4 +++-
>  2 files changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/src/config.h b/src/config.h
> index 93c8dbc2d530..9abe355b6c47 100644
> --- a/src/config.h
> +++ b/src/config.h
> @@ -17,7 +17,8 @@
>  // Maximum number of map entries in the e820 map
>  #define BUILD_MAX_E820 32
>  // Space to reserve in high-memory for tables
> -#define BUILD_MAX_HIGHTABLE (256*1024)
> +#define BUILD_MIN_HIGHTABLE (256*1024)
> +#define BUILD_MAX_HIGHTABLE (16*1024*1024)
>  // Largest supported externaly facing drive id
>  #define BUILD_MAX_EXTDRIVE 16
>  // Number of bytes the smbios may be and still live in the f-segment
> diff --git a/src/malloc.c b/src/malloc.c
> index 7fa50a85595b..967e000f51ba 100644
> --- a/src/malloc.c
> +++ b/src/malloc.c
> @@ -423,7 +423,7 @@ malloc_preinit(void)
>  
>      // Populate temp high ram
>      u32 highram_start = 0;
> -    u32 highram_size = BUILD_MAX_HIGHTABLE;
> +    u32 highram_size = BUILD_MIN_HIGHTABLE;
>      int i;
>      for (i=e820_count-1; i>=0; i--) {
>          struct e820entry *en = &e820_list[i];
> @@ -434,6 +434,8 @@ malloc_preinit(void)
>              continue;
>          u32 s = en->start, e = end;
>          if (!highram_start) {
> +            if (e - s > BUILD_MAX_HIGHTABLE * 16)
> +                highram_size = BUILD_MAX_HIGHTABLE;
>              u32 newe = ALIGN_DOWN(e - highram_size, MALLOC_MIN_ALIGN);
>              if (newe <= e && newe >= s) {
>                  highram_start = newe;

Thanks, but I'm still seeing a corner case where this fails - if
ALIGN_DOWN() falls below s.  In general, it seems odd to assign
highram_size with the possability of not assigning highram_start.

Cheers,
-Kevin
_______________________________________________
SeaBIOS mailing list -- seabios@seabios.org
To unsubscribe send an email to seabios-leave@seabios.org
[SeaBIOS] Re: [PATCH v3 2/2] malloc: use large ZoneHigh when there is enough memory
Posted by Gerd Hoffmann 7 months ago
> >          if (!highram_start) {
> > +            if (e - s > BUILD_MAX_HIGHTABLE * 16)
> > +                highram_size = BUILD_MAX_HIGHTABLE;
> >              u32 newe = ALIGN_DOWN(e - highram_size, MALLOC_MIN_ALIGN);
> >              if (newe <= e && newe >= s) {
> >                  highram_start = newe;
> 
> Thanks, but I'm still seeing a corner case where this fails - if
> ALIGN_DOWN() falls below s.

Given that the code requires the memory block being 16x the size of the
zonehigh allocation (i.e. use 16M in case the block is 256M or larger)
I fail to see how any reasonable alignment requirement can make that
fail ...

take care,
  Gerd

_______________________________________________
SeaBIOS mailing list -- seabios@seabios.org
To unsubscribe send an email to seabios-leave@seabios.org
[SeaBIOS] Re: [PATCH v3 2/2] malloc: use large ZoneHigh when there is enough memory
Posted by Kevin O'Connor 7 months ago
On Wed, Apr 27, 2022 at 08:26:35AM +0200, Gerd Hoffmann wrote:
> > >          if (!highram_start) {
> > > +            if (e - s > BUILD_MAX_HIGHTABLE * 16)
> > > +                highram_size = BUILD_MAX_HIGHTABLE;
> > >              u32 newe = ALIGN_DOWN(e - highram_size, MALLOC_MIN_ALIGN);
> > >              if (newe <= e && newe >= s) {
> > >                  highram_start = newe;
> > 
> > Thanks, but I'm still seeing a corner case where this fails - if
> > ALIGN_DOWN() falls below s.
> 
> Given that the code requires the memory block being 16x the size of the
> zonehigh allocation (i.e. use 16M in case the block is 256M or larger)
> I fail to see how any reasonable alignment requirement can make that
> fail ...

My mistake.

I do think your new v4 version of the code is easier to understand
though.

Cheers,
-Kevin
_______________________________________________
SeaBIOS mailing list -- seabios@seabios.org
To unsubscribe send an email to seabios-leave@seabios.org
[SeaBIOS] Re: [PATCH v3 2/2] malloc: use large ZoneHigh when there is enough memory
Posted by Gerd Hoffmann 7 months ago
  Hi,
 
> I do think your new v4 version of the code is easier to understand
> though.

Great, that was precisely the point of doing a v4 ;)

take care,
  Gerd

_______________________________________________
SeaBIOS mailing list -- seabios@seabios.org
To unsubscribe send an email to seabios-leave@seabios.org