Discussion:
using MmMapLockedPages
(too old to reply)
kobi n
2007-08-13 15:14:07 UTC
Permalink
Hi,

my driver needs to allocate a large amount of buffers and map them to user
space.
previously this was done by allocating the buffers from the non-paged pool
and then locking them by MmBuildMdlForNonPagedPool.
today we want the buffers to be allocated from the Paged-pool. so after the
allocation from of each buffer from the paged-pool, i use mmProbeAndLock to
lock
the pages and then mmMapLockedPages. for some reason , after doing that
well for ~32000 buffers, the mmMapLocked pages starts to fail and i cant
figure out why.
i know that mmMapLockedPages should be replaced with
MmMapLockedPagesSpecifyCache but when i try it same result. 32000 buffers
succeded mapping and the rest just won't.

thanks,
kobi.
Don Burn
2007-08-13 15:41:12 UTC
Permalink
You have not said how big the buffers are, remember there are limits to
PagedPool they are just larger than NonPagedPool. Also, depending on the
size of things, even if you get the buffers from a source other than
PagedPool you will find that the page tables and page directory information
at some point hits the NonPagedPool limits.

Why do you need this many buffers? Also, you do realize that you have
opened a major security hole by mapping from kernel to user space?
--
Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting
Website: http://www.windrvr.com
Blog: http://msmvps.com/blogs/WinDrvr
Remove StopSpam to reply
Post by kobi n
Hi,
my driver needs to allocate a large amount of buffers and map them to user
space.
previously this was done by allocating the buffers from the non-paged pool
and then locking them by MmBuildMdlForNonPagedPool.
today we want the buffers to be allocated from the Paged-pool. so after the
allocation from of each buffer from the paged-pool, i use mmProbeAndLock to
lock
the pages and then mmMapLockedPages. for some reason , after doing that
well for ~32000 buffers, the mmMapLocked pages starts to fail and i cant
figure out why.
i know that mmMapLockedPages should be replaced with
MmMapLockedPagesSpecifyCache but when i try it same result. 32000 buffers
succeded mapping and the rest just won't.
thanks,
kobi.
kobi n
2007-08-14 06:34:00 UTC
Permalink
first, i'm aware thar mapping from kernel to user has its problems but at
this point
i have to continue with it.
the number of buffers is about 30,000 to 50,000 or even more. many buffers.
these are used to contain streaming audio and each of them is 4k so each can
reside on a single physical page.

i've also noticed the methods - MmMapLockedPagesWithReservedMapping and
MmAllocateMappingAddress which are described to help you in case of
mmMapLockedPages fails. is this what i need to have a successfull mapping ?
Post by Don Burn
You have not said how big the buffers are, remember there are limits to
PagedPool they are just larger than NonPagedPool. Also, depending on the
size of things, even if you get the buffers from a source other than
PagedPool you will find that the page tables and page directory information
at some point hits the NonPagedPool limits.
Why do you need this many buffers? Also, you do realize that you have
opened a major security hole by mapping from kernel to user space?
--
Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting
Website: http://www.windrvr.com
Blog: http://msmvps.com/blogs/WinDrvr
Remove StopSpam to reply
Post by kobi n
Hi,
my driver needs to allocate a large amount of buffers and map them to user
space.
previously this was done by allocating the buffers from the non-paged pool
and then locking them by MmBuildMdlForNonPagedPool.
today we want the buffers to be allocated from the Paged-pool. so after the
allocation from of each buffer from the paged-pool, i use mmProbeAndLock to
lock
the pages and then mmMapLockedPages. for some reason , after doing that
well for ~32000 buffers, the mmMapLocked pages starts to fail and i cant
figure out why.
i know that mmMapLockedPages should be replaced with
MmMapLockedPagesSpecifyCache but when i try it same result. 32000 buffers
succeded mapping and the rest just won't.
thanks,
kobi.
Maxim S. Shatskih
2007-08-14 09:15:26 UTC
Permalink
Use 300 buffers, each logically subdivided to 100 frames, instead of 30000
buffers.

