Skip to content

Commit 1e84a3d

Browse files
author
Matthew Wilcox (Oracle)
committed
truncate,shmem: Add truncate_inode_folio()
Convert all callers of truncate_inode_page() to call truncate_inode_folio() instead, and move the declaration to mm/internal.h. Move the assertion that the caller is not passing in a tail page to generic_error_remove_page(). We can't entirely remove the struct page from the callers yet because the page pointer in the pvec might be a shadow/dax/swap entry instead of actually a page. Signed-off-by: Matthew Wilcox (Oracle) <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Reviewed-by: William Kucharski <[email protected]>
1 parent 7b774aa commit 1e84a3d

File tree

4 files changed

+16
-14
lines changed

4 files changed

+16
-14
lines changed

include/linux/mm.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1859,7 +1859,6 @@ extern void truncate_pagecache(struct inode *inode, loff_t new);
18591859
extern void truncate_setsize(struct inode *inode, loff_t newsize);
18601860
void pagecache_isize_extended(struct inode *inode, loff_t from, loff_t to);
18611861
void truncate_pagecache_range(struct inode *inode, loff_t offset, loff_t end);
1862-
int truncate_inode_page(struct address_space *mapping, struct page *page);
18631862
int generic_error_remove_page(struct address_space *mapping, struct page *page);
18641863
int invalidate_inode_page(struct page *page);
18651864

mm/internal.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ static inline void force_page_cache_readahead(struct address_space *mapping,
9292

9393
unsigned find_lock_entries(struct address_space *mapping, pgoff_t start,
9494
pgoff_t end, struct pagevec *pvec, pgoff_t *indices);
95+
int truncate_inode_folio(struct address_space *mapping, struct folio *folio);
9596

9697
/**
9798
* folio_evictable - Test whether a folio is evictable.

mm/shmem.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -950,7 +950,7 @@ static void shmem_undo_range(struct inode *inode, loff_t lstart, loff_t lend,
950950
index += folio_nr_pages(folio) - 1;
951951

952952
if (!unfalloc || !folio_test_uptodate(folio))
953-
truncate_inode_page(mapping, &folio->page);
953+
truncate_inode_folio(mapping, folio);
954954
folio_unlock(folio);
955955
}
956956
pagevec_remove_exceptionals(&pvec);
@@ -1027,7 +1027,8 @@ static void shmem_undo_range(struct inode *inode, loff_t lstart, loff_t lend,
10271027
}
10281028
VM_BUG_ON_PAGE(PageWriteback(page), page);
10291029
if (shmem_punch_compound(page, start, end))
1030-
truncate_inode_page(mapping, page);
1030+
truncate_inode_folio(mapping,
1031+
page_folio(page));
10311032
else if (IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE)) {
10321033
/* Wipe the page and don't get stuck */
10331034
clear_highpage(page);

mm/truncate.c

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -218,12 +218,9 @@ invalidate_complete_page(struct address_space *mapping, struct page *page)
218218
return ret;
219219
}
220220

221-
int truncate_inode_page(struct address_space *mapping, struct page *page)
221+
int truncate_inode_folio(struct address_space *mapping, struct folio *folio)
222222
{
223-
struct folio *folio = page_folio(page);
224-
VM_BUG_ON_PAGE(PageTail(page), page);
225-
226-
if (page->mapping != mapping)
223+
if (folio->mapping != mapping)
227224
return -EIO;
228225

229226
truncate_cleanup_folio(folio);
@@ -236,6 +233,8 @@ int truncate_inode_page(struct address_space *mapping, struct page *page)
236233
*/
237234
int generic_error_remove_page(struct address_space *mapping, struct page *page)
238235
{
236+
VM_BUG_ON_PAGE(PageTail(page), page);
237+
239238
if (!mapping)
240239
return -EINVAL;
241240
/*
@@ -244,7 +243,7 @@ int generic_error_remove_page(struct address_space *mapping, struct page *page)
244243
*/
245244
if (!S_ISREG(mapping->host->i_mode))
246245
return -EIO;
247-
return truncate_inode_page(mapping, page);
246+
return truncate_inode_folio(mapping, page_folio(page));
248247
}
249248
EXPORT_SYMBOL(generic_error_remove_page);
250249

@@ -395,18 +394,20 @@ void truncate_inode_pages_range(struct address_space *mapping,
395394

396395
for (i = 0; i < pagevec_count(&pvec); i++) {
397396
struct page *page = pvec.pages[i];
397+
struct folio *folio;
398398

399399
/* We rely upon deletion not changing page->index */
400400
index = indices[i];
401401

402402
if (xa_is_value(page))
403403
continue;
404+
folio = page_folio(page);
404405

405-
lock_page(page);
406-
WARN_ON(page_to_index(page) != index);
407-
wait_on_page_writeback(page);
408-
truncate_inode_page(mapping, page);
409-
unlock_page(page);
406+
folio_lock(folio);
407+
VM_BUG_ON_FOLIO(!folio_contains(folio, index), folio);
408+
folio_wait_writeback(folio);
409+
truncate_inode_folio(mapping, folio);
410+
folio_unlock(folio);
410411
}
411412
truncate_exceptional_pvec_entries(mapping, &pvec, indices);
412413
pagevec_release(&pvec);

0 commit comments

Comments
 (0)