Windows System Software -- Consulting, Training, Development -- Unique Expertise, Guaranteed Results

Home NTDEV
Before Posting...
Please check out the Community Guidelines in the Announcements and Administration Category.

More Info on Driver Writing and Debugging


The free OSR Learning Library has more than 50 articles on a wide variety of topics about writing and debugging device drivers and Minifilters. From introductory level to advanced. All the articles have been recently reviewed and updated, and are written using the clear and definitive style you've come to expect from OSR over the years.


Check out The OSR Learning Library at: https://www.osr.com/osr-learning-library/


StorPortAllocatePool vs StorPortAllocateContiguousMemorySpecifyCacheNode for DMA

Suresh_PatilSuresh_Patil Member Posts: 122
Hi,

Can we use StorPortAllocatePool for getting virtual address and then use StorPortGetPhysicalAddress on that virtual address for doing DMA to disk for sending READ/WRITE requests to disk?

When I tried doing so I saw intermittent crashes while running IO. However after replacing StorPortAllocatePool by StorPortAllocateContiguousMemorySpecifyCacheNode routine I see more stable behavior.
Is it recommended to use StorPortAllocateContiguousMemorySpecifyCacheNode for doing normal READ/WRITE IO operations to disk? Thanks.

Regards,
Suresh

Comments

  • Slava_ImameevSlava_Imameev Member Posts: 480
    > "Is it recommended to use StorPortAllocateContiguousMemorySpecifyCacheNode for
    doing normal READ/WRITE IO operations to disk"

    No, if you are not ignoring *Length value returned by StorPortGetPhysicalAddress which might be less than the size of a buffer allocated by StorPortAllocatePool

    > "StorPortAllocateContiguousMemorySpecifyCacheNode routine I see more stable
    behavior"

    Did you mean that you still experienced crashes?
  • Tim_RobertsTim_Roberts Member - All Emails Posts: 13,397
    [email protected] wrote:
    > Can we use StorPortAllocatePool for getting virtual address and then use StorPortGetPhysicalAddress on that virtual address for doing DMA to disk for sending READ/WRITE requests to disk?
    >
    > When I tried doing so I saw intermittent crashes while running IO.

    You are aware, I hope, that StorPortGetPhysicalAddress only returns the
    physical address of the first page. A buffer that is contiguous in
    virtual space is almost never contiguous in physical space. Example:

    virtual physical
    1234000 9AB000
    1235000 17F6000
    1236000 17000
    1237000 F739000

    If you have buffers more than 4096 bytes, you need to use
    StorPortGetScatterGatherList.


    > However after replacing StorPortAllocatePool by StorPortAllocateContiguousMemorySpecifyCacheNode routine I see more stable behavior.
    > Is it recommended to use StorPortAllocateContiguousMemorySpecifyCacheNode for doing normal READ/WRITE IO operations to disk? Thanks.

    If your hardware supports scatter/gather, use
    StorPortGetScatterGatherList. If it does not, you'll either need to do
    your DMA one page at a time, or you'll have to use a common buffer.

    --
    Tim Roberts, [email protected]
    Providenza & Boekelheide, Inc.

    Tim Roberts, [email protected]
    Providenza & Boekelheide, Inc.

  • Suresh_PatilSuresh_Patil Member Posts: 122
    Thanks Tim! I overlooked the non-contiguous physical address nature of StorPortAllocatePool.
    Unfortunately our hardware does not support scatter-gather. But I was wondering then why did you suggest to do DMA one page at a time instead of using StorPortAllocateContiguousMemorySpecifyCacheNode ?

    @Slava: No, with StorPortAllocateContiguousMemorySpecifyCacheNode there were no more crashes. Sorry for confusing :-)

    Regards,
    Suresh
  • Tim_RobertsTim_Roberts Member - All Emails Posts: 13,397
    On Aug 17, 2016, at 11:13 PM, [email protected] wrote:
    >
    > Thanks Tim! I overlooked the non-contiguous physical address nature of StorPortAllocatePool.
    > Unfortunately our hardware does not support scatter-gather. But I was wondering then why did you suggest to do DMA one page at a time instead of using StorPortAllocateContiguousMemorySpecifyCacheNode ?

    If you are given a buffer from above and your hardware does not support DMA, you have two options. You can do the DMA from the original buffer one page at a time, or you can allocate a common buffer, copy the data over, and DMA in one bunch.

    It's not immediately obvious which option is faster. For a 64k buffer, you have the cost of setting up 16 transfers vs the cost of copying the buffer.

    Tim Roberts, [email protected]
    Providenza & Boekelheide, Inc.

    Tim Roberts, [email protected]
    Providenza & Boekelheide, Inc.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Upcoming OSR Seminars
OSR has suspended in-person seminars due to the Covid-19 outbreak. But, don't miss your training! Attend via the internet instead!
Kernel Debugging 30 Mar 2020 OSR Seminar Space
Developing Minifilters 15 Jun 2020 LIVE ONLINE
Writing WDF Drivers 22 June 2020 LIVE ONLINE
Internals & Software Drivers 28 Sept 2020 Dulles, VA