Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1nhPJR-0005Ki-CD for mharc-grub-devel@gnu.org; Thu, 21 Apr 2022 01:25:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42718) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nhPJP-0005Da-5E for grub-devel@gnu.org; Thu, 21 Apr 2022 01:25:03 -0400 Received: from mail-pf1-x429.google.com ([2607:f8b0:4864:20::429]:43771) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nhPJN-0005fA-CI for grub-devel@gnu.org; Thu, 21 Apr 2022 01:25:02 -0400 Received: by mail-pf1-x429.google.com with SMTP id y14so3191285pfe.10 for ; Wed, 20 Apr 2022 22:25:00 -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=QpMKCl+ZN6ZuG1UBzYAmTWIcf9U9ZETZFTFApRPo6f4=; b=PmqKjlM5NMMFpAbXFdSkfD4ryfKA/eXQS6/MreKTmPbh+Z/ERTSkzcBtokhGGvL8RX sq7PIUw3yYPA35izK9rh2OnvJP6TNyyWmE8dcQzkuDblB9gzubQ9UwSmqI0WlM5uh0Az 9xRJGNEcFeWS7GnjoLDkJObT3p1BI/RzoE2jc= 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=QpMKCl+ZN6ZuG1UBzYAmTWIcf9U9ZETZFTFApRPo6f4=; b=0qU8+2jRuxlio0l/rmEO8u119F9Aa4u3xH7e2f4KXw/rGVym4Kl4V80Lqmiz/FCt8h yZ8SZ+zI6JsJXc1MMN8YCfpqNrsHD5OpjlS0OX7wC9M/3AooMVceRWTuJWfQWfj8n5lP 7y5EM8xQzQq0rs3A6bCYPxrOpLFhWiJ6Lz/5Sg/hPsnJOMVrnGJBceXmwCRpdGxKfNkm HdSJy7qZ2iXJx0uQuXIQOKB+RV1YdNuyu5QNX/9jLAcMvGmAX+Ne2CWnJqkix3Fmhu0w olfAewrFVAmqM81H2tIp54YcsN352a8RuNrcEgILOgLrGsv7ISZ0gYVx6d0ZSt25X3fm SmwQ== X-Gm-Message-State: AOAM530Vnj1VzJuAZBM9t6BeLmfxjTxspembHaIcQ6wJ23T/qpkDLkba ujPVb5J/k096rHiTMBST2Tjh+mdanSdPNA== X-Google-Smtp-Source: ABdhPJzCY/EEt1/DXi/3u7RYgHMVbVMTLT40AHfDneT7C09HwfAqhYdYBPZVdk8sZzhRqX5P9u79Ew== X-Received: by 2002:a63:6c02:0:b0:398:833b:f739 with SMTP id h2-20020a636c02000000b00398833bf739mr22809857pgc.524.1650518699857; Wed, 20 Apr 2022 22:24:59 -0700 (PDT) Received: from localhost ([2001:4479:e000:e400:4260:be14:52a8:8c94]) by smtp.gmail.com with ESMTPSA id y9-20020aa79429000000b0050ad02027d9sm2766503pfo.197.2022.04.20.22.24.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Apr 2022 22:24:59 -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, Daniel Axtens , Daniel Kiper Subject: [PATCH v3 07/15] efi: mm: Always request a fixed number of pages on init Date: Thu, 21 Apr 2022 15:24:19 +1000 Message-Id: <20220421052427.1389987-8-dja@axtens.net> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220421052427.1389987-1-dja@axtens.net> References: <20220421052427.1389987-1-dja@axtens.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2607:f8b0:4864:20::429; envelope-from=dja@axtens.net; helo=mail-pf1-x429.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, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 21 Apr 2022 05:25:03 -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 Signed-off-by: Daniel Axtens Reviewed-by: Daniel Kiper --- 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 d8e4114541a4..0bccd24f304f 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.32.0