英文:
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).
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论