public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Laszlo Ersek" <lersek@redhat.com>
To: devel@edk2.groups.io, kraxel@redhat.com
Cc: Jiewen Yao <jiewen.yao@intel.com>,
	Oliver Steffen <osteffen@redhat.com>,
	Ard Biesheuvel <ardb+tianocore@kernel.org>
Subject: Re: [edk2-devel] [PATCH v2 2/4] OvmfPkg/PlatformPei: consider AP stacks for pei memory cap
Date: Mon, 5 Feb 2024 08:57:46 +0100	[thread overview]
Message-ID: <0299daa3-b139-dc10-ecbc-0863c40bbd39@redhat.com> (raw)
In-Reply-To: <20240202104720.1275308-3-kraxel@redhat.com>

On 2/2/24 11:47, Gerd Hoffmann wrote:
> Needed to avoid running out of memory when booting
> with a large (~2048) number of vcpus.
> 
> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
> ---
>  OvmfPkg/PlatformPei/MemDetect.c | 17 ++++++++++++++---
>  1 file changed, 14 insertions(+), 3 deletions(-)
> 
> diff --git a/OvmfPkg/PlatformPei/MemDetect.c b/OvmfPkg/PlatformPei/MemDetect.c
> index 1684a3783546..83f1c1d02a26 100644
> --- a/OvmfPkg/PlatformPei/MemDetect.c
> +++ b/OvmfPkg/PlatformPei/MemDetect.c
> @@ -187,6 +187,8 @@ GetPeiMemoryCap (
>    UINT32   Pml4Entries;
>    UINT32   PdpEntries;
>    UINTN    TotalPages;
> +  UINT64   ApStacks;
> +  UINT64   MemoryCap;
>  
>    //
>    // If DXE is 32-bit, then just return the traditional 64 MB cap.
> @@ -234,12 +236,21 @@ GetPeiMemoryCap (
>                 (PdpEntries + 1) * Pml4Entries + 1;
>    ASSERT (TotalPages <= 0x40201);
>  
> +  //
> +  // With 32k stacks and 4096 vcpus this lands at 128 MB (far away
> +  // from MAX_UINT32).
> +  //
> +  ApStacks = PlatformInfoHob->PcdCpuMaxLogicalProcessorNumber * PcdGet32 (PcdCpuApStackSize);
> +
>    //
>    // Add 64 MB for miscellaneous allocations. Note that for
> -  // PhysMemAddressWidth values close to 36, the cap will actually be
> -  // dominated by this increment.
> +  // PhysMemAddressWidth values close to 36 and a small number of
> +  // CPUs, the cap will actually be dominated by this increment.
>    //
> -  return (UINT32)(EFI_PAGES_TO_SIZE (TotalPages) + SIZE_64MB);
> +  MemoryCap = EFI_PAGES_TO_SIZE (TotalPages) + ApStacks + SIZE_64MB;
> +
> +  ASSERT (MemoryCap <= MAX_UINT32);
> +  return (UINT32)MemoryCap;
>  }
>  
>  /**

Yes, this looks good. At this point, EFI_PAGES_TO_SIZE (TotalPages) is
~1GB at most, and ApStacks is empirically <= 128 MB, plus ApStacks is
UINT64. Therefore on IA32X64 we have

  UINT64 = (UINT32 + UINT64) + INT32
->
  UINT64 = (UINT64 + UINT64) + INT32
->
  UINT64 = UINT64 + INT32
->
  UINT64 = UINT64 + UINT64
->
  UINT64 = UINT64

OK!

Reviewed-by: Laszlo Ersek <lersek@redhat.com>




-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#115103): https://edk2.groups.io/g/devel/message/115103
Mute This Topic: https://groups.io/mt/104117099/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



  reply	other threads:[~2024-02-05  7:57 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-02 10:47 [edk2-devel] [PATCH v2 0/4] OvmfPkg/PlatformPei: scaleability fixes for GetPeiMemoryCap() Gerd Hoffmann
2024-02-02 10:47 ` [edk2-devel] [PATCH v2 1/4] OvmfPkg/PlatformPei: log a warning when memory is tight Gerd Hoffmann
2024-02-05  7:45   ` Laszlo Ersek
2024-02-02 10:47 ` [edk2-devel] [PATCH v2 2/4] OvmfPkg/PlatformPei: consider AP stacks for pei memory cap Gerd Hoffmann
2024-02-05  7:57   ` Laszlo Ersek [this message]
2024-02-02 10:47 ` [edk2-devel] [PATCH v2 3/4] OvmfPkg/PlatformPei: rewrite page table calculation Gerd Hoffmann
2024-02-05  8:14   ` Laszlo Ersek
2024-02-05  8:19     ` Laszlo Ersek
2024-02-14  9:32     ` Gerd Hoffmann
2024-02-14 10:48       ` Laszlo Ersek
2024-02-14 11:07         ` Gerd Hoffmann
2024-02-14 11:58           ` Laszlo Ersek
2024-02-02 10:47 ` [edk2-devel] [PATCH v2 4/4] OvmfPkg/PlatformPei: log pei memory cap details Gerd Hoffmann
2024-02-05  8:27   ` Laszlo Ersek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=0299daa3-b139-dc10-ecbc-0863c40bbd39@redhat.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox