mirror of
https://github.com/reactos/reactos.git
synced 2025-08-05 18:42:56 +00:00
[NTOS]: Write missing color code in certain PFN functions, and fix existing code where needed. Add some debugging. For now, turned off until testing succeeds.
[NTOS]: Redocument which MMPFN fields are violated by ReactOS-internal values. This has gotten much better than before. svn path=/trunk/; revision=48925
This commit is contained in:
parent
119639a212
commit
f41dde713f
3 changed files with 137 additions and 33 deletions
|
@ -306,30 +306,30 @@ typedef struct _MMPFNENTRY
|
||||||
USHORT Modified:1;
|
USHORT Modified:1;
|
||||||
USHORT ReadInProgress:1; // StartOfAllocation
|
USHORT ReadInProgress:1; // StartOfAllocation
|
||||||
USHORT WriteInProgress:1; // EndOfAllocation
|
USHORT WriteInProgress:1; // EndOfAllocation
|
||||||
USHORT PrototypePte:1; // Zero
|
USHORT PrototypePte:1;
|
||||||
USHORT PageColor:4; // LockCount
|
USHORT PageColor:4;
|
||||||
USHORT PageLocation:3; // Consumer
|
USHORT PageLocation:3;
|
||||||
USHORT RemovalRequested:1;
|
USHORT RemovalRequested:1;
|
||||||
USHORT CacheAttribute:2; // Type
|
USHORT CacheAttribute:2;
|
||||||
USHORT Rom:1;
|
USHORT Rom:1;
|
||||||
USHORT ParityError:1;
|
USHORT ParityError:1; // HasRmap
|
||||||
} MMPFNENTRY;
|
} MMPFNENTRY;
|
||||||
|
|
||||||
typedef struct _MMPFN
|
typedef struct _MMPFN
|
||||||
{
|
{
|
||||||
union
|
union
|
||||||
{
|
{
|
||||||
PFN_NUMBER Flink; // ListEntry.Flink
|
PFN_NUMBER Flink;
|
||||||
ULONG WsIndex;
|
ULONG WsIndex; // SavedSwapEntry
|
||||||
PKEVENT Event;
|
PKEVENT Event;
|
||||||
NTSTATUS ReadStatus;
|
NTSTATUS ReadStatus;
|
||||||
SINGLE_LIST_ENTRY NextStackPfn;
|
SINGLE_LIST_ENTRY NextStackPfn;
|
||||||
} u1;
|
} u1;
|
||||||
PMMPTE PteAddress; // ListEntry.Blink
|
PMMPTE PteAddress;
|
||||||
union
|
union
|
||||||
{
|
{
|
||||||
PFN_NUMBER Blink;
|
PFN_NUMBER Blink;
|
||||||
ULONG_PTR ShareCount; // MapCount
|
ULONG_PTR ShareCount;
|
||||||
} u2;
|
} u2;
|
||||||
union
|
union
|
||||||
{
|
{
|
||||||
|
@ -351,7 +351,7 @@ typedef struct _MMPFN
|
||||||
};
|
};
|
||||||
union
|
union
|
||||||
{
|
{
|
||||||
ULONG_PTR EntireFrame; // SavedSwapEntry
|
ULONG_PTR EntireFrame;
|
||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
ULONG_PTR PteFrame:25;
|
ULONG_PTR PteFrame:25;
|
||||||
|
|
|
@ -933,12 +933,6 @@ MiUnlinkFreeOrZeroedPage(
|
||||||
IN PMMPFN Entry
|
IN PMMPFN Entry
|
||||||
);
|
);
|
||||||
|
|
||||||
PMMPFN
|
|
||||||
NTAPI
|
|
||||||
MiRemoveHeadList(
|
|
||||||
IN PMMPFNLIST ListHead
|
|
||||||
);
|
|
||||||
|
|
||||||
PFN_NUMBER
|
PFN_NUMBER
|
||||||
NTAPI
|
NTAPI
|
||||||
MiAllocatePfn(
|
MiAllocatePfn(
|
||||||
|
|
|
@ -78,6 +78,11 @@ MiUnlinkFreeOrZeroedPage(IN PMMPFN Entry)
|
||||||
PFN_NUMBER OldFlink, OldBlink;
|
PFN_NUMBER OldFlink, OldBlink;
|
||||||
PMMPFNLIST ListHead;
|
PMMPFNLIST ListHead;
|
||||||
MMLISTS ListName;
|
MMLISTS ListName;
|
||||||
|
#ifdef ARM3_COLORS
|
||||||
|
ULONG Color;
|
||||||
|
PMMCOLOR_TABLES ColorTable;
|
||||||
|
PMMPFN Pfn1;
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Make sure the PFN lock is held */
|
/* Make sure the PFN lock is held */
|
||||||
ASSERT(KeGetCurrentIrql() == DISPATCH_LEVEL);
|
ASSERT(KeGetCurrentIrql() == DISPATCH_LEVEL);
|
||||||
|
@ -124,13 +129,64 @@ MiUnlinkFreeOrZeroedPage(IN PMMPFN Entry)
|
||||||
/* Set the list head's backlink instead */
|
/* Set the list head's backlink instead */
|
||||||
ListHead->Flink = OldFlink;
|
ListHead->Flink = OldFlink;
|
||||||
}
|
}
|
||||||
|
#ifdef ARM3_COLORS
|
||||||
|
/* Get the page color */
|
||||||
|
OldBlink = MiGetPfnEntryIndex(Entry);
|
||||||
|
Color = OldBlink & MmSecondaryColorMask;
|
||||||
|
DPRINT1("Color: %lx\n", Color);
|
||||||
|
|
||||||
|
/* Get the first page on the color list */
|
||||||
|
ColorTable = &MmFreePagesByColor[ListName][Color];
|
||||||
|
DPRINT1("Color table: %p %lx\n", ColorTable, ColorTable->Flink);
|
||||||
|
|
||||||
|
/* Check if this was was actually the head */
|
||||||
|
OldFlink = ColorTable->Flink;
|
||||||
|
if (OldFlink == OldBlink)
|
||||||
|
{
|
||||||
|
/* Make the table point to the next page this page was linking to */
|
||||||
|
ColorTable->Flink = Entry->OriginalPte.u.Long;
|
||||||
|
if (ColorTable->Flink != LIST_HEAD)
|
||||||
|
{
|
||||||
|
/* And make the previous link point to the head now */
|
||||||
|
MiGetPfnEntry(ColorTable->Flink)->u4.PteFrame = -1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* And if that page was the head, loop the list back around */
|
||||||
|
ColorTable->Blink = (PVOID)LIST_HEAD;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* This page shouldn't be pointing back to the head */
|
||||||
|
ASSERT(Entry->u4.PteFrame != -1);
|
||||||
|
|
||||||
|
/* Make the back link point to whoever the next page is */
|
||||||
|
Pfn1 = MiGetPfnEntry(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->u4.PteFrame = -1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* Then the table is directly back pointing to this page now */
|
||||||
|
ColorTable->Blink = Pfn1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* One less colored page */
|
||||||
|
ASSERT(ColorTable->Count >= 1);
|
||||||
|
ColorTable->Count--;
|
||||||
|
#endif
|
||||||
/* We are not on a list anymore */
|
/* We are not on a list anymore */
|
||||||
Entry->u1.Flink = Entry->u2.Blink = 0;
|
Entry->u1.Flink = Entry->u2.Blink = 0;
|
||||||
ASSERT_LIST_INVARIANT(ListHead);
|
ASSERT_LIST_INVARIANT(ListHead);
|
||||||
|
|
||||||
/* FIXME: Deal with color list */
|
|
||||||
|
|
||||||
/* See if we hit any thresholds */
|
/* See if we hit any thresholds */
|
||||||
if (MmAvailablePages == MmHighMemoryThreshold)
|
if (MmAvailablePages == MmHighMemoryThreshold)
|
||||||
{
|
{
|
||||||
|
@ -160,9 +216,9 @@ MiRemovePageByColor(IN PFN_NUMBER PageIndex,
|
||||||
MMLISTS ListName;
|
MMLISTS ListName;
|
||||||
PFN_NUMBER OldFlink, OldBlink;
|
PFN_NUMBER OldFlink, OldBlink;
|
||||||
ULONG OldColor, OldCache;
|
ULONG OldColor, OldCache;
|
||||||
#if 0
|
#ifdef ARM3_COLORS
|
||||||
PMMCOLOR_TABLES ColorTable;
|
PMMCOLOR_TABLES ColorTable;
|
||||||
#endif
|
#endif
|
||||||
/* Make sure PFN lock is held */
|
/* Make sure PFN lock is held */
|
||||||
ASSERT(KeGetCurrentIrql() == DISPATCH_LEVEL);
|
ASSERT(KeGetCurrentIrql() == DISPATCH_LEVEL);
|
||||||
ASSERT(Color < MmSecondaryColors);
|
ASSERT(Color < MmSecondaryColors);
|
||||||
|
@ -221,18 +277,22 @@ MiRemovePageByColor(IN PFN_NUMBER PageIndex,
|
||||||
Pfn1->u3.e2.ShortFlags = 0;
|
Pfn1->u3.e2.ShortFlags = 0;
|
||||||
Pfn1->u3.e1.PageColor = OldColor;
|
Pfn1->u3.e1.PageColor = OldColor;
|
||||||
Pfn1->u3.e1.CacheAttribute = OldCache;
|
Pfn1->u3.e1.CacheAttribute = OldCache;
|
||||||
|
#ifdef ARM3_COLORS
|
||||||
#if 0 // When switching to ARM3
|
|
||||||
/* Get the first page on the color list */
|
/* Get the first page on the color list */
|
||||||
|
ASSERT(Color < MmSecondaryColors);
|
||||||
ColorTable = &MmFreePagesByColor[ListName][Color];
|
ColorTable = &MmFreePagesByColor[ListName][Color];
|
||||||
ASSERT(ColorTable->Count >= 1);
|
ASSERT(ColorTable->Count >= 1);
|
||||||
|
|
||||||
/* Set the forward link to whoever we were pointing to */
|
/* Set the forward link to whoever we were pointing to */
|
||||||
|
DPRINT1("Has RMAP: %lx (link: %lx)\n", Pfn1->u3.e1.ParityError, Pfn1->OriginalPte.u.Long);
|
||||||
|
DPRINT1("Color table: %p %lx\n", ColorTable, ColorTable->Flink);
|
||||||
ColorTable->Flink = Pfn1->OriginalPte.u.Long;
|
ColorTable->Flink = Pfn1->OriginalPte.u.Long;
|
||||||
|
|
||||||
|
/* Get the first page on the color list */
|
||||||
if (ColorTable->Flink == LIST_HEAD)
|
if (ColorTable->Flink == LIST_HEAD)
|
||||||
{
|
{
|
||||||
/* This is the beginning of the list, so set the sentinel value */
|
/* This is the beginning of the list, so set the sentinel value */
|
||||||
ColorTable->Blink = LIST_HEAD;
|
ColorTable->Blink = (PVOID)LIST_HEAD;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -240,8 +300,8 @@ MiRemovePageByColor(IN PFN_NUMBER PageIndex,
|
||||||
MiGetPfnEntry(ColorTable->Flink)->u4.PteFrame = -1;
|
MiGetPfnEntry(ColorTable->Flink)->u4.PteFrame = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* One more page */
|
/* One less page */
|
||||||
ColorTable->Total++;
|
ColorTable->Count--;
|
||||||
#endif
|
#endif
|
||||||
/* See if we hit any thresholds */
|
/* See if we hit any thresholds */
|
||||||
if (MmAvailablePages == MmHighMemoryThreshold)
|
if (MmAvailablePages == MmHighMemoryThreshold)
|
||||||
|
@ -404,7 +464,7 @@ MiInsertPageInFreeList(IN PFN_NUMBER PageFrameIndex)
|
||||||
PMMPFNLIST ListHead;
|
PMMPFNLIST ListHead;
|
||||||
PFN_NUMBER LastPage;
|
PFN_NUMBER LastPage;
|
||||||
PMMPFN Pfn1;
|
PMMPFN Pfn1;
|
||||||
#if 0
|
#ifdef ARM3_COLORS
|
||||||
ULONG Color;
|
ULONG Color;
|
||||||
PMMPFN Blink;
|
PMMPFN Blink;
|
||||||
PMMCOLOR_TABLES ColorTable;
|
PMMCOLOR_TABLES ColorTable;
|
||||||
|
@ -473,13 +533,15 @@ MiInsertPageInFreeList(IN PFN_NUMBER PageFrameIndex)
|
||||||
/* Otherwise check if we reached the high threshold and signal the event */
|
/* Otherwise check if we reached the high threshold and signal the event */
|
||||||
KeSetEvent(MiHighMemoryEvent, 0, FALSE);
|
KeSetEvent(MiHighMemoryEvent, 0, FALSE);
|
||||||
}
|
}
|
||||||
|
#ifdef ARM3_COLORS
|
||||||
#if 0 // When using ARM3 PFN
|
|
||||||
/* Get the page color */
|
/* Get the page color */
|
||||||
Color = PageFrameIndex & MmSecondaryColorMask;
|
Color = PageFrameIndex & MmSecondaryColorMask;
|
||||||
|
DPRINT1("Color: %lx\n", Color);
|
||||||
|
|
||||||
/* Get the first page on the color list */
|
/* Get the first page on the color list */
|
||||||
ColorTable = &MmFreePagesByColor[FreePageList][Color];
|
ColorTable = &MmFreePagesByColor[FreePageList][Color];
|
||||||
|
DPRINT1("Color table: %p %lx\n", ColorTable, ColorTable->Flink);
|
||||||
|
DPRINT1("Has RMAP: %lx (link: %lx)\n", Pfn1->u3.e1.ParityError, Pfn1->OriginalPte.u.Long);
|
||||||
if (ColorTable->Flink == LIST_HEAD)
|
if (ColorTable->Flink == LIST_HEAD)
|
||||||
{
|
{
|
||||||
/* The list is empty, so we are the first page */
|
/* The list is empty, so we are the first page */
|
||||||
|
@ -492,18 +554,24 @@ MiInsertPageInFreeList(IN PFN_NUMBER PageFrameIndex)
|
||||||
Blink = (PMMPFN)ColorTable->Blink;
|
Blink = (PMMPFN)ColorTable->Blink;
|
||||||
|
|
||||||
/* Make it link to us */
|
/* Make it link to us */
|
||||||
Pfn1->u4.PteFrame = MI_PFNENTRY_TO_PFN(Blink);
|
Pfn1->u4.PteFrame = MiGetPfnEntryIndex(Blink);
|
||||||
|
|
||||||
|
/* If there is an original pte, it should be an old link, NOT a ReactOS RMAP */
|
||||||
|
DPRINT1("Has RMAP: %lx (link: %lx)\n", Blink->u3.e1.ParityError, Blink->OriginalPte.u.Long);
|
||||||
|
ASSERT(Blink->u3.e1.ParityError == FALSE);
|
||||||
Blink->OriginalPte.u.Long = PageFrameIndex;
|
Blink->OriginalPte.u.Long = PageFrameIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Now initialize our own list pointers */
|
/* Now initialize our own list pointers */
|
||||||
ColorTable->Blink = Pfn1;
|
ColorTable->Blink = Pfn1;
|
||||||
|
|
||||||
|
/* If there is an original pte, it should be an old link, NOT a ReactOS RMAP */
|
||||||
|
ASSERT(Pfn1->u3.e1.ParityError == FALSE);
|
||||||
Pfn1->OriginalPte.u.Long = LIST_HEAD;
|
Pfn1->OriginalPte.u.Long = LIST_HEAD;
|
||||||
|
|
||||||
/* And increase the count in the colored list */
|
/* And increase the count in the colored list */
|
||||||
ColorTable->Count++;
|
ColorTable->Count++;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Notify zero page thread if enough pages are on the free list now */
|
/* Notify zero page thread if enough pages are on the free list now */
|
||||||
if ((ListHead->Total >= 8) && !(MmZeroingPageThreadActive))
|
if ((ListHead->Total >= 8) && !(MmZeroingPageThreadActive))
|
||||||
{
|
{
|
||||||
|
@ -522,7 +590,10 @@ MiInsertPageInList(IN PMMPFNLIST ListHead,
|
||||||
PFN_NUMBER Flink;
|
PFN_NUMBER Flink;
|
||||||
PMMPFN Pfn1, Pfn2;
|
PMMPFN Pfn1, Pfn2;
|
||||||
MMLISTS ListName;
|
MMLISTS ListName;
|
||||||
|
#ifdef ARM3_COLORS
|
||||||
|
PMMCOLOR_TABLES ColorHead;
|
||||||
|
ULONG Color;
|
||||||
|
#endif
|
||||||
/* For free pages, use MiInsertPageInFreeList */
|
/* For free pages, use MiInsertPageInFreeList */
|
||||||
ASSERT(ListHead != &MmFreePageListHead);
|
ASSERT(ListHead != &MmFreePageListHead);
|
||||||
|
|
||||||
|
@ -585,8 +656,47 @@ MiInsertPageInList(IN PMMPFNLIST ListHead,
|
||||||
/* Otherwise check if we reached the high threshold and signal the event */
|
/* Otherwise check if we reached the high threshold and signal the event */
|
||||||
KeSetEvent(MiHighMemoryEvent, 0, FALSE);
|
KeSetEvent(MiHighMemoryEvent, 0, FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef ARM3_COLORS
|
||||||
|
ASSERT(ListName == ZeroedPageList);
|
||||||
|
ASSERT(Pfn1->u4.InPageError == 0);
|
||||||
|
|
||||||
|
/* Get the page color */
|
||||||
|
Color = PageFrameIndex & MmSecondaryColorMask;
|
||||||
|
DPRINT1("Color: %lx\n", Color);
|
||||||
|
|
||||||
|
/* Get the list for this color */
|
||||||
|
ColorHead = &MmFreePagesByColor[ZeroedPageList][Color];
|
||||||
|
|
||||||
|
/* 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->u3.e1.ParityError == FALSE);
|
||||||
|
|
||||||
/* FIXME: Color code handling */
|
/* Make this page point back to the list, and point forwards to the old head */
|
||||||
|
Pfn1->OriginalPte.u.Long = Flink;
|
||||||
|
Pfn1->u4.PteFrame = -1;
|
||||||
|
|
||||||
|
/* Set the new head */
|
||||||
|
ColorHead->Flink = PageFrameIndex;
|
||||||
|
|
||||||
|
/* Was the head empty? */
|
||||||
|
if (Flink != LIST_HEAD)
|
||||||
|
{
|
||||||
|
/* No, so make the old head point to this page */
|
||||||
|
Pfn2 = MiGetPfnEntry(Flink);
|
||||||
|
Pfn2->u4.PteFrame = PageFrameIndex;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* Yes, make it loop back to this page */
|
||||||
|
ColorHead->Blink = (PVOID)Pfn1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* One more paged on the colored list */
|
||||||
|
ColorHead->Count++;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
VOID
|
VOID
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue