Skip to content

Commit e8693bc

Browse files
author
Christoph Hellwig
committed
aio: allow direct aio poll comletions for keyed wakeups
If we get a keyed wakeup for a aio poll waitqueue and wake can acquire the ctx_lock without spinning we can just complete the iocb straight from the wakeup callback to avoid a context switch. Signed-off-by: Christoph Hellwig <[email protected]> Tested-by: Avi Kivity <[email protected]>
1 parent bfe4037 commit e8693bc

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

fs/aio.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1672,13 +1672,26 @@ static int aio_poll_wake(struct wait_queue_entry *wait, unsigned mode, int sync,
16721672
void *key)
16731673
{
16741674
struct poll_iocb *req = container_of(wait, struct poll_iocb, wait);
1675+
struct aio_kiocb *iocb = container_of(req, struct aio_kiocb, poll);
16751676
__poll_t mask = key_to_poll(key);
16761677

16771678
req->woken = true;
16781679

16791680
/* for instances that support it check for an event match first: */
1680-
if (mask && !(mask & req->events))
1681-
return 0;
1681+
if (mask) {
1682+
if (!(mask & req->events))
1683+
return 0;
1684+
1685+
/* try to complete the iocb inline if we can: */
1686+
if (spin_trylock(&iocb->ki_ctx->ctx_lock)) {
1687+
list_del(&iocb->ki_list);
1688+
spin_unlock(&iocb->ki_ctx->ctx_lock);
1689+
1690+
list_del_init(&req->wait.entry);
1691+
aio_poll_complete(iocb, mask);
1692+
return 1;
1693+
}
1694+
}
16821695

16831696
list_del_init(&req->wait.entry);
16841697
schedule_work(&req->work);

0 commit comments

Comments
 (0)