From: Maxim S. Shatskih on
> To be honest, I don't really know the difference between physically
> contiguous and virtually contiguous ...

Any allocation call (except MmAllocatePagesForMdl which does not allocate virtual addresses at all) will give you virtually contiguous memory.

Physically contiguous means that the underlying physical pages are also contiguous. This is only important for DMA, since no other code (except DMA and MM's internals) even care about the underlying physical addresses.

And yes, MmAllocateContiguousMemory is provided for _DMA adapter object implementors_ to implement ->AllocateCommonBuffer. The DMA-capable drivers must use ->AllocateCommonBuffer.

>I guess virtually contiguous is
> fragmented blocks that are somehow made to look like one big block.

Do you know what are physical and virtual addresses?

Virtual addresses are the pointers, or address values in the machine code.

Physical addresses are the addresses set to the physical CPU's addressing bus.

The CPU has the page tables to perform transparent automatic translations virtual -> physical. These page tables are maintained by the OS's MM, and there are APIs which you can use to govern this translation.

This is how per-process address spaces are implemented in the OS, and also some other things like MmMapLockedPages/MmGetSystemAddressForMdlSafe.

> Anyway, I'm using the memory as a packet data history buffer ... I use
> offsets into it, I search for recurring patterns in it, I might also need to
> iterate all the way through it (by incrementing a UCHAR pointer) ...

Bad idea. Implement a parser state machine instead - like the GNU grep or sed does (see the sources).

> this sounds like it needs to be physically contiguous.

No.

--
Maxim S. Shatskih
Windows DDK MVP
maxim(a)storagecraft.com
http://www.storagecraft.com

From: mirage2k2 on
I get what you are saying about virtual and physical contiguous memory. So
what function should I call to allocate virtual contiguous memory that can be
accessed at DISPATCH_LEVEL? I'm hoping that the answer is not a function
that allocates from non-paged pool ... because then I am back to square 1 ...
there just isn't enough of it.

Mirage2k2

"Maxim S. Shatskih" wrote:

> > To be honest, I don't really know the difference between physically
> > contiguous and virtually contiguous ...
>
> Any allocation call (except MmAllocatePagesForMdl which does not allocate virtual addresses at all) will give you virtually contiguous memory.
>
> Physically contiguous means that the underlying physical pages are also contiguous. This is only important for DMA, since no other code (except DMA and MM's internals) even care about the underlying physical addresses.
>
> And yes, MmAllocateContiguousMemory is provided for _DMA adapter object implementors_ to implement ->AllocateCommonBuffer. The DMA-capable drivers must use ->AllocateCommonBuffer.
>
> >I guess virtually contiguous is
> > fragmented blocks that are somehow made to look like one big block.
>
> Do you know what are physical and virtual addresses?
>
> Virtual addresses are the pointers, or address values in the machine code.
>
> Physical addresses are the addresses set to the physical CPU's addressing bus.
>
> The CPU has the page tables to perform transparent automatic translations virtual -> physical. These page tables are maintained by the OS's MM, and there are APIs which you can use to govern this translation.
>
> This is how per-process address spaces are implemented in the OS, and also some other things like MmMapLockedPages/MmGetSystemAddressForMdlSafe.
>
> > Anyway, I'm using the memory as a packet data history buffer ... I use
> > offsets into it, I search for recurring patterns in it, I might also need to
> > iterate all the way through it (by incrementing a UCHAR pointer) ...
>
> Bad idea. Implement a parser state machine instead - like the GNU grep or sed does (see the sources).
>
> > this sounds like it needs to be physically contiguous.
>
> No.
>
> --
> Maxim S. Shatskih
> Windows DDK MVP
> maxim(a)storagecraft.com
> http://www.storagecraft.com
>
> .
>
From: mirage2k2 on
The help for MmAllocateContiguousMemory says that it will try non-paged pool
first and if the allocation fails then it will allocate from unused pages
(physical I guess). So why do you think that MmAllocateContiguousMemory
could fail in a situation where NdisAllocateMemoryWithTag would not?

My requirement is large allocations of memory that cannot be paged out, so
if MmAllocateContiguousMemory can get me these allocations what is there for
me to worry about?

Is there another alternative ... can I allocate from paged memory and then
call some memory manager function to get the memory paged in and locked in?

Mirage2k2

"Maxim S. Shatskih" wrote:

> > To be honest, I don't really know the difference between physically
> > contiguous and virtually contiguous ...
>
> Any allocation call (except MmAllocatePagesForMdl which does not allocate virtual addresses at all) will give you virtually contiguous memory.
>
> Physically contiguous means that the underlying physical pages are also contiguous. This is only important for DMA, since no other code (except DMA and MM's internals) even care about the underlying physical addresses.
>
> And yes, MmAllocateContiguousMemory is provided for _DMA adapter object implementors_ to implement ->AllocateCommonBuffer. The DMA-capable drivers must use ->AllocateCommonBuffer.
>
> >I guess virtually contiguous is
> > fragmented blocks that are somehow made to look like one big block.
>
> Do you know what are physical and virtual addresses?
>
> Virtual addresses are the pointers, or address values in the machine code.
>
> Physical addresses are the addresses set to the physical CPU's addressing bus.
>
> The CPU has the page tables to perform transparent automatic translations virtual -> physical. These page tables are maintained by the OS's MM, and there are APIs which you can use to govern this translation.
>
> This is how per-process address spaces are implemented in the OS, and also some other things like MmMapLockedPages/MmGetSystemAddressForMdlSafe.
>
> > Anyway, I'm using the memory as a packet data history buffer ... I use
> > offsets into it, I search for recurring patterns in it, I might also need to
> > iterate all the way through it (by incrementing a UCHAR pointer) ...
>
> Bad idea. Implement a parser state machine instead - like the GNU grep or sed does (see the sources).
>
> > this sounds like it needs to be physically contiguous.
>
> No.
>
> --
> Maxim S. Shatskih
> Windows DDK MVP
> maxim(a)storagecraft.com
> http://www.storagecraft.com
>
> .
>