Skip to content

Commit 9cf3516

Browse files
committed
fs: add IOCB flags related to passing back dio completions
Async dio completions generally happen from hard/soft IRQ context, which means that users like iomap may need to defer some of the completion handling to a workqueue. This is less efficient than having the original issuer handle it, like we do for sync IO, and it adds latency to the completions. Add IOCB_DIO_CALLER_COMP, which the issuer can set if it is able to safely punt these completions to a safe context. If the dio handler is aware of this flag, assign a callback handler in kiocb->dio_complete and associated data io kiocb->private. The issuer will then call this handler with that data from task context. No functional changes in this patch. Reviewed-by: Darrick J. Wong <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Reviewed-by: Dave Chinner <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent 7b3c14d commit 9cf3516

File tree

1 file changed

+33
-2
lines changed

1 file changed

+33
-2
lines changed

include/linux/fs.h

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,20 @@ enum rw_hint {
338338
#define IOCB_NOIO (1 << 20)
339339
/* can use bio alloc cache */
340340
#define IOCB_ALLOC_CACHE (1 << 21)
341+
/*
342+
* IOCB_DIO_CALLER_COMP can be set by the iocb owner, to indicate that the
343+
* iocb completion can be passed back to the owner for execution from a safe
344+
* context rather than needing to be punted through a workqueue. If this
345+
* flag is set, the bio completion handling may set iocb->dio_complete to a
346+
* handler function and iocb->private to context information for that handler.
347+
* The issuer should call the handler with that context information from task
348+
* context to complete the processing of the iocb. Note that while this
349+
* provides a task context for the dio_complete() callback, it should only be
350+
* used on the completion side for non-IO generating completions. It's fine to
351+
* call blocking functions from this callback, but they should not wait for
352+
* unrelated IO (like cache flushing, new IO generation, etc).
353+
*/
354+
#define IOCB_DIO_CALLER_COMP (1 << 22)
341355

342356
/* for use in trace events */
343357
#define TRACE_IOCB_STRINGS \
@@ -351,7 +365,8 @@ enum rw_hint {
351365
{ IOCB_WRITE, "WRITE" }, \
352366
{ IOCB_WAITQ, "WAITQ" }, \
353367
{ IOCB_NOIO, "NOIO" }, \
354-
{ IOCB_ALLOC_CACHE, "ALLOC_CACHE" }
368+
{ IOCB_ALLOC_CACHE, "ALLOC_CACHE" }, \
369+
{ IOCB_DIO_CALLER_COMP, "CALLER_COMP" }
355370

356371
struct kiocb {
357372
struct file *ki_filp;
@@ -360,7 +375,23 @@ struct kiocb {
360375
void *private;
361376
int ki_flags;
362377
u16 ki_ioprio; /* See linux/ioprio.h */
363-
struct wait_page_queue *ki_waitq; /* for async buffered IO */
378+
union {
379+
/*
380+
* Only used for async buffered reads, where it denotes the
381+
* page waitqueue associated with completing the read. Valid
382+
* IFF IOCB_WAITQ is set.
383+
*/
384+
struct wait_page_queue *ki_waitq;
385+
/*
386+
* Can be used for O_DIRECT IO, where the completion handling
387+
* is punted back to the issuer of the IO. May only be set
388+
* if IOCB_DIO_CALLER_COMP is set by the issuer, and the issuer
389+
* must then check for presence of this handler when ki_complete
390+
* is invoked. The data passed in to this handler must be
391+
* assigned to ->private when dio_complete is assigned.
392+
*/
393+
ssize_t (*dio_complete)(void *data);
394+
};
364395
};
365396

366397
static inline bool is_sync_kiocb(struct kiocb *kiocb)

0 commit comments

Comments
 (0)