无法分配超过2047MB的内存块 [英] not able to allocate more than 2047MB memory chunk

查看:124
本文介绍了无法分配超过2047MB的内存块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


环境:


Windows 10 IOT x64虚拟机


Visual Studio 2017社区版


项目类型:windows driver - >遗产 - > WDM驱动程序


RAM大小:5 GB


------------------


尝试在物理内存中分配超过2Gb的内存块,能够分配2047 MB​​的内存块,但无法分配任何大于2047 MB​​的块。


但按照Microsoft,在Windows 64位上架构我们可以分配非分页内存高达75%的RAM或128 GB

(以较低者为准)


示例源代码如下:


#include" ntddk.h"



PVOID AllocatedMemory = NULL;






NTSTATUS DriverEntry(PDRIVER_OBJECT DriverObject,PUNICODE_STRING RegistryPath)


{


<跨度>&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;
NTSTATUS status = STATUS_SUCCESS;


&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;
DriverObject-> DriverUnload =卸载;


                 AllocatedMemory = ExAllocatePoolWithTag(NonPagedPool,2048 * 1024 *
1024,'Tag1');


               
if(AllocatedMemory!= NULL)


<跨度>&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;
{


   &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP;&NBSP;
KdPrint(("2048 MB NonCachedMemory已分配。\\\\ n"));


               
}


   &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;
其他


   &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;
{


   &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP;&NBSP;
KdPrint(("未分配2048 MB NonCachedMemory。\\\\ n"));


               
}


   &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;
返回状态;


}


VOID卸载(PDRIVER_OBJECT DriverObject)


{


<跨度>&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;
if(AllocatedMemory!= NULL)


<跨度>&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;
{


   &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP;&NBSP;
ExFreePoolWithTag(AllocatedMemory,'Tag1');


<跨度>&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;
KdPrint(("2048 MB NonCachedMemory被释放。\\\\ n"));


               
}


}


请建议如何分配超过2 GB的内存块。


谢谢

解决方案

Hello  Programmer1982,


您分配池的能力受限于您拥有的RAM数量以上。



大缓冲区(IMO)的最佳选择是使用MmAllocatePagesForMdl()为缓冲区分配大量非分页物理页面。 T 他的
电话没有这样的限制。


最好的问候,


Michael


Hi All,

Environment :

virtual machine of Windows 10 IOT x64

Visual studio 2017 community edition

project type : windows driver -> Legacy -> WDM driver

RAM size : 5 GB

------------------

Trying to allocate more than 2Gb of memory chunk in physical memory, able to allocate 2047 MB of memory chunk but it fails to allocate any chunk greater that 2047 MB.

but as per Microsoft, on Windows 64-bit architecture we can assign non paged memory up to 75% of RAM or 128 GB
(Whichever is lower)

sample source code is as follows:

#include "ntddk.h"

PVOID AllocatedMemory = NULL;

NTSTATUS DriverEntry(PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath)

{

                NTSTATUS status = STATUS_SUCCESS;

                DriverObject->DriverUnload = Unload;

                AllocatedMemory = ExAllocatePoolWithTag(NonPagedPool, 2048 * 1024 * 1024, 'Tag1');

                if (AllocatedMemory != NULL)

                {

                                KdPrint(("2048 MB NonCachedMemory is allocated. \r\n"));

                }

                else

                {

                                KdPrint(("2048 MB NonCachedMemory is not allocated. \r\n"));

                }

                return status;

}

VOID Unload(PDRIVER_OBJECT DriverObject)

{

                if (AllocatedMemory != NULL)

                {

                                ExFreePoolWithTag(AllocatedMemory, 'Tag1');

                                KdPrint(("2048 MB NonCachedMemory is freed. \r\n"));

                }

}

please suggest how can memory chunk more than 2 GB can be allocated.

Thank You

解决方案

Hello Programmer1982,

Your ability to allocate pool is limited by more than the number of GB of RAM you have.

Your best bet for a large buffer (IMO) is to use MmAllocatePagesForMdl() to allocate a large number of non-paged physical pages for your buffer. This call has no such limitations.

Best Regards,

Michael


这篇关于无法分配超过2047MB的内存块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