Windows System Software -- Consulting, Training, Development -- Unique Expertise, Guaranteed Results

Home NTDEV
Before Posting...
Please check out the Community Guidelines in the Announcements and Administration Category.

More Info on Driver Writing and Debugging


The free OSR Learning Library has more than 50 articles on a wide variety of topics about writing and debugging device drivers and Minifilters. From introductory level to advanced. All the articles have been recently reviewed and updated, and are written using the clear and definitive style you've come to expect from OSR over the years.


Check out The OSR Learning Library at: https://www.osr.com/osr-learning-library/


not able to allocate more than 2047MB memory chunk

ashi2109ashi2109 Member Posts: 2

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

Comments

  • anton_bassovanton_bassov Member Posts: 5,158

    on Windows 64-bit architecture we can assign non paged memory up to 75% of RAM or 128 GB

    So what???? Even if you have assigned 75% of RAM (i.e 3750 MB in your case) to non-paged pool it does not necessarily imply that all this memory is going to be available to your driver. What about the other drivers that allocate non-paged memory? There is a good chance that 2047 MB of RAM is all that is left in the pool by the time you attempt your allocation. It never occurred to you to think this way, did it..

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

    ....and, once we are at it, NonCachedMemory and non-paged pool are totally unrelated concepts anyway.....

    Anton Bassov

  • ashi2109ashi2109 Member Posts: 2

    It is confirmed from the windbg (!vm extension) and task manager that sufficient non paged memory is available at the time of memory allocation and also while trying to allocate two chunks of 2047 MB each the memory allocation becomes successful.
    Also while trying to allocate the paged memory the same limitation occurred, 2047 MB memory allocated successfully but failed to allocate any chunk greater than 2047 MB.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Upcoming OSR Seminars
OSR has suspended in-person seminars due to the Covid-19 outbreak. But, don't miss your training! Attend via the internet instead!
Kernel Debugging 30 Mar 2020 OSR Seminar Space
Developing Minifilters 15 Jun 2020 LIVE ONLINE
Writing WDF Drivers 22 June 2020 LIVE ONLINE
Internals & Software Drivers 28 Sept 2020 Dulles, VA