ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

lookas.c
Go to the documentation of this file.
00001 /*
00002 * PROJECT:         ReactOS Kernel
00003 * LICENSE:         GPL - See COPYING in the top level directory
00004 * FILE:            ntoskrnl/ex/lookas.c
00005 * PURPOSE:         Lookaside Lists
00006 * PROGRAMMERS:     Alex Ionescu (alex.ionescu@reactos.org)
00007 */
00008 
00009 /* INCLUDES ******************************************************************/
00010 
00011 #include <ntoskrnl.h>
00012 #define NDEBUG
00013 #include <debug.h>
00014 
00015 #if defined (ALLOC_PRAGMA)
00016 #pragma alloc_text(INIT, ExpInitLookasideLists)
00017 #endif
00018 
00019 /* GLOBALS *******************************************************************/
00020 
00021 LIST_ENTRY ExpNonPagedLookasideListHead;
00022 KSPIN_LOCK ExpNonPagedLookasideListLock;
00023 LIST_ENTRY ExpPagedLookasideListHead;
00024 KSPIN_LOCK ExpPagedLookasideListLock;
00025 LIST_ENTRY ExSystemLookasideListHead;
00026 LIST_ENTRY ExPoolLookasideListHead;
00027 GENERAL_LOOKASIDE ExpSmallNPagedPoolLookasideLists[MAXIMUM_PROCESSORS];
00028 GENERAL_LOOKASIDE ExpSmallPagedPoolLookasideLists[MAXIMUM_PROCESSORS];
00029 
00030 /* PRIVATE FUNCTIONS *********************************************************/
00031 
00032 VOID
00033 NTAPI
00034 INIT_FUNCTION
00035 ExInitializeSystemLookasideList(IN PGENERAL_LOOKASIDE List,
00036                                 IN POOL_TYPE Type,
00037                                 IN ULONG Size,
00038                                 IN ULONG Tag,
00039                                 IN USHORT MaximumDepth,
00040                                 IN PLIST_ENTRY ListHead)
00041 {
00042     /* Initialize the list */
00043     List->Tag = Tag;
00044     List->Type = Type;
00045     List->Size = Size;
00046     InsertHeadList(ListHead, &List->ListEntry);
00047     List->MaximumDepth = MaximumDepth;
00048     List->Depth = 2;
00049     List->Allocate = ExAllocatePoolWithTag;
00050     List->Free = ExFreePool;
00051     InitializeSListHead(&List->ListHead);
00052     List->TotalAllocates = 0;
00053     List->AllocateHits = 0;
00054     List->TotalFrees = 0;
00055     List->FreeHits = 0;
00056     List->LastTotalAllocates = 0;
00057     List->LastAllocateHits = 0;
00058 }
00059 
00060 VOID
00061 NTAPI
00062 INIT_FUNCTION
00063 ExInitPoolLookasidePointers(VOID)
00064 {
00065     ULONG i;
00066     PKPRCB Prcb = KeGetCurrentPrcb();
00067     PGENERAL_LOOKASIDE Entry;
00068 
00069     /* Loop for all pool lists */
00070     for (i = 0; i < MAXIMUM_PROCESSORS; i++)
00071     {
00072         /* Initialize the non-paged list */
00073         Entry = &ExpSmallNPagedPoolLookasideLists[i];
00074         InitializeSListHead(&Entry->ListHead);
00075 
00076         /* Bind to PRCB */
00077         Prcb->PPNPagedLookasideList[i].P = Entry;
00078         Prcb->PPNPagedLookasideList[i].L = Entry;
00079 
00080         /* Initialize the paged list */
00081         Entry = &ExpSmallPagedPoolLookasideLists[i];
00082         InitializeSListHead(&Entry->ListHead);
00083 
00084         /* Bind to PRCB */
00085         Prcb->PPPagedLookasideList[i].P = Entry;
00086         Prcb->PPPagedLookasideList[i].L = Entry;
00087     }
00088 }
00089 
00090 VOID
00091 NTAPI
00092 INIT_FUNCTION
00093 ExpInitLookasideLists()
00094 {
00095     ULONG i;
00096 
00097     /* Initialize locks and lists */
00098     InitializeListHead(&ExpNonPagedLookasideListHead);
00099     InitializeListHead(&ExpPagedLookasideListHead);
00100     InitializeListHead(&ExSystemLookasideListHead);
00101     InitializeListHead(&ExPoolLookasideListHead);
00102     KeInitializeSpinLock(&ExpNonPagedLookasideListLock);
00103     KeInitializeSpinLock(&ExpPagedLookasideListLock);
00104 
00105     /* Initialize the system lookaside lists */
00106     for (i = 0; i < MAXIMUM_PROCESSORS; i++)
00107     {
00108         /* Initialize the non-paged list */
00109         ExInitializeSystemLookasideList(&ExpSmallNPagedPoolLookasideLists[i],
00110                                         NonPagedPool,
00111                                         (i + 1) * 8,
00112                                         'looP',
00113                                         256,
00114                                         &ExPoolLookasideListHead);
00115 
00116         /* Initialize the paged list */
00117         ExInitializeSystemLookasideList(&ExpSmallPagedPoolLookasideLists[i],
00118                                         PagedPool,
00119                                         (i + 1) * 8,
00120                                         'looP',
00121                                         256,
00122                                         &ExPoolLookasideListHead);
00123     }
00124 }
00125 
00126 /* PUBLIC FUNCTIONS **********************************************************/
00127 
00128 /*
00129  * @implemented
00130  */
00131 PVOID
00132 NTAPI
00133 ExiAllocateFromPagedLookasideList(IN PPAGED_LOOKASIDE_LIST Lookaside)
00134 {
00135     PVOID Entry;
00136 
00137     Lookaside->L.TotalAllocates++;
00138     Entry = InterlockedPopEntrySList(&Lookaside->L.ListHead);
00139     if (!Entry)
00140     {
00141         Lookaside->L.AllocateMisses++;
00142         Entry = (Lookaside->L.Allocate)(Lookaside->L.Type,
00143                                         Lookaside->L.Size,
00144                                         Lookaside->L.Tag);
00145     }
00146     return Entry;
00147 }
00148 
00149 /*
00150  * @implemented
00151  */
00152 VOID
00153 NTAPI
00154 ExiFreeToPagedLookasideList(IN PPAGED_LOOKASIDE_LIST  Lookaside,
00155                             IN PVOID  Entry)
00156 {
00157     Lookaside->L.TotalFrees++;
00158     if (ExQueryDepthSList(&Lookaside->L.ListHead) >= Lookaside->L.Depth)
00159     {
00160         Lookaside->L.FreeMisses++;
00161         (Lookaside->L.Free)(Entry);
00162     }
00163     else
00164     {
00165         InterlockedPushEntrySList(&Lookaside->L.ListHead, (PSLIST_ENTRY)Entry);
00166     }
00167 }
00168 
00169 /*
00170  * @implemented
00171  */
00172 VOID
00173 NTAPI
00174 ExDeleteNPagedLookasideList(IN PNPAGED_LOOKASIDE_LIST Lookaside)
00175 {
00176     KIRQL OldIrql;
00177     PVOID Entry;
00178 
00179     /* Pop all entries off the stack and release their resources */
00180     for (;;)
00181     {
00182         Entry = InterlockedPopEntrySList(&Lookaside->L.ListHead);
00183         if (!Entry) break;
00184         (*Lookaside->L.Free)(Entry);
00185     }
00186 
00187     /* Remove from list */
00188     KeAcquireSpinLock(&ExpNonPagedLookasideListLock, &OldIrql);
00189     RemoveEntryList(&Lookaside->L.ListEntry);
00190     KeReleaseSpinLock(&ExpNonPagedLookasideListLock, OldIrql);
00191 }
00192 
00193 /*
00194  * @implemented
00195  */
00196 VOID
00197 NTAPI
00198 ExDeletePagedLookasideList(IN PPAGED_LOOKASIDE_LIST Lookaside)
00199 {
00200     KIRQL OldIrql;
00201     PVOID Entry;
00202 
00203     /* Pop all entries off the stack and release their resources */
00204     for (;;)
00205     {
00206         Entry = InterlockedPopEntrySList(&Lookaside->L.ListHead);
00207         if (!Entry) break;
00208         (*Lookaside->L.Free)(Entry);
00209     }
00210 
00211     /* Remove from list */
00212     KeAcquireSpinLock(&ExpPagedLookasideListLock, &OldIrql);
00213     RemoveEntryList(&Lookaside->L.ListEntry);
00214     KeReleaseSpinLock(&ExpPagedLookasideListLock, OldIrql);
00215 }
00216 
00217 /*
00218  * @implemented
00219  */
00220 VOID
00221 NTAPI
00222 ExInitializeNPagedLookasideList(IN PNPAGED_LOOKASIDE_LIST Lookaside,
00223                                 IN PALLOCATE_FUNCTION Allocate OPTIONAL,
00224                                 IN PFREE_FUNCTION Free OPTIONAL,
00225                                 IN ULONG Flags,
00226                                 IN SIZE_T Size,
00227                                 IN ULONG Tag,
00228                                 IN USHORT Depth)
00229 {
00230     /* Initialize the Header */
00231     ExInitializeSListHead(&Lookaside->L.ListHead);
00232     Lookaside->L.TotalAllocates = 0;
00233     Lookaside->L.AllocateMisses = 0;
00234     Lookaside->L.TotalFrees = 0;
00235     Lookaside->L.FreeMisses = 0;
00236     Lookaside->L.Type = NonPagedPool | Flags;
00237     Lookaside->L.Tag = Tag;
00238     Lookaside->L.Size = (ULONG)Size;
00239     Lookaside->L.Depth = 4;
00240     Lookaside->L.MaximumDepth = 256;
00241     Lookaside->L.LastTotalAllocates = 0;
00242     Lookaside->L.LastAllocateMisses = 0;
00243 
00244     /* Set the Allocate/Free Routines */
00245     if (Allocate)
00246     {
00247         Lookaside->L.Allocate = Allocate;
00248     }
00249     else
00250     {
00251         Lookaside->L.Allocate = ExAllocatePoolWithTag;
00252     }
00253 
00254     if (Free)
00255     {
00256         Lookaside->L.Free = Free;
00257     }
00258     else
00259     {
00260         Lookaside->L.Free = ExFreePool;
00261     }
00262 
00263     /* Insert it into the list */
00264     ExInterlockedInsertTailList(&ExpNonPagedLookasideListHead,
00265                                 &Lookaside->L.ListEntry,
00266                                 &ExpNonPagedLookasideListLock);
00267 }
00268 
00269 /*
00270  * @implemented
00271  */
00272 VOID
00273 NTAPI
00274 ExInitializePagedLookasideList(IN PPAGED_LOOKASIDE_LIST Lookaside,
00275                                IN PALLOCATE_FUNCTION Allocate OPTIONAL,
00276                                IN PFREE_FUNCTION Free OPTIONAL,
00277                                IN ULONG Flags,
00278                                IN SIZE_T Size,
00279                                IN ULONG Tag,
00280                                IN USHORT Depth)
00281 {
00282     /* Initialize the Header */
00283     ExInitializeSListHead(&Lookaside->L.ListHead);
00284     Lookaside->L.TotalAllocates = 0;
00285     Lookaside->L.AllocateMisses = 0;
00286     Lookaside->L.TotalFrees = 0;
00287     Lookaside->L.FreeMisses = 0;
00288     Lookaside->L.Type = PagedPool | Flags;
00289     Lookaside->L.Tag = Tag;
00290     Lookaside->L.Size = (ULONG)Size;
00291     Lookaside->L.Depth = 4;
00292     Lookaside->L.MaximumDepth = 256;
00293     Lookaside->L.LastTotalAllocates = 0;
00294     Lookaside->L.LastAllocateMisses = 0;
00295 
00296     /* Set the Allocate/Free Routines */
00297     if (Allocate)
00298     {
00299         Lookaside->L.Allocate = Allocate;
00300     }
00301     else
00302     {
00303         Lookaside->L.Allocate = ExAllocatePoolWithTag;
00304     }
00305 
00306     if (Free)
00307     {
00308         Lookaside->L.Free = Free;
00309     }
00310     else
00311     {
00312         Lookaside->L.Free = ExFreePool;
00313     }
00314 
00315     /* Insert it into the list */
00316     ExInterlockedInsertTailList(&ExpPagedLookasideListHead,
00317                                 &Lookaside->L.ListEntry,
00318                                 &ExpPagedLookasideListLock);
00319 }
00320 
00321 /* EOF */

Generated on Sun May 27 2012 04:37:10 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.