Dear All,

At my driver I need a really huge memory buffer. I am trying to
allocate it from non-paged memory pool, since I need to perform a
series of DMA transfers from lots of PCI devices installed in the
system. Actually, every instance of my driver requires about 24 Megs
of memory and we are planning to have about 16 such devices installed.
What a disaster, I can load drivers only for 6 my devices, all other
fail on allocating memory from non-paged pool. I decided to allocate
memory from paged pool and lock it down in physical memory, using
MmProbeAndLockPages(), but was able to load only 4 instances of my
driver. What I am doing wrong?

With best regards,
Vladimir S. Mirgorodsky

Re: Windows XP & non-paged pool by Maxim

Maxim
Wed Oct 10 20:19:33 PDT 2007

Try using MmAllocatePagesForMdl.

Then create sub-MDLs for this MDL using IoAllocateMdl/IoBuildPartialMdl,
and use these sub-MDLs for DMA or - via MmGetSystemAddressForMdlSafe - for data
access by pointer.

Anyway I can suggest even a smarter architecture for this. Namely -
allocate the memory in the app using VirtualAlloc, then pass the memory chunks
to the driver using ReadFile or DeviceIoControl.

The driver will get these memory chunks as Irp->MdlAddress and pass them to
the DMA engine. You can send many overlapped IO requests from the app, each
with its own buffer, thus creating the queue managed by the app.

This is the best idea. Allocating huge buffers in the driver at
MN_START_DEVICE time seems much worse.

--
Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
maxim@storagecraft.com
http://www.storagecraft.com

<v_mirgorodsky@yahoo.com> wrote in message
news:1192045644.240190.94550@19g2000hsx.googlegroups.com...
> Dear All,
>
> At my driver I need a really huge memory buffer. I am trying to
> allocate it from non-paged memory pool, since I need to perform a
> series of DMA transfers from lots of PCI devices installed in the
> system. Actually, every instance of my driver requires about 24 Megs
> of memory and we are planning to have about 16 such devices installed.
> What a disaster, I can load drivers only for 6 my devices, all other
> fail on allocating memory from non-paged pool. I decided to allocate
> memory from paged pool and lock it down in physical memory, using
> MmProbeAndLockPages(), but was able to load only 4 instances of my
> driver. What I am doing wrong?
>
> With best regards,
> Vladimir S. Mirgorodsky
>


Re: Windows XP & non-paged pool by v_mirgorodsky

v_mirgorodsky
Thu Oct 11 07:11:31 PDT 2007

Thank you, Maxim, for your response. Using application allocated
memory is not very convenient in my case, since application can not
react as quickly as necessary for my device memory requirements. In
response to MN_START_DEVICE I allocate only small portion of
theoretically required buffer and use it for device operation. As soon
as device memory requirements grow or application delays data
processing, I allocate more chunks of memory and map them for DMA
transfers. It is really difficult to predict certain situation and 24
Megs were taken as a worst case estimation during my stress tests.
MmAllocatePagesForMdl() seems suit the best. Is there any WDM
compatible equivalent of MmAllocatePagesForMdl()?

With best regards,
Vladimir S. Mirgorodsky

On Oct 11, 6:19 am, "Maxim S. Shatskih" <ma...@storagecraft.com>
wrote:
> Try using MmAllocatePagesForMdl.
>
> Then create sub-MDLs for this MDL using IoAllocateMdl/IoBuildPartialMdl,
> and use these sub-MDLs for DMA or - via MmGetSystemAddressForMdlSafe - for data
> access by pointer.
>
> Anyway I can suggest even a smarter architecture for this. Namely -
> allocate the memory in the app using VirtualAlloc, then pass the memory chunks
> to the driver using ReadFile or DeviceIoControl.
>
> The driver will get these memory chunks as Irp->MdlAddress and pass them to
> the DMA engine. You can send many overlapped IO requests from the app, each
> with its own buffer, thus creating the queue managed by the app.
>
> This is the best idea. Allocating huge buffers in the driver at
> MN_START_DEVICE time seems much worse.
>
> --
> Maxim Shatskih, Windows DDK MVP
> StorageCraft Corporation
> ma...@storagecraft.comhttp://www.storagecraft.com
>
> <v_mirgorod...@yahoo.com> wrote in message
>
> news:1192045644.240190.94550@19g2000hsx.googlegroups.com...
>
> > Dear All,
>
> > At my driver I need a really huge memory buffer. I am trying to
> > allocate it from non-paged memory pool, since I need to perform a
> > series of DMA transfers from lots of PCI devices installed in the
> > system. Actually, every instance of my driver requires about 24 Megs
> > of memory and we are planning to have about 16 such devices installed.
> > What a disaster, I can load drivers only for 6 my devices, all other
> > fail on allocating memory from non-paged pool. I decided to allocate
> > memory from paged pool and lock it down in physical memory, using
> > MmProbeAndLockPages(), but was able to load only 4 instances of my
> > driver. What I am doing wrong?
>
> > With best regards,
> > Vladimir S. Mirgorodsky



Re: Windows XP & non-paged pool by Maxim

Maxim
Thu Oct 11 12:55:36 PDT 2007

> MmAllocatePagesForMdl() seems suit the best. Is there any WDM
> compatible equivalent of MmAllocatePagesForMdl()?

MmAllocatePagesForMdl is WDM.

--
Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
maxim@storagecraft.com
http://www.storagecraft.com