Muli Ben-Yehuda's journal

October 25, 2004

Locking user space memory

Filed under: Uncategorized — Muli Ben-Yehuda @ 3:10 PM

A common question is “how do I lock user space memory?”. The context is usually when the memory is going to be used for DMA to or from a device.

The best way is to have user space request the memory from your driver via an mmap() on a character device files. Sometimes, however, this is not feasible. In those cases, you have two choices:

– If you have control of the user space application, use the POSIX mlock() and munlock() APIs.

_ if you only have control of the driver side, use the get_user_pages() API in the kernel. lwn.net has an excellent article on get_user_pages, and common pitfalls.

Blog at WordPress.com.