Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1maCFm-0007Jj-S9 for mharc-grub-devel@gnu.org; Tue, 12 Oct 2021 03:31:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42622) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1maCFY-0007F2-SL for grub-devel@gnu.org; Tue, 12 Oct 2021 03:31:02 -0400 Received: from mail-pj1-x1035.google.com ([2607:f8b0:4864:20::1035]:40486) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1maCFW-0006fS-L0 for grub-devel@gnu.org; Tue, 12 Oct 2021 03:31:00 -0400 Received: by mail-pj1-x1035.google.com with SMTP id pf6-20020a17090b1d8600b0019fa884ab85so1231543pjb.5 for ; Tue, 12 Oct 2021 00:30:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=axtens.net; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=uJ6E3xNkw77q3dgg9OP8lJ9W9X3adxP9iCjWNFOp/f0=; b=qWBCqR2tPo7Ezq74LbKDqndgAPQrhCuBtGZU3ZMmsuYp8NSfnvLuZnVJkhvxkTBz0/ wykW3FmljIjtwF3h2utfP56KXokh91yGm+YeUzsVpnrllTVdtBcNUkyrm8dH5aOxpJk9 /jvDIs+BM+nhukKQuLRnJgB65NDFtR18e9euQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=uJ6E3xNkw77q3dgg9OP8lJ9W9X3adxP9iCjWNFOp/f0=; b=PB/7urUYW3JmIRyMmlN0w2q7AvjHxxepNQR/lzIQnZIEaNDwZdGvI09lDxTY9e8Tnh 72RgINUpBfJcDqd5OvwJvUVyQr01IWvCNK3mNFROBatsBePwW7LIZ6LVVqaZFPAoHFnP YJiHRseXk3x1irZU6DSLQM5y08SNU5YCbWwHnLNbqfxM3GSn8oxitCdqvYVcWBaF8Vab PHTYlYalbbQQiQeoz1JvaTkywr1m5coH0KZ9fS8mFhutueVBqeXcclbia0olp3Q2Cu9+ PkG6h6AWaLhgY411Xl90b7vnR8d9UyKzLDUyRpYUza+qbO8HWYMszH1fcxzR5eGKL0d1 Z5tg== X-Gm-Message-State: AOAM5320RWDhd9c28+rlhGK3XWJwTkZj9+wdFieHDZqotxwIRoN/ZEOv TBzSpL6pOHCKonJFd82V31Nj1V4xQ53/Bw== X-Google-Smtp-Source: ABdhPJxpsL7x+wGbPv98NUdZ7PnV7vEKktiM6QN19Ici6PJ41ufBTg5jX3sxTrBaYXlbWgJwjuEi8w== X-Received: by 2002:a17:902:7885:b0:13e:ecb:f214 with SMTP id q5-20020a170902788500b0013e0ecbf214mr28636086pll.87.1634023855700; Tue, 12 Oct 2021 00:30:55 -0700 (PDT) Received: from localhost ([2001:4479:e300:600:41fe:d15:934f:4029]) by smtp.gmail.com with ESMTPSA id s30sm10301673pgo.39.2021.10.12.00.30.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Oct 2021 00:30:55 -0700 (PDT) From: Daniel Axtens To: grub-devel@gnu.org Cc: leif@nuviainc.com, stefanb@linux.ibm.com, ps@pks.im, dkiper@net-space.pl Subject: [PATCH 10/19] efi: mm: Always request a fixed number of pages on init Date: Tue, 12 Oct 2021 18:29:59 +1100 Message-Id: <20211012073008.4059133-11-dja@axtens.net> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211012073008.4059133-1-dja@axtens.net> References: <20211012073008.4059133-1-dja@axtens.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2607:f8b0:4864:20::1035; envelope-from=dja@axtens.net; helo=mail-pj1-x1035.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 12 Oct 2021 07:31:02 -0000 From: Patrick Steinhardt When initializing the EFI memory subsytem, we will by default request a quarter of the available memory, bounded by a minimum/maximum value. Given that we're about to extend the EFI memory system to dynamically request additional pages from the firmware as required, this scaling of requested memory based on available memory will not make a lot of sense anymore. Remove this logic as a preparatory patch such that we'll instead defer to the runtime memory allocator. Note that ideally, we'd want to change this after dynamic requesting of pages has been implemented for the EFI platform. But because we'll need to split up initialization of the memory subsystem and the request of pages from the firmware, we'd have to duplicate quite some logic at first only to remove it afterwards again. This seems quite pointless, so we instead have patches slightly out of order. Signed-off-by: Patrick Steinhardt --- grub-core/kern/efi/mm.c | 35 +++-------------------------------- 1 file changed, 3 insertions(+), 32 deletions(-) diff --git a/grub-core/kern/efi/mm.c b/grub-core/kern/efi/mm.c index 9838fb2f50db..4d276bc87a4c 100644 --- a/grub-core/kern/efi/mm.c +++ b/grub-core/kern/efi/mm.c @@ -38,9 +38,8 @@ a multiplier of 4KB. */ #define MEMORY_MAP_SIZE 0x3000 -/* The minimum and maximum heap size for GRUB itself. */ -#define MIN_HEAP_SIZE 0x100000 -#define MAX_HEAP_SIZE (1600 * 0x100000) +/* The default heap size for GRUB itself in bytes. */ +#define DEFAULT_HEAP_SIZE 0x100000 static void *finish_mmap_buf = 0; static grub_efi_uintn_t finish_mmap_size = 0; @@ -478,23 +477,6 @@ filter_memory_map (grub_efi_memory_descriptor_t *memory_map, return filtered_desc; } -/* Return the total number of pages. */ -static grub_efi_uint64_t -get_total_pages (grub_efi_memory_descriptor_t *memory_map, - grub_efi_uintn_t desc_size, - grub_efi_memory_descriptor_t *memory_map_end) -{ - grub_efi_memory_descriptor_t *desc; - grub_efi_uint64_t total = 0; - - for (desc = memory_map; - desc < memory_map_end; - desc = NEXT_MEMORY_DESCRIPTOR (desc, desc_size)) - total += desc->num_pages; - - return total; -} - /* Add memory regions. */ static void add_memory_regions (grub_efi_memory_descriptor_t *memory_map, @@ -583,8 +565,6 @@ grub_efi_mm_init (void) grub_efi_memory_descriptor_t *filtered_memory_map_end; grub_efi_uintn_t map_size; grub_efi_uintn_t desc_size; - grub_efi_uint64_t total_pages; - grub_efi_uint64_t required_pages; int mm_status; /* Prepare a memory region to store two memory maps. */ @@ -624,22 +604,13 @@ grub_efi_mm_init (void) filtered_memory_map_end = filter_memory_map (memory_map, filtered_memory_map, desc_size, memory_map_end); - /* By default, request a quarter of the available memory. */ - total_pages = get_total_pages (filtered_memory_map, desc_size, - filtered_memory_map_end); - required_pages = (total_pages >> 2); - if (required_pages < BYTES_TO_PAGES (MIN_HEAP_SIZE)) - required_pages = BYTES_TO_PAGES (MIN_HEAP_SIZE); - else if (required_pages > BYTES_TO_PAGES (MAX_HEAP_SIZE)) - required_pages = BYTES_TO_PAGES (MAX_HEAP_SIZE); - /* Sort the filtered descriptors, so that GRUB can allocate pages from smaller regions. */ sort_memory_map (filtered_memory_map, desc_size, filtered_memory_map_end); /* Allocate memory regions for GRUB's memory management. */ add_memory_regions (filtered_memory_map, desc_size, - filtered_memory_map_end, required_pages); + filtered_memory_map_end, BYTES_TO_PAGES (DEFAULT_HEAP_SIZE)); #if 0 /* For debug. */ -- 2.30.2