diff options
Diffstat (limited to 'mm/mincore.c')
| -rw-r--r-- | mm/mincore.c | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/mm/mincore.c b/mm/mincore.c index 10dabefc3acc..20fd0967d3cb 100644 --- a/mm/mincore.c +++ b/mm/mincore.c @@ -64,8 +64,33 @@ static unsigned char mincore_page(struct address_space *mapping, pgoff_t index) * any other file mapping (ie. marked !present and faulted in with * tmpfs's .fault). So swapped out tmpfs mappings are tested here. */ - folio = filemap_get_incore_folio(mapping, index); - if (!IS_ERR(folio)) { + if (IS_ENABLED(CONFIG_SWAP) && shmem_mapping(mapping)) { + folio = filemap_get_entry(mapping, index); + /* + * shmem/tmpfs may return swap: account for swapcache + * page too. + */ + if (xa_is_value(folio)) { + struct swap_info_struct *si; + swp_entry_t swp = radix_to_swp_entry(folio); + /* There might be swapin error entries in shmem mapping. */ + if (non_swap_entry(swp)) + return 0; + /* Prevent swap device to being swapoff under us */ + si = get_swap_device(swp); + if (si) { + folio = filemap_get_folio(swap_address_space(swp), + swap_cache_index(swp)); + put_swap_device(si); + } else { + return 0; + } + } + } else { + folio = filemap_get_folio(mapping, index); + } + + if (!IS_ERR_OR_NULL(folio)) { present = folio_test_uptodate(folio); folio_put(folio); } |
