update for HEAD-2003021201
[reactos.git] / ntoskrnl / mm / rmap.c
index 056b906..2848be4 100644 (file)
@@ -50,6 +50,7 @@ typedef struct _MM_RMAP_ENTRY
 /* GLOBALS ******************************************************************/
 
 static FAST_MUTEX RmapListLock;
+static NPAGED_LOOKASIDE_LIST RmapLookasideList;
 
 /* FUNCTIONS ****************************************************************/
 
@@ -57,6 +58,13 @@ VOID
 MmInitializeRmapList(VOID)
 {
   ExInitializeFastMutex(&RmapListLock);
+  ExInitializeNPagedLookasideList (&RmapLookasideList,
+                                  NULL,
+                                  NULL,
+                                  0,
+                                  sizeof(MM_RMAP_ENTRY),
+                                  TAG_RMAP,
+                                  50);
 }
 
 NTSTATUS
@@ -104,6 +112,7 @@ MmWritePagePhysicalAddress(PHYSICAL_ADDRESS PhysicalAddress)
   MemoryArea = MmOpenMemoryAreaByAddress(&Process->AddressSpace, Address);
   if (MemoryArea == NULL)
     {
+      MmUnlockAddressSpace(&Process->AddressSpace);
       ObDereferenceObject(Process);
       return(STATUS_UNSUCCESSFUL);
     }
@@ -355,7 +364,7 @@ MmInsertRmap(PHYSICAL_ADDRESS PhysicalAddress, PEPROCESS Process,
 
   Address = (PVOID)PAGE_ROUND_DOWN(Address);
 
-  new_entry = ExAllocatePoolWithTag(NonPagedPool, sizeof(MM_RMAP_ENTRY), TAG_RMAP);
+  new_entry = ExAllocateFromNPagedLookasideList(&RmapLookasideList);
   if (new_entry == NULL)
     {
       KeBugCheck(0);
@@ -404,7 +413,7 @@ MmDeleteAllRmaps(PHYSICAL_ADDRESS PhysicalAddress, PVOID Context,
          DeleteMapping(Context, previous_entry->Process, 
                        previous_entry->Address);
        }
-      ExFreePool(previous_entry);
+      ExFreeToNPagedLookasideList(&RmapLookasideList, previous_entry);
     }
   MmSetRmapListHeadPage(PhysicalAddress, NULL);
   ExReleaseFastMutex(&RmapListLock);
@@ -427,15 +436,13 @@ MmDeleteRmap(PHYSICAL_ADDRESS PhysicalAddress, PEPROCESS Process,
          if (previous_entry == NULL)
            {
              MmSetRmapListHeadPage(PhysicalAddress, current_entry->Next);
-             ExReleaseFastMutex(&RmapListLock);
-             ExFreePool(current_entry);
            }
          else
            {
              previous_entry->Next = current_entry->Next;
-             ExReleaseFastMutex(&RmapListLock);
-             ExFreePool(current_entry);
            }
+         ExReleaseFastMutex(&RmapListLock);
+         ExFreeToNPagedLookasideList(&RmapLookasideList, current_entry);
          return;
        }
       previous_entry = current_entry;