检查Linux页面缓存条目的有效性

huangapple go评论63阅读模式
英文:

Check Linux Pagecache Entry Validity

问题

我使用find_get_entries()检索所有打开的文件相关联的pagecache页面。对于每个检索到的页面,将需要调用put_page()来将页面的引用计数恢复到其先前的状态。find_get_entries()似乎存在竞争条件。在某些情况下,返回的struct page *元素包含垃圾(可能是因为与索引相关联的页面已被驱逐)。因此,在这种页面上调用put_page()将导致内核崩溃。我该如何避免这种情况?

英文:

I used find_get_entries() to retrieve pagecache pages associated with all opened files. For each retrieved page, a put_page() invocation will be needed to revert the page reference count to its previous state. find_get_entries() seems to be racy. In some scenarios, the returned struct page * element contains garbage (perhaps because the page associated with an index has been evicted). Therefore, a put_page() call on such a page will cause kernel panic. How can I avoid this situation?

答案1

得分: 1

似乎最近被驱逐页面的阴影条目等(通过调用xa_is_value()识别)也将在entries参数中返回。可以通过检查它们的LSB(即,如果(unsigned long)entries[i]&1不为零,则该元素是有效页面)来识别并忽略它们。

英文:

It seems that the shadow entries of recently evicted pages, etc. (recognized by calling xa_is_value()) will also be returned in the entries parameter. They can be identified and ignored by checking their LSB (i.e., if (unsigned long)entries[i] & 1 is not zero, the element is not a valid page).

huangapple
  • 本文由 发表于 2023年5月29日 00:44:48
  • 转载请务必保留本文链接:https://go.coder-hub.com/76352548.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定