Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

lookasid.c File Reference

#include "ntrtlp.h"
#include "heap.h"
#include "heappriv.h"

Go to the source code of this file.

Defines

#define MINIMUM_LOOKASIDE_DEPTH   4
#define MINIMUM_ALLOCATION_THRESHOLD   25

Functions

VOID RtlpInitializeHeapLookaside (IN PHEAP_LOOKASIDE Lookaside, IN USHORT Depth)
VOID RtlpDeleteHeapLookaside (IN PHEAP_LOOKASIDE Lookaside)
VOID RtlpAdjustHeapLookasideDepth (IN PHEAP_LOOKASIDE Lookaside)
PVOID RtlpAllocateFromHeapLookaside (IN PHEAP_LOOKASIDE Lookaside)
BOOLEAN RtlpFreeToHeapLookaside (IN PHEAP_LOOKASIDE Lookaside, IN PVOID Entry)


Define Documentation

#define MINIMUM_ALLOCATION_THRESHOLD   25
 

Definition at line 36 of file rtl/lookasid.c.

#define MINIMUM_LOOKASIDE_DEPTH   4
 

Definition at line 30 of file rtl/lookasid.c.


Function Documentation

VOID RtlpAdjustHeapLookasideDepth IN PHEAP_LOOKASIDE  Lookaside  ) 
 

Definition at line 130 of file rtl/lookasid.c.

References MINIMUM_ALLOCATION_THRESHOLD, MINIMUM_LOOKASIDE_DEPTH, and USHORT.

Referenced by RtlAllocateHeap().

00136 : 00137 00138 This function is called periodically to adjust the maximum depth of 00139 a single heap lookaside list. 00140 00141 Arguments: 00142 00143 Lookaside - Supplies a pointer to a heap lookaside list structure. 00144 00145 Return Value: 00146 00147 None. 00148 00149 --*/ 00150 00151 { 00152 ULONG Allocates; 00153 ULONG Misses; 00154 00155 // 00156 // Compute the total number of allocations and misses for this scan 00157 // period. 00158 // 00159 00160 Allocates = Lookaside->TotalAllocates - Lookaside->LastTotalAllocates; 00161 Lookaside->LastTotalAllocates = Lookaside->TotalAllocates; 00162 Misses = Lookaside->AllocateMisses - Lookaside->LastAllocateMisses; 00163 Lookaside->LastAllocateMisses = Lookaside->AllocateMisses; 00164 00165 // 00166 // Compute target depth of lookaside list. 00167 // 00168 00169 { 00170 ULONG Ratio; 00171 ULONG Target; 00172 00173 // 00174 // If the allocate rate is less than the mimimum threshold, then lower 00175 // the maximum depth of the lookaside list. Otherwise, if the miss rate 00176 // is less than .5%, then lower the maximum depth. Otherwise, raise the 00177 // maximum depth based on the miss rate. 00178 // 00179 00180 if (Misses >= Allocates) { 00181 Misses = Allocates; 00182 } 00183 00184 if (Allocates == 0) { 00185 Allocates = 1; 00186 } 00187 00188 Ratio = (Misses * 1000) / Allocates; 00189 Target = Lookaside->Depth; 00190 if (Allocates < MINIMUM_ALLOCATION_THRESHOLD) { 00191 if (Target > (MINIMUM_LOOKASIDE_DEPTH + 10)) { 00192 Target -= 10; 00193 00194 } else { 00195 Target = MINIMUM_LOOKASIDE_DEPTH; 00196 } 00197 00198 } else if (Ratio < 5) { 00199 if (Target > (MINIMUM_LOOKASIDE_DEPTH + 1)) { 00200 Target -= 1; 00201 00202 } else { 00203 Target = MINIMUM_LOOKASIDE_DEPTH; 00204 } 00205 00206 } else { 00207 Target += ((Ratio * Lookaside->MaximumDepth) / (1000 * 2)) + 5; 00208 if (Target > Lookaside->MaximumDepth) { 00209 Target = Lookaside->MaximumDepth; 00210 } 00211 } 00212 00213 Lookaside->Depth = (USHORT)Target; 00214 } 00215 00216 return; 00217 }

PVOID RtlpAllocateFromHeapLookaside IN PHEAP_LOOKASIDE  Lookaside  ) 
 

Definition at line 222 of file rtl/lookasid.c.

References EXCEPTION_EXECUTE_HANDLER, NULL, and RtlpInterlockedPopEntrySList().

Referenced by RtlAllocateHeap(), RtlValidateHeap(), and RtlWalkHeap().

