public inbox for io-uring@vger.kernel.org
 help / color / mirror / Atom feed
From: Kanchan Joshi <joshi.k@samsung.com>
To: axboe@kernel.dk, kbusch@kernel.org, hch@lst.de, hare@suse.de,
	sagi@grimberg.me, martin.petersen@oracle.com, brauner@kernel.org,
	viro@zeniv.linux.org.uk, jack@suse.cz, jaegeuk@kernel.org,
	bcrl@kvack.org, dhowells@redhat.com, bvanassche@acm.org,
	asml.silence@gmail.com
Cc: linux-nvme@lists.infradead.org, linux-fsdevel@vger.kernel.org,
	io-uring@vger.kernel.org, linux-block@vger.kernel.org,
	linux-aio@kvack.org, gost.dev@samsung.com, vishak.g@samsung.com,
	javier.gonz@samsung.com, Kanchan Joshi <joshi.k@samsung.com>,
	Nitesh Shetty <nj.shetty@samsung.com>
Subject: [PATCH v7 2/3] block, fs: restore kiocb based write hint processing
Date: Mon, 30 Sep 2024 23:43:04 +0530	[thread overview]
Message-ID: <20240930181305.17286-3-joshi.k@samsung.com> (raw)
In-Reply-To: <20240930181305.17286-1-joshi.k@samsung.com>

