Commit 69bbb87b authored by Matthew Wilcox (Oracle)'s avatar Matthew Wilcox (Oracle) Committed by Andrew Morton

shmem: convert shmem_write_end() to use a folio

Use a folio internally to shmem_write_end() which saves a number of calls
to compound_head() and lets us get rid of the custom code to zero out the
rest of a THP and supports folios of arbitrary size.

Link: https://lkml.kernel.org/r/20230112131031.1209553-1-willy@infradead.orgSigned-off-by: default avatarMatthew Wilcox (Oracle) <willy@infradead.org>
Reviewed-by: default avatarWilliam Kucharski <william.kucharski@oracle.com>
Cc: Hugh Dickins <hughd@google.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
parent a6fddef4
...@@ -2578,33 +2578,23 @@ shmem_write_end(struct file *file, struct address_space *mapping, ...@@ -2578,33 +2578,23 @@ shmem_write_end(struct file *file, struct address_space *mapping,
loff_t pos, unsigned len, unsigned copied, loff_t pos, unsigned len, unsigned copied,
struct page *page, void *fsdata) struct page *page, void *fsdata)
{ {
struct folio *folio = page_folio(page);
struct inode *inode = mapping->host; struct inode *inode = mapping->host;
if (pos + copied > inode->i_size) if (pos + copied > inode->i_size)
i_size_write(inode, pos + copied); i_size_write(inode, pos + copied);
if (!PageUptodate(page)) { if (!folio_test_uptodate(folio)) {
struct page *head = compound_head(page); if (copied < folio_size(folio)) {
if (PageTransCompound(page)) { size_t from = offset_in_folio(folio, pos);
int i; folio_zero_segments(folio, 0, from,
from + copied, folio_size(folio));
for (i = 0; i < HPAGE_PMD_NR; i++) {
if (head + i == page)
continue;
clear_highpage(head + i);
flush_dcache_page(head + i);
}
}
if (copied < PAGE_SIZE) {
unsigned from = pos & (PAGE_SIZE - 1);
zero_user_segments(page, 0, from,
from + copied, PAGE_SIZE);
} }
SetPageUptodate(head); folio_mark_uptodate(folio);
} }
set_page_dirty(page); folio_mark_dirty(folio);
unlock_page(page); folio_unlock(folio);
put_page(page); folio_put(folio);
return copied; return copied;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment