The MmAllocatePagesForMdl routine allocates zero-filled, nonpaged, physical memory pages to an MDL.
PMDL MmAllocatePagesForMdl( PHYSICAL_ADDRESS LowAddress, PHYSICAL_ADDRESS HighAddress, PHYSICAL_ADDRESS SkipBytes, SIZE_T TotalBytes );
Specifies the physical address of the start of the first address range from which the allocated pages can come. If MmAllocatePagesForMdl cannot allocate the requested number of bytes in the first address range, it iterates through additional address ranges to get more pages. At each iteration, MmAllocatePagesForMdl adds the value of SkipBytes to the previous start address to obtain the start of the next address range.
Specifies the physical address of the end of the first address range from which the allocated pages can come.
Specifies the number of bytes to skip from the start of the previous address range from which the allocated pages can come. SkipBytes must be an integer multiple of the virtual memory page size, in bytes.
Specifies the total number of bytes to allocate for the MDL.
MmAllocatePagesForMdl returns one of the following:
||The MDL pointer describes a set of physical pages in the specified address range. If the requested number of bytes is not available, the MDL describes as much physical memory as is available.|
||There are no physical memory pages in the specified address ranges, or there is not enough memory pool for the MDL itself.|
Drivers that are running in Windows Server 2003 Service Pack 1 (SP1) and later versions of Windows should use the MmAllocatePagesForMdlEx routine instead of MmAllocatePagesForMdl. MmAllocatePagesForMdlEx provides better performance than MmAllocatePagesForMdl by avoiding unnecessary flushes of the TLB and cache memory.
The physical memory pages that are returned by MmAllocatePagesForMdl are typically not contiguous pages. MmAllocatePagesForMdl always fills the allocated pages in the returned MDL with zeros.
MmAllocatePagesForMdl is designed to be used by kernel-mode drivers that do not need corresponding virtual addresses (that is, they need physical pages and do not need the pages to be physically contiguous) or by kernel-mode drivers that can achieve substantial performance gains if physical memory for a device is allocated in a specific physical address range. A driver for an AGP graphics card is an example of such a driver.
Depending on how much physical memory is currently available in the requested ranges, MmAllocatePagesForMdl might return an MDL that describes less memory than was requested. The routine returns NULL if no memory was allocated. The caller should check the amount of memory that is actually allocated to the MDL.
The caller must use MmFreePagesFromMdl to release the memory pages that are described by an MDL that was created by MmAllocatePagesForMdl. After calling MmFreePagesFromMdl, the caller must also call ExFreePool to release the memory that is allocated for the MDL structure itself.
In Windows 2000 and later versions of Windows, the maximum amount of memory that MmAllocatePagesForMdl can allocate in a single call is (4 gigabytes - PAGE_SIZE). The routine can satisfy an allocation request for this amount only if enough pages are available.
MmAllocatePagesForMdl runs at IRQL <= APC_LEVEL. Windows Server 2008 and later versions of the Windows operating system enable MmAllocatePagesForMdl callers to call at DISPATCH_LEVEL. However, you can improve driver performance by calling at APC_LEVEL or below.
|Minimum supported client||Available in Windows 2000 and later versions of Windows; however, MmAllocatePagesForMdlEx should be used instead of MmAllocatePagesForMdl in Windows Server 2003 Service Pack 1 (SP1) and later versions of Windows.|
|Header||wdm.h (include Wdm.h, Ntddk.h, Ntifs.h)|
|IRQL||See Remarks section.|
|DDI compliance rules||IrqlMmApcLte, HwStorPortProhibitedDDIs, SpNoWait, StorPortStartIo|
Send feedback about: