Author: sir_richard
Date: Thu Nov 11 13:15:40 2010
New Revision: 49559
URL: http://svn.reactos.org/svn/reactos?rev=49559&view=rev
Log:
[NTOS]: Start using colored pages. This will help performance on real systems significantly as cache is now taken into account by the memory manager. Also radically changes the way page allocations are given out and creates a less uniform physical memory layout. The fact this now works means that the PFN lists are finally now sane.
Modified:
trunk/reactos/ntoskrnl/mm/ARM3/pfnlist.c
Modified: trunk/reactos/ntoskrnl/mm/ARM3/pfnlist.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/mm/ARM3/pfnlist.c…
==============================================================================
--- trunk/reactos/ntoskrnl/mm/ARM3/pfnlist.c [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/mm/ARM3/pfnlist.c [iso-8859-1] Thu Nov 11 13:15:40 2010
@@ -356,18 +356,15 @@
ASSERT(KeGetCurrentIrql() == DISPATCH_LEVEL);
ASSERT(MmAvailablePages != 0);
ASSERT(Color < MmSecondaryColors);
-#if 0
+
/* Check the colored free list */
PageIndex = MmFreePagesByColor[FreePageList][Color].Flink;
- DPRINT1("Found free page: %lx\n", PageIndex);
if (PageIndex == LIST_HEAD)
{
/* Check the colored zero list */
PageIndex = MmFreePagesByColor[ZeroedPageList][Color].Flink;
- DPRINT1("Found zero page: %lx\n", PageIndex);
if (PageIndex == LIST_HEAD)
{
-#endif
/* Check the free list */
ASSERT_LIST_INVARIANT(&MmFreePageListHead);
PageIndex = MmFreePageListHead.Flink;
@@ -385,10 +382,9 @@
ASSERT(MmZeroedPageListHead.Total == 0);
}
}
-#if 0
}
}
-#endif
+
/* Remove the page from its list */
PageIndex = MiRemovePageByColor(PageIndex, Color);
@@ -419,11 +415,9 @@
ASSERT(Color < MmSecondaryColors);
/* Check the colored zero list */
-#if 0
PageIndex = MmFreePagesByColor[ZeroedPageList][Color].Flink;
if (PageIndex == LIST_HEAD)
{
-#endif
/* Check the zero list */
ASSERT_LIST_INVARIANT(&MmZeroedPageListHead);
PageIndex = MmZeroedPageListHead.Flink;
@@ -433,12 +427,11 @@
/* This means there's no zero pages, we have to look for free ones */
ASSERT(MmZeroedPageListHead.Total == 0);
Zero = TRUE;
-#if 0
+
/* Check the colored free list */
PageIndex = MmFreePagesByColor[FreePageList][Color].Flink;
if (PageIndex == LIST_HEAD)
{
-#endif
/* Check the free list */
ASSERT_LIST_INVARIANT(&MmFreePageListHead);
PageIndex = MmFreePageListHead.Flink;
@@ -449,13 +442,9 @@
/* FIXME: Should check the standby list */
ASSERT(MmZeroedPageListHead.Total == 0);
}
-#if 0
}
-#endif
}
-#if 0
- }
-#endif
+ }
/* Sanity checks */
Pfn1 = MI_PFN_ELEMENT(PageIndex);
Author: sir_richard
Date: Thu Nov 11 13:13:05 2010
New Revision: 49558
URL: http://svn.reactos.org/svn/reactos?rev=49558&view=rev
Log:
[NTOS]: Use MI_PFN_ELEMENT in this code, as the extra checks done by MiGetPfnEntry are irrelevant and slow things down.
[NTOS]: Remove some old ReactOS hacks before we had MMROSPFNDATA.
Modified:
trunk/reactos/ntoskrnl/mm/ARM3/pfnlist.c
Modified: trunk/reactos/ntoskrnl/mm/ARM3/pfnlist.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/mm/ARM3/pfnlist.c…
==============================================================================
--- trunk/reactos/ntoskrnl/mm/ARM3/pfnlist.c [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/mm/ARM3/pfnlist.c [iso-8859-1] Thu Nov 11 13:13:05 2010
@@ -113,7 +113,7 @@
if (OldFlink != LIST_HEAD)
{
/* It is not, so set the backlink of the actual entry, to our backlink */
- MiGetPfnEntry(OldFlink)->u2.Blink = OldBlink;
+ MI_PFN_ELEMENT(OldFlink)->u2.Blink = OldBlink;
}
else
{
@@ -125,7 +125,7 @@
if (OldBlink != LIST_HEAD)
{
/* It is not, so set the backlink of the actual entry, to our backlink */
- MiGetPfnEntry(OldBlink)->u1.Flink = OldFlink;
+ MI_PFN_ELEMENT(OldBlink)->u1.Flink = OldFlink;
}
else
{
@@ -149,7 +149,7 @@
if (ColorTable->Flink != LIST_HEAD)
{
/* And make the previous link point to the head now */
- MiGetPfnEntry(ColorTable->Flink)->u4.PteFrame = COLORED_LIST_HEAD;
+ MI_PFN_ELEMENT(ColorTable->Flink)->u4.PteFrame = COLORED_LIST_HEAD;
}
else
{
@@ -163,14 +163,14 @@
ASSERT(Entry->u4.PteFrame != COLORED_LIST_HEAD);
/* Make the back link point to whoever the next page is */
- Pfn1 = MiGetPfnEntry(Entry->u4.PteFrame);
+ Pfn1 = MI_PFN_ELEMENT(Entry->u4.PteFrame);
Pfn1->OriginalPte.u.Long = Entry->OriginalPte.u.Long;
/* Check if this page was pointing to the head */
if (Entry->OriginalPte.u.Long != LIST_HEAD)
{
/* Make the back link point to the head */
- Pfn1 = MiGetPfnEntry(Entry->OriginalPte.u.Long);
+ Pfn1 = MI_PFN_ELEMENT(Entry->OriginalPte.u.Long);
Pfn1->u4.PteFrame = Entry->u4.PteFrame;
}
else
@@ -235,7 +235,7 @@
ASSERT(Color < MmSecondaryColors);
/* Get the PFN entry */
- Pfn1 = MiGetPfnEntry(PageIndex);
+ Pfn1 = MI_PFN_ELEMENT(PageIndex);
ASSERT(Pfn1->u3.e1.RemovalRequested == 0);
ASSERT(Pfn1->u3.e1.Rom == 0);
@@ -260,7 +260,7 @@
if (OldFlink != LIST_HEAD)
{
/* It is not, so set the backlink of the actual entry, to our backlink */
- MiGetPfnEntry(OldFlink)->u2.Blink = OldBlink;
+ MI_PFN_ELEMENT(OldFlink)->u2.Blink = OldBlink;
}
else
{
@@ -272,7 +272,7 @@
if (OldBlink != LIST_HEAD)
{
/* It is not, so set the backlink of the actual entry, to our backlink */
- MiGetPfnEntry(OldBlink)->u1.Flink = OldFlink;
+ MI_PFN_ELEMENT(OldBlink)->u1.Flink = OldFlink;
}
else
{
@@ -306,7 +306,7 @@
else
{
/* The list is empty, so we are the first page */
- MiGetPfnEntry(ColorTable->Flink)->u4.PteFrame = COLORED_LIST_HEAD;
+ MI_PFN_ELEMENT(ColorTable->Flink)->u4.PteFrame = COLORED_LIST_HEAD;
}
/* One less page */
@@ -393,7 +393,7 @@
PageIndex = MiRemovePageByColor(PageIndex, Color);
/* Sanity checks */
- Pfn1 = MiGetPfnEntry(PageIndex);
+ Pfn1 = MI_PFN_ELEMENT(PageIndex);
ASSERT((Pfn1->u3.e1.PageLocation == FreePageList) ||
(Pfn1->u3.e1.PageLocation == ZeroedPageList));
ASSERT(Pfn1->u3.e2.ReferenceCount == 0);
@@ -458,13 +458,13 @@
#endif
/* Sanity checks */
- Pfn1 = MiGetPfnEntry(PageIndex);
+ Pfn1 = MI_PFN_ELEMENT(PageIndex);
ASSERT((Pfn1->u3.e1.PageLocation == FreePageList) ||
(Pfn1->u3.e1.PageLocation == ZeroedPageList));
/* Remove the page from its list */
PageIndex = MiRemovePageByColor(PageIndex, Color);
- ASSERT(Pfn1 == MiGetPfnEntry(PageIndex));
+ ASSERT(Pfn1 == MI_PFN_ELEMENT(PageIndex));
/* Zero it, if needed */
if (Zero) MiZeroPhysicalPage(PageIndex);
@@ -497,7 +497,7 @@
(PageFrameIndex >= MmLowestPhysicalPage));
/* Get the PFN entry */
- Pfn1 = MiGetPfnEntry(PageFrameIndex);
+ Pfn1 = MI_PFN_ELEMENT(PageFrameIndex);
/* Sanity checks that a right kind of page is being inserted here */
ASSERT(Pfn1->u4.MustBeCached == 0);
@@ -516,7 +516,7 @@
if (LastPage != LIST_HEAD)
{
/* Link us with the previous page, so we're at the end now */
- MiGetPfnEntry(LastPage)->u1.Flink = PageFrameIndex;
+ MI_PFN_ELEMENT(LastPage)->u1.Flink = PageFrameIndex;
}
else
{
@@ -571,19 +571,15 @@
/* Get the previous page */
Blink = (PMMPFN)ColorTable->Blink;
- /* Make it link to us */
+ /* Make it link to us, and link back to it */
+ Blink->OriginalPte.u.Long = PageFrameIndex;
Pfn1->u4.PteFrame = MiGetPfnEntryIndex(Blink);
-
- /* If there is an original pte, it should be an old link, NOT a ReactOS RMAP */
- ASSERT(Blink->u4.AweAllocation == FALSE);
- Blink->OriginalPte.u.Long = PageFrameIndex;
}
/* Now initialize our own list pointers */
ColorTable->Blink = Pfn1;
- /* If there is an original pte, it should be an old link, NOT a ReactOS RMAP */
- ASSERT(Pfn1->u4.AweAllocation == FALSE);
+ /* This page is now the last */
Pfn1->OriginalPte.u.Long = LIST_HEAD;
/* And increase the count in the colored list */
@@ -627,7 +623,7 @@
(PageFrameIndex >= MmLowestPhysicalPage));
/* Page should be unused */
- Pfn1 = MiGetPfnEntry(PageFrameIndex);
+ Pfn1 = MI_PFN_ELEMENT(PageFrameIndex);
ASSERT(Pfn1->u3.e2.ReferenceCount == 0);
ASSERT(Pfn1->u3.e1.Rom != 1);
@@ -651,7 +647,7 @@
if (Flink != LIST_HEAD)
{
/* It wasn't, so update the backlink of the previous head page */
- Pfn2 = MiGetPfnEntry(Flink);
+ Pfn2 = MI_PFN_ELEMENT(Flink);
Pfn2->u2.Blink = PageFrameIndex;
}
else
@@ -691,9 +687,6 @@
/* Get the old head */
Flink = ColorHead->Flink;
- /* If there is an original pte, it should be an old link, NOT a ReactOS RMAP */
- ASSERT(Pfn1->u4.AweAllocation == FALSE);
-
/* Make this page point back to the list, and point forwards to the old head */
Pfn1->OriginalPte.u.Long = Flink;
Pfn1->u4.PteFrame = COLORED_LIST_HEAD;
@@ -705,7 +698,7 @@
if (Flink != LIST_HEAD)
{
/* No, so make the old head point to this page */
- Pfn2 = MiGetPfnEntry(Flink);
+ Pfn2 = MI_PFN_ELEMENT(Flink);
Pfn2->u4.PteFrame = PageFrameIndex;
}
else
@@ -737,7 +730,7 @@
ASSERT(KeGetCurrentIrql() == DISPATCH_LEVEL);
/* Setup the PTE */
- Pfn1 = MiGetPfnEntry(PageFrameIndex);
+ Pfn1 = MI_PFN_ELEMENT(PageFrameIndex);
Pfn1->PteAddress = PointerPte;
/* Check if this PFN is part of a valid address space */
@@ -788,7 +781,7 @@
Pfn1->u4.PteFrame = PageFrameIndex;
/* Increase its share count so we don't get rid of it */
- Pfn1 = MiGetPfnEntry(PageFrameIndex);
+ Pfn1 = MI_PFN_ELEMENT(PageFrameIndex);
Pfn1->u2.ShareCount++;
}
@@ -842,8 +835,8 @@
IN PFN_NUMBER PageFrameIndex)
{
ASSERT(PageFrameIndex > 0);
- ASSERT(MiGetPfnEntry(PageFrameIndex) != NULL);
- ASSERT(Pfn1 == MiGetPfnEntry(PageFrameIndex));
+ ASSERT(MI_PFN_ELEMENT(PageFrameIndex) != NULL);
+ ASSERT(Pfn1 == MI_PFN_ELEMENT(PageFrameIndex));
ASSERT(MI_IS_ROS_PFN(Pfn1) == FALSE);
/* Page must be in-use */
@@ -880,13 +873,7 @@
/* Clear the last reference */
Pfn1->u3.e2.ReferenceCount = 0;
-
- /*
- * OriginalPte is used by AweReferenceCount in ReactOS, but either
- * ways we shouldn't be seeing RMAP entries at this point
- */
ASSERT(Pfn1->OriginalPte.u.Soft.Prototype == 0);
- ASSERT(Pfn1->u4.AweAllocation == FALSE);
/* Mark the page temporarily as valid, we're going to make it free soon */
Pfn1->u3.e1.PageLocation = ActiveAndValid;
@@ -912,7 +899,7 @@
/* Sanity checks on the page */
ASSERT(PageFrameIndex < MmHighestPhysicalPage);
- ASSERT(Pfn1 == MiGetPfnEntry(PageFrameIndex));
+ ASSERT(Pfn1 == MI_PFN_ELEMENT(PageFrameIndex));
ASSERT(Pfn1->u3.e2.ReferenceCount != 0);
/* Dereference the page, bail out if it's still alive */
@@ -954,7 +941,7 @@
PMMPFN Pfn1;
/* Setup the PTE */
- Pfn1 = MiGetPfnEntry(PageFrameIndex);
+ Pfn1 = MI_PFN_ELEMENT(PageFrameIndex);
Pfn1->PteAddress = PointerPte;
/* Make this a software PTE */
@@ -975,7 +962,7 @@
Pfn1->u4.PteFrame = PteFrame;
/* Increase its share count so we don't get rid of it */
- Pfn1 = MiGetPfnEntry(PteFrame);
+ Pfn1 = MI_PFN_ELEMENT(PteFrame);
Pfn1->u2.ShareCount++;
}
}
Author: sir_richard
Date: Thu Nov 11 13:08:41 2010
New Revision: 49557
URL: http://svn.reactos.org/svn/reactos?rev=49557&view=rev
Log:
[NTOS]: Fix a bug in MiRemovePageByColor which caused corruption of the page list and could lead to crashes, re-use of freed memory, assuming active memory was free, etc.
Modified:
trunk/reactos/ntoskrnl/mm/ARM3/pfnlist.c
Modified: trunk/reactos/ntoskrnl/mm/ARM3/pfnlist.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/mm/ARM3/pfnlist.c…
==============================================================================
--- trunk/reactos/ntoskrnl/mm/ARM3/pfnlist.c [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/mm/ARM3/pfnlist.c [iso-8859-1] Thu Nov 11 13:08:41 2010
@@ -265,7 +265,7 @@
else
{
/* Set the list head's backlink instead */
- ListHead->Blink = OldFlink;
+ ListHead->Blink = OldBlink;
}
/* Check if the back entry is the list head */
Author: sir_richard
Date: Thu Nov 11 13:05:52 2010
New Revision: 49556
URL: http://svn.reactos.org/svn/reactos?rev=49556&view=rev
Log:
[NTOS]: Fix another bug in the continuous memory allocation code, which would go off-by-one while looping the PFN entries for the allocation, and corrupt the PteFrame/PteAddress of an unrelated PFN entry. If this PFN was in the active lists, it would cause page table leaks and faults, if the page was on a free list, it would override the colored list backlink and corrupt the list, later causing unlinked pages to remain linked to the list.
Modified:
trunk/reactos/ntoskrnl/mm/ARM3/contmem.c
Modified: trunk/reactos/ntoskrnl/mm/ARM3/contmem.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/mm/ARM3/contmem.c…
==============================================================================
--- trunk/reactos/ntoskrnl/mm/ARM3/contmem.c [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/mm/ARM3/contmem.c [iso-8859-1] Thu Nov 11 13:05:52 2010
@@ -79,7 +79,6 @@
//
if (MiIsPfnInUse(Pfn1))
{
- //DPRINT1("In use: reset\n");
Length = 0;
continue;
}
@@ -94,7 +93,6 @@
//
// It does not, so bail out
//
- //DPRINT1("Doesn't match restrictions: reset\n");
continue;
}
@@ -368,7 +366,7 @@
/* Write the PTE address */
Pfn1->PteAddress = PointerPte;
Pfn1->u4.PteFrame = PFN_FROM_PTE(MiAddressToPte(PointerPte++));
- } while (Pfn1++ < EndPfn);
+ } while (++Pfn1 < EndPfn);
/* Return the address */
return BaseAddress;