ReactOS 0.4.15-dev-8146-gdc0ed6d
lookas.c
Go to the documentation of this file.
1/*
2* PROJECT: ReactOS Kernel
3* LICENSE: GPL - See COPYING in the top level directory
4* FILE: ntoskrnl/ex/lookas.c
5* PURPOSE: Lookaside Lists
6* PROGRAMMERS: Alex Ionescu (alex.ionescu@reactos.org)
7*/
8
9/* INCLUDES ******************************************************************/
10
11#include <ntoskrnl.h>
12#define NDEBUG
13#include <debug.h>
14
15/* GLOBALS *******************************************************************/
16
25
26/* PRIVATE FUNCTIONS *********************************************************/
27
28CODE_SEG("INIT")
29VOID
34 IN ULONG Tag,
35 IN USHORT MaximumDepth,
36 IN PLIST_ENTRY ListHead)
37{
38 /* Initialize the list */
39 List->Tag = Tag;
40 List->Type = Type;
41 List->Size = Size;
42 InsertHeadList(ListHead, &List->ListEntry);
43 List->MaximumDepth = MaximumDepth;
44 List->Depth = 2;
45 List->Allocate = ExAllocatePoolWithTag;
46 List->Free = ExFreePool;
47 InitializeSListHead(&List->ListHead);
48 List->TotalAllocates = 0;
49 List->AllocateHits = 0;
50 List->TotalFrees = 0;
51 List->FreeHits = 0;
52 List->LastTotalAllocates = 0;
53 List->LastAllocateHits = 0;
54}
55
56CODE_SEG("INIT")
57VOID
60{
61 ULONG i;
62 PKPRCB Prcb = KeGetCurrentPrcb();
64
65 /* Loop for all pool lists */
66 for (i = 0; i < NUMBER_POOL_LOOKASIDE_LISTS; i++)
67 {
68 /* Initialize the non-paged list */
70 InitializeSListHead(&Entry->ListHead);
71
72 /* Bind to PRCB */
73 Prcb->PPNPagedLookasideList[i].P = Entry;
74 Prcb->PPNPagedLookasideList[i].L = Entry;
75
76 /* Initialize the paged list */
78 InitializeSListHead(&Entry->ListHead);
79
80 /* Bind to PRCB */
81 Prcb->PPPagedLookasideList[i].P = Entry;
82 Prcb->PPPagedLookasideList[i].L = Entry;
83 }
84}
85
86CODE_SEG("INIT")
87VOID
90{
91 ULONG i;
92
93 /* Initialize locks and lists */
100
101 /* Initialize the system lookaside lists */
102 for (i = 0; i < NUMBER_POOL_LOOKASIDE_LISTS; i++)
103 {
104 /* Initialize the non-paged list */
107 (i + 1) * 8,
108 'looP',
109 256,
111
112 /* Initialize the paged list */
114 PagedPool,
115 (i + 1) * 8,
116 'looP',
117 256,
119 }
120}
121
122/* PUBLIC FUNCTIONS **********************************************************/
123
124/*
125 * @implemented
126 */
127PVOID
128NTAPI
130{
131 PVOID Entry;
132
133 Lookaside->L.TotalAllocates++;
135 if (!Entry)
136 {
137 Lookaside->L.AllocateMisses++;
138 Entry = (Lookaside->L.Allocate)(Lookaside->L.Type,
139 Lookaside->L.Size,
140 Lookaside->L.Tag);
141 }
142 return Entry;
143}
144
145/*
146 * @implemented
147 */
148VOID
149NTAPI
151 IN PVOID Entry)
152{
153 Lookaside->L.TotalFrees++;
154 if (ExQueryDepthSList(&Lookaside->L.ListHead) >= Lookaside->L.Depth)
155 {
156 Lookaside->L.FreeMisses++;
157 (Lookaside->L.Free)(Entry);
158 }
159 else
160 {
162 }
163}
164
165/*
166 * @implemented
167 */
168VOID
169NTAPI
171{
173 PVOID Entry;
174
175 /* Pop all entries off the stack and release their resources */
176 for (;;)
177 {
179 if (!Entry) break;
180 (*Lookaside->L.Free)(Entry);
181 }
182
183 /* Remove from list */
185 RemoveEntryList(&Lookaside->L.ListEntry);
187}
188
189/*
190 * @implemented
191 */
192VOID
193NTAPI
195{
197 PVOID Entry;
198
199 /* Pop all entries off the stack and release their resources */
200 for (;;)
201 {
203 if (!Entry) break;
204 (*Lookaside->L.Free)(Entry);
205 }
206
207 /* Remove from list */
209 RemoveEntryList(&Lookaside->L.ListEntry);
211}
212
213/*
214 * @implemented
215 */
216VOID
217NTAPI
219 IN PALLOCATE_FUNCTION Allocate OPTIONAL,
220 IN PFREE_FUNCTION Free OPTIONAL,
221 IN ULONG Flags,
222 IN SIZE_T Size,
223 IN ULONG Tag,
225{
226 /* Initialize the Header */
227 ExInitializeSListHead(&Lookaside->L.ListHead);
228 Lookaside->L.TotalAllocates = 0;
229 Lookaside->L.AllocateMisses = 0;
230 Lookaside->L.TotalFrees = 0;
231 Lookaside->L.FreeMisses = 0;
232 Lookaside->L.Type = NonPagedPool | Flags;
233 Lookaside->L.Tag = Tag;
234 Lookaside->L.Size = (ULONG)Size;
235 Lookaside->L.Depth = 4;
236 Lookaside->L.MaximumDepth = 256;
237 Lookaside->L.LastTotalAllocates = 0;
238 Lookaside->L.LastAllocateMisses = 0;
239
240 /* Set the Allocate/Free Routines */
241 if (Allocate)
242 {
243 Lookaside->L.Allocate = Allocate;
244 }
245 else
246 {
247 Lookaside->L.Allocate = ExAllocatePoolWithTag;
248 }
249
250 if (Free)
251 {
252 Lookaside->L.Free = Free;
253 }
254 else
255 {
256 Lookaside->L.Free = ExFreePool;
257 }
258
259 /* Insert it into the list */
261 &Lookaside->L.ListEntry,
263}
264
265/*
266 * @implemented
267 */
268VOID
269NTAPI
271 IN PALLOCATE_FUNCTION Allocate OPTIONAL,
272 IN PFREE_FUNCTION Free OPTIONAL,
273 IN ULONG Flags,
274 IN SIZE_T Size,
275 IN ULONG Tag,
277{
278 /* Initialize the Header */
279 ExInitializeSListHead(&Lookaside->L.ListHead);
280 Lookaside->L.TotalAllocates = 0;
281 Lookaside->L.AllocateMisses = 0;
282 Lookaside->L.TotalFrees = 0;
283 Lookaside->L.FreeMisses = 0;
284 Lookaside->L.Type = PagedPool | Flags;
285 Lookaside->L.Tag = Tag;
286 Lookaside->L.Size = (ULONG)Size;
287 Lookaside->L.Depth = 4;
288 Lookaside->L.MaximumDepth = 256;
289 Lookaside->L.LastTotalAllocates = 0;
290 Lookaside->L.LastAllocateMisses = 0;
291
292 /* Set the Allocate/Free Routines */
293 if (Allocate)
294 {
295 Lookaside->L.Allocate = Allocate;
296 }
297 else
298 {
299 Lookaside->L.Allocate = ExAllocatePoolWithTag;
300 }
301
302 if (Free)
303 {
304 Lookaside->L.Free = Free;
305 }
306 else
307 {
308 Lookaside->L.Free = ExFreePool;
309 }
310
311 /* Insert it into the list */
313 &Lookaside->L.ListEntry,
315}
316
317/* EOF */
#define CODE_SEG(...)
Type
Definition: Type.h:7
#define RemoveEntryList(Entry)
Definition: env_spec_w32.h:986
#define InsertHeadList(ListHead, Entry)
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
UCHAR KIRQL
Definition: env_spec_w32.h:591
ULONG KSPIN_LOCK
Definition: env_spec_w32.h:72
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
#define NonPagedPool
Definition: env_spec_w32.h:307
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
#define KeInitializeSpinLock(sl)
Definition: env_spec_w32.h:604
#define PagedPool
Definition: env_spec_w32.h:308
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
PLIST_ENTRY NTAPI ExInterlockedInsertTailList(IN OUT PLIST_ENTRY ListHead, IN OUT PLIST_ENTRY ListEntry, IN OUT PKSPIN_LOCK Lock)
Definition: interlocked.c:140
VOID ExpInitLookasideLists()
VOID NTAPI ExInitializePagedLookasideList(IN PPAGED_LOOKASIDE_LIST Lookaside, IN PALLOCATE_FUNCTION Allocate OPTIONAL, IN PFREE_FUNCTION Free OPTIONAL, IN ULONG Flags, IN SIZE_T Size, IN ULONG Tag, IN USHORT Depth)
Definition: lookas.c:270
KSPIN_LOCK ExpPagedLookasideListLock
Definition: lookas.c:20
PVOID NTAPI ExiAllocateFromPagedLookasideList(IN PPAGED_LOOKASIDE_LIST Lookaside)
Definition: lookas.c:129
VOID NTAPI ExInitializeSystemLookasideList(IN PGENERAL_LOOKASIDE List, IN POOL_TYPE Type, IN ULONG Size, IN ULONG Tag, IN USHORT MaximumDepth, IN PLIST_ENTRY ListHead)
Definition: lookas.c:31
LIST_ENTRY ExPoolLookasideListHead
Definition: lookas.c:22
KSPIN_LOCK ExpNonPagedLookasideListLock
Definition: lookas.c:18
LIST_ENTRY ExpPagedLookasideListHead
Definition: lookas.c:19
GENERAL_LOOKASIDE ExpSmallNPagedPoolLookasideLists[NUMBER_POOL_LOOKASIDE_LISTS]
Definition: lookas.c:23
VOID NTAPI ExiFreeToPagedLookasideList(IN PPAGED_LOOKASIDE_LIST Lookaside, IN PVOID Entry)
Definition: lookas.c:150
VOID NTAPI ExDeletePagedLookasideList(IN PPAGED_LOOKASIDE_LIST Lookaside)
Definition: lookas.c:194
LIST_ENTRY ExSystemLookasideListHead
Definition: lookas.c:21
LIST_ENTRY ExpNonPagedLookasideListHead
Definition: lookas.c:17
VOID NTAPI ExInitPoolLookasidePointers(VOID)
Definition: lookas.c:59
GENERAL_LOOKASIDE ExpSmallPagedPoolLookasideLists[NUMBER_POOL_LOOKASIDE_LISTS]
Definition: lookas.c:24
VOID NTAPI ExDeleteNPagedLookasideList(IN PNPAGED_LOOKASIDE_LIST Lookaside)
Definition: lookas.c:170
VOID NTAPI ExInitializeNPagedLookasideList(IN PNPAGED_LOOKASIDE_LIST Lookaside, IN PALLOCATE_FUNCTION Allocate OPTIONAL, IN PFREE_FUNCTION Free OPTIONAL, IN ULONG Flags, IN SIZE_T Size, IN ULONG Tag, IN USHORT Depth)
Definition: lookas.c:218
#define NUMBER_POOL_LOOKASIDE_LISTS
Definition: ketypes.h:371
FORCEINLINE struct _KPRCB * KeGetCurrentPrcb(VOID)
Definition: ketypes.h:1161
unsigned short USHORT
Definition: pedump.c:61
PULONG MinorVersion OPTIONAL
Definition: CrossNt.h:68
base of all file and directory entries
Definition: entries.h:83
GENERAL_LOOKASIDE_POOL PPNPagedLookasideList[NUMBER_POOL_LOOKASIDE_LISTS]
Definition: ketypes.h:709
GENERAL_LOOKASIDE_POOL PPPagedLookasideList[NUMBER_POOL_LOOKASIDE_LISTS]
Definition: ketypes.h:710
Definition: typedefs.h:120
INT POOL_TYPE
Definition: typedefs.h:78
#define NTAPI
Definition: typedefs.h:36
ULONG_PTR SIZE_T
Definition: typedefs.h:80
#define IN
Definition: typedefs.h:39
uint32_t ULONG
Definition: typedefs.h:59
_Must_inspect_result_ _In_ WDFDEVICE _In_ BOOLEAN _In_opt_ PVOID Tag
Definition: wdfdevice.h:4065
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4533
_Must_inspect_result_ _In_opt_ PWDF_OBJECT_ATTRIBUTES _In_ _In_ _Strict_type_match_ POOL_TYPE _In_opt_ PWDF_OBJECT_ATTRIBUTES _In_opt_ ULONG _Out_ WDFLOOKASIDE * Lookaside
Definition: wdfmemory.h:414
_Must_inspect_result_ _In_ WDFCMRESLIST List
Definition: wdfresource.h:550
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
FORCEINLINE USHORT ExQueryDepthSList(_In_ PSLIST_HEADER SListHead)
Definition: exfuncs.h:153
_In_opt_ PALLOCATE_FUNCTION Allocate
Definition: exfuncs.h:814
_In_opt_ PALLOCATE_FUNCTION _In_opt_ PFREE_FUNCTION _In_ ULONG _In_ SIZE_T _In_ ULONG _In_ USHORT Depth
Definition: exfuncs.h:819
#define ExInitializeSListHead
_In_opt_ PALLOCATE_FUNCTION _In_opt_ PFREE_FUNCTION Free
Definition: exfuncs.h:815
struct LOOKASIDE_ALIGN _GENERAL_LOOKASIDE GENERAL_LOOKASIDE
struct LOOKASIDE_ALIGN _GENERAL_LOOKASIDE * PGENERAL_LOOKASIDE
struct LOOKASIDE_ALIGN _NPAGED_LOOKASIDE_LIST * PNPAGED_LOOKASIDE_LIST
struct LOOKASIDE_ALIGN _PAGED_LOOKASIDE_LIST * PPAGED_LOOKASIDE_LIST
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:778
#define InterlockedPushEntrySList(SListHead, SListEntry)
Definition: rtlfuncs.h:3389
#define InterlockedPopEntrySList(SListHead)
Definition: rtlfuncs.h:3392
FORCEINLINE VOID InitializeSListHead(_Out_ PSLIST_HEADER SListHead)
Definition: rtlfuncs.h:3351
#define PSLIST_ENTRY
Definition: rtltypes.h:134