Reduce the required low memory.

This commit is contained in:
longpanda 2022-05-03 18:41:16 +08:00
parent 75c6c7257f
commit 69da3a59d8
2 changed files with 28 additions and 8 deletions

View 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;
/* 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_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
@ -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);
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_required_pages = required_pages;
g_new_required_pages = required_pages;
/* 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
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;
*required = g_required_pages;
*org_required = g_org_required_pages;
*new_required = g_new_required_pages;
}

View 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;
grub_uint64_t required;
grub_uint64_t org_required;
grub_uint64_t new_required;
(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("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;
(void)required;
(void)org_required;
(void)new_required;
grub_printf("Non EFI mode!\n");
#endif