How to allocate 16 gigs of memory in windows

Hi,

Can some one help me with what function in windows I can allocate 16 gigs of memory. I have more than 40 gigs of memory so available memory is not a problem for me.

You don’t say whether this is user space or kernel space, also what
version of Windows are you using?

Don Burn (MVP, Windows DKD)
Windows Filesystem and Driver Consulting
Website: http://www.windrvr.com
Blog: http://msmvps.com/blogs/WinDrvr

xxxxx@gmail.com” wrote in message
news:xxxxx@ntdev:

> Hi,
>
> Can some one help me with what function in windows I can allocate 16 gigs of memory. I have more than 40 gigs of memory so available memory is not a problem for me.

Windows server 2008 R2 and Memory allocation is in kernel mode.

You ARE kidding. Right?

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of
xxxxx@gmail.com
Sent: Sunday, November 07, 2010 5:19 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] How to allocate 16 gigs of memory in windows

Hi,

Can some one help me with what function in windows I can allocate 16
gigs of memory. I have more than 40 gigs of memory so available memory is
not a problem for me.


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

That isn’t going to directly happen as the kernel address space, even
on a 40g system, is less than 16g. However you can get at a user mode
address space from the kernel. Did you expect this memory to be
non-paged?

Mark Roddy

On Sun, Nov 7, 2010 at 6:50 PM, wrote:
> Windows server 2008 R2 and Memory allocation is in kernel mode.
>
> —
> NTDEV is sponsored by OSR
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer
>

It can be application space or in kenel space. All i am doing is testing .May I know why I cant allocate that much in kernel space ?

WS08 R2 is 64-bit only. On 64 bit with 40 GB of RAM it should be possible to allocate ~30 GB of nonpaged pool, and even more than that if it’s paged pool.

MmAllocatePagesForMdlEx is another possibility, but you will have to split the allocation into multiple chunks since the size of each MDL is limited to slightly less than 4 GB.

Thanks,
Pavel

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of Mark Roddy
Sent: Monday, November 08, 2010 6:43 AM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] How to allocate 16 gigs of memory in windows

That isn’t going to directly happen as the kernel address space, even on a 40g system, is less than 16g. However you can get at a user mode address space from the kernel. Did you expect this memory to be non-paged?

Mark Roddy

On Sun, Nov 7, 2010 at 6:50 PM, wrote:
> Windows server 2008 R2 and Memory allocation is in kernel mode.
>
> —
> NTDEV is sponsored by OSR
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

@Pavel MmAllocatePagesForMdlEx() is the only function I can use ? I have to do 4 times to get 16 gigs right ?

No, you can also use ExAllocatePoolWithTag.

But if you decide to use MmAllocatePagesForMdlEx then yes, you’ll have to call it 4 times to get 16 GB.

Thanks,
Pavel

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@gmail.com
Sent: Tuesday, November 09, 2010 2:34 PM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] How to allocate 16 gigs of memory in windows

@Pavel MmAllocatePagesForMdlEx() is the only function I can use ? I have to do 4 times to get 16 gigs right ?

@Pavel can I use a single call to ExAllocatePoolWithTag to allocate 16 gigs ? Also I would like to see a sample driver using MmAllocatePagesForMdlEx . Is there an example in DDk or any other external link is ok for me.

Yes it’s possible to allocate 16 GB in a single ExAllocatePool call, assuming the system has enough available commit and (for non-paged pool) enough available physical memory.

99% of the time you should just use the pool. MmAllocatePagesForMdl and other Mm allocation functions should only be used when you need some specific functionality they provide (e.g. you want physical pages to come from a specific range, or be physically contiguous etc).

Thanks,
Pavel

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@gmail.com
Sent: Tuesday, November 09, 2010 2:56 PM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] How to allocate 16 gigs of memory in windows

@Pavel can I use a single call to ExAllocatePoolWithTag to allocate 16 gigs ? Also I would like to see a sample driver using MmAllocatePagesForMdlEx . Is there an example in DDk or any other external link is ok for me.


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

@Pavel Is there a sample driver showing the usage of ExAllocatePool ?

xxxxx@gmail.com wrote:

@Pavel Is there a sample driver showing the usage of ExAllocatePool ?

You must be kidding. Did you do any web searching at all before asking
this? Your question is very much like asking for sample programs
showing the usage of malloc. If I may be blunt, if you can’t figure out
how to use ExAllocatePool, then you are NOT ready to be programming
kernel drivers.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

@Tim sorry Its not ExallocatePool. Its MmAllocatePagesForMdl

xxxxx@gmail.com wrote:

@Tim sorry Its not ExallocatePool. Its MmAllocatePagesForMdl

Again, this is a question you could have answered in 2 minutes on your own:

C:\Dev>cd \ddk\7600\src

C:\DDK\7600\src>findstr /s MmAllocatePagesForMdl *.c *.cpp

C:\DDK\7600\src>

No. There are no samples that use this API.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

Do you want that paged or unpaged memory? Do you need it as a single
virtually contiguous chunk? Chances are slim to nil you will get 16 GB of
physically contiguous memory.

A few random ideas, which since I see the clock is about 4am, may be a
little less than fully baked…

I’ve never allocated a single chunk of memory anywhere near that size from
kernel mode. My guess is that may exceed the maximum size of pool
allocations. From user mode you could call VirtualAlloc for that large an
allocation, but since MDL’s can’t represent > 4 GB (and perhaps less) there
is no way to pass 16 GB to kernel mode and get a system virtual address for
it.

You might try ZwCreateSection/ZwMapViewOfSection although the CommitSize
field of ZwMapViewOfSection is a 32-bit unsigned value, so that may be a
limit. You might be able to map multiple views of the section though.

I initially was going to suggest you might try MmAllocatePagesForMdl,
although see MmGetMdlByteCount returns a 32-bit length, so an MDL has a hard
upper limit of 4G.

You might be able to use MmAllocateMappingAddress to allocate a large chunk
of kernel virtual address space, and then use
MmMapLockedPagesWithReservedMapping with some smaller chunks (like from
MmAllocatePagesForMdl) to associate physical memory with the virtual
addresses.

You might also just consider adjusting your data structure to use smaller
chunks.

Also, you might want to allocate that much memory using large page mappings.

Jan

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:bounce-430961-
xxxxx@lists.osr.com] On Behalf Of xxxxx@gmail.com
Sent: Sunday, November 07, 2010 3:19 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] How to allocate 16 gigs of memory in windows

Hi,

Can some one help me with what function in windows I can allocate 16
gigs
of memory. I have more than 40 gigs of memory so available memory is not a
problem for me.


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer