Author: arty
Date: Sun Aug 17 16:10:35 2008
New Revision: 35416
URL:
http://svn.reactos.org/svn/reactos?rev=35416&view=rev
Log:
More WIP for newcc. Not completely working.
Added:
branches/arty-newcc/ntoskrnl/ntoskrnl.spec
- copied unchanged from r35355, trunk/reactos/ntoskrnl/ntoskrnl.spec
Modified:
branches/arty-newcc/ntoskrnl/cache/cachesub.c
branches/arty-newcc/ntoskrnl/cache/copysup.c
branches/arty-newcc/ntoskrnl/cache/fssup.c
branches/arty-newcc/ntoskrnl/cache/lazyrite.c
branches/arty-newcc/ntoskrnl/cache/pinsup.c
branches/arty-newcc/ntoskrnl/include/internal/cc.h
branches/arty-newcc/ntoskrnl/mm/section.c
Modified: branches/arty-newcc/ntoskrnl/cache/cachesub.c
URL:
http://svn.reactos.org/svn/reactos/branches/arty-newcc/ntoskrnl/cache/cache…
==============================================================================
--- branches/arty-newcc/ntoskrnl/cache/cachesub.c [iso-8859-1] (original)
+++ branches/arty-newcc/ntoskrnl/cache/cachesub.c [iso-8859-1] Sun Aug 17 16:10:35 2008
@@ -10,7 +10,7 @@
/* INCLUDES *******************************************************************/
#include <ntoskrnl.h>
-#define NDEBUG
+//#define NDEBUG
#include <debug.h>
/* GLOBALS ********************************************************************/
@@ -20,6 +20,10 @@
PDEVICE_OBJECT
NTAPI
MmGetDeviceObjectForFile(IN PFILE_OBJECT FileObject);
+
+BOOLEAN
+NTAPI
+MmIsCOWAddress(PEPROCESS Process, PVOID Address);
NTSTATUS
NTAPI
@@ -29,60 +33,85 @@
PVOID Buffer,
PIO_STATUS_BLOCK ReadStatus)
{
- NTSTATUS Status;
- PIRP Irp = NULL;
- KEVENT ReadWait;
- PDEVICE_OBJECT DeviceObject = MmGetDeviceObjectForFile(FileObject);
- PIO_STACK_LOCATION IrpSp;
-
+ ULONG Length = PAGE_SIZE;
+ NTSTATUS Status;
+ PIRP Irp = NULL;
+ KEVENT ReadWait;
+ PDEVICE_OBJECT DeviceObject = MmGetDeviceObjectForFile(FileObject);
+ PIO_STACK_LOCATION IrpSp;
+ KIRQL OldIrql;
+
+ KeRaiseIrql(DISPATCH_LEVEL, &OldIrql);
+
+ if (MmIsDirtyPage(PsInitialSystemProcess, Buffer) &&
+ !MmIsCOWAddress(PsInitialSystemProcess, Buffer))
+ {
+ DPRINT1
+ ("PAGING WRITE (FLUSH) File %wZ Offset %x Length %d\n",
+ &FileObject->FileName,
+ FileOffset->u.LowPart,
+ Length);
+
+ MmSetCleanPage(PsInitialSystemProcess, Buffer);
+
+ KeLowerIrql(OldIrql);
+
KeInitializeEvent(&ReadWait, NotificationEvent, FALSE);
Irp = IoBuildAsynchronousFsdRequest
- (IRP_MJ_WRITE,
- DeviceObject,
- Buffer,
- PAGE_SIZE,
- FileOffset,
- ReadStatus);
+ (IRP_MJ_WRITE,
+ DeviceObject,
+ Buffer,
+ Length,
+ FileOffset,
+ ReadStatus);
if (!Irp)
{
- return STATUS_NO_MEMORY;
+ return STATUS_NO_MEMORY;
}
Irp->Flags |= IRP_PAGING_IO | IRP_SYNCHRONOUS_PAGING_IO | IRP_NOCACHE;
-
+
ObReferenceObject(FileObject);
-
+
Irp->UserEvent = &ReadWait;
Irp->Tail.Overlay.OriginalFileObject = FileObject;
Irp->Tail.Overlay.Thread = PsGetCurrentThread();
IrpSp = IoGetNextIrpStackLocation(Irp);
IrpSp->FileObject = FileObject;
-
+
Status = IoCallDriver(DeviceObject, Irp);
if (Status == STATUS_PENDING)
{
- if (!NT_SUCCESS
- (KeWaitForSingleObject
- (&ReadWait,
- Suspended,
- KernelMode,
- FALSE,
- NULL)))
- {
- DPRINT1("Warning: Failed to wait for synchronous IRP\n");
- ASSERT(FALSE);
- ObDereferenceObject(FileObject);
- return Status;
- }
- }
-
+ if (!NT_SUCCESS
+ (KeWaitForSingleObject
+ (&ReadWait,
+ Suspended,
+ KernelMode,
+ FALSE,
+ NULL)))
+ {
+ DPRINT1("Warning: Failed to wait for synchronous IRP\n");
+ ASSERT(FALSE);
+ ObDereferenceObject(FileObject);
+ return Status;
+ }
+ }
+
ObDereferenceObject(FileObject);
+ MmDeleteHyperspaceMapping(Buffer);
DPRINT("Paging IO Done: %08x\n", ReadStatus->Status);
-
- return ReadStatus->Status;
+ }
+ else
+ {
+ ReadStatus->Status = STATUS_SUCCESS;
+ ReadStatus->Information = PAGE_SIZE;
+ KeLowerIrql(OldIrql);
+ }
+
+ return ReadStatus->Status;
}
VOID
@@ -156,6 +185,8 @@
LARGE_INTEGER ToWrite = *FileOffset;
IO_STATUS_BLOCK IOSB;
+ DPRINT("CcFlushCache\n");
+
BOOLEAN Result = CcpMapData
((PNOCC_CACHE_MAP)SectionObjectPointer->SharedCacheMap,
FileOffset,
@@ -170,11 +201,18 @@
ToWrite.LowPart = PAGE_ROUND_DOWN(FileOffset->LowPart);
for (BufPage = BufStart;
- BufPage < BufStart + PAGE_ROUND_UP(Length);
- BufPage += PAGE_SIZE)
- {
- CcpSimpleWrite(Bcb->FileObject, &ToWrite, BufPage, &IOSB);
- ToWrite.QuadPart += PAGE_SIZE;
+ BufPage < BufStart + PAGE_ROUND_UP(Length);
+ BufPage += PAGE_SIZE)
+ {
+ DPRINT
+ ("CcpSimpleWrite: [%wZ] %x:%d\n",
+ &Bcb->FileObject->FileName,
+ Bcb->FileOffset.LowPart,
+ Bcb->Length);
+ CcpSimpleWrite(Bcb->FileObject, &ToWrite, BufPage, &IOSB);
+ DPRINT
+ ("Page Write: %08x\n", IOSB.Status);
+ ToWrite.QuadPart += PAGE_SIZE;
}
CcUnpinData(Bcb);
@@ -189,15 +227,15 @@
IoStatus->Status = IOSB.Status;
IoStatus->Information = 0;
}
-}
-
+ DPRINT("CcFlushCache -> %08x\n", IOSB.Status);
+}
+
+// Always succeeds for us
PVOID
NTAPI
CcRemapBcb(IN PVOID Bcb)
{
- UNIMPLEMENTED;
- while (TRUE);
- return NULL;
+ return Bcb;
}
@@ -205,8 +243,14 @@
NTAPI
CcRepinBcb(IN PVOID Bcb)
{
- UNIMPLEMENTED;
- while (TRUE);
+ PVOID TheBcb;
+ PNOCC_BCB RealBcb = (PNOCC_BCB)Bcb;
+ CcPinMappedData
+ (RealBcb->FileObject,
+ &RealBcb->FileOffset,
+ RealBcb->Length,
+ PIN_WAIT,
+ &TheBcb);
}
VOID
@@ -215,8 +259,18 @@
IN BOOLEAN WriteThrough,
OUT PIO_STATUS_BLOCK IoStatus)
{
- UNIMPLEMENTED;
- while (TRUE);
+ PNOCC_BCB RealBcb = (PNOCC_BCB)RealBcb;
+
+ CcUnpinData(Bcb);
+
+ if (WriteThrough)
+ {
+ CcFlushCache
+ (RealBcb->FileObject->SectionObjectPointer,
+ &RealBcb->FileOffset,
+ RealBcb->Length,
+ IoStatus);
+ }
}
/* EOF */
Modified: branches/arty-newcc/ntoskrnl/cache/copysup.c
URL:
http://svn.reactos.org/svn/reactos/branches/arty-newcc/ntoskrnl/cache/copys…
==============================================================================
--- branches/arty-newcc/ntoskrnl/cache/copysup.c [iso-8859-1] (original)
+++ branches/arty-newcc/ntoskrnl/cache/copysup.c [iso-8859-1] Sun Aug 17 16:10:35 2008
@@ -25,45 +25,6 @@
#define TAG_COPY_WRITE TAG('R', 'i', 't', 'e')
/* FUNCTIONS ******************************************************************/
-
-NTSTATUS
-NTAPI
-DoDeviceRead(PFILE_OBJECT FileObject,
- LARGE_INTEGER SectorBase,
- PCHAR SystemBuffer,
- ULONG AlignSize,
- ULONG *LengthRead)
-{
- IO_STATUS_BLOCK IoStatusBlock = {{0}};
- NTSTATUS Status;
- KEVENT Event;
- PMDL Mdl;
-
- /* Create an MDL for the transfer */
- Mdl = IoAllocateMdl(SystemBuffer, AlignSize, TRUE, FALSE, NULL);
- MmBuildMdlForNonPagedPool(Mdl),
- Mdl->MdlFlags |= (MDL_PAGES_LOCKED | MDL_IO_PAGE_READ);
-
- /* Setup the event */
- KeInitializeEvent(&Event, NotificationEvent, FALSE);
-
- /* Read the page */
- Status = IoPageRead(FileObject, Mdl, &SectorBase, &Event,
&IoStatusBlock);
- if (Status == STATUS_PENDING)
- {
- /* Do the wait */
- KeWaitForSingleObject(&Event, Suspended, KernelMode, FALSE, NULL);
- Status = IoStatusBlock.Status;
- }
-
- /* Free the MDL */
- IoFreeMdl(Mdl);
-
- /* Save how much we read, if needed */
- if (LengthRead) *LengthRead = IoStatusBlock.Information;
-
- return Status;
-}
BOOLEAN
NTAPI
Modified: branches/arty-newcc/ntoskrnl/cache/fssup.c
URL:
http://svn.reactos.org/svn/reactos/branches/arty-newcc/ntoskrnl/cache/fssup…
==============================================================================
--- branches/arty-newcc/ntoskrnl/cache/fssup.c [iso-8859-1] (original)
+++ branches/arty-newcc/ntoskrnl/cache/fssup.c [iso-8859-1] Sun Aug 17 16:10:35 2008
@@ -17,9 +17,11 @@
PFSN_PREFETCHER_GLOBALS CcPfGlobals;
extern LONG CcOutstandingDeletes;
+extern KEVENT CcpLazyWriteEvent;
extern VOID STDCALL CcpUnmapThread(PVOID Unused);
-HANDLE CcUnmapThreadHandle;
-CLIENT_ID CcUnmapThreadId;
+extern VOID STDCALL CcpLazyWriteThread(PVOID Unused);
+HANDLE CcUnmapThreadHandle, CcLazyWriteThreadHandle;
+CLIENT_ID CcUnmapThreadId, CcLazyWriteThreadId;
/* FUNCTIONS ******************************************************************/
@@ -38,6 +40,7 @@
}
KeInitializeEvent(&CcDeleteEvent, SynchronizationEvent, FALSE);
+ KeInitializeEvent(&CcpLazyWriteEvent, SynchronizationEvent, FALSE);
CcCacheBitmap->Buffer = ((PULONG)&CcCacheBitmap[1]);
CcCacheBitmap->SizeOfBitMap = ROUND_UP(CACHE_NUM_SECTIONS, 32);
DPRINT("Cache has %d entries\n", CcCacheBitmap->SizeOfBitMap);
@@ -56,6 +59,20 @@
KEBUGCHECK(0);
}
+ Status = PsCreateSystemThread
+ (&CcLazyWriteThreadHandle,
+ THREAD_ALL_ACCESS,
+ NULL,
+ NULL,
+ &CcLazyWriteThreadId,
+ (PKSTART_ROUTINE) CcpLazyWriteThread,
+ NULL);
+
+ if (!NT_SUCCESS(Status))
+ {
+ KEBUGCHECK(0);
+ }
+
return TRUE;
}
@@ -173,18 +190,15 @@
NTAPI
CcGetFileObjectFromSectionPtrs(IN PSECTION_OBJECT_POINTERS SectionObjectPointer)
{
- UNIMPLEMENTED;
- while (TRUE);
- return NULL;
+ return ((PNOCC_CACHE_MAP)SectionObjectPointer->SharedCacheMap)->FileObject;
}
PFILE_OBJECT
NTAPI
CcGetFileObjectFromBcb(IN PVOID Bcb)
{
- UNIMPLEMENTED;
- while (TRUE);
- return NULL;
+ PNOCC_BCB RealBcb = (PNOCC_BCB)Bcb;
+ return RealBcb->FileObject;
}
/* EOF */
Modified: branches/arty-newcc/ntoskrnl/cache/lazyrite.c
URL:
http://svn.reactos.org/svn/reactos/branches/arty-newcc/ntoskrnl/cache/lazyr…
==============================================================================
--- branches/arty-newcc/ntoskrnl/cache/lazyrite.c [iso-8859-1] (original)
+++ branches/arty-newcc/ntoskrnl/cache/lazyrite.c [iso-8859-1] Sun Aug 17 16:10:35 2008
@@ -9,19 +9,63 @@
/* INCLUDES *******************************************************************/
#include <ntoskrnl.h>
-#define NDEBUG
+//#define NDEBUG
#include <debug.h>
/* GLOBALS ********************************************************************/
+KEVENT CcpLazyWriteEvent;
+
/* FUNCTIONS ******************************************************************/
+
+VOID STDCALL
+CcpLazyWriteThread(PVOID Unused)
+{
+ ULONG i;
+ BOOLEAN GotLock;
+ PNOCC_BCB RealBcb;
+ LARGE_INTEGER Interval;
+ IO_STATUS_BLOCK IoStatus;
+
+ while (TRUE)
+ {
+ for (i = 0; i < CACHE_NUM_SECTIONS; i++)
+ {
+ RealBcb = &CcCacheSections[i];
+ CcpLock(&CcMutex);
+ GotLock = RealBcb->RefCount == 1;
+ if (GotLock) RealBcb->RefCount++;
+ CcpUnlock(&CcMutex);
+ // Pinned (temporarily)
+ if (GotLock)
+ {
+ DPRINT("CcpLazyWrite: Flush #%x\n", i);
+ CcFlushCache
+ (RealBcb->FileObject->SectionObjectPointer,
+ &RealBcb->FileOffset,
+ RealBcb->Length,
+ &IoStatus);
+
+ DPRINT
+ ("CcpLazyWriteThread UnmapIoStatus.Status %08x IoStatus.Information
%08x\n",
+ IoStatus.Status,
+ IoStatus.Information);
+
+ CcUnpinData(RealBcb);
+ DPRINT("CcpLazyWrite: done #%x\n", i);
+ }
+ }
+ KeSetEvent(&CcpLazyWriteEvent, IO_DISK_INCREMENT, TRUE);
+ Interval.QuadPart = -1000000L;
+ KeDelayExecutionThread(KernelMode, FALSE, &Interval);
+ }
+}
NTSTATUS
NTAPI
CcWaitForCurrentLazyWriterActivity(VOID)
{
- UNIMPLEMENTED;
- while (TRUE);
+ KeWaitForSingleObject(&CcpLazyWriteEvent, Executive, KernelMode, FALSE, NULL);
return STATUS_SUCCESS;
}
Modified: branches/arty-newcc/ntoskrnl/cache/pinsup.c
URL:
http://svn.reactos.org/svn/reactos/branches/arty-newcc/ntoskrnl/cache/pinsu…
==============================================================================
--- branches/arty-newcc/ntoskrnl/cache/pinsup.c [iso-8859-1] (original)
+++ branches/arty-newcc/ntoskrnl/cache/pinsup.c [iso-8859-1] Sun Aug 17 16:10:35 2008
@@ -10,7 +10,7 @@
/* INCLUDES *******************************************************************/
#include <ntoskrnl.h>
-#define NDEBUG
+//#define NDEBUG
#include <debug.h>
/* GLOBALS ********************************************************************/
@@ -29,9 +29,11 @@
typedef struct _NOCC_UNMAP_CHAIN
{
- PVOID Buffer;
- PVOID SectionObject;
- PVOID FileObject;
+ PVOID Buffer;
+ PSECTION_OBJECT SectionObject;
+ PFILE_OBJECT FileObject;
+ LARGE_INTEGER FileOffset;
+ ULONG Length;
} NOCC_UNMAP_CHAIN, *PNOCC_UNMAP_CHAIN;
NOCC_UNMAP_CHAIN CcUnmapChain[CACHE_NUM_SECTIONS];
@@ -60,6 +62,7 @@
VOID CcpPerformUnmapWork()
{
NOCC_UNMAP_CHAIN WorkingOn;
+ IO_STATUS_BLOCK IoStatus;
ULONG NumElements;
KeAcquireGuardedMutex(&CcMutex);
@@ -70,6 +73,12 @@
WorkingOn = CcUnmapChain[0];
RtlMoveMemory(&CcUnmapChain[0], &CcUnmapChain[1], NumElements *
sizeof(NOCC_UNMAP_CHAIN));
KeReleaseGuardedMutex(&CcMutex);
+ CcFlushCache
+ (WorkingOn.FileObject->SectionObjectPointer,
+ &WorkingOn.FileOffset,
+ WorkingOn.Length,
+ &IoStatus);
+ DPRINT1("Status result from flush: %08x\n", IoStatus.Status);
MmUnmapViewInSystemSpace(WorkingOn.Buffer);
ObDereferenceObject(WorkingOn.SectionObject);
DPRINT1("Done unmapping\n");
@@ -110,7 +119,8 @@
UnmapWork->Buffer = Bcb->BaseAddress;
UnmapWork->SectionObject = Bcb->SectionObject;
UnmapWork->FileObject = Bcb->FileObject;
-
+ UnmapWork->FileOffset = Bcb->FileOffset;
+ UnmapWork->Length = Bcb->Length;
Bcb->BaseAddress = NULL;
Bcb->Length = 0;
Bcb->FileOffset.QuadPart = 0;
@@ -206,9 +216,18 @@
PLARGE_INTEGER FileOffset)
{
ULONG i = INVALID_CACHE;
- PNOCC_CACHE_MAP Map =
(PNOCC_CACHE_MAP)FileObject->SectionObjectPointer->SharedCacheMap;
+ PNOCC_CACHE_MAP Map;
PNOCC_BCB Bcb;
+ DPRINT("AllocateCacheSections: FileObject %x\n", FileObject);
+ DPRINT
+ ("AllocateCacheSections: FileObject->SectionObjectPointer: %x\n",
+ FileObject->SectionObjectPointer);
+ Map = (PNOCC_CACHE_MAP)FileObject->SectionObjectPointer->SharedCacheMap;
+
+ if (!Map)
+ return INVALID_CACHE;
+
DPRINT("Allocating Cache Section (File already has %d sections)\n",
Map->NumberOfMaps);
i = RtlFindClearBitsAndSet
@@ -217,6 +236,8 @@
if (i != INVALID_CACHE)
{
+ DPRINT("Setting up Bcb #%x\n", i);
+
Bcb = &CcCacheSections[i];
ASSERT(Bcb->RefCount < 2);
@@ -229,7 +250,7 @@
ASSERT(!Bcb->RefCount);
Bcb->RefCount = 1;
- //DPRINT("Bcb #%x RefCount %d\n", Bcb - CcCacheSections, Bcb->RefCount);
+ DPRINT("Bcb #%x RefCount %d\n", Bcb - CcCacheSections, Bcb->RefCount);
ObReferenceObject(SectionObject);
Bcb->FileObject = FileObject;
@@ -239,7 +260,11 @@
Map->NumberOfMaps++;
InsertTailList(&Map->AssociatedBcb, &Bcb->ThisFileList);
-
+
+ if (!RtlTestBit(CcCacheBitmap, i))
+ {
+ DPRINT("Somebody stoeled BCB #%x\n", i);
+ }
ASSERT(RtlTestBit(CcCacheBitmap, i));
DPRINT("Allocated #%x\n", i);
Modified: branches/arty-newcc/ntoskrnl/include/internal/cc.h
URL:
http://svn.reactos.org/svn/reactos/branches/arty-newcc/ntoskrnl/include/int…
==============================================================================
--- branches/arty-newcc/ntoskrnl/include/internal/cc.h [iso-8859-1] (original)
+++ branches/arty-newcc/ntoskrnl/include/internal/cc.h [iso-8859-1] Sun Aug 17 16:10:35
2008
@@ -239,9 +239,19 @@
extern KEVENT CcDeleteEvent;
extern ULONG CcCacheClockHand;
extern LIST_ENTRY CcPendingUnmap;
+extern KEVENT CcpLazyWriteEvent;
extern VOID CcpLock();
extern VOID CcpUnlock();
extern VOID CcpDereferenceCache(ULONG Sector);
+BOOLEAN
+NTAPI
+CcpMapData
+(IN PNOCC_CACHE_MAP Map,
+ IN PLARGE_INTEGER FileOffset,
+ IN ULONG Length,
+ IN ULONG Flags,
+ OUT PVOID *BcbResult,
+ OUT PVOID *Buffer);
#endif
Modified: branches/arty-newcc/ntoskrnl/mm/section.c
URL:
http://svn.reactos.org/svn/reactos/branches/arty-newcc/ntoskrnl/mm/section.…
==============================================================================
--- branches/arty-newcc/ntoskrnl/mm/section.c [iso-8859-1] (original)
+++ branches/arty-newcc/ntoskrnl/mm/section.c [iso-8859-1] Sun Aug 17 16:10:35 2008
@@ -161,6 +161,12 @@
PDEVICE_OBJECT DeviceObject = MmGetDeviceObjectForFile(FileObject);
PIO_STACK_LOCATION IrpSp;
+ DPRINT1
+ ("PAGING READ File %wZ Offset %x Length %d\n",
+ &FileObject->FileName,
+ FileOffset->u.LowPart,
+ Length);
+
KeInitializeEvent(&ReadWait, NotificationEvent, FALSE);
Irp = IoBuildAsynchronousFsdRequest
@@ -226,6 +232,12 @@
PDEVICE_OBJECT DeviceObject = MmGetDeviceObjectForFile(FileObject);
PIO_STACK_LOCATION IrpSp;
+ DPRINT1
+ ("PAGING WRITE File %wZ Offset %x Length %d\n",
+ &FileObject->FileName,
+ FileOffset->u.LowPart,
+ Length);
+
KeInitializeEvent(&ReadWait, NotificationEvent, FALSE);
Irp = IoBuildAsynchronousFsdRequest
@@ -333,6 +345,21 @@
*/
RtlCreateUnicodeString(ModuleName, L"C:\\ReactOS\\system32\\ntdll.dll");
return STATUS_SUCCESS;
+}
+
+BOOLEAN
+NTAPI
+MmIsCOWAddress(IN PEPROCESS Process, IN PVOID Address)
+{
+ BOOLEAN IsCow = TRUE; /* Don't write unless we're sure */
+ PMEMORY_AREA MemoryArea;
+
+ MmLockAddressSpace(&Process->VadRoot);
+ MemoryArea = MmLocateMemoryAreaByAddress(&Process->VadRoot, Address);
+ ASSERT(MemoryArea);
+ IsCow = MemoryArea->Data.SectionData.WriteCopyView;
+ MmUnlockAddressSpace(&Process->VadRoot);
+ return IsCow;
}
/* Note: Mmsp prefix denotes "Memory Manager Section Private". */
@@ -3788,7 +3815,7 @@
return(Status);
}
-VOID static
+VOID
MmFreeSectionPage(PVOID Context, MEMORY_AREA* MemoryArea, PVOID Address,
PFN_TYPE Page, SWAPENTRY SwapEntry, BOOLEAN Dirty)
{