struct kiocb has a 2 bytes hole that developed post commit 41d36a9f3e53
("fs: remove kiocb.ki_hint").
But write hint has made a comeback with commit 449813515d3e ("block, fs:
Restore the per-bio/request data lifetime fields").

This patch uses the leftover space in kiocb to carve 1 byte field
ki_write_hint.
Restore the code that operates on kiocb to use ki_write_hint instead of
inode hint value.

This does not bring any behavior change, but needed to enable per-io
hints (by another patch).

Signed-off-by: Kanchan Joshi <joshi.k@samsung.com>
Signed-off-by: Nitesh Shetty <nj.shetty@samsung.com>
Reviewed-by: Hannes Reinecke <hare@suse.de>
---
 block/fops.c         | 6 +++---
 fs/aio.c             | 1 +
 fs/cachefiles/io.c   | 1 +
 fs/direct-io.c       | 2 +-
 fs/iomap/direct-io.c | 2 +-
 include/linux/fs.h   | 8 ++++++++
 io_uring/rw.c        | 1 +
 7 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/block/fops.c b/block/fops.c
index e696ae53bf1e..85b9b97d372c 100644
--- a/block/fops.c
+++ b/block/fops.c
@@ -74,7 +74,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;
@@ -203,7 +203,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;
@@ -319,7 +319,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;
 
diff --git a/fs/aio.c b/fs/aio.c
index e8920178b50f..db618817e670 100644
--- a/fs/aio.c
+++ b/fs/aio.c
@@ -1517,6 +1517,7 @@ static int aio_prep_rw(struct kiocb *req, const struct iocb *iocb, int rw_type)
 	req->ki_flags = req->ki_filp->f_iocb_flags | IOCB_AIO_RW;
 	if (iocb->aio_flags & IOCB_FLAG_RESFD)
 		req->ki_flags |= IOCB_EVENTFD;
+	req->ki_write_hint = file_write_hint(req->ki_filp);
 	if (iocb->aio_flags & IOCB_FLAG_IOPRIO) {
 		/*
 		 * If the IOCB_FLAG_IOPRIO flag of aio_flags is set, then
diff --git a/fs/cachefiles/io.c b/fs/cachefiles/io.c
index 6a821a959b59..c3db102ae64e 100644
--- a/fs/cachefiles/io.c
+++ b/fs/cachefiles/io.c
@@ -309,6 +309,7 @@ int __cachefiles_write(struct cachefiles_object *object,
 	ki->iocb.ki_pos		= start_pos;
 	ki->iocb.ki_flags	= IOCB_DIRECT | IOCB_WRITE;
 	ki->iocb.ki_ioprio	= get_current_ioprio();
+	ki->iocb.ki_write_hint  = file_write_hint(file);
 	ki->object		= object;
 	ki->start		= start_pos;
 	ki->len			= len;
diff --git a/fs/direct-io.c b/fs/direct-io.c
index bbd05f1a2145..73629e26becb 100644
--- a/fs/direct-io.c
+++ b/fs/direct-io.c
@@ -409,7 +409,7 @@ dio_bio_alloc(struct dio *dio, struct dio_submit *sdio,
 		bio->bi_end_io = dio_bio_end_io;
 	if (dio->is_pinned)
 		bio_set_flag(bio, BIO_PAGE_PINNED);
-	bio->bi_write_hint = file_inode(dio->iocb->ki_filp)->i_write_hint;
+	bio->bi_write_hint = dio->iocb->ki_write_hint;
 
 	sdio->bio = bio;
 	sdio->logical_offset_in_bio = sdio->cur_page_fs_offset;
diff --git a/fs/iomap/direct-io.c b/fs/iomap/direct-io.c
index f637aa0706a3..fff43f121ee6 100644
--- a/fs/iomap/direct-io.c
+++ b/fs/iomap/direct-io.c
@@ -397,7 +397,7 @@ static loff_t iomap_dio_bio_iter(const struct iomap_iter *iter,
 		fscrypt_set_bio_crypt_ctx(bio, inode, pos >> inode->i_blkbits,
 					  GFP_KERNEL);
 		bio->bi_iter.bi_sector = iomap_sector(iomap, pos);
-		bio->bi_write_hint = inode->i_write_hint;
+		bio->bi_write_hint = dio->iocb->ki_write_hint;
 		bio->bi_ioprio = dio->iocb->ki_ioprio;
 		bio->bi_private = dio;
 		bio->bi_end_io = iomap_dio_bio_end_io;
diff --git a/include/linux/fs.h b/include/linux/fs.h
index e3c603d01337..3dfe6de7b611 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 */
+	enum rw_hint		ki_write_hint;
 	union {
 		/*
 		 * Only used for async buffered reads, where it denotes the
@@ -2337,12 +2338,18 @@ static inline bool HAS_UNMAPPED_ID(struct mnt_idmap *idmap,
 	       !vfsgid_valid(i_gid_into_vfsgid(idmap, inode));
 }
 
+static inline enum rw_hint file_write_hint(struct file *filp)
+{
+	return file_inode(filp)->i_write_hint;
+}
+
 static inline void init_sync_kiocb(struct kiocb *kiocb, struct file *filp)
 {
 	*kiocb = (struct kiocb) {
 		.ki_filp = filp,
 		.ki_flags = filp->f_iocb_flags,
 		.ki_ioprio = get_current_ioprio(),
+		.ki_write_hint = file_write_hint(filp),
 	};
 }
 
@@ -2353,6 +2360,7 @@ static inline void kiocb_clone(struct kiocb *kiocb, struct kiocb *kiocb_src,
 		.ki_filp = filp,
 		.ki_flags = kiocb_src->ki_flags,
 		.ki_ioprio = kiocb_src->ki_ioprio,
+		.ki_write_hint = kiocb_src->ki_write_hint,
 		.ki_pos = kiocb_src->ki_pos,
 	};
 }
diff --git a/io_uring/rw.c b/io_uring/rw.c
index f023ff49c688..510123d3d837 100644
--- a/io_uring/rw.c
+++ b/io_uring/rw.c
@@ -1023,6 +1023,7 @@ int io_write(struct io_kiocb *req, unsigned int issue_flags)
 	if (unlikely(ret))
 		return ret;
 	req->cqe.res = iov_iter_count(&io->iter);
+	rw->kiocb.ki_write_hint = file_write_hint(rw->kiocb.ki_filp);
 
 	if (force_nonblock) {
 		/* If the file doesn't support async, just async punt */
-- 
2.25.1


  parent reply	other threads:[~2024-09-30 18:21 UTC|newest]

Thread overview: 86+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20240930182052epcas5p37edefa7556b87c3fbb543275756ac736@epcas5p3.samsung.com>
2024-09-30 18:13 ` [PATCH v7 0/3] FDP and per-io hints Kanchan Joshi
2024-09-30 18:13   ` [PATCH v7 1/3] nvme: enable FDP support Kanchan Joshi
2024-10-02 18:37     ` Bart Van Assche
2024-10-03 12:55       ` Christoph Hellwig
2024-09-30 18:13   ` Kanchan Joshi [this message]
2024-09-30 18:13   ` [PATCH v7 3/3] io_uring: enable per-io hinting capability Kanchan Joshi
2024-10-02 14:26     ` Pavel Begunkov
2024-10-17 14:58       ` Kanchan Joshi
2024-10-02 18:29     ` Bart Van Assche
2024-10-01  9:20   ` [PATCH v7 0/3] FDP and per-io hints Christoph Hellwig
2024-10-01 15:58     ` James R. Bergsten
2024-10-01 16:18     ` Jens Axboe
2024-10-02  7:51       ` Christoph Hellwig
2024-10-02 15:03         ` Jens Axboe
2024-10-02 15:13           ` Christoph Hellwig
2024-10-02 15:17             ` Keith Busch
2024-10-02 15:19               ` Christoph Hellwig
2024-10-02 15:33                 ` Keith Busch
2024-10-03 12:51                   ` Christoph Hellwig
2024-10-02 15:47                 ` Martin K. Petersen
2024-10-02 18:34                   ` Bart Van Assche
2024-10-03 12:55                     ` Christoph Hellwig
2024-10-03 21:48                       ` Keith Busch
2024-10-03 22:00                         ` Bart Van Assche
2024-10-03 22:12                           ` Jens Axboe
2024-10-03 22:17                           ` Keith Busch
2024-10-04  6:21                       ` Javier González
2024-10-04  6:24                         ` Christoph Hellwig
2024-10-04  6:59                           ` Javier González
2024-10-04 12:32                             ` Christoph Hellwig
2024-10-07 11:29                               ` Javier González
2024-10-08 12:27                                 ` Christoph Hellwig
2024-10-03 12:54                   ` Christoph Hellwig
2024-10-03 22:14                     ` Jens Axboe
2024-10-04  5:31                       ` Christoph Hellwig
2024-10-04  6:18                         ` Javier González
2024-10-04  6:27                           ` Christoph Hellwig
2024-10-04  6:52                             ` Javier González
2024-10-04 12:30                               ` Christoph Hellwig
2024-10-07 10:10                                 ` Javier González
2024-10-08 10:06                                   ` Hans Holmberg
2024-10-09 14:36                                     ` Javier Gonzalez
2024-10-10  6:40                                       ` Hans Holmberg
2024-10-10  7:13                                         ` Javier Gonzalez
2024-10-10  9:20                                           ` Christoph Hellwig
2024-10-10 12:22                                             ` Javier Gonzalez
2024-10-11  8:56                                               ` Christoph Hellwig
2024-10-11 12:21                                                 ` Javier Gonzalez
2024-10-11 16:59                                                   ` Keith Busch
2024-10-10 10:46                                           ` Hans Holmberg
2024-10-10 12:27                                             ` Javier Gonzalez
2024-10-11  8:59                                               ` Christoph Hellwig
2024-10-08 12:25                                   ` Christoph Hellwig
2024-10-08 14:44                                     ` Keith Busch
2024-10-09  9:28                                       ` Christoph Hellwig
2024-10-09 15:06                                         ` Keith Busch
2024-10-10  7:07                                           ` Javier González
2024-10-10  9:13                                             ` Christoph Hellwig
2024-10-10 11:59                                               ` Javier González
2024-10-11  9:02                                                 ` Christoph Hellwig
2024-10-11 17:08                                                   ` Jens Axboe
2024-10-14  6:21                                                     ` Christoph Hellwig
2024-10-14  7:02                                                       ` Javier Gonzalez
2024-10-14  7:47                                                         ` Christoph Hellwig
2024-10-14  9:08                                                           ` Javier Gonzalez
2024-10-14 11:50                                                             ` Christoph Hellwig
2024-10-15  3:07                                                               ` Javier Gonzalez
2024-10-15  5:30                                                                 ` Christoph Hellwig
2024-10-10  9:10                                           ` Christoph Hellwig
2024-10-09 16:28                                         ` Nitesh Shetty
2024-10-02 15:22             ` Jens Axboe
2024-10-01 16:23     ` Keith Busch
2024-10-02  7:49       ` Christoph Hellwig
2024-10-02 14:56         ` Keith Busch
2024-10-02 15:00           ` Jens Axboe
2024-10-03  0:20   ` Bart Van Assche
2024-10-15  5:50   ` Christoph Hellwig
2024-10-15 15:09     ` Keith Busch
2024-10-15 15:22       ` Christoph Hellwig
2024-10-17 14:35     ` Kanchan Joshi
2024-10-17 15:23       ` Christoph Hellwig
2024-10-17 15:44         ` Keith Busch
2024-10-17 15:46           ` Christoph Hellwig
2024-10-17 16:06             ` Keith Busch
2024-10-17 16:15           ` Bart Van Assche
2024-10-17 16:23             ` Keith Busch

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=20240930181305.17286-3-joshi.k@samsung.com \
    --to=joshi.k@samsung.com \
    --cc=asml.silence@gmail.com \
    --cc=axboe@kernel.dk \
    --cc=bcrl@kvack.org \
    --cc=brauner@kernel.org \
    --cc=bvanassche@acm.org \
    --cc=dhowells@redhat.com \
    --cc=gost.dev@samsung.com \
    --cc=hare@suse.de \
    --cc=hch@lst.de \
    --cc=io-uring@vger.kernel.org \
    --cc=jack@suse.cz \
    --cc=jaegeuk@kernel.org \
    --cc=javier.gonz@samsung.com \
    --cc=kbusch@kernel.org \
    --cc=linux-aio@kvack.org \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-nvme@lists.infradead.org \
    --cc=martin.petersen@oracle.com \
    --cc=nj.shetty@samsung.com \
    --cc=sagi@grimberg.me \
    --cc=viro@zeniv.linux.org.uk \
    --cc=vishak.g@samsung.com \
    /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