How do “pinned” pages in Linux present (or actually “pin”) themselves

半城伤御伤魂 提交于 2019-12-22 08:57:13

问题


I am using get_user_pages in a Linux kernel driver to pin memory for the purposes of [hardware] DMA. It all seems to work fine - but I am having a hard time proving that the "pinning" is doing the proper thing.

When I inspect the flags on the physical pages after doing get_user_pages - the pages don't appear "locked" (as one might think they should be). In fact, I see no difference between the flags of otherwise "active" pages vs. those I have "pinned" via get_user_pages.

The only difference I see is that get_user_pages has taken a refcount on the page. So I guess my question is - is holding this reference alone sufficient to guarantee that this page will never be swapped-out, moved, or that my user-space's vaddr will still/always reference the same underlying page?

All the driver source I can find seems to use this mechanism, and documentation seems to indicate that this is the correct way - but I am having a hard time "proving" that this will give me the correct, reliable, intended behavior.


回答1:


Holding a refcount looks sufficient to prevent the page from being pushed out, invalidated or migrated; thus safe for dma-type operations. Migration is discussed in Documentation/vm/page_migrate; the others require spelunking in the vm code. The short version is that to push a page requires getting all of its references dropped.

Notice that refcount and mapcount are different notions -- mapcount just means somebody has a virtual reference to it; refcount means they have an actual reference to it. A swapped out page can have a large mapcount.

Also note that as of https://lkml.org/lkml/2019/11/25/684 there is a less obscure interface for this.



来源:https://stackoverflow.com/questions/48931940/how-do-pinned-pages-in-linux-present-or-actually-pin-themselves

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!