tmpfs currently zeroes !uptodate folios at shmem_writeout() time to ensure they are zeroed in swap. We want to expand this behavior to zero post-eof ranges to better abide POSIX file extension requirements. As a first step, split out the existing zeroing code into a separate block. No functional changes in this patch. Signed-off-by: Brian Foster --- mm/shmem.c | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/mm/shmem.c b/mm/shmem.c index 0a25ee095b86..651602460770 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -1626,22 +1626,23 @@ int shmem_writeout(struct folio *folio, struct swap_iocb **plug, * good idea to continue anyway, once we're pushing into swap. So * reactivate the folio, and let shmem_fallocate() quit when too many. */ + if (!folio_test_uptodate(folio) && inode->i_private) { + struct shmem_falloc *shmem_falloc; + spin_lock(&inode->i_lock); + shmem_falloc = inode->i_private; + if (shmem_falloc && + !shmem_falloc->waitq && + index >= shmem_falloc->start && + index < shmem_falloc->next) + shmem_falloc->nr_unswapped += nr_pages; + else + shmem_falloc = NULL; + spin_unlock(&inode->i_lock); + if (shmem_falloc) + goto redirty; + } + if (!folio_test_uptodate(folio)) { - if (inode->i_private) { - struct shmem_falloc *shmem_falloc; - spin_lock(&inode->i_lock); - shmem_falloc = inode->i_private; - if (shmem_falloc && - !shmem_falloc->waitq && - index >= shmem_falloc->start && - index < shmem_falloc->next) - shmem_falloc->nr_unswapped += nr_pages; - else - shmem_falloc = NULL; - spin_unlock(&inode->i_lock); - if (shmem_falloc) - goto redirty; - } folio_zero_range(folio, 0, folio_size(folio)); flush_dcache_folio(folio); folio_mark_uptodate(folio); -- 2.51.1