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

@@ -30,7 +30,6 @@ namespace MM
STATIC ULONGLONG NumberOfPhysicalPages; STATIC ULONGLONG NumberOfPhysicalPages;
STATIC LOADER_MEMORY_DESCRIPTOR OriginalFreeDescriptor; STATIC LOADER_MEMORY_DESCRIPTOR OriginalFreeDescriptor;
STATIC PMMPFNLIST PageLocationList[]; STATIC PMMPFNLIST PageLocationList[];
STATIC PFN_NUMBER PfnDatabaseSize;
STATIC MMPFNLIST RomPagesList; STATIC MMPFNLIST RomPagesList;
STATIC MMPFNLIST StandbyPagesList; STATIC MMPFNLIST StandbyPagesList;
STATIC MMPFNLIST ZeroedPagesList; STATIC MMPFNLIST ZeroedPagesList;
@@ -38,7 +37,7 @@ namespace MM
public: public:
STATIC XTAPI PFN_NUMBER AllocateBootstrapPages(IN PFN_NUMBER NumberOfPages); STATIC XTAPI PFN_NUMBER AllocateBootstrapPages(IN PFN_NUMBER NumberOfPages);
STATIC XTAPI PFN_NUMBER AllocatePhysicalPage(IN ULONG Color); STATIC XTAPI PFN_NUMBER AllocatePhysicalPage(IN ULONG Color);
STATIC XTAPI VOID ComputePfnDatabaseSize(VOID); STATIC XTAPI VOID ComputePfnDatabaseSize(OUT PPFN_NUMBER DatabaseSize);
STATIC XTAPI VOID DecrementReferenceCount(IN PMMPFN Pfn1, STATIC XTAPI VOID DecrementReferenceCount(IN PMMPFN Pfn1,
IN PFN_NUMBER PageFrameIndex, IN PFN_NUMBER PageFrameIndex,
IN BOOLEAN BeginStandbyList = FALSE); IN BOOLEAN BeginStandbyList = FALSE);
@@ -48,7 +47,6 @@ namespace MM
STATIC XTAPI VOID FreePhysicalPage(IN PMMPTE PointerPte); STATIC XTAPI VOID FreePhysicalPage(IN PMMPTE PointerPte);
STATIC XTAPI ULONG_PTR GetHighestPhysicalPage(VOID); STATIC XTAPI ULONG_PTR GetHighestPhysicalPage(VOID);
STATIC XTAPI ULONGLONG GetNumberOfPhysicalPages(VOID); STATIC XTAPI ULONGLONG GetNumberOfPhysicalPages(VOID);
STATIC XTAPI PFN_NUMBER GetPfnDatabaseSize(VOID);
STATIC XTAPI PMMPFN GetPfnEntry(IN PFN_NUMBER Pfn); STATIC XTAPI PMMPFN GetPfnEntry(IN PFN_NUMBER Pfn);
STATIC XTAPI VOID InitializePfnDatabase(VOID); STATIC XTAPI VOID InitializePfnDatabase(VOID);
STATIC VOID XTAPI LinkPfnToPte(IN PFN_NUMBER PageFrameIndex, STATIC VOID XTAPI LinkPfnToPte(IN PFN_NUMBER PageFrameIndex,

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -112,9 +112,6 @@ MM::Manager::InitializeMemoryManager(VOID)
/* Compute page colors to reduce CPU cache conflicts */ /* Compute page colors to reduce CPU cache conflicts */
MM::Colors::ComputePageColoring(); MM::Colors::ComputePageColoring();
/* Compute allocation size for the PFN database */
MM::Pfn::ComputePfnDatabaseSize();
/* Initialize memory layout */ /* Initialize memory layout */
InitializeMemoryLayout(); 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. * 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. * @return This routine does not return any value.
* *
* @since XT 1.0 * @since XT 1.0
*/ */
XTAPI XTAPI
VOID 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 */ /* Calculate the total number of pages required for the PFN database */
PfnDatabaseSize = (HighestPhysicalPage + 1) * sizeof(MMPFN); PfnDatabaseSize = (HighestPhysicalPage + 1) * sizeof(MMPFN);
PfnDatabaseSize += (MM::Colors::GetPagingColors() * sizeof(MMCOLOR_TABLES) * 2); PfnDatabaseSize += (MM::Colors::GetPagingColors() * sizeof(MMCOLOR_TABLES) * 2);
PfnDatabaseSize = ROUND_UP(PfnDatabaseSize, MM_PAGE_SIZE); PfnDatabaseSize = ROUND_UP(PfnDatabaseSize, MM_PAGE_SIZE);
PfnDatabaseSize >>= MM_PAGE_SHIFT; PfnDatabaseSize >>= MM_PAGE_SHIFT;
/* Return the PFN database size */
*DatabaseSize = PfnDatabaseSize;
} }
/** /**
@@ -373,21 +381,6 @@ MM::Pfn::GetNumberOfPhysicalPages(VOID)
return NumberOfPhysicalPages; 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. * Retrieves a pointer to the PFN database entry for a given physical page.
* *