Hi Group,
After allocating memory using ExAllocatePoolWithTag( PagedPool,… ), is
there a way to lock it in, so that it is always resident and never pages out
? If so, how to do it from my kernel driver ? Note that I am interested in
allocating only from PagedPool and lock it in and I will be doing this only
if there is more than 1GB of physical memory in the box.
–
Cheers
Check Abdoul
Sure, allocate an MDL for it and the do an MmProbeAndLockPages.
Remember to do an MMUnlockpages before freeing the MDL.
–Mark Cariddi
OSR, Open SYstems Resources, Inc.
On Mon, 5 Jun 2006 15:54:46 -0400, “CheckAbdoul”
wrote:
>Hi Group,
>
> After allocating memory using ExAllocatePoolWithTag( PagedPool,… ), is
>there a way to lock it in, so that it is always resident and never pages out
>? If so, how to do it from my kernel driver ? Note that I am interested in
>allocating only from PagedPool and lock it in and I will be doing this only
>if there is more than 1GB of physical memory in the box.
You can always build an MDL for it, lock the MDL and then map the MDL to
an address that won’t be put onto the transition list by working-set
trimming.
You might also look at MmAllocatePagesForMdl if what you need to do is
allocate a large amount of non-paged memory.
What’s the rational for doing this only on large-memory machines? Are
you thinking that you’ll make something faster if you can dedicate a
bunch of memory to your driver?
-p
-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of CheckAbdoul
Sent: Monday, June 05, 2006 12:55 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] Locking Paged pool Memory
Hi Group,
After allocating memory using ExAllocatePoolWithTag( PagedPool,…
), is there a way to lock it in, so that it is always resident and never
pages out ? If so, how to do it from my kernel driver ? Note that I am
interested in allocating only from PagedPool and lock it in and I will
be doing this only if there is more than 1GB of physical memory in the
box.
–
Cheers
Check Abdoul
Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256
To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer
Just for my own curiosity, how does one obtain “an address that won’t be
put onto the transition list by working-set trimming.” in order to do
what you described?
Beverly
-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Peter Wieland
Sent: Monday, June 05, 2006 4:08 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] Locking Paged pool Memory
You can always build an MDL for it, lock the MDL and then map the MDL to
an address that won’t be put onto the transition list by working-set
trimming.
You might also look at MmAllocatePagesForMdl if what you need to do is
allocate a large amount of non-paged memory.
What’s the rational for doing this only on large-memory machines? Are
you thinking that you’ll make something faster if you can dedicate a
bunch of memory to your driver?
-p
-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of CheckAbdoul
Sent: Monday, June 05, 2006 12:55 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] Locking Paged pool Memory
Hi Group,
After allocating memory using ExAllocatePoolWithTag( PagedPool,…
), is there a way to lock it in, so that it is always resident and never
pages out ? If so, how to do it from my kernel driver ? Note that I am
interested in allocating only from PagedPool and lock it in and I will
be doing this only if there is more than 1GB of physical memory in the
box.
–
Cheers
Check Abdoul
Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256
To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer
Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256
To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer
MmAllocatePagesForMdl() will allocate memory from the non-paged memory,
I want to allocate from the paged pool and lock it. I will try Mark’s
suggestion.
> Are you thinking that you’ll make something faster if you can dedicate a
> bunch of memory to your driver?
No. This is a special case where I have to allocated around 150MB of
memory ( which I cannot allocate from the non-paged pool ) and keep it
around. My allocation of 150MB memory from the paged pool succeeds, but I
want to make it resident.
Thanks.
–
Cheers
Check Abdoul
“Peter Wieland” wrote in message
news:xxxxx@ntdev…
You can always build an MDL for it, lock the MDL and then map the MDL to
an address that won’t be put onto the transition list by working-set
trimming.
You might also look at MmAllocatePagesForMdl if what you need to do is
allocate a large amount of non-paged memory.
What’s the rational for doing this only on large-memory machines? Are
you thinking that you’ll make something faster if you can dedicate a
bunch of memory to your driver?
-p
-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of CheckAbdoul
Sent: Monday, June 05, 2006 12:55 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] Locking Paged pool Memory
Hi Group,
After allocating memory using ExAllocatePoolWithTag( PagedPool,…
), is there a way to lock it in, so that it is always resident and never
pages out ? If so, how to do it from my kernel driver ? Note that I am
interested in allocating only from PagedPool and lock it in and I will
be doing this only if there is more than 1GB of physical memory in the
box.
–
Cheers
Check Abdoul
------------------
—
Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256
To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer
> MmAllocatePagesForMdl() will allocate memory from the non-paged
memory,
I want to allocate from the paged pool and lock it. I will try Mark’s
suggestion.
MmAllocatePagesForMdl doesn’t allocate pages from non-paged POOL, it just
grabs pages from the list of free pages. There is the caveat:
MmAllocatePagesForMdl doesn’t force swap-out and doesn’t wait for free pages
to be produced so it could allocate less pages than requested.
Dmitriy Budko
VMware
Hi Mark,
Thanks for the suggestion. By the way if I use
ExAllocatePoolWithTag(PagedPool,… ) is the allocated memory contiguous ?
I am trying to have a memory disk that can hold around 150MB of
files. I tried allocating from the non-paged pool but the OS is allowing me
to allocate only 127MB ( on a 2003 R2 system ) regardless of whatever values
I tried with the “NonPagedPoolSize” registry key. If I understood you
correctly, can you tell me if the following will work ?
#define MEMREQUIRED 0x9600000; /* 150 MB */
MyDiskAlloc()
{
pMem = ExAllocatePoolWithTag(PagedPool, MEMREQUIRED, MYTAG ) ;
PMDL mdl = IoAllocateMdl( pMem , MEMREQUIRED, FALSE, FALSE,
NULL );
if( !mdl )
{
ntStatus = STATUS_INSUFFICIENT_RESOURCES;
ExFreePoolWithTag( pMem , MYTAG );
return ntStatus;
}
try
{
MmProbeAndLockPages(mdl, KernelMode, IoWriteAccess);
}
except(EXCEPTION_EXECUTE_HANDLER)
{
NTSTATUS status = GetExceptionCode();
IoFreeMdl(mdl);
mdl = NULL;
}
}
MyDiskFree()
{
// cleanup code
MmUnlockPages( mdl );
IoFreeMdl(mdl);
mdl = NULL;
}
–
Cheers
Check Abdoul
“Mark J. Cariddi” wrote in message news:xxxxx@ntdev…
> Sure, allocate an MDL for it and the do an MmProbeAndLockPages.
>
> Remember to do an MMUnlockpages before freeing the MDL.
>
> --Mark Cariddi
> OSR, Open SYstems Resources, Inc.
>
> On Mon, 5 Jun 2006 15:54:46 -0400, “CheckAbdoul”
> wrote:
>
>>Hi Group,
>>
>> After allocating memory using ExAllocatePoolWithTag( PagedPool,… ),
>> is
>>there a way to lock it in, so that it is always resident and never pages
>>out
>>? If so, how to do it from my kernel driver ? Note that I am interested in
>>allocating only from PagedPool and lock it in and I will be doing this
>>only
>>if there is more than 1GB of physical memory in the box.
>
> Thanks for the suggestion. By the way if I use
ExAllocatePoolWithTag(PagedPool,… ) is the allocated memory contiguous ?
Nope, no reason to believe that a multi-page pool buffer will be physically
contiguous.
-scott
–
Scott Noone
Software Engineer
OSR Open Systems Resources, Inc.
http://www.osronline.com
“CheckAbdoul” wrote in message news:xxxxx@ntdev…
> Hi Mark,
>
> Thanks for the suggestion. By the way if I use
> ExAllocatePoolWithTag(PagedPool,… ) is the allocated memory contiguous ?
>
> I am trying to have a memory disk that can hold around 150MB of
> files. I tried allocating from the non-paged pool but the OS is allowing
> me to allocate only 127MB ( on a 2003 R2 system ) regardless of whatever
> values I tried with the “NonPagedPoolSize” registry key. If I understood
> you correctly, can you tell me if the following will work ?
>
>
> #define MEMREQUIRED 0x9600000; /* 150 MB */
> MyDiskAlloc()
> {
> pMem = ExAllocatePoolWithTag(PagedPool, MEMREQUIRED, MYTAG ) ;
> PMDL mdl = IoAllocateMdl( pMem , MEMREQUIRED, FALSE, FALSE,
> NULL );
> if( !mdl )
> {
> ntStatus = STATUS_INSUFFICIENT_RESOURCES;
> ExFreePoolWithTag( pMem , MYTAG );
> return ntStatus;
> }
>
> try
> {
> MmProbeAndLockPages(mdl, KernelMode, IoWriteAccess);
> }
> except(EXCEPTION_EXECUTE_HANDLER)
> {
> NTSTATUS status = GetExceptionCode();
> IoFreeMdl(mdl);
> mdl = NULL;
> }
>
> }
>
> MyDiskFree()
> {
> // cleanup code
> MmUnlockPages( mdl );
> IoFreeMdl(mdl);
> mdl = NULL;
> }
>
>
>
> –
> Cheers
> Check Abdoul
> ------------------
>
>
>
> “Mark J. Cariddi” wrote in message news:xxxxx@ntdev…
>> Sure, allocate an MDL for it and the do an MmProbeAndLockPages.
>>
>> Remember to do an MMUnlockpages before freeing the MDL.
>>
>> --Mark Cariddi
>> OSR, Open SYstems Resources, Inc.
>>
>> On Mon, 5 Jun 2006 15:54:46 -0400, “CheckAbdoul”
>> wrote:
>>
>>>Hi Group,
>>>
>>> After allocating memory using ExAllocatePoolWithTag( PagedPool,… ),
>>> is
>>>there a way to lock it in, so that it is always resident and never pages
>>>out
>>>? If so, how to do it from my kernel driver ? Note that I am interested
>>>in
>>>allocating only from PagedPool and lock it in and I will be doing this
>>>only
>>>if there is more than 1GB of physical memory in the box.
>>
>
>
>
Thanks Scott. Looks like both ( allocating from paged pool & non-paged
pool ) of my approaches are wrong. So, what is the proper way to create a
memory disk which can hold around 150MB worth of file data ?
–
Cheers
Check Abdoul
“Scott Noone” wrote in message news:xxxxx@ntdev…
>> Thanks for the suggestion. By the way if I use
>> ExAllocatePoolWithTag(PagedPool,… ) is the allocated memory contiguous
>> ?
>
> Nope, no reason to believe that a multi-page pool buffer will be
> physically contiguous.
>
> -scott
>
> –
> Scott Noone
> Software Engineer
> OSR Open Systems Resources, Inc.
> http://www.osronline.com
>
>
> “CheckAbdoul” wrote in message news:xxxxx@ntdev…
>> Hi Mark,
>>
>> Thanks for the suggestion. By the way if I use
>> ExAllocatePoolWithTag(PagedPool,… ) is the allocated memory contiguous
>> ?
>>
>> I am trying to have a memory disk that can hold around 150MB of
>> files. I tried allocating from the non-paged pool but the OS is allowing
>> me to allocate only 127MB ( on a 2003 R2 system ) regardless of whatever
>> values I tried with the “NonPagedPoolSize” registry key. If I understood
>> you correctly, can you tell me if the following will work ?
>>
>>
>> #define MEMREQUIRED 0x9600000; /* 150 MB */
>> MyDiskAlloc()
>> {
>> pMem = ExAllocatePoolWithTag(PagedPool, MEMREQUIRED, MYTAG ) ;
>> PMDL mdl = IoAllocateMdl( pMem , MEMREQUIRED, FALSE, FALSE,
>> NULL );
>> if( !mdl )
>> {
>> ntStatus = STATUS_INSUFFICIENT_RESOURCES;
>> ExFreePoolWithTag( pMem , MYTAG );
>> return ntStatus;
>> }
>>
>> try
>> {
>> MmProbeAndLockPages(mdl, KernelMode, IoWriteAccess);
>> }
>> except(EXCEPTION_EXECUTE_HANDLER)
>> {
>> NTSTATUS status = GetExceptionCode();
>> IoFreeMdl(mdl);
>> mdl = NULL;
>> }
>>
>> }
>>
>> MyDiskFree()
>> {
>> // cleanup code
>> MmUnlockPages( mdl );
>> IoFreeMdl(mdl);
>> mdl = NULL;
>> }
>>
>>
>>
>> –
>> Cheers
>> Check Abdoul
>> ------------------
>>
>>
>>
>> “Mark J. Cariddi” wrote in message news:xxxxx@ntdev…
>>> Sure, allocate an MDL for it and the do an MmProbeAndLockPages.
>>>
>>> Remember to do an MMUnlockpages before freeing the MDL.
>>>
>>> --Mark Cariddi
>>> OSR, Open SYstems Resources, Inc.
>>>
>>> On Mon, 5 Jun 2006 15:54:46 -0400, “CheckAbdoul”
>>> wrote:
>>>
>>>>Hi Group,
>>>>
>>>> After allocating memory using ExAllocatePoolWithTag(
>>>> PagedPool,… ), is
>>>>there a way to lock it in, so that it is always resident and never pages
>>>>out
>>>>? If so, how to do it from my kernel driver ? Note that I am interested
>>>>in
>>>>allocating only from PagedPool and lock it in and I will be doing this
>>>>only
>>>>if there is more than 1GB of physical memory in the box.
>>>
>>
>>
>>
>
>
>
Why do you need your memory to be physically contiguous?
It’s actually not clear to me why you need the memory to be virtually
contiguous either. Your virtual disk driver will be handling Read &
Write requests and you can easily walk through a table to find the
memory block which holds the data for any particular disk offset. This
would let you allocate memory in smaller chunks, and might even let you
keep large amounts of the disk unallocated if it hadn’t ever been
written to.
-p
-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of CheckAbdoul
Sent: Monday, June 05, 2006 3:03 PM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] Locking Paged pool Memory
Thanks Scott. Looks like both ( allocating from paged pool &
non-paged pool ) of my approaches are wrong. So, what is the proper way
to create a memory disk which can hold around 150MB worth of file data ?
–
Cheers
Check Abdoul
“Scott Noone” wrote in message news:xxxxx@ntdev…
>> Thanks for the suggestion. By the way if I use
>> ExAllocatePoolWithTag(PagedPool,… ) is the allocated memory
>> contiguous ?
>
> Nope, no reason to believe that a multi-page pool buffer will be
> physically contiguous.
>
> -scott
>
> –
> Scott Noone
> Software Engineer
> OSR Open Systems Resources, Inc.
> http://www.osronline.com
>
>
> “CheckAbdoul” wrote in message
news:xxxxx@ntdev…
>> Hi Mark,
>>
>> Thanks for the suggestion. By the way if I use
>> ExAllocatePoolWithTag(PagedPool,… ) is the allocated memory
>> contiguous ?
>>
>> I am trying to have a memory disk that can hold around 150MB
>> of files. I tried allocating from the non-paged pool but the OS is
>> allowing me to allocate only 127MB ( on a 2003 R2 system ) regardless
>> of whatever values I tried with the “NonPagedPoolSize” registry key.
>> If I understood you correctly, can you tell me if the following will
work ?
>>
>>
>> #define MEMREQUIRED 0x9600000; /* 150 MB */
>> MyDiskAlloc()
>> {
>> pMem = ExAllocatePoolWithTag(PagedPool, MEMREQUIRED, MYTAG
) ;
>> PMDL mdl = IoAllocateMdl( pMem , MEMREQUIRED, FALSE,
>> FALSE, NULL );
>> if( !mdl )
>> {
>> ntStatus = STATUS_INSUFFICIENT_RESOURCES;
>> ExFreePoolWithTag( pMem , MYTAG );
>> return ntStatus;
>> }
>>
>> try
>> {
>> MmProbeAndLockPages(mdl, KernelMode,
IoWriteAccess);
>> }
>> except(EXCEPTION_EXECUTE_HANDLER)
>> {
>> NTSTATUS status = GetExceptionCode();
>> IoFreeMdl(mdl);
>> mdl = NULL;
>> }
>>
>> }
>>
>> MyDiskFree()
>> {
>> // cleanup code
>> MmUnlockPages( mdl );
>> IoFreeMdl(mdl);
>> mdl = NULL;
>> }
>>
>>
>>
>> –
>> Cheers
>> Check Abdoul
>> ------------------
>>
>>
>>
>> “Mark J. Cariddi” wrote in message
news:xxxxx@ntdev…
>>> Sure, allocate an MDL for it and the do an MmProbeAndLockPages.
>>>
>>> Remember to do an MMUnlockpages before freeing the MDL.
>>>
>>> --Mark Cariddi
>>> OSR, Open SYstems Resources, Inc.
>>>
>>> On Mon, 5 Jun 2006 15:54:46 -0400, “CheckAbdoul”
>>> wrote:
>>>
>>>>Hi Group,
>>>>
>>>> After allocating memory using ExAllocatePoolWithTag(
>>>>PagedPool,… ), is there a way to lock it in, so that it is always
>>>>resident and never pages out ? If so, how to do it from my kernel
>>>>driver ? Note that I am interested in allocating only from PagedPool
>>>>and lock it in and I will be doing this only if there is more than
>>>>1GB of physical memory in the box.
>>>
>>
>>
>>
>
>
>
—
Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256
To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer
CheckAbdoul wrote:
Thanks Scott. Looks like both ( allocating from paged pool & non-paged
pool ) of my approaches are wrong. So, what is the proper way to create a
memory disk which can hold around 150MB worth of file data ?
Why does a “memory disk” need to be physically contiguous? Note that
all memory allocations are guaranteed to be contiguous in VIRTUAL
memory, which is usually what you want.
If you really need 150MB of physically contiguous memory, you basically
have two options. One, use MmAllocateContiguousMemory at startup time,
before system entropy has reduced the amount of physically contiguous
memory available. Even this is somewhat of a crap shoot, but will
usually succeed. Two, use the /burnmem switch in boot.ini to reduce the
amount of memory that NT uses, and use the untouched memory as your own
private space. Finding that memory is left as an exercise for the reader.
If you’re really just doing a virtual disk drive, then why do you even
want it to be non-pageable? The memory manager is a much better judge
of page usage than you are. If it decides to swap your data to disk,
then it really is the case that someone else needs the memory more than
you. By interfering with this, you are only going to reduce net system
performance.
–
Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.
I just like to second Peter Wieland’s question: why would a memory disk need
one huge block of virtually contiguous memory?
=====================
Mark Roddy DDK MVP
Windows 2003/XP/2000 Consulting
Hollis Technology Solutions 603-321-1032
www.hollistech.com
-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Tim Roberts
Sent: Monday, June 05, 2006 6:31 PM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] Locking Paged pool Memory
CheckAbdoul wrote:
> Thanks Scott. Looks like both ( allocating from paged pool &
>non-paged pool ) of my approaches are wrong. So, what is the
proper way
>to create a memory disk which can hold around 150MB worth of
file data ?
>
Why does a “memory disk” need to be physically contiguous?
Note that all memory allocations are guaranteed to be
contiguous in VIRTUAL memory, which is usually what you want.
If you really need 150MB of physically contiguous memory, you
basically have two options. One, use
MmAllocateContiguousMemory at startup time, before system
entropy has reduced the amount of physically contiguous
memory available. Even this is somewhat of a crap shoot, but
will usually succeed. Two, use the /burnmem switch in
boot.ini to reduce the amount of memory that NT uses, and use
the untouched memory as your own private space. Finding that
memory is left as an exercise for the reader.
If you’re really just doing a virtual disk drive, then why do
you even want it to be non-pageable? The memory manager is a
much better judge of page usage than you are. If it decides
to swap your data to disk, then it really is the case that
someone else needs the memory more than you. By interfering
with this, you are only going to reduce net system performance.
–
Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.
Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256
To unsubscribe, visit the List Server section of OSR Online
at http://www.osronline.com/page.cfm?name=ListServer
Create a MDL over it and call MmProbeAndLockPages. Nevertheless, the PTEs
still can be invalidated - the only guarantee for the locked pages that they
will not be reused for anything else.
Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com
----- Original Message -----
From: “CheckAbdoul”
Newsgroups: ntdev
To: “Windows System Software Devs Interest List”
Sent: Monday, June 05, 2006 11:54 PM
Subject: [ntdev] Locking Paged pool Memory
> Hi Group,
>
> After allocating memory using ExAllocatePoolWithTag( PagedPool,… ), is
> there a way to lock it in, so that it is always resident and never pages out
> ? If so, how to do it from my kernel driver ? Note that I am interested in
> allocating only from PagedPool and lock it in and I will be doing this only
> if there is more than 1GB of physical memory in the box.
>
> –
> Cheers
> Check Abdoul
> ------------------
>
>
>
> —
> Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256
>
> To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer
> files. I tried allocating from the non-paged pool but the OS is allowing me
to allocate only 127MB ( on a 2003 R2 system ) regardless of whatever values
You can also allocate memory in the user address space of System process, by
ZwCreateSection without a file handle and ZwMapViewOfSection from the system
thread context.
Such memory will be accessible from system thread context under the
__try/__except block.
Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com