Message ID | 20190110024404.25372-16-axboe@kernel.dk (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | [01/15] fs: add an iopoll method to struct file_operations | expand |
Jens Axboe <axboe@kernel.dk> writes: > Add hint on whether a read was served out of the page cache, or if it > hit media. This is useful for buffered async IO, O_DIRECT reads would > never have this set (for obvious reasons). > > If the read hit page cache, cqe->flags will have IOCQE_FLAG_CACHEHIT > set. We may want to hold off on this one until the whole mincore/RWF_NOWAIT debate is sorted. [1] Cheers, Jeff [1] https://lore.kernel.org/lkml/20190109022430.GE27534@dastard/
On 1/10/19 4:12 PM, Jeff Moyer wrote: > Jens Axboe <axboe@kernel.dk> writes: > >> Add hint on whether a read was served out of the page cache, or if it >> hit media. This is useful for buffered async IO, O_DIRECT reads would >> never have this set (for obvious reasons). >> >> If the read hit page cache, cqe->flags will have IOCQE_FLAG_CACHEHIT >> set. > > We may want to hold off on this one until the whole mincore/RWF_NOWAIT > debate is sorted. [1] Definitely, it's why it's separate and at the end of the series. But in reality, this doesn't leak anything that timing doesn't already tell you. So it's kind of a moot point.
diff --git a/fs/io_uring.c b/fs/io_uring.c index 6c62329b00ec..f2a603c447ba 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -511,11 +511,16 @@ static void io_fill_cq_error(struct io_ring_ctx *ctx, struct sqe_submit *s, static void io_complete_scqring_rw(struct kiocb *kiocb, long res, long res2) { struct io_kiocb *iocb = container_of(kiocb, struct io_kiocb, rw); + unsigned ev_flags = 0; kiocb_end_write(kiocb); fput(kiocb->ki_filp); - io_cqring_fill_event(iocb->ki_ctx, iocb->ki_index, res, 0); + + if (res > 0 && test_bit(KIOCB_F_FORCE_NONBLOCK, &iocb->ki_flags)) + ev_flags = IOCQE_FLAG_CACHEHIT; + + io_cqring_fill_event(iocb->ki_ctx, iocb->ki_index, res, ev_flags); io_free_kiocb(iocb); } diff --git a/include/uapi/linux/io_uring.h b/include/uapi/linux/io_uring.h index 9321eb97479d..20e4c22e040d 100644 --- a/include/uapi/linux/io_uring.h +++ b/include/uapi/linux/io_uring.h @@ -55,6 +55,11 @@ struct io_uring_cqe { __u32 flags; }; +/* + * io_uring_event->flags + */ +#define IOCQE_FLAG_CACHEHIT (1 << 0) /* IO did not hit media */ + /* * Magic offsets for the application to mmap the data it needs */
Add hint on whether a read was served out of the page cache, or if it hit media. This is useful for buffered async IO, O_DIRECT reads would never have this set (for obvious reasons). If the read hit page cache, cqe->flags will have IOCQE_FLAG_CACHEHIT set. Signed-off-by: Jens Axboe <axboe@kernel.dk> --- fs/io_uring.c | 7 ++++++- include/uapi/linux/io_uring.h | 5 +++++ 2 files changed, 11 insertions(+), 1 deletion(-)