[ros-diffs] [ros-arm-bringup] 34869: More over-engineering: there really isn't any reason to keep track of the "LowestAddress" of the process' addres space. At first sight, this looked like a dynamic value that would define the lowest address at which the process has allocated memory, but this isn't the case -- the variable actually defines the lowest valid address a process can allocate memory at. This is pretty much a static value, that was compute by MmInitializeProcessAddressSpace, to either MM_LOWEST_USER_ADDRESS or MmSystemRangeStart, based on whether or not the address space has an owner process (meaning it is a user-mode address space) or not (meaning it is a kernel mode address space). This patch removes that value and all the complex code around checking it, and replaces it with a much simpler design: if there is an owner process, use MM_LOWEST_USER_ADDRESS during gap calculations, otherwise, use MmSystemRangeStart. This is both faster, and wastes less space by not tracking static data.

ros-arm-bringup at svn.reactos.org ros-arm-bringup at svn.reactos.org
Mon Jul 28 01:03:21 CEST 2008


Author: ros-arm-bringup
Date: Sun Jul 27 18:03:20 2008
New Revision: 34869

URL: http://svn.reactos.org/svn/reactos?rev=34869&view=rev
Log:
More over-engineering: there really isn't any reason to keep track of the "LowestAddress" of the process' addres space. At first sight, this looked like a dynamic value that would define the
lowest address at which the process has allocated memory, but this isn't the case -- the variable actually defines the lowest valid address a process can allocate memory at. This is pretty
much a static value, that was compute by MmInitializeProcessAddressSpace, to either MM_LOWEST_USER_ADDRESS or MmSystemRangeStart, based on whether or not the address space has an owner process
(meaning it is a user-mode address space) or not (meaning it is a kernel mode address space).
This patch removes that value and all the complex code around checking it, and replaces it with a much simpler design: if there is an owner process, use MM_LOWEST_USER_ADDRESS during gap
calculations, otherwise, use MmSystemRangeStart. This is both faster, and wastes less space by not tracking static data.


Modified:
    trunk/reactos/ntoskrnl/include/internal/mm.h
    trunk/reactos/ntoskrnl/mm/aspace.c
    trunk/reactos/ntoskrnl/mm/marea.c

