linux-scsi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Keith Busch <kbusch@meta.com>
To: <linux-block@vger.kernel.org>, <linux-nvme@lists.infradead.org>,
	<linux-scsi@vger.kernel.org>, <io-uring@vger.kernel.org>
Cc: <linux-fsdevel@vger.kernel.org>, <hch@lst.de>,
	<joshi.k@samsung.com>, <javier.gonz@samsung.com>,
	<bvanassche@acm.org>, Keith Busch <kbusch@kernel.org>
Subject: [PATCHv9 4/7] block, fs: add write hint to kiocb
Date: Fri, 25 Oct 2024 14:36:42 -0700	[thread overview]
Message-ID: <20241025213645.3464331-5-kbusch@meta.com> (raw)
In-Reply-To: <20241025213645.3464331-1-kbusch@meta.com>

From: Keith Busch <kbusch@kernel.org>

This prepares for sources other than the inode to provide a write hint.
The block layer will use it for direct IO if the requested hint is
within the block device's capabilities.

Signed-off-by: Keith Busch <kbusch@kernel.org>
---
 block/fops.c       | 26 +++++++++++++++++++++++---
 include/linux/fs.h |  1 +
 2 files changed, 24 insertions(+), 3 deletions(-)

diff --git a/block/fops.c b/block/fops.c
index 2d01c90076813..e3f3f1957d86d 100644
--- a/block/fops.c
+++ b/block/fops.c
@@ -71,7 +71,7 @@ static ssize_t __blkdev_direct_IO_simple(struct kiocb *iocb,
 		bio_init(&bio, bdev, vecs, nr_pages, dio_bio_write_op(iocb));
 	}
 	bio.bi_iter.bi_sector = pos >> SECTOR_SHIFT;
-	bio.bi_write_hint = file_inode(iocb->ki_filp)->i_write_hint;
+	bio.bi_write_hint = iocb->ki_write_hint;
 	bio.bi_ioprio = iocb->ki_ioprio;
 	if (iocb->ki_flags & IOCB_ATOMIC)
 		bio.bi_opf |= REQ_ATOMIC;
@@ -200,7 +200,7 @@ static ssize_t __blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *iter,
 
 	for (;;) {
 		bio->bi_iter.bi_sector = pos >> SECTOR_SHIFT;
-		bio->bi_write_hint = file_inode(iocb->ki_filp)->i_write_hint;
+		bio->bi_write_hint = iocb->ki_write_hint;
 		bio->bi_private = dio;
 		bio->bi_end_io = blkdev_bio_end_io;
 		bio->bi_ioprio = iocb->ki_ioprio;
@@ -316,7 +316,7 @@ static ssize_t __blkdev_direct_IO_async(struct kiocb *iocb,
 	dio->flags = 0;
 	dio->iocb = iocb;
 	bio->bi_iter.bi_sector = pos >> SECTOR_SHIFT;
-	bio->bi_write_hint = file_inode(iocb->ki_filp)->i_write_hint;
+	bio->bi_write_hint = iocb->ki_write_hint;
 	bio->bi_end_io = blkdev_bio_end_io_async;
 	bio->bi_ioprio = iocb->ki_ioprio;
 
@@ -362,6 +362,23 @@ static ssize_t __blkdev_direct_IO_async(struct kiocb *iocb,
 	return -EIOCBQUEUED;
 }
 
+static u16 blkdev_write_hint(struct kiocb *iocb, struct block_device *bdev)
+{
+	u16 hint = iocb->ki_write_hint;
+
+	if (!hint)
+		return file_inode(iocb->ki_filp)->i_write_hint;
+
+	if (hint > bdev_max_write_hints(bdev))
+		return file_inode(iocb->ki_filp)->i_write_hint;
+
+	if (bdev_is_partition(bdev) &&
+	    !test_bit(hint - 1, bdev->write_hint_mask))
+		return file_inode(iocb->ki_filp)->i_write_hint;
+
+	return hint;
+}
+
 static ssize_t blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *iter)
 {
 	struct block_device *bdev = I_BDEV(iocb->ki_filp->f_mapping->host);
@@ -373,6 +390,9 @@ static ssize_t blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *iter)
 	if (blkdev_dio_invalid(bdev, iocb, iter))
 		return -EINVAL;
 
+	if (iov_iter_rw(iter) == WRITE)
+		iocb->ki_write_hint = blkdev_write_hint(iocb, bdev);
+
 	nr_pages = bio_iov_vecs_to_alloc(iter, BIO_MAX_VECS + 1);
 	if (likely(nr_pages <= BIO_MAX_VECS)) {
 		if (is_sync_kiocb(iocb))
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 4b5cad44a1268..1a00accf412e5 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -370,6 +370,7 @@ struct kiocb {
 	void			*private;
 	int			ki_flags;
 	u16			ki_ioprio; /* See linux/ioprio.h */
+	u16			ki_write_hint;
 	union {
 		/*
 		 * Only used for async buffered reads, where it denotes the
-- 
2.43.5


  parent reply	other threads:[~2024-10-25 21:37 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-25 21:36 [PATCHv9 0/7] write hints with nvme fdp, scsi streams Keith Busch
2024-10-25 21:36 ` [PATCHv9 3/7] block: allow ability to limit partition write hints Keith Busch
2024-10-28 11:58   ` Christoph Hellwig
2024-10-28 14:49     ` Keith Busch
2024-10-28 14:40   ` Kanchan Joshi
2024-10-28 18:27   ` Bart Van Assche
2024-10-28 19:46     ` Keith Busch
2024-10-25 21:36 ` Keith Busch [this message]
2024-10-28 11:59   ` [PATCHv9 4/7] block, fs: add write hint to kiocb Christoph Hellwig
2024-10-28 14:38     ` Keith Busch
2024-10-28 16:08       ` Christoph Hellwig
2024-10-25 21:36 ` [PATCHv9 7/7] scsi: set permanent stream count in block limits Keith Busch
2024-10-28 16:13   ` Bart Van Assche
2024-10-29  7:10   ` Hannes Reinecke
2024-10-28 11:49 ` [PATCHv9 0/7] write hints with nvme fdp, scsi streams Christoph Hellwig
     [not found] ` <20241025213645.3464331-3-kbusch@meta.com>
2024-10-28 11:51   ` [PATCHv9 2/7] block: introduce max_write_hints queue limit Christoph Hellwig
2024-10-28 11:52     ` Christoph Hellwig
     [not found] ` <20241025213645.3464331-2-kbusch@meta.com>
2024-10-28 18:19   ` [PATCHv9 1/7] block: use generic u16 for write hints Bart Van Assche
2024-10-28 18:38     ` Keith Busch
     [not found] ` <20241025213645.3464331-6-kbusch@meta.com>
2024-10-29 12:46   ` [PATCHv9 5/7] io_uring: enable per-io hinting capability Anuj gupta

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=20241025213645.3464331-5-kbusch@meta.com \
    --to=kbusch@meta.com \
    --cc=bvanassche@acm.org \
    --cc=hch@lst.de \
    --cc=io-uring@vger.kernel.org \
    --cc=javier.gonz@samsung.com \
    --cc=joshi.k@samsung.com \
    --cc=kbusch@kernel.org \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-nvme@lists.infradead.org \
    --cc=linux-scsi@vger.kernel.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;
as well as URLs for NNTP newsgroup(s).