linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Brian Foster <bfoster@redhat.com>
To: linux-mm@kvack.org
Cc: Hugh Dickins <hughd@google.com>,
	Baolin Wang <baolin.wang@linux.alibaba.com>
Subject: [PATCH v3 1/3] tmpfs: factor out folio zeroing logic at writeout time
Date: Fri, 21 Nov 2025 10:22:44 -0500	[thread overview]
Message-ID: <20251121152246.1023918-2-bfoster@redhat.com> (raw)
In-Reply-To: <20251121152246.1023918-1-bfoster@redhat.com>

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 <bfoster@redhat.com>
---
 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



  reply	other threads:[~2025-11-21 15:23 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-21 15:22 [PATCH v3 0/3] tmpfs: zero post-eof ranges on file extension Brian Foster
2025-11-21 15:22 ` Brian Foster [this message]
2025-11-21 15:22 ` [PATCH v3 2/3] tmpfs: zero post-eof folio ranges on swapout Brian Foster
2025-11-21 15:22 ` [PATCH v3 3/3] tmpfs: zero post-eof ranges on file extension Brian Foster
2025-11-25  2:20 ` [PATCH v3 0/3] " Baolin Wang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20251121152246.1023918-2-bfoster@redhat.com \
    --to=bfoster@redhat.com \
    --cc=baolin.wang@linux.alibaba.com \
    --cc=hughd@google.com \
    --cc=linux-mm@kvack.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox