This is question about Linux (driver-related). Suppose we have some hardware, capable of doing large DMA accesses (multimegabyte read or write, you may think about CUDA card or network card). The data to be transferred to/from device was allocated in user-space and is placed in user-space.

So, I think that right way is to mlock() memory range which will be accessed with DMA. Then user process will call my driver to initiate the DMA transfer. After transfer is started, my user-space process is still working in other threads.

Some time later, when I believe that data is transferred, I want to do munlock() the memory range from user-space thread.

Is it legal? What if I call munlock() before the actual DMA transfer is ended?

Will this munlock() success or fail? Or will it block until DMA transfer is finished?

PS: question is originally from Zan Lynx, id13422 at SO.

有帮助吗?

解决方案

It is the responsibility of the device driver to lock all memory that is to be used for DMA, and to ensure that it stays locked.

If the memory is already locked, the driver still has to get an additional reference to the page to prevent it from being unlocked too early.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top