]> glassweightruler.freedombox.rocks Git - Ventoy.git/commitdiff
Reduce the required low memory.
authorlongpanda <admin@ventoy.net>
Tue, 3 May 2022 10:41:16 +0000 (18:41 +0800)
committerlongpanda <admin@ventoy.net>
Tue, 3 May 2022 10:41:16 +0000 (18:41 +0800)
GRUB2/MOD_SRC/grub-2.04/grub-core/kern/efi/mm.c
GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_cmd.c

index cb65cb352f34a32614e49dbae64fdfad3a62aed9..5a70e0984f031f74eb614256a4c962fb8a572869 100644 (file)
@@ -49,8 +49,11 @@ static grub_efi_uintn_t finish_desc_size;
 static grub_efi_uint32_t finish_desc_version;
 int grub_efi_is_finished = 0;
 
 static grub_efi_uint32_t finish_desc_version;
 int grub_efi_is_finished = 0;
 
+/* 160MB  160 * 1024 * 1024 / 4096 */
+#define VTOY_CHAIN_MIN_PAGES   (160 * 256)
 static grub_efi_uint64_t g_total_pages;
 static grub_efi_uint64_t g_total_pages;
-static grub_efi_uint64_t g_required_pages;
+static grub_efi_uint64_t g_org_required_pages;
+static grub_efi_uint64_t g_new_required_pages;
 
 /*
  * We need to roll back EFI allocations on exit. Remember allocations that
 
 /*
  * We need to roll back EFI allocations on exit. Remember allocations that
@@ -617,8 +620,21 @@ grub_efi_mm_init (void)
   else if (required_pages > BYTES_TO_PAGES (MAX_HEAP_SIZE))
     required_pages = BYTES_TO_PAGES (MAX_HEAP_SIZE);
 
   else if (required_pages > BYTES_TO_PAGES (MAX_HEAP_SIZE))
     required_pages = BYTES_TO_PAGES (MAX_HEAP_SIZE);
 
+  g_org_required_pages = required_pages;
+  if (((total_pages - required_pages) >> 2) < VTOY_CHAIN_MIN_PAGES)
+  {
+      if (total_pages > (VTOY_CHAIN_MIN_PAGES << 2))
+      {
+          g_new_required_pages = total_pages - (VTOY_CHAIN_MIN_PAGES << 2);
+          if (g_new_required_pages >= 8192)
+          {
+              required_pages = g_new_required_pages;
+          }          
+      }
+  }
+
   g_total_pages = total_pages;
   g_total_pages = total_pages;
-  g_required_pages = required_pages;
+  g_new_required_pages = required_pages;
 
   /* Sort the filtered descriptors, so that GRUB can allocate pages
      from smaller regions.  */
 
   /* Sort the filtered descriptors, so that GRUB can allocate pages
      from smaller regions.  */
@@ -677,9 +693,10 @@ grub_efi_get_ram_base(grub_addr_t *base_addr)
 }
 #endif
 
 }
 #endif
 
-void grub_efi_get_reserved_page_num(grub_uint64_t *total, grub_uint64_t *required)
+void grub_efi_get_reserved_page_num(grub_uint64_t *total, grub_uint64_t *org_required, grub_uint64_t *new_required)
 {
     *total = g_total_pages;
 {
     *total = g_total_pages;
-    *required = g_required_pages;
+    *org_required = g_org_required_pages;
+    *new_required = g_new_required_pages;
 }
 
 }
 
index 1d1b972fa7b28d0469d6bb0f6cc8d2b853287f04..fdb929613bf8a2065c175e688719c5942fefc09a 100644 (file)
@@ -5571,19 +5571,22 @@ static grub_err_t ventoy_cmd_fn_mutex_lock(grub_extcmd_context_t ctxt, int argc,
 static grub_err_t ventoy_cmd_dump_rsv_page(grub_extcmd_context_t ctxt, int argc, char **args)
 {
     grub_uint64_t total;
 static grub_err_t ventoy_cmd_dump_rsv_page(grub_extcmd_context_t ctxt, int argc, char **args)
 {
     grub_uint64_t total;
-    grub_uint64_t required;
+    grub_uint64_t org_required;
+    grub_uint64_t new_required;
     
     (void)ctxt;
     (void)argc;
     (void)args;
 
 #ifdef GRUB_MACHINE_EFI
     
     (void)ctxt;
     (void)argc;
     (void)args;
 
 #ifdef GRUB_MACHINE_EFI
-    grub_efi_get_reserved_page_num(&total, &required);
+    grub_efi_get_reserved_page_num(&total, &org_required, &new_required);
     grub_printf("Total pages: %llu\n", (unsigned long long)total);
     grub_printf("Total pages: %llu\n", (unsigned long long)total);
-    grub_printf("Required pages: %llu\n", (unsigned long long)required);
+    grub_printf("OrgReq pages: %llu\n", (unsigned long long)org_required);
+    grub_printf("NewReq pages: %llu\n", (unsigned long long)new_required);
 #else
     (void)total;
 #else
     (void)total;
-    (void)required;
+    (void)org_required;
+    (void)new_required;
     grub_printf("Non EFI mode!\n");
 #endif
 
     grub_printf("Non EFI mode!\n");
 #endif