Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

170 lines
3.8 KiB

  1. /*++
  2. Copyright (c) 1999-2002 Microsoft Corporation
  3. Module Name:
  4. pplasl.c
  5. Abstract:
  6. This file contains the implementation of a per-processor lookaside
  7. list manager.
  8. Author:
  9. Shaun Cox (shaunco) 25-Oct-1999
  10. --*/
  11. #include "precomp.h"
  12. HANDLE
  13. PplCreatePool(
  14. IN PALLOCATE_FUNCTION Allocate,
  15. IN PFREE_FUNCTION Free,
  16. IN ULONG Flags,
  17. IN SIZE_T Size,
  18. IN ULONG Tag,
  19. IN USHORT Depth
  20. )
  21. {
  22. HANDLE PoolHandle;
  23. SIZE_T PoolSize;
  24. CLONG NumberLookasideLists;
  25. CLONG i;
  26. PUL_NPAGED_LOOKASIDE_LIST Lookaside;
  27. // Allocate room for 1 lookaside list per processor plus 1 extra
  28. // lookaside list for overflow. Only allocate 1 lookaside list if
  29. // we're on a single processor machine.
  30. //
  31. NumberLookasideLists = g_UlNumberOfProcessors;
  32. if (g_UlNumberOfProcessors > 1)
  33. {
  34. NumberLookasideLists++;
  35. }
  36. PoolSize = sizeof(UL_NPAGED_LOOKASIDE_LIST) * NumberLookasideLists;
  37. PoolHandle = UL_ALLOCATE_POOL(NonPagedPool, PoolSize, Tag);
  38. if (PoolHandle)
  39. {
  40. for (i = 0, Lookaside = (PUL_NPAGED_LOOKASIDE_LIST)PoolHandle;
  41. i < NumberLookasideLists;
  42. i++, Lookaside++)
  43. {
  44. ExInitializeNPagedLookasideList(
  45. &Lookaside->List,
  46. Allocate,
  47. Free,
  48. Flags,
  49. Size,
  50. Tag,
  51. Depth);
  52. // ExInitializeNPagedLookasideList doesn't really set the
  53. // maximum depth to Depth, so we'll do it here.
  54. //
  55. if (Depth != 0)
  56. {
  57. Lookaside->List.L.MaximumDepth = Depth;
  58. }
  59. }
  60. }
  61. return PoolHandle;
  62. }
  63. VOID
  64. PplDestroyPool(
  65. IN HANDLE PoolHandle,
  66. IN ULONG Tag
  67. )
  68. {
  69. CLONG NumberLookasideLists;
  70. CLONG i;
  71. PUL_NPAGED_LOOKASIDE_LIST Lookaside;
  72. #if !DBG
  73. UNREFERENCED_PARAMETER(Tag);
  74. #endif
  75. if (!PoolHandle)
  76. {
  77. return;
  78. }
  79. NumberLookasideLists = g_UlNumberOfProcessors;
  80. if (g_UlNumberOfProcessors > 1)
  81. {
  82. NumberLookasideLists++;
  83. }
  84. for (i = 0, Lookaside = (PUL_NPAGED_LOOKASIDE_LIST)PoolHandle;
  85. i < NumberLookasideLists;
  86. i++, Lookaside++)
  87. {
  88. ExDeleteNPagedLookasideList(&Lookaside->List);
  89. }
  90. UL_FREE_POOL(PoolHandle, Tag);
  91. }
  92. HANDLE
  93. PpslCreatePool(
  94. IN ULONG Tag,
  95. IN USHORT MaxDepth,
  96. IN USHORT MinDepth
  97. )
  98. {
  99. PPER_PROC_SLISTS pPPSList;
  100. HANDLE PoolHandle;
  101. SIZE_T PoolSize;
  102. CLONG NumberSLists;
  103. CLONG i;
  104. NumberSLists = g_UlNumberOfProcessors + 1;
  105. PoolSize = sizeof(PER_PROC_SLISTS) * NumberSLists;
  106. PoolHandle = UL_ALLOCATE_POOL(NonPagedPool, PoolSize, Tag);
  107. if (PoolHandle)
  108. {
  109. for (i = 0; i < NumberSLists; i++)
  110. {
  111. pPPSList = PER_PROC_SLIST(PoolHandle, i);
  112. ExInitializeSListHead(&(pPPSList->SL));
  113. pPPSList->MaxDepth = MaxDepth;
  114. pPPSList->MinDepth = MinDepth;
  115. pPPSList->Delta = 0;
  116. pPPSList->EntriesServed = 0;
  117. pPPSList->PrevEntriesServed = 0;
  118. #if DBG
  119. pPPSList->TotalServed = 0;
  120. #endif
  121. }
  122. }
  123. return PoolHandle;
  124. }
  125. VOID
  126. PpslDestroyPool(
  127. IN HANDLE PoolHandle,
  128. IN ULONG Tag
  129. )
  130. {
  131. #if !DBG
  132. UNREFERENCED_PARAMETER(Tag);
  133. #endif
  134. if (!PoolHandle)
  135. {
  136. return;
  137. }
  138. UL_FREE_POOL(PoolHandle, Tag);
  139. }