MmAllocatePagesForMdl routine
MmAllocatePagesForMdl 例程申请一块以零填充的,非分页的,物理内存页面给一个MDL。
Syntax
PMDL MmAllocatePagesForMdl(
_In_ PHYSICAL_ADDRESS LowAddress,
_In_ PHYSICAL_ADDRESS HighAddress,
_In_ PHYSICAL_ADDRESS SkipBytes,
_In_ SIZE_T TotalBytes
);
Parameters
LowAddress [in]
Specifies the physical address of the start of the first address range from which the allocated pages can come.
If MmAllocatePagesForMdlcannot 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.指定可以申请的开始物理地址。如果 MmAllocatePagesForMdl不能在第一个地址范围内申请要求数量字节数的内存,它遍历额外的地址范围去获取更多的页面。在每次的遍历过程中,MmAllocatePagesForMdl 在上一个开始地址的基础上增加SkipBytes的值去获取下一个地址范围的值。
HighAddress [in]
Specifies the physical address of the end of the first address range from which the allocated pages can come.
SkipBytes [in]
Specifies the number of bytes to skip from the start of the previous address range from which the allocated pages can come.
指定从上一个地址范围的开始位置要跳过多少个字节。SkipBytes 必须是一个虚拟内存页面大小的整数倍,单位为字节。
TotalBytes [in]
指定为MDL申请多少字节数的物理内存。
Return value
MmAllocatePagesForMdl 返回一下值中的一个:
返回值 | 描述 |
MDL pointer | 描述在指定地址范围内的物理页面集合的MDL指针。如果请求的数量不可用( If the requested number of bytes is not available),MDL尽可能多描述物理内存。 |
NULL | 在指定的地址范围内无足够的物理内存页面,或者没有足够的物理内存池以存放此MDL。 |
Remarks
在Windows Server 2003 Service Pack 1 (SP1)以之后版本中运行的驱动程序应当使用MmAllocatePagesForMdlEx 代替 MmAllocatePagesForMdl。MmAllocatePagesForMdlEx 通过避免非必要的TLB刷新和缓冲内存提供更好的性能。
MmAllocatePagesForMdl 返回的物理内存页面通常是不相邻的。MmAllocatePagesForMdl 总是将申请给MDL的页面填充0.
MmAllocatePagesForMdl 被设计用于不需要对应虚拟地址的内核驱动(也就是,他们需要物理页面但是不需要这些页面是物理上相邻的),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.AGP显卡驱动程序是一个这种驱动的例子。依赖于当前物理内存的可用数量,MmAllocatePagesForMdl 可能返回一个描述实际数量少于请求数量内存的MDL。如果无内存可分配,例程返回NULL。调用者应当检查实际被分配给MDL的物理内存数量。
调用者必须使用MmFreePagesFromMdl 释放MmAllocatePagesForMdl所创建MDL描述的内存。在调用MmFreePagesFromMdl之后,调用这同样必须调用ExFreePool 去释放MDL自身占用的内存。
在Windows 2000 及其之后版本的Windows中, 单个MmAllocatePagesForMdl 调用可以申请的最大内存数量为(4 G- PAGE_SIZE). 但例程只能在有足够物理页面的情况才能满足一个这种请求。
MmAllocatePagesForMdl runs at IRQL <= APC_LEVEL. Windows Server 2008 及其之后版本的windows操作系统可以让调用者在DISPATCH_LEVEL上调用这个例程。然而通过在APC_LEVEL或之下的级别中调用可以提高驱动的性能。
Requirements
Target platform | |
Version | Available in Windows 2000 and later versions of Windows; however, MmAllocatePagesForMdlEx should be used instead ofMmAllocatePagesForMdl in Windows Server 2003 Service Pack 1 (SP1) and later versions of Windows. |
Header | Wdm.h (include Wdm.h, Ntddk.h, or Ntifs.h) |
Library | NtosKrnl.lib |
DLL | NtosKrnl.exe |
IRQL | See Remarks section. |
DDI compliance rules | IrqlMmApcLte, HwStorPortProhibitedDDIs, SpNoWait, StorPortStartIo |
See also