diff --git a/mm/shmem.c b/mm/shmem.c index c44d2dd71c89..af49d6bf6382 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -1481,6 +1481,15 @@ static void shmem_undo_range(struct inode *inode, loff_t lstart, uoff_t lend, index = start; break; } + } else if (folio->mapping) { + /* + * Splitting failed, but the part in the + * range is already zeroed. The folio + * was not dropped, so skip it when + * restarting the scan to avoid retrying + * it forever. + */ + start = max(start, folio_next_index(folio)); } } folio_unlock(folio);