I want to be able to remove a page from page cache so that next access to this page (by any process) will trigger a page fault. I'm doing this from the kernel, and I have a pointer to struct page
I wish to remove.
Deleting from page cache is easy (done by __delete_from_page_cache()
), but I don't know how to "unmap" this page from all processes mapping it into their VMAs. I tried using try_to_unmap(my_page, cpu_page, TTU_UNMAP|TTU_IGNORE_MLOCK|TTU_IGNORE_ACCESS)
from rmap.c
but it doesn't seem to do what I want it to.
Any help is highly appreciated.
Thank you!
How to unmap struct page from all PTEs mapping it
Asked Answered
© 2022 - 2024 — McMap. All rights reserved.
delete_from_page_cache
instead of__delete_from_page_cache
to get the lock on the page tree? I supposetry_to_unmap
is returningfalse
then, right? Which Linux kernel version are you using? – Kellnertrylock_page
(which is absolutely critical for correctness)... – Kellnertry_to_unmap
is called to unmap the page from address spaces (you can pass these flags thoughTTU_UNMAP | TTU_IGNORE_MLOCK | TTU_IGNORE_ACCESS
). Different things need to be done depending on the result of that operation. Then, assuming the result wasSWAP_SUCCESS
, if the page is dirty, flush the TLBs of all cores, and write it back if required. Finally, the page is removed from the swap cache. The closest that I could find for removing pages from the page cache isinvalidate_mapping_pages
, which removes a range of pages, not just one... – Kellnerinvalidate_inode_page
in a critical section guarded by the page lock. It is this function that eventually calls__delete_from_page_cache
. However, it does not handle cases where the page is dirty, locked, under writeback or mapped into pagetables. So have to handle these cases similar to what's done inshrink_page_list
. For example, you have to calltry_to_unmap
before attempting to remove the page from the cache. – Kellner