00001 /*++ 00002 00003 Copyright (c) 1990 Microsoft Corporation 00004 00005 Module Name: 00006 00007 cachedat.c 00008 00009 Abstract: 00010 00011 This module implements the Memory Management based cache management 00012 routines for the common Cache subsystem. 00013 00014 Author: 00015 00016 Tom Miller [TomM] 4-May-1990 00017 00018 Revision History: 00019 00020 --*/ 00021 00022 #include "cc.h" 00023 00024 // 00025 // Global SharedCacheMap lists and resource to synchronize access to it. 00026 // 00027 // 00028 00029 extern KSPIN_LOCK CcMasterSpinLock; 00030 LIST_ENTRY CcCleanSharedCacheMapList; 00031 SHARED_CACHE_MAP_LIST_CURSOR CcDirtySharedCacheMapList; 00032 SHARED_CACHE_MAP_LIST_CURSOR CcLazyWriterCursor; 00033 00034 // 00035 // Worker thread structures: 00036 // 00037 // A spinlock to synchronize all three lists. 00038 // A count of the number of worker threads Cc will use 00039 // A count of the number of worker threads Cc in use 00040 // A listhead for preinitialized executive work items for Cc use. 00041 // A listhead for an express queue of WORK_QUEUE_ENTRYs 00042 // A listhead for a regular queue of WORK_QUEUE_ENTRYs 00043 // A listhead for a post-tick queue of WORK_QUEUE_ENTRYs 00044 // 00045 // A flag indicating if we are throttling the queue to a single thread 00046 // 00047 00048 extern KSPIN_LOCK CcWorkQueueSpinlock; 00049 ULONG CcNumberWorkerThreads = 0; 00050 ULONG CcNumberActiveWorkerThreads = 0; 00051 LIST_ENTRY CcIdleWorkerThreadList; 00052 LIST_ENTRY CcExpressWorkQueue; 00053 LIST_ENTRY CcRegularWorkQueue; 00054 LIST_ENTRY CcPostTickWorkQueue; 00055 00056 BOOLEAN CcQueueThrottle = FALSE; 00057 00058 // 00059 // Store the current idle delay and target time to clean all. We must calculate 00060 // the idle delay in terms of clock ticks for the lazy writer timeout. 00061 // 00062 00063 ULONG CcIdleDelayTick; 00064 LARGE_INTEGER CcNoDelay; 00065 LARGE_INTEGER CcFirstDelay = {(ULONG)-(3*LAZY_WRITER_IDLE_DELAY), -1}; 00066 LARGE_INTEGER CcIdleDelay = {(ULONG)-LAZY_WRITER_IDLE_DELAY, -1}; 00067 LARGE_INTEGER CcCollisionDelay = {(ULONG)-LAZY_WRITER_COLLISION_DELAY, -1}; 00068 LARGE_INTEGER CcTargetCleanDelay = {(ULONG)-(LONG)(LAZY_WRITER_IDLE_DELAY * (LAZY_WRITER_MAX_AGE_TARGET + 1)), -1}; 00069 00070 // 00071 // Spinlock for controlling access to Vacb and related global structures, 00072 // and a counter indicating how many Vcbs are active. 00073 // 00074 00075 extern KSPIN_LOCK CcVacbSpinLock; 00076 ULONG CcNumberVacbs; 00077 00078 // 00079 // Pointer to the global Vacb vector. 00080 // 00081 00082 PVACB CcVacbs; 00083 PVACB CcBeyondVacbs; 00084 LIST_ENTRY CcVacbLru; 00085 ULONG CcMaxVacbLevelsSeen = 1; 00086 ULONG CcVacbLevelEntries = 0; 00087 PVACB *CcVacbLevelFreeList = NULL; 00088 ULONG CcVacbLevelWithBcbsEntries = 0; 00089 PVACB *CcVacbLevelWithBcbsFreeList = NULL; 00090 00091 // 00092 // Deferred write list and respective Thresholds 00093 // 00094 00095 extern KSPIN_LOCK CcDeferredWriteSpinLock; 00096 LIST_ENTRY CcDeferredWrites; 00097 ULONG CcDirtyPageThreshold; 00098 ULONG CcDirtyPageTarget; 00099 ULONG CcPagesYetToWrite; 00100 ULONG CcPagesWrittenLastTime = 0; 00101 ULONG CcDirtyPagesLastScan = 0; 00102 ULONG CcAvailablePagesThreshold = 100; 00103 ULONG CcTotalDirtyPages = 0; 00104 00105 // 00106 // Captured system size 00107 // 00108 00109 MM_SYSTEMSIZE CcCapturedSystemSize; 00110 00111 // 00112 // Number of outstanding aggresive zeroers in the system. Used 00113 // to throttle the activity. 00114 // 00115 00116 LONG CcAggressiveZeroCount; 00117 LONG CcAggressiveZeroThreshold; 00118 00119 // 00120 // Tuning options du Jour 00121 // 00122 00123 ULONG CcTune = 0; 00124 00125 // 00126 // Global structure controlling lazy writer algorithms 00127 // 00128 00129 LAZY_WRITER LazyWriter; 00130 00131 NPAGED_LOOKASIDE_LIST CcTwilightLookasideList; 00132 00133 #ifdef CCDBG 00134 00135 LONG CcDebugTraceLevel = 0; 00136 LONG CcDebugTraceIndent = 0; 00137 00138 #ifdef CCDBG_LOCK 00139 extern KSPIN_LOCK CcDebugTraceLock; 00140 #endif // def CCDBG_LOCK 00141 00142 #endif 00143 00144 // 00145 // Global list of pinned Bcbs which may be examined for debug purposes 00146 // 00147 00148 #if DBG 00149 00150 ULONG CcBcbCount; 00151 LIST_ENTRY CcBcbList; 00152 extern KSPIN_LOCK CcBcbSpinLock; 00153 00154 #endif 00155 00156 // 00157 // Throw away miss counter. 00158 // 00159 00160 ULONG CcThrowAway; 00161 00162 // 00163 // Performance Counters 00164 // 00165 00166 ULONG CcFastReadNoWait; 00167 ULONG CcFastReadWait; 00168 ULONG CcFastReadResourceMiss; 00169 ULONG CcFastReadNotPossible; 00170 00171 ULONG CcFastMdlReadNoWait; 00172 ULONG CcFastMdlReadWait; 00173 ULONG CcFastMdlReadResourceMiss; 00174 ULONG CcFastMdlReadNotPossible; 00175 00176 ULONG CcMapDataNoWait; 00177 ULONG CcMapDataWait; 00178 ULONG CcMapDataNoWaitMiss; 00179 ULONG CcMapDataWaitMiss; 00180 00181 ULONG CcPinMappedDataCount; 00182 00183 ULONG CcPinReadNoWait; 00184 ULONG CcPinReadWait; 00185 ULONG CcPinReadNoWaitMiss; 00186 ULONG CcPinReadWaitMiss; 00187 00188 ULONG CcCopyReadNoWait; 00189 ULONG CcCopyReadWait; 00190 ULONG CcCopyReadNoWaitMiss; 00191 ULONG CcCopyReadWaitMiss; 00192 00193 ULONG CcMdlReadNoWait; 00194 ULONG CcMdlReadWait; 00195 ULONG CcMdlReadNoWaitMiss; 00196 ULONG CcMdlReadWaitMiss; 00197 00198 ULONG CcReadAheadIos; 00199 00200 ULONG CcLazyWriteHotSpots; 00201 ULONG CcLazyWriteIos; 00202 ULONG CcLazyWritePages; 00203 ULONG CcDataFlushes; 00204 ULONG CcDataPages; 00205 00206 PULONG CcMissCounter = &CcThrowAway;