@@ -1361,6 +1361,7 @@ static void aio_complete(struct aio_kiocb *iocb, long res, long res2)
struct kioctx *ctx = iocb->ki_ctx;
if (ctx->flags & IOCTX_FLAG_SCQRING) {
+ int nowait = test_bit(KIOCB_F_FORCE_NONBLOCK, &iocb->ki_flags);
unsigned long flags;
struct io_event *ev;
unsigned int tail;
@@ -1372,10 +1373,12 @@ static void aio_complete(struct aio_kiocb *iocb, long res, long res2)
* see it and punt to workqueue. This is just for buffered
* aio reads.
*/
- if (res == -EAGAIN &&
- test_bit(KIOCB_F_FORCE_NONBLOCK, &iocb->ki_flags)) {
+ if (res == -EAGAIN && nowait) {
ctx->submit_eagain = 1;
} else {
+ if (nowait)
+ res2 = IOEV_RES2_CACHEHIT;
+
/*
* If we can't get a cq entry, userspace overflowed the
* submission (by quite a lot). Flag it as an overflow
@@ -66,6 +66,12 @@ struct io_event {
__s64 res2; /* secondary result */
};
+/*
+ * aio CQ ring commandeers the otherwise unused ev->res2 to provide
+ * metadata about the IO.
+ */
+#define IOEV_RES2_CACHEHIT (1 << 0) /* IO did not hit media */
+
/*
* we always use a 64bit off_t when communicating
* with userland. its up to libraries to do the
We don't use this at all, grab it to provide hints about the data. The first hint we add is IORING_RES2_CACHEHIT, whether a read was served out of the page cache, or if it hit media. This is useful for buffered aio, O_DIRECT reads would never have this set (for obvious reasons). Signed-off-by: Jens Axboe <axboe@kernel.dk> --- fs/aio.c | 7 +++++-- include/uapi/linux/aio_abi.h | 6 ++++++ 2 files changed, 11 insertions(+), 2 deletions(-)