00228 : 00229 00230 This function removes (pops) the first entry from the specified 00231 heap lookaside list. 00232 00233 Arguments: 00234 00235 Lookaside - Supplies a pointer to a paged lookaside list structure. 00236 00237 Return Value: 00238 00239 If an entry is removed from the specified lookaside list, then the 00240 address of the entry is returned as the function value. Otherwise, 00241 NULL is returned. 00242 00243 --*/ 00244 00245 { 00246 00247 PVOID Entry; 00248 00249 Lookaside->TotalAllocates += 1; 00250 00251 // 00252 // We need to protect ourselves from a second thread that can cause us 00253 // to fault on the pop. If we do fault then we'll just do a regular pop 00254 // operation 00255 // 00256 00257 #if defined(_X86_) 00258 00259 if (USER_SHARED_DATA->ProcessorFeatures[PF_COMPARE_EXCHANGE_DOUBLE]) { 00260 00261 #endif // defined(_X86_) 00262 00263 try { 00264 00265 Entry = RtlpInterlockedPopEntrySList(&Lookaside->ListHead); 00266 00267 } except (EXCEPTION_EXECUTE_HANDLER) { 00268 00269 Entry = NULL; 00270 } 00271 00272 if (Entry != NULL) { 00273 00274 return Entry; 00275 } 00276 #if defined(_X86_) 00277 00278 } 00279 00280 #endif // defined(_X86_) 00281 00282 Lookaside->AllocateMisses += 1; 00283 return NULL; 00284 }

VOID RtlpDeleteHeapLookaside IN PHEAP_LOOKASIDE  Lookaside  ) 
 

Definition at line 101 of file rtl/lookasid.c.

00107 : 00108 00109 This function frees any entries specified by the lookaside structure. 00110 00111 Arguments: 00112 00113 Lookaside - Supplies a pointer to a heap lookaside list structure. 00114 00115 Return Value: 00116 00117 None. 00118 00119 --*/ 00120 00121 { 00122 00123 PVOID Entry; 00124 00125 return; 00126 }

BOOLEAN RtlpFreeToHeapLookaside IN PHEAP_LOOKASIDE  Lookaside,
IN PVOID  Entry
 

Definition at line 288 of file rtl/lookasid.c.

References EXCEPTION_EXECUTE_HANDLER, FALSE, RtlpInterlockedPushEntrySList(), RtlpQueryDepthSList, and TRUE.

Referenced by RtlFreeHeap().

00295 : 00296 00297 This function inserts (pushes) the specified entry into the specified 00298 paged lookaside list. 00299 00300 Arguments: 00301 00302 Lookaside - Supplies a pointer to a paged lookaside list structure. 00303 00304 Entry - Supples a pointer to the entry that is inserted in the 00305 lookaside list. 00306 00307 Return Value: 00308 00309 BOOLEAN - TRUE if the entry was put on the lookaside list and FALSE 00310 otherwise. 00311 00312 --*/ 00313 00314 { 00315 Lookaside->TotalFrees += 1; 00316 00317 #if defined(_X86_) 00318 00319 if (USER_SHARED_DATA->ProcessorFeatures[PF_COMPARE_EXCHANGE_DOUBLE]) { 00320 00321 #endif // defined(_X86_) 00322 00323 if (RtlpQueryDepthSList(&Lookaside->ListHead) < Lookaside->Depth) { 00324 00325 // 00326 // We need to protect ourselves from a second thread that can 00327 // cause us to fault on the push. If we do fault then we'll 00328 // just do a regular free operation 00329 // 00330 00331 try { 00332 00333 RtlpInterlockedPushEntrySList(&Lookaside->ListHead, 00334 (PSINGLE_LIST_ENTRY)Entry); 00335 00336 } except (EXCEPTION_EXECUTE_HANDLER) { 00337 00338 Lookaside->FreeMisses += 1; 00339 00340 return FALSE; 00341 } 00342 00343 return TRUE; 00344 } 00345 00346 #if defined(_X86_) 00347 00348 } 00349 00350 #endif // defined(_X86_) 00351 00352 Lookaside->FreeMisses += 1; 00353 00354 return FALSE; 00355 }

VOID RtlpInitializeHeapLookaside IN PHEAP_LOOKASIDE  Lookaside,
IN USHORT  Depth
 

Definition at line 45 of file rtl/lookasid.c.

References MINIMUM_LOOKASIDE_DEPTH, and RtlpInitializeSListHead.

Referenced by RtlCreateHeap().

00052 : 00053 00054 This function initializes a heap lookaside list structure 00055 00056 Arguments: 00057 00058 Lookaside - Supplies a pointer to a heap lookaside list structure. 00059 00060 Allocate - Supplies a pointer to an allocate function. 00061 00062 Free - Supplies a pointer to a free function. 00063 00064 HeapHandle - Supplies a pointer to the heap that backs this lookaside list 00065 00066 Flags - Supplies a set of heap flags. 00067 00068 Size - Supplies the size for the lookaside list entries. 00069 00070 Depth - Supplies the maximum depth of the lookaside list. 00071 00072 Return Value: 00073 00074 None. 00075 00076 --*/ 00077 00078 { 00079 00080 // 00081 // Initialize the lookaside list structure. 00082 // 00083 00084 RtlpInitializeSListHead(&Lookaside->ListHead); 00085 00086 Lookaside->Depth = MINIMUM_LOOKASIDE_DEPTH; 00087 Lookaside->MaximumDepth = 256; //Depth; 00088 Lookaside->TotalAllocates = 0; 00089 Lookaside->AllocateMisses = 0; 00090 Lookaside->TotalFrees = 0; 00091 Lookaside->FreeMisses = 0; 00092 00093 Lookaside->LastTotalAllocates = 0; 00094 Lookaside->LastAllocateMisses = 0; 00095 00096 return; 00097 }


Generated on Sat May 15 19:44:33 2004 for test by doxygen 1.3.7