- Changed MmGetContinuousPages from using an alignment to using a boundary.

- Removed MmAllocateContiguousAlignedMemory. 

svn path=/trunk/; revision=17185
This commit is contained in:
Hartmut Birr
2005-08-07 23:07:17 +00:00
parent 73a4ae89a5
commit 6faab780d4
4 changed files with 122 additions and 133 deletions
+6 -7
View File
@@ -667,7 +667,7 @@ PVOID MmInitializePageList(ULONG_PTR FirstPhysKernelAddress,
PFN_TYPE MmGetContinuousPages(ULONG NumberOfBytes,
PHYSICAL_ADDRESS LowestAcceptableAddress,
PHYSICAL_ADDRESS HighestAcceptableAddress,
ULONG Alignment);
PHYSICAL_ADDRESS BoundaryAddressMultiple);
NTSTATUS MmInitZeroPageThread(VOID);
@@ -795,12 +795,11 @@ NTSTATUS MmTrimUserMemory(ULONG Target, ULONG Priority, PULONG NrFreedPages);
/* cont.c ********************************************************************/
PVOID STDCALL
MmAllocateContiguousAlignedMemory(IN ULONG NumberOfBytes,
IN PHYSICAL_ADDRESS LowestAcceptableAddress,
IN PHYSICAL_ADDRESS HighestAcceptableAddress,
IN PHYSICAL_ADDRESS BoundaryAddressMultiple OPTIONAL,
IN MEMORY_CACHING_TYPE CacheType OPTIONAL,
IN ULONG Alignment);
MmAllocateContiguousMemorySpecifyCache(IN SIZE_T NumberOfBytes,
IN PHYSICAL_ADDRESS LowestAcceptableAddress,
IN PHYSICAL_ADDRESS HighestAcceptableAddress,
IN PHYSICAL_ADDRESS BoundaryAddressMultiple OPTIONAL,
IN MEMORY_CACHING_TYPE CacheType OPTIONAL);
/* region.c ************************************************************/
+43 -69
View File
@@ -28,16 +28,44 @@ MmFreeContinuousPage(PVOID Context, MEMORY_AREA* MemoryArea, PVOID Address,
}
}
/*
/**********************************************************************
* NAME EXPORTED
* MmAllocateContiguousMemorySpecifyCache@32
*
* DESCRIPTION
* Allocates a range of physically contiguous memory
* with a cache parameter.
*
* ARGUMENTS
* NumberOfBytes
* Size of the memory block to allocate;
*
* LowestAcceptableAddress
* Lowest address valid for the caller.
*
* HighestAcceptableAddress
* Highest address valid for the caller.
*
* BoundaryAddressMultiple
* Address multiple not to be crossed by allocated buffer (optional).
*
* CacheType
* Type of caching to use.
*
* RETURN VALUE
* The virtual address of the memory block on success;
* NULL on error.
*
* REVISIONS
*
* @implemented
*/
PVOID STDCALL
MmAllocateContiguousAlignedMemory(IN ULONG NumberOfBytes,
IN PHYSICAL_ADDRESS LowestAcceptableAddress OPTIONAL,
IN PHYSICAL_ADDRESS HighestAcceptableAddress,
IN PHYSICAL_ADDRESS BoundaryAddressMultiple OPTIONAL,
IN MEMORY_CACHING_TYPE CacheType OPTIONAL,
IN ULONG Alignment)
MmAllocateContiguousMemorySpecifyCache(IN SIZE_T NumberOfBytes,
IN PHYSICAL_ADDRESS LowestAcceptableAddress OPTIONAL,
IN PHYSICAL_ADDRESS HighestAcceptableAddress,
IN PHYSICAL_ADDRESS BoundaryAddressMultiple OPTIONAL,
IN MEMORY_CACHING_TYPE CacheType OPTIONAL)
{
PMEMORY_AREA MArea;
NTSTATUS Status;
@@ -66,7 +94,7 @@ MmAllocateContiguousAlignedMemory(IN ULONG NumberOfBytes,
&MArea,
FALSE,
FALSE,
BoundaryAddressMultiple);
(PHYSICAL_ADDRESS)0LL);
MmUnlockAddressSpace(MmGetKernelAddressSpace());
if (!NT_SUCCESS(Status))
@@ -77,7 +105,7 @@ MmAllocateContiguousAlignedMemory(IN ULONG NumberOfBytes,
PBase = MmGetContinuousPages(NumberOfBytes,
LowestAcceptableAddress,
HighestAcceptableAddress,
Alignment);
BoundaryAddressMultiple);
if (PBase == 0)
{
MmLockAddressSpace(MmGetKernelAddressSpace());
@@ -91,7 +119,7 @@ MmAllocateContiguousAlignedMemory(IN ULONG NumberOfBytes,
for (i = 0; i < (PAGE_ROUND_UP(NumberOfBytes) / PAGE_SIZE); i++, PBase++)
{
MmCreateVirtualMapping(NULL,
(char*)BaseAddress + (i * 4096),
(char*)BaseAddress + (i * PAGE_SIZE),
Attributes,
&PBase,
1);
@@ -130,18 +158,11 @@ PVOID STDCALL
MmAllocateContiguousMemory (IN ULONG NumberOfBytes,
IN PHYSICAL_ADDRESS HighestAcceptableAddress)
{
PHYSICAL_ADDRESS LowestAcceptableAddress;
PHYSICAL_ADDRESS BoundaryAddressMultiple;
LowestAcceptableAddress.QuadPart = 0;
BoundaryAddressMultiple.QuadPart = 0;
return(MmAllocateContiguousAlignedMemory(NumberOfBytes,
LowestAcceptableAddress,
HighestAcceptableAddress,
BoundaryAddressMultiple,
MmCached,
PAGE_SIZE));
return MmAllocateContiguousMemorySpecifyCache(NumberOfBytes,
(PHYSICAL_ADDRESS)0LL,
HighestAcceptableAddress,
(PHYSICAL_ADDRESS)0LL,
MmCached);
}
@@ -179,53 +200,6 @@ MmFreeContiguousMemory(IN PVOID BaseAddress)
MmUnlockAddressSpace(MmGetKernelAddressSpace());
}
/**********************************************************************
* NAME EXPORTED
* MmAllocateContiguousMemorySpecifyCache@32
*
* DESCRIPTION
* Allocates a range of physically contiguous memory
* with a cache parameter.
*
* ARGUMENTS
* NumberOfBytes
* Size of the memory block to allocate;
*
* LowestAcceptableAddress
* Lowest address valid for the caller.
*
* HighestAcceptableAddress
* Highest address valid for the caller.
*
* BoundaryAddressMultiple
* Address multiple not to be crossed by allocated buffer (optional).
*
* CacheType
* Type of caching to use.
*
* RETURN VALUE
* The virtual address of the memory block on success;
* NULL on error.
*
* REVISIONS
*
* @implemented
*/
PVOID STDCALL
MmAllocateContiguousMemorySpecifyCache (IN ULONG NumberOfBytes,
IN PHYSICAL_ADDRESS LowestAcceptableAddress,
IN PHYSICAL_ADDRESS HighestAcceptableAddress,
IN PHYSICAL_ADDRESS BoundaryAddressMultiple OPTIONAL,
IN MEMORY_CACHING_TYPE CacheType)
{
return(MmAllocateContiguousAlignedMemory(NumberOfBytes,
LowestAcceptableAddress,
HighestAcceptableAddress,
BoundaryAddressMultiple,
CacheType,
PAGE_SIZE));
}
/**********************************************************************
* NAME EXPORTED
* MmFreeContiguousMemorySpecifyCache@12
+73 -56
View File
@@ -161,85 +161,102 @@ PFN_TYPE
MmGetContinuousPages(ULONG NumberOfBytes,
PHYSICAL_ADDRESS LowestAcceptableAddress,
PHYSICAL_ADDRESS HighestAcceptableAddress,
ULONG Alignment)
PHYSICAL_ADDRESS BoundaryAddressMultiple)
{
ULONG NrPages;
ULONG i;
ULONG i, j;
ULONG start;
ULONG last;
ULONG length;
ULONG boundary;
KIRQL oldIrql;
NrPages = PAGE_ROUND_UP(NumberOfBytes) / PAGE_SIZE;
KeAcquireSpinLock(&PageListLock, &oldIrql);
start = -1;
length = 0;
for (i = (LowestAcceptableAddress.QuadPart / PAGE_SIZE); i < (HighestAcceptableAddress.QuadPart / PAGE_SIZE); )
last = min(HighestAcceptableAddress.QuadPart / PAGE_SIZE, MmPageArraySize - 1);
boundary = BoundaryAddressMultiple.QuadPart / PAGE_SIZE;
for (j = 0; j < 2; j++)
{
if (MmPageArray[i].Flags.Type == MM_PHYSICAL_PAGE_FREE)
start = -1;
length = 0;
/* First try to allocate the pages above the 16MB area. This may fail
* because there are not enough continuous pages or we cannot allocate
* pages above the 16MB area because the caller has specify an upper limit.
* The second try uses the specified lower limit.
*/
for (i = j == 0 ? 0x100000 / PAGE_SIZE : LowestAcceptableAddress.QuadPart / PAGE_SIZE; i <= last; )
{
if (start == (ULONG)-1)
if (MmPageArray[i].Flags.Type == MM_PHYSICAL_PAGE_FREE)
{
start = i;
length = 1;
if (start == (ULONG)-1)
{
start = i;
length = 1;
}
else
{
length++;
if (boundary)
{
if (start / boundary != i / boundary)
{
start = i;
length = 1;
}
}
}
if (length == NrPages)
{
break;
}
}
else
{
length++;
start = (ULONG)-1;
}
i++;
if (length == NrPages)
}
if (start != (ULONG)-1 && length == NrPages)
{
for (i = start; i < (start + length); i++)
{
break;
RemoveEntryList(&MmPageArray[i].ListEntry);
if (MmPageArray[i].Flags.Zero == 0)
{
UnzeroedPageCount--;
}
MmStats.NrFreePages--;
MmStats.NrSystemPages++;
MmPageArray[i].Flags.Type = MM_PHYSICAL_PAGE_USED;
MmPageArray[i].Flags.Consumer = MC_NPPOOL;
MmPageArray[i].ReferenceCount = 1;
MmPageArray[i].LockCount = 0;
MmPageArray[i].MapCount = 0;
MmPageArray[i].SavedSwapEntry = 0;
InsertTailList(&UsedPageListHeads[MC_NPPOOL],
&MmPageArray[i].ListEntry);
}
KeReleaseSpinLock(&PageListLock, oldIrql);
for (i = start; i < (start + length); i++)
{
if (MmPageArray[i].Flags.Zero == 0)
{
MiZeroPage(i);
}
else
{
MmPageArray[i].Flags.Zero = 0;
}
}
return start;
}
else
{
start = -1;
/*
* Fast forward to the base of the next aligned region
*/
i = ROUND_UP((i + 1), (Alignment / PAGE_SIZE));
}
}
if (start == (ULONG)-1 || length != NrPages)
{
KeReleaseSpinLock(&PageListLock, oldIrql);
return 0;
}
for (i = start; i < (start + length); i++)
{
RemoveEntryList(&MmPageArray[i].ListEntry);
if (MmPageArray[i].Flags.Zero == 0)
{
UnzeroedPageCount--;
}
MmStats.NrFreePages--;
MmStats.NrSystemPages++;
MmPageArray[i].Flags.Type = MM_PHYSICAL_PAGE_USED;
MmPageArray[i].Flags.Consumer = MC_NPPOOL;
MmPageArray[i].ReferenceCount = 1;
MmPageArray[i].LockCount = 0;
MmPageArray[i].MapCount = 0;
MmPageArray[i].SavedSwapEntry = 0;
InsertTailList(&UsedPageListHeads[MC_NPPOOL],
&MmPageArray[i].ListEntry);
}
KeReleaseSpinLock(&PageListLock, oldIrql);
for (i = start; i < (start + length); i++)
{
if (MmPageArray[i].Flags.Zero == 0)
{
MiZeroPage(i);
}
else
{
MmPageArray[i].Flags.Zero = 0;
}
}
return start;
return 0;
}
-1
View File
@@ -680,7 +680,6 @@ MmAddPhysicalMemory@8
MmAddVerifierThunks@8
MmAdjustWorkingSetSize@12
MmAdvanceMdl@8
MmAllocateContiguousAlignedMemory@36
MmAllocateContiguousMemory@12
MmAllocateContiguousMemorySpecifyCache@32
MmAllocateMappingAddress@8