Skip to content

[REBASE & FF] Add PEI Memory Bins#1759

Open
os-d wants to merge 9 commits intomicrosoft:release/202511from
os-d:mem_bin_mu
Open

[REBASE & FF] Add PEI Memory Bins#1759
os-d wants to merge 9 commits intomicrosoft:release/202511from
os-d:mem_bin_mu

Conversation

@os-d
Copy link
Copy Markdown
Contributor

@os-d os-d commented Apr 10, 2026

Description

Due to the slow speed of review in edk2 and the platform need for this feature now, tianocore/edk2#12086 is being brought to Mu first.

This also reverts a Mu change around memory bins that was rejected upstream in favor of a different approach brought in with the PEI bins.

  • Impacts functionality?
  • Impacts security?
  • Breaking change?
  • Includes tests?
  • Includes documentation?

How This Was Tested

Physical and virtual platforms with a variety of scenarios, detailed in edk2 PR.

Integration Instructions

To opt into PEI memory bins a platform must, in any order:

  • Set gEfiMdeModulePkgTokenSpaceGuid.PcdPeiMemoryBinsEnable to TRUE in their DSC.
  • Produce the Memory Type Information HOB in SEC or pre-mem PEI.
  • Optionally produce the Resource Descriptor HOB owned by gEfiMemoryTypeInformationGuid in SEC or pre-mem PEI. This must
    not be produced post-mem or DXE will ignore the PEI memory bins because of conflicting Resource Descriptor HOBs.

os-d added 9 commits April 10, 2026 09:23
…t type information (microsoft#1429)"

This reverts commit b79a6ef as it
was rejected upstream in favor a different solution.
This commits splits out logic currently contained in
Gcd.c and Page.c to a new file called
MemoryBin.c. This is set up in preparation to
add support to PEI for memory bins (an S4 resume stability
feature).

MemoryBin.c takes all global state in as parameters so that
DXE core can use globals and PEI core can use HOBs.

This was requested not to be a library.

Signed-off-by: Oliver Smith-Denny <osde@microsoft.com>
Currently, there is no guarantee that the memory bins will be
allocated contiguously. However, this is a requirement to use
the resource descriptor HOB that describes the memory bin
range.

This commit updates AllocateMemoryTypeInformationBins() to
allocate a contiguous range.

Signed-off-by: Oliver Smith-Denny <osde@microsoft.com>
CoreSetMemoryTypeInformationRange() currently calculates the bin
size needed independently from the CalculateTotalMemoryBinSizeNeeded()
function. This commit updates to use that function and remove the
duplication.

Signed-off-by: Oliver Smith-Denny <osde@microsoft.com>
In order to prepare for PEI core to use the memory bin
feature, add a DefaultBin field to the stats structure
to track which bins simply point to the default bin.

This also adds a helper function to initialize the statistics.

Signed-off-by: Oliver Smith-Denny <osde@microsoft.com>
This commit adds a parameter to the memory bin allocation function
to tell it whether it should create the Resource Descriptor HOB
owned by gMemoryTypeInformationGuid. This will be used by PEI to
tell DXE where the memory bins are.

Signed-off-by: Oliver Smith-Denny <osde@microsoft.com>
This commit adds opt-in support for post-mem PEI memory bins.
See the README for full details.

MemoryBin.c is duplicated to PeiCore per request.

Signed-off-by: Oliver Smith-Denny <osde@microsoft.com>
If memory bins are enabled for PEI, PEI will produce
Memory Allocation HOBs marked with gEfiMemoryTypeInformationGuid.
If these exist, DXE core will now process the stats from them
to have accurate numbers.

Signed-off-by: Oliver Smith-Denny <osde@microsoft.com>
This commit adds unit tests and documentation for the Memory Bin
feature.

Signed-off-by: Oliver Smith-Denny <osde@microsoft.com>
@os-d os-d requested review from kuqin12 and makubacki April 10, 2026 18:17
@mu-automation
Copy link
Copy Markdown
Contributor

mu-automation bot commented Apr 10, 2026

✅ QEMU Validation Passed

Source Dependencies

Repository Commit
mu_basecore f74d16a
mu_tiano_platforms e7f5cec

Results

Platform Target Build Boot Overall Boot Time Build Logs Boot Logs
Q35 DEBUG ✅ success ✅ success 0m 17s Build Logs Boot Logs
SBSA DEBUG ✅ success ✅ success 0m 30s Build Logs Boot Logs

Workflow run: https://github.com/microsoft/mu_basecore/actions/runs/24257963960

This comment was automatically generated by the Mu QEMU PR Validation workflow.

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Apr 10, 2026

Codecov Report

❌ Patch coverage is 16.61507% with 808 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (release/202511@4db4609). Learn more about missing BASE report.

Files with missing lines Patch % Lines
MdeModulePkg/Core/Pei/Memory/MemoryBin.c 0.00% 275 Missing ⚠️
MdeModulePkg/Core/Dxe/Mem/Page.c 0.00% 270 Missing ⚠️
MdeModulePkg/Core/Pei/Memory/MemoryServices.c 0.00% 223 Missing ⚠️
MdeModulePkg/Core/Dxe/Mem/MemoryBin.c 80.50% 32 Missing and 7 partials ⚠️
MdeModulePkg/Core/Dxe/Gcd/Gcd.c 0.00% 1 Missing ⚠️
Additional details and impacted files
@@                Coverage Diff                @@
##             release/202511    #1759   +/-   ##
=================================================
  Coverage                  ?    1.88%           
=================================================
  Files                     ?     1152           
  Lines                     ?   376482           
  Branches                  ?     3282           
=================================================
  Hits                      ?     7097           
  Misses                    ?   369322           
  Partials                  ?       63           
Flag Coverage Δ
FmpDevicePkg 9.53% <ø> (?)
MdeModulePkg 1.64% <16.61%> (?)
NetworkPkg 0.55% <ø> (?)
PolicyServicePkg 30.42% <ø> (?)
SecurityPkg 1.61% <ø> (?)
UefiCpuPkg 4.78% <ø> (?)
UnitTestFrameworkPkg 11.70% <ø> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants