2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS kernel
4 * FILE: ntoskrnl/cc/cacheman.c
5 * PURPOSE: Cache manager
7 * PROGRAMMERS: David Welch (welch@cwcom.net)
8 * Pierre Schweitzer (pierre@reactos.org)
11 /* INCLUDES *****************************************************************/
17 BOOLEAN CcPfEnablePrefetcher
;
18 PFSN_PREFETCHER_GLOBALS CcPfGlobals
;
19 MM_SYSTEMSIZE CcCapturedSystemSize
;
21 static ULONG BugCheckFileId
= 0x4 << 16;
23 /* FUNCTIONS *****************************************************************/
28 CcPfInitializePrefetcher(VOID
)
31 DbgPrintEx(DPFLTR_PREFETCHER_ID
,
33 "CCPF: InitializePrefetecher()\n");
35 /* Setup the Prefetcher Data */
36 InitializeListHead(&CcPfGlobals
.ActiveTraces
);
37 InitializeListHead(&CcPfGlobals
.CompletedTraces
);
38 ExInitializeFastMutex(&CcPfGlobals
.CompletedTracesLock
);
40 /* FIXME: Setup the rest of the prefetecher */
46 CcInitializeCacheManager(VOID
)
52 /* Initialize lazy-writer lists */
53 InitializeListHead(&CcIdleWorkerThreadList
);
54 InitializeListHead(&CcRegularWorkQueue
);
56 /* Define lazy writer threshold and the amount of workers,
57 * depending on the system type
59 CcCapturedSystemSize
= MmQuerySystemSize();
60 switch (CcCapturedSystemSize
)
63 CcNumberWorkerThreads
= ExCriticalWorkerThreads
- 1;
64 CcDirtyPageThreshold
= MmNumberOfPhysicalPages
/ 8;
68 CcNumberWorkerThreads
= ExCriticalWorkerThreads
- 1;
69 CcDirtyPageThreshold
= MmNumberOfPhysicalPages
/ 4;
73 CcNumberWorkerThreads
= ExCriticalWorkerThreads
- 2;
74 CcDirtyPageThreshold
= MmNumberOfPhysicalPages
/ 8 + MmNumberOfPhysicalPages
/ 4;
78 CcNumberWorkerThreads
= 1;
79 CcDirtyPageThreshold
= MmNumberOfPhysicalPages
/ 8;
83 /* Allocate a work item for all our threads */
84 for (Thread
= 0; Thread
< CcNumberWorkerThreads
; ++Thread
)
86 PWORK_QUEUE_ITEM Item
;
88 Item
= ExAllocatePoolWithTag(NonPagedPool
, sizeof(WORK_QUEUE_ITEM
), 'qWcC');
94 /* By default, it's obviously idle */
95 ExInitializeWorkItem(Item
, CcWorkerThread
, Item
);
96 InsertTailList(&CcIdleWorkerThreadList
, &Item
->List
);
99 /* Initialize our lazy writer */
100 RtlZeroMemory(&LazyWriter
, sizeof(LazyWriter
));
101 InitializeListHead(&LazyWriter
.WorkQueue
);
102 /* Delay activation of the lazy writer */
103 KeInitializeDpc(&LazyWriter
.ScanDpc
, CcScanDpc
, NULL
);
104 KeInitializeTimer(&LazyWriter
.ScanTimer
);
106 /* Lookaside list for our work items */
107 ExInitializeNPagedLookasideList(&CcTwilightLookasideList
, NULL
, NULL
, 0, sizeof(WORK_QUEUE_ENTRY
), 'KWcC', 0);
109 /* HACK: for lazy writer watching */
110 KeInitializeEvent(&iLazyWriterNotify
, NotificationEvent
, FALSE
);
117 CcShutdownSystem(VOID
)
127 CcGetFlushedValidData (
128 IN PSECTION_OBJECT_POINTERS SectionObjectPointer
,
129 IN BOOLEAN BcbListHeld
159 CcScheduleReadAhead (
160 IN PFILE_OBJECT FileObject
,
161 IN PLARGE_INTEGER FileOffset
,
173 CcSetAdditionalCacheAttributes (
174 IN PFILE_OBJECT FileObject
,
175 IN BOOLEAN DisableReadAhead
,
176 IN BOOLEAN DisableWriteBehind
179 CCTRACE(CC_API_DEBUG
, "FileObject=%p DisableReadAhead=%d DisableWriteBehind=%d\n",
180 FileObject
, DisableReadAhead
, DisableWriteBehind
);
190 CcSetBcbOwnerPointer (
195 PINTERNAL_BCB iBcb
= Bcb
;
197 CCTRACE(CC_API_DEBUG
, "Bcb=%p Owner=%p\n",
200 if (!ExIsResourceAcquiredExclusiveLite(&iBcb
->Lock
) && !ExIsResourceAcquiredSharedLite(&iBcb
->Lock
))
202 DPRINT1("Current thread doesn't own resource!\n");
206 ExSetResourceOwnerPointer(&iBcb
->Lock
, Owner
);
214 CcSetDirtyPageThreshold (
215 IN PFILE_OBJECT FileObject
,
216 IN ULONG DirtyPageThreshold
219 PFSRTL_COMMON_FCB_HEADER Fcb
;
220 PROS_SHARED_CACHE_MAP SharedCacheMap
;
222 CCTRACE(CC_API_DEBUG
, "FileObject=%p DirtyPageThreshold=%lu\n",
223 FileObject
, DirtyPageThreshold
);
225 SharedCacheMap
= FileObject
->SectionObjectPointer
->SharedCacheMap
;
226 if (SharedCacheMap
!= NULL
)
228 SharedCacheMap
->DirtyPageThreshold
= DirtyPageThreshold
;
231 Fcb
= FileObject
->FsContext
;
232 if (!BooleanFlagOn(Fcb
->Flags
, FSRTL_FLAG_LIMIT_MODIFIED_PAGES
))
234 SetFlag(Fcb
->Flags
, FSRTL_FLAG_LIMIT_MODIFIED_PAGES
);
243 CcSetReadAheadGranularity (
244 IN PFILE_OBJECT FileObject
,
250 CCTRACE(CC_API_DEBUG
, "FileObject=%p Granularity=%lu\n",
251 FileObject
, Granularity
);
253 if (!Warn
++) UNIMPLEMENTED
;