How to map common buffer pages to contiguous virtual addresses

The messages about memory mapping reminded me of a problem I’ve been trying
to figure out. I’m trying to improve the performance of one of our drivers
in low-memory conditions. In the DDK, it says
(DMA_OPERATIONS->AllocateCommonBuffer):

“If a driver needs several pages of common buffer space, but the pages need
not be contiguous, the driver should make several one-page requests to
AllocateCommonBuffer instead of one large request. This approach conserves
contiguous memory. … After start-up, it is possible that only one-page
requests will succeed, if any.”

OK, that makes sense. My hardware can support several non-contiguous
physical pages. But the software wants to copy data to/from the common
buffer. Is there a way I can map several 1-page common buffer pages into
contiguous kernel memory virtual addresses? I’ve looked through the DDK,
and a call to MmAllocateMappingAddress plus one call to
MmMapLockedPagesWithReservedMapping for each common buffer page look like a
possibility. But MmMapLockedPagesWithReservedMapping wants an MDL on which
MmProbeAndLockPages has been called. I can create an MDL for the common
buffer pages with IoAllocateMdl, but is it safe to call IoAllocateMdl and
MmProbeAndLockPages on a common buffer? And do I still need to call
MmProbeAndLockPages, since the common buffer is already locked down?

Or is there an easier way to do this that I’ve missed?

Thanks!

-Dan

> physical pages. But the software wants to copy data to/from the common

buffer. Is there a way I can map several 1-page common buffer pages into
contiguous kernel memory virtual addresses?

You need the contiguous virtual addresses only if you have a data structure
which crosses the page boundary. In this case, it is a great idea to use
multi-page common buffer.

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