diff options
| -rw-r--r-- | mm/shmem.c | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/mm/shmem.c b/mm/shmem.c index b8399bb71997..cd686a4900f4 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -2612,11 +2612,14 @@ static int shmem_swapin_folio(struct inode *inode, pgoff_t index, * and swap cache folios are never partially freed. */ folio_lock(folio); - if (!folio_matches_swap_entry(folio, swap) || - shmem_confirm_swap(mapping, index, swap) < 0) { + if (!folio_matches_swap_entry(folio, swap)) { error = -EEXIST; goto unlock; } + if (shmem_confirm_swap(mapping, index, swap) < 0) { + error = -EEXIST; + goto failed; + } if (!folio_test_uptodate(folio)) { error = -EIO; goto failed; @@ -2657,6 +2660,15 @@ failed: error = -EEXIST; if (error == -EIO) shmem_set_folio_swapin_error(inode, index, folio, swap); + /* + * A large folio that does not fit the mapping, e.g. because its swap + * entries were freed and reused, would be found again on every retry. + * Drop it from the swap cache so the retry can swap in a fitting one. + */ + if (error == -EEXIST && folio && folio_test_large(folio) && + !folio_test_anon(folio) && !folio_test_dirty(folio) && + !folio_test_writeback(folio)) + swap_cache_del_folio(folio); unlock: if (folio) folio_unlock(folio); |