The user mode address space granularity is 64KB, so, each of your buffers
takes 64KB of user addresses. With 30-50K buffers, you will hit the limit of
2GB (or even 3GB) for user address space.

Anyway the design is bad. Use pending IOCTLs instead of these buffers.

DirectShow - the primary Windows environment for audio - uses no user mode
buffer mapping.
--
Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
***@storagecraft.com
http://www.storagecraft.com
Post by kobi n
first, i'm aware thar mapping from kernel to user has its problems but at
this point
i have to continue with it.
the number of buffers is about 30,000 to 50,000 or even more. many buffers.
these are used to contain streaming audio and each of them is 4k so each can
reside on a single physical page.
i've also noticed the methods - MmMapLockedPagesWithReservedMapping and
MmAllocateMappingAddress which are described to help you in case of
mmMapLockedPages fails. is this what i need to have a successfull mapping ?
Post by Don Burn
You have not said how big the buffers are, remember there are limits to
PagedPool they are just larger than NonPagedPool. Also, depending on the
size of things, even if you get the buffers from a source other than
PagedPool you will find that the page tables and page directory information
at some point hits the NonPagedPool limits.
Why do you need this many buffers? Also, you do realize that you have
opened a major security hole by mapping from kernel to user space?
--
Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting
Website: http://www.windrvr.com
Blog: http://msmvps.com/blogs/WinDrvr
Remove StopSpam to reply
Post by kobi n
Hi,
my driver needs to allocate a large amount of buffers and map them to user
space.
previously this was done by allocating the buffers from the non-paged pool
and then locking them by MmBuildMdlForNonPagedPool.
today we want the buffers to be allocated from the Paged-pool. so after the
allocation from of each buffer from the paged-pool, i use mmProbeAndLock to
lock
the pages and then mmMapLockedPages. for some reason , after doing that
well for ~32000 buffers, the mmMapLocked pages starts to fail and i cant
figure out why.
i know that mmMapLockedPages should be replaced with
MmMapLockedPagesSpecifyCache but when i try it same result. 32000 buffers
succeded mapping and the rest just won't.
thanks,
kobi.
kuasha
2007-08-17 00:46:28 UTC
Permalink
I do not know the context of doint this- but you may consider the following
approach:

In user mode application allocate the memory.
Issue a IOCTRL request to the driver using METHOD_OUT_DIRECT.
In driver use code like this:

PMDL pMdl = pIrp->MdlAddress;
MmProbeAndLockPages(pMdl, KernelMode , IoWriteAccess);
pSharedSection=(PSHARED_SECTION)
MmGetSystemAddressForMdlSafe(pMdl,NormalPagePriority);

pIrp->IoStatus.Status=STATUS_PENDING;
pIrp->IoStatus.Information=0;
IoMarkIrpPending( pIrp );
pShareMemIrp=pIrp;

return STATUS_PENDING;

Oh, from user mode you should use a separate handle to the driver and use a
separate thread. When you want you can use another IOCTL and unmap the memory
and complete the Irp.

I have tried this few days ago. So I paste it here to share :D.
--
Sincerely,
Maruf Maniruzzaman,
Software Engineer,
KAZ Software Limited,
Dhaka, Bangladesh.
http://www.kaz.com.bd
http://www.kuashaonline.com
Post by kobi n
Hi,
my driver needs to allocate a large amount of buffers and map them to user
space.
previously this was done by allocating the buffers from the non-paged pool
and then locking them by MmBuildMdlForNonPagedPool.
today we want the buffers to be allocated from the Paged-pool. so after the
allocation from of each buffer from the paged-pool, i use mmProbeAndLock to
lock
the pages and then mmMapLockedPages. for some reason , after doing that
well for ~32000 buffers, the mmMapLocked pages starts to fail and i cant
figure out why.
i know that mmMapLockedPages should be replaced with
MmMapLockedPagesSpecifyCache but when i try it same result. 32000 buffers
succeded mapping and the rest just won't.
thanks,
kobi.
Loading...