Move PFN database size tracking to memory layout
Some checks failed
Builds / ExectOS (amd64, release) (push) Failing after 20s
Builds / ExectOS (i686, release) (push) Failing after 22s
Builds / ExectOS (i686, debug) (push) Failing after 29s
Builds / ExectOS (amd64, debug) (push) Failing after 30s

This commit is contained in:
2026-01-29 22:26:31 +01:00
parent 58669d3074
commit 5e3fb7a5a3
8 changed files with 26 additions and 41 deletions

View File

@@ -21,7 +21,6 @@ VOID
MM::Manager::InitializeMemoryLayout(VOID)
{
ULONG_PTR PagedPoolSize, PteCount;
PFN_NUMBER PfnDatabaseSize;
ULONG PtesPerPage;
/* Get the number of PTEs per page and calculate size of paged pool (at least 32MiB) */
@@ -30,7 +29,7 @@ MM::Manager::InitializeMemoryLayout(VOID)
PagedPoolSize = PteCount * PtesPerPage * MM_PAGE_SIZE;
/* Retrieve the PFN database size */
PfnDatabaseSize = MM::Pfn::GetPfnDatabaseSize();
MM::Pfn::GetPfnDatabaseSize(&MemoryLayout.PfnDatabaseSize);
/* Define the number of system PTEs */
NumberOfSystemPtes = MM_DEFAULT_NUMBER_SYSTEM_PTES;
@@ -43,7 +42,7 @@ MM::Manager::InitializeMemoryLayout(VOID)
MemoryLayout.SelfMapAddress = (PVOID)MM_P5E_LA57_BASE;
/* Define the non-paged and paged pool regions */
MemoryLayout.NonPagedPoolStart = (PVOID)((ULONG_PTR)MemoryLayout.PfnDatabase + PfnDatabaseSize * MM_PAGE_SIZE);
MemoryLayout.NonPagedPoolStart = (PVOID)((ULONG_PTR)MemoryLayout.PfnDatabase + MemoryLayout.PfnDatabaseSize * MM_PAGE_SIZE);
MemoryLayout.NonPagedPoolEnd = (PVOID)0xFFFEFFFFFFBFFFFFULL;
MemoryLayout.PagedPoolStart = (PVOID)0xFFFEF8A000000000ULL;
MemoryLayout.PagedPoolEnd = (PVOID)(((ULONG_PTR)MemoryLayout.PagedPoolStart + PagedPoolSize) - 1);
@@ -60,7 +59,7 @@ MM::Manager::InitializeMemoryLayout(VOID)
MemoryLayout.SelfMapAddress = (PVOID)MM_PXE_BASE;
/* Define the non-paged and paged pool regions */
MemoryLayout.NonPagedPoolStart = (PVOID)((ULONG_PTR)MemoryLayout.PfnDatabase + PfnDatabaseSize * MM_PAGE_SIZE);
MemoryLayout.NonPagedPoolStart = (PVOID)((ULONG_PTR)MemoryLayout.PfnDatabase + MemoryLayout.PfnDatabaseSize * MM_PAGE_SIZE);
MemoryLayout.NonPagedPoolEnd = (PVOID)0xFFFFFFFFFFBFFFFFULL;
MemoryLayout.PagedPoolStart = (PVOID)0xFFFFF8A000000000ULL;
MemoryLayout.PagedPoolEnd = (PVOID)(((ULONG_PTR)MemoryLayout.PagedPoolStart + PagedPoolSize) - 1);

View File

@@ -40,7 +40,7 @@ MM::Pfn::InitializePfnDatabase(VOID)
MemoryLayout = MM::Manager::GetMemoryLayout();
/* Get the PFN database size and calculate the end of the PFN database virtual address space */
PfnDatabaseEnd = (PUCHAR)MemoryLayout->PfnDatabase + (PfnDatabaseSize * MM_PAGE_SIZE) - 1;
PfnDatabaseEnd = (PUCHAR)MemoryLayout->PfnDatabase + (MemoryLayout->PfnDatabaseSize * MM_PAGE_SIZE) - 1;
/* Get a template PTE for mapping the PFN database pages */
ValidPte = MM::Pte::GetValidPte();
@@ -88,10 +88,11 @@ MM::Pfn::InitializePfnDatabase(VOID)
if(Descriptor == FreeDescriptor)
{
/* Initialize PFNs for the remaining free memory */
ProcessMemoryDescriptor(BasePage + PfnDatabaseSize, PageCount - PfnDatabaseSize, LoaderFree);
ProcessMemoryDescriptor(BasePage + MemoryLayout->PfnDatabaseSize,
PageCount - MemoryLayout->PfnDatabaseSize, LoaderFree);
/* Initialize PFNs for the physical pages backing the PFN database */
ProcessMemoryDescriptor(BasePage, PfnDatabaseSize, LoaderMemoryData);
ProcessMemoryDescriptor(BasePage, MemoryLayout->PfnDatabaseSize, LoaderMemoryData);
}
else
{

View File

@@ -82,9 +82,6 @@ PMMPFNLIST MM::Pfn::PageLocationList[] = {&ZeroedPagesList,
NULLPTR,
NULLPTR};
/* Size of the PFN database in pages */
PFN_NUMBER MM::Pfn::PfnDatabaseSize;
/* List containing pages mapped as Read-Only (ROM) */
MMPFNLIST MM::Pfn::RomPagesList = {0, StandbyPageList, MAXULONG_PTR, MAXULONG_PTR};

View File

@@ -21,7 +21,7 @@ VOID
MM::Manager::InitializeMemoryLayout(VOID)
{
ULONG_PTR PagedPoolSize, PteCount;
PFN_NUMBER PfnDatabaseSize, PhysicalPages;
PFN_NUMBER PhysicalPages;
ULONG PtesPerPage;
/* Define the number of system PTEs */
@@ -48,7 +48,7 @@ MM::Manager::InitializeMemoryLayout(VOID)
PagedPoolSize = PteCount * PtesPerPage * MM_PAGE_SIZE;
/* Retrieve the PFN database size */
PfnDatabaseSize = MM::Pfn::GetPfnDatabaseSize();
MM::Pfn::GetPfnDatabaseSize(&MemoryLayout.PfnDatabaseSize);
/* Check if 3-level paging (PAE) is enabled */
if(MM::Paging::GetXpaStatus())
@@ -58,7 +58,7 @@ MM::Manager::InitializeMemoryLayout(VOID)
MemoryLayout.SelfMapAddress = (PVOID)MM_PTE_BASE;
/* Define the non-paged and paged pool regions */
MemoryLayout.NonPagedPoolStart = (PVOID)((ULONG_PTR)MemoryLayout.PfnDatabase + PfnDatabaseSize * MM_PAGE_SIZE);
MemoryLayout.NonPagedPoolStart = (PVOID)((ULONG_PTR)MemoryLayout.PfnDatabase + MemoryLayout.PfnDatabaseSize * MM_PAGE_SIZE);
MemoryLayout.NonPagedPoolEnd = (PVOID)0xEEFFFFFF;
MemoryLayout.PagedPoolStart = (PVOID)0xE2000000;
MemoryLayout.PagedPoolEnd = (PVOID)(((ULONG_PTR)MemoryLayout.PagedPoolStart + PagedPoolSize) - 1);
@@ -75,7 +75,7 @@ MM::Manager::InitializeMemoryLayout(VOID)
MemoryLayout.SelfMapAddress = (PVOID)MM_PTE_BASE;
/* Define the non-paged and paged pool regions */
MemoryLayout.NonPagedPoolStart = (PVOID)((ULONG_PTR)MemoryLayout.PfnDatabase + PfnDatabaseSize * MM_PAGE_SIZE);
MemoryLayout.NonPagedPoolStart = (PVOID)((ULONG_PTR)MemoryLayout.PfnDatabase + MemoryLayout.PfnDatabaseSize * MM_PAGE_SIZE);
MemoryLayout.NonPagedPoolEnd = (PVOID)0xFFBE0000;
MemoryLayout.PagedPoolStart = (PVOID)0xE1000000;
MemoryLayout.PagedPoolEnd = (PVOID)(((ULONG_PTR)MemoryLayout.PagedPoolStart + PagedPoolSize) - 1);

View File

@@ -39,7 +39,7 @@ MM::Pfn::InitializePfnDatabase(VOID)
MemoryLayout = MM::Manager::GetMemoryLayout();
/* Get the PFN database size and calculate the end of the PFN database virtual address space */
PfnDatabaseEnd = (PUCHAR)MemoryLayout->PfnDatabase + (PfnDatabaseSize * MM_PAGE_SIZE) - 1;
PfnDatabaseEnd = (PUCHAR)MemoryLayout->PfnDatabase + (MemoryLayout->PfnDatabaseSize * MM_PAGE_SIZE) - 1;
/* Get a template PTE for mapping the PFN database pages */
ValidPte = MM::Pte::GetValidPte();
@@ -49,7 +49,7 @@ MM::Pfn::InitializePfnDatabase(VOID)
MM::Pte::MapPTE(MemoryLayout->PfnDatabase, PfnDatabaseEnd, ValidPte);
/* Zero PFN database virtual space */
RTL::Memory::ZeroMemory(MemoryLayout->PfnDatabase, PfnDatabaseSize * MM_PAGE_SIZE);
RTL::Memory::ZeroMemory(MemoryLayout->PfnDatabase, MemoryLayout->PfnDatabaseSize * MM_PAGE_SIZE);
/* Initialize the color tables */
MM::Colors::InitializeColorTables();
@@ -73,12 +73,12 @@ MM::Pfn::InitializePfnDatabase(VOID)
if(Descriptor == FreeDescriptor)
{
/* Initialize PFNs for the remaining free memory after the PFN database */
ProcessMemoryDescriptor(OriginalFreeDescriptor.BasePage + PfnDatabaseSize,
OriginalFreeDescriptor.PageCount - PfnDatabaseSize,
ProcessMemoryDescriptor(OriginalFreeDescriptor.BasePage + MemoryLayout->PfnDatabaseSize,
OriginalFreeDescriptor.PageCount - MemoryLayout->PfnDatabaseSize,
LoaderFree);
/* Initialize PFNs for the physical pages backing the PFN database itself */
ProcessMemoryDescriptor(OriginalFreeDescriptor.BasePage, PfnDatabaseSize, LoaderMemoryData);
ProcessMemoryDescriptor(OriginalFreeDescriptor.BasePage, MemoryLayout->PfnDatabaseSize, LoaderMemoryData);
}
else
{

View File

@@ -112,9 +112,6 @@ MM::Manager::InitializeMemoryManager(VOID)
/* Compute page colors to reduce CPU cache conflicts */
MM::Colors::ComputePageColoring();
/* Compute allocation size for the PFN database */
MM::Pfn::ComputePfnDatabaseSize();
/* Initialize memory layout */
InitializeMemoryLayout();

View File

@@ -99,19 +99,27 @@ MM::Pfn::AllocatePhysicalPage(IN ULONG Color)
/**
* Calculates the total number of pages required for the PFN database and its associated color tables.
*
* @param DatabaseSize
* A pointer to a variable that will receive the number of pages required for the PFN database.
*
* @return This routine does not return any value.
*
* @since XT 1.0
*/
XTAPI
VOID
MM::Pfn::ComputePfnDatabaseSize(VOID)
MM::Pfn::ComputePfnDatabaseSize(OUT PPFN_NUMBER DatabaseSize)
{
PFN_NUMBER PfnDatabaseSize;
/* Calculate the total number of pages required for the PFN database */
PfnDatabaseSize = (HighestPhysicalPage + 1) * sizeof(MMPFN);
PfnDatabaseSize += (MM::Colors::GetPagingColors() * sizeof(MMCOLOR_TABLES) * 2);
PfnDatabaseSize = ROUND_UP(PfnDatabaseSize, MM_PAGE_SIZE);
PfnDatabaseSize >>= MM_PAGE_SHIFT;
/* Return the PFN database size */
*DatabaseSize = PfnDatabaseSize;
}
/**
@@ -373,21 +381,6 @@ MM::Pfn::GetNumberOfPhysicalPages(VOID)
return NumberOfPhysicalPages;
}
/**
* Gets the size of the PFN database and its associated structures, in pages.
*
* @return This routine returns the total number of pages required for the PFN database and its associated structures.
*
* @since XT 1.0
*/
XTAPI
PFN_NUMBER
MM::Pfn::GetPfnDatabaseSize(VOID)
{
/* Return the pre-calculated size of the PFN database in pages */
return PfnDatabaseSize;
}
/**
* Retrieves a pointer to the PFN database entry for a given physical page.
*