Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
diff --git a/mm/shmem.c b/mm/shmem.c
index e4c9e5c7081f..1fb3f69e19e2 100644
--- a/mm/shmem.c
+++ b/mm/shmem.c
@@ -959,11 +959,13 @@ static void shmem_undo_range(struct inode *inode, loff_t lstart, loff_t lend,
folio = shmem_get_partial_folio(inode, lstart >> PAGE_SHIFT);
if (folio) {
same_folio = lend < folio_pos(folio) + folio_size(folio);
- folio_mark_dirty(folio);
- if (!truncate_inode_partial_folio(folio, lstart, lend)) {
- start = folio->index + folio_nr_pages(folio);
- if (same_folio)
- end = folio->index;
+ if (!unfalloc || !folio_test_uptodate(folio)) {
+ folio_mark_dirty(folio);
+ if (!truncate_inode_partial_folio(folio, lstart, lend)) {
+ start = folio->index + folio_nr_pages(folio);
+ if (same_folio)
+ end = folio->index;
+ }
}
folio_unlock(folio);
folio_put(folio);
@@ -973,9 +975,11 @@ static void shmem_undo_range(struct inode *inode, loff_t lstart, loff_t lend,
if (!same_folio)
folio = shmem_get_partial_folio(inode, lend >> PAGE_SHIFT);
if (folio) {
- folio_mark_dirty(folio);
- if (!truncate_inode_partial_folio(folio, lstart, lend))
- end = folio->index;
+ if (!unfalloc || !folio_test_uptodate(folio)) {
+ folio_mark_dirty(folio);
+ if (!truncate_inode_partial_folio(folio, lstart, lend))
+ end = folio->index;
+ }
folio_unlock(folio);
folio_put(folio);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment