linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Pankaj Raghav <p.raghav@samsung.com>
To: "Darrick J . Wong" <djwong@kernel.org>, hch@lst.de, willy@infradead.org
Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org,
	David Hildenbrand <david@redhat.com>,
	linux-fsdevel@vger.kernel.org, mcgrof@kernel.org,
	gost.dev@samsung.com, Andrew Morton <akpm@linux-foundation.org>,
	kernel@pankajraghav.com, Pankaj Raghav <p.raghav@samsung.com>
Subject: [RFC 3/3] iomap: use LARGE_ZERO_PAGE in iomap_dio_zero()
Date: Fri, 16 May 2025 12:10:54 +0200	[thread overview]
Message-ID: <20250516101054.676046-4-p.raghav@samsung.com> (raw)
In-Reply-To: <20250516101054.676046-1-p.raghav@samsung.com>

Use LARGE_ZERO_PAGE instead of custom allocated 64k zero pages. The
downside is we might end up using ZERO_PAGE on systems that do not
enable LARGE_ZERO_PAGE feature.

Signed-off-by: Pankaj Raghav <p.raghav@samsung.com>
---
 fs/iomap/direct-io.c | 31 +++++++++----------------------
 1 file changed, 9 insertions(+), 22 deletions(-)

diff --git a/fs/iomap/direct-io.c b/fs/iomap/direct-io.c
index 844261a31156..6a2b6726a156 100644
--- a/fs/iomap/direct-io.c
+++ b/fs/iomap/direct-io.c
@@ -29,13 +29,6 @@
 #define IOMAP_DIO_WRITE		(1U << 30)
 #define IOMAP_DIO_DIRTY		(1U << 31)
 
-/*
- * Used for sub block zeroing in iomap_dio_zero()
- */
-#define IOMAP_ZERO_PAGE_SIZE (SZ_64K)
-#define IOMAP_ZERO_PAGE_ORDER (get_order(IOMAP_ZERO_PAGE_SIZE))
-static struct page *zero_page;
-
 struct iomap_dio {
 	struct kiocb		*iocb;
 	const struct iomap_dio_ops *dops;
@@ -290,23 +283,29 @@ static int iomap_dio_zero(const struct iomap_iter *iter, struct iomap_dio *dio,
 {
 	struct inode *inode = file_inode(dio->iocb->ki_filp);
 	struct bio *bio;
+	int nr_vecs = max(1, i_blocksize(inode) / ZERO_LARGE_PAGE_SIZE);
 
 	if (!len)
 		return 0;
 	/*
 	 * Max block size supported is 64k
 	 */
-	if (WARN_ON_ONCE(len > IOMAP_ZERO_PAGE_SIZE))
+	if (WARN_ON_ONCE(len > SZ_64K))
 		return -EINVAL;
 
-	bio = iomap_dio_alloc_bio(iter, dio, 1, REQ_OP_WRITE | REQ_SYNC | REQ_IDLE);
+	bio = iomap_dio_alloc_bio(iter, dio, nr_vecs, REQ_OP_WRITE | REQ_SYNC | REQ_IDLE);
 	fscrypt_set_bio_crypt_ctx(bio, inode, pos >> inode->i_blkbits,
 				  GFP_KERNEL);
 	bio->bi_iter.bi_sector = iomap_sector(&iter->iomap, pos);
 	bio->bi_private = dio;
 	bio->bi_end_io = iomap_dio_bio_end_io;
 
-	__bio_add_page(bio, zero_page, len, 0);
+	while (len) {
+		unsigned int io_len = min_t(unsigned int, len, ZERO_LARGE_PAGE_SIZE);
+
+		__bio_add_page(bio, ZERO_LARGE_PAGE(0), len, 0);
+		len -= io_len;
+	}
 	iomap_dio_submit_bio(iter, dio, bio, pos);
 	return 0;
 }
@@ -827,15 +826,3 @@ iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter,
 	return iomap_dio_complete(dio);
 }
 EXPORT_SYMBOL_GPL(iomap_dio_rw);
-
-static int __init iomap_dio_init(void)
-{
-	zero_page = alloc_pages(GFP_KERNEL | __GFP_ZERO,
-				IOMAP_ZERO_PAGE_ORDER);
-
-	if (!zero_page)
-		return -ENOMEM;
-
-	return 0;
-}
-fs_initcall(iomap_dio_init);
-- 
2.47.2



      parent reply	other threads:[~2025-05-16 10:11 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-16 10:10 [RFC 0/3] add large zero page for zeroing out larger segments Pankaj Raghav
2025-05-16 10:10 ` [RFC 1/3] mm: add large zero page for efficient zeroing of " Pankaj Raghav
2025-05-16 12:21   ` David Hildenbrand
2025-05-16 13:03     ` Pankaj Raghav (Samsung)
2025-05-16 14:54       ` David Hildenbrand
2025-05-16 10:10 ` [RFC 2/3] block: use LARGE_ZERO_PAGE in __blkdev_issue_zero_pages() Pankaj Raghav
2025-05-16 10:10 ` Pankaj Raghav [this message]

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=20250516101054.676046-4-p.raghav@samsung.com \
    --to=p.raghav@samsung.com \
    --cc=akpm@linux-foundation.org \
    --cc=david@redhat.com \
    --cc=djwong@kernel.org \
    --cc=gost.dev@samsung.com \
    --cc=hch@lst.de \
    --cc=kernel@pankajraghav.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mcgrof@kernel.org \
    --cc=willy@infradead.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