如何“固定" Linux中的页面会自己显示(或实际上是“固定") [英] How do "pinned" pages in Linux present (or actually "pin") themselves

查看:80
本文介绍了如何“固定" Linux中的页面会自己显示(或实际上是“固定")的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Linux内核驱动程序中使用get_user_pages来固定内存,以用于[硬件] DMA.一切似乎都可以正常工作-但我很难证明固定"功能是正确的.

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.

当我在执行get_user_pages之后检查物理页面上的标志时,这些页面不会出现锁定"状态(可能有人认为应该如此).实际上,我发现其他活动"页面的标志与我通过get_user_pages固定"的页面的标志之间没有区别.

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.

我看到的 only 区别是get_user_pages在页面上使用了 refcount .所以我想我的问题是-仅保持引用 足以保证该页面永远不会被换出,移动,或者我的用户空间的vaddr仍然/始终引用同一基础页面?

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.

推荐答案

拥有refcount看起来足以防止页面被推出,失效或迁移;因此对于dma型操作是安全的.迁移在Documentation/vm/page_migrate中进行了讨论;其他的则需要在vm代码中进行拼写.简短的版本是要推送页面,需要删除其所有引用.

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.

请注意,refcount和mapcount是不同的概念-mapcount只是意味着有人对其进行了虚拟引用; refcount表示他们有实际引用.换出的页面可能具有较大的地图计数.

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.

还请注意,截至 https://lkml.org/lkml/2019/11/25/684 界面对此不太清晰.

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

这篇关于如何“固定" Linux中的页面会自己显示(或实际上是“固定")的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