Modified: trunk/reactos/ntoskrnl/include/internal/mm.h
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/include/internal/mm.h?rev=34869&r1=34868&r2=34869&view=diff
==============================================================================
--- trunk/reactos/ntoskrnl/include/internal/mm.h [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/include/internal/mm.h [iso-8859-1] Sun Jul 27 18:03:20 2008
@@ -253,7 +253,6 @@
 typedef struct _MADDRESS_SPACE
 {
     PMEMORY_AREA MemoryAreaRoot;
-    PVOID LowestAddress;
     PEPROCESS Process;
     PEX_PUSH_LOCK Lock;
 } MADDRESS_SPACE, *PMADDRESS_SPACE;

Modified: trunk/reactos/ntoskrnl/mm/aspace.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/mm/aspace.c?rev=34869&r1=34868&r2=34869&view=diff
==============================================================================
--- trunk/reactos/ntoskrnl/mm/aspace.c [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/mm/aspace.c [iso-8859-1] Sun Jul 27 18:03:20 2008
@@ -43,14 +43,12 @@
 
     if (Process != NULL)
     {
-        AddressSpace->LowestAddress = MM_LOWEST_USER_ADDRESS;
         AddressSpace->Process = Process;
         AddressSpace->Lock = (PEX_PUSH_LOCK)&Process->AddressCreationLock;
         ExInitializePushLock((PULONG_PTR)AddressSpace->Lock);        
     }
     else
     {
-        AddressSpace->LowestAddress = MmSystemRangeStart;
         AddressSpace->Process = NULL;
         AddressSpace->Lock = (PEX_PUSH_LOCK)&PsGetCurrentProcess()->AddressCreationLock;
         ExInitializePushLock((PULONG_PTR)AddressSpace->Lock);

Modified: trunk/reactos/ntoskrnl/mm/marea.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/mm/marea.c?rev=34869&r1=34868&r2=34869&view=diff
==============================================================================
--- trunk/reactos/ntoskrnl/mm/marea.c [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/mm/marea.c [iso-8859-1] Sun Jul 27 18:03:20 2008
@@ -177,8 +177,7 @@
    {
       /* FiN: The starting address can be NULL if someone explicitely asks
        * for NULL address. */
-      ASSERT(Node->StartingAddress >= AddressSpace->LowestAddress ||
-             Node->StartingAddress == NULL);
+      ASSERT(Node->StartingAddress == NULL);
       ASSERT(Node->EndingAddress >= Node->StartingAddress);
    }
 }
@@ -471,7 +470,8 @@
    ULONG_PTR Length,
    ULONG_PTR Granularity)
 {
-   PVOID HighestAddress = AddressSpace->LowestAddress < MmSystemRangeStart ?
+   PVOID LowestAddress  = AddressSpace->Process ? MM_LOWEST_USER_ADDRESS : MmSystemRangeStart;
+   PVOID HighestAddress = AddressSpace->Process ?
                           (PVOID)((ULONG_PTR)MmSystemRangeStart - 1) : (PVOID)MAXULONG_PTR;
    PVOID AlignedAddress;
    PMEMORY_AREA Node;
@@ -481,9 +481,9 @@
    MmVerifyMemoryAreas(AddressSpace);
 
    DPRINT("LowestAddress: %p HighestAddress: %p\n",
-          AddressSpace->LowestAddress, HighestAddress);
-
-   AlignedAddress = MM_ROUND_UP(AddressSpace->LowestAddress, Granularity);
+          LowestAddress, HighestAddress);
+
+   AlignedAddress = MM_ROUND_UP(LowestAddress, Granularity);
 
    /* Special case for empty tree. */
    if (AddressSpace->MemoryAreaRoot == NULL)
@@ -529,7 +529,7 @@
    }
 
    /* Check if there is enough space before the first memory area. */
-   AlignedAddress = MM_ROUND_UP(AddressSpace->LowestAddress, Granularity);
+   AlignedAddress = MM_ROUND_UP(LowestAddress, Granularity);
    if (FirstNode->StartingAddress > AlignedAddress &&
        (ULONG_PTR)FirstNode->StartingAddress - (ULONG_PTR)AlignedAddress >= Length)
    {
@@ -548,7 +548,8 @@
    ULONG_PTR Length,
    ULONG_PTR Granularity)
 {
-   PVOID HighestAddress = AddressSpace->LowestAddress < MmSystemRangeStart ?
+   PVOID LowestAddress  = AddressSpace->Process ? MM_LOWEST_USER_ADDRESS : MmSystemRangeStart;
+   PVOID HighestAddress = AddressSpace->Process ?
                           (PVOID)((ULONG_PTR)MmSystemRangeStart - 1) : (PVOID)MAXULONG_PTR;
    PVOID AlignedAddress;
    PMEMORY_AREA Node;
@@ -557,7 +558,7 @@
    MmVerifyMemoryAreas(AddressSpace);
 
    DPRINT("LowestAddress: %p HighestAddress: %p\n",
-          AddressSpace->LowestAddress, HighestAddress);
+          LowestAddress, HighestAddress);
 
    AlignedAddress = MM_ROUND_DOWN((ULONG_PTR)HighestAddress - Length + 1, Granularity);
 
@@ -568,7 +569,7 @@
    /* Special case for empty tree. */
    if (AddressSpace->MemoryAreaRoot == NULL)
    {
-      if (AlignedAddress >= (PVOID)AddressSpace->LowestAddress)
+      if (AlignedAddress >= LowestAddress)
       {
          DPRINT("MmFindGapTopDown: %p\n", AlignedAddress);
          return AlignedAddress;
@@ -616,7 +617,7 @@
    if (AlignedAddress > PreviousNode->StartingAddress)
       return NULL;
 
-   if (AlignedAddress >= (PVOID)AddressSpace->LowestAddress)
+   if (AlignedAddress >= LowestAddress)
    {
       DPRINT("MmFindGapTopDown: %p\n", AlignedAddress);
       return AlignedAddress;
@@ -647,14 +648,15 @@
 {
    PMEMORY_AREA Node = AddressSpace->MemoryAreaRoot;
    PMEMORY_AREA RightNeighbour = NULL;
-   PVOID HighestAddress = AddressSpace->LowestAddress < MmSystemRangeStart ?
+   PVOID LowestAddress  = AddressSpace->Process ? MM_LOWEST_USER_ADDRESS : MmSystemRangeStart;
+   PVOID HighestAddress = AddressSpace->Process ?
                           (PVOID)((ULONG_PTR)MmSystemRangeStart - 1) : (PVOID)MAXULONG_PTR;
 
    MmVerifyMemoryAreas(AddressSpace);
 
    Address = MM_ROUND_DOWN(Address, PAGE_SIZE);
 
-   if (AddressSpace->LowestAddress < MmSystemRangeStart)
+   if (LowestAddress < MmSystemRangeStart)
    {
       if (Address >= MmSystemRangeStart)
       {
@@ -663,7 +665,7 @@
    }
    else
    {
-      if (Address < AddressSpace->LowestAddress)
+      if (Address < LowestAddress)
       {
          return 0;
       }
@@ -973,14 +975,13 @@
                          - (ULONG_PTR) MM_ROUND_DOWN(*BaseAddress, Granularity));
       *BaseAddress = MM_ROUND_DOWN(*BaseAddress, Granularity);
 
-      if (AddressSpace->LowestAddress == MmSystemRangeStart &&
-          *BaseAddress < MmSystemRangeStart)
+      if (!AddressSpace->Process && *BaseAddress < MmSystemRangeStart)
       {
          CHECKPOINT;
          return STATUS_ACCESS_VIOLATION;
       }
 
-      if (AddressSpace->LowestAddress < MmSystemRangeStart &&
+      if (AddressSpace->Process &&
           (ULONG_PTR)(*BaseAddress) + tmpLength > (ULONG_PTR)MmSystemRangeStart)
       {
          CHECKPOINT;



More information about the Ros-diffs mailing list