From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 09C37C43334 for ; Wed, 1 Jun 2022 21:04:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231149AbiFAVEr (ORCPT ); Wed, 1 Jun 2022 17:04:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39036 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230454AbiFAVEd (ORCPT ); Wed, 1 Jun 2022 17:04:33 -0400 Received: from mx0b-00082601.pphosted.com (mx0b-00082601.pphosted.com [67.231.153.30]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 78EE516A27A for ; Wed, 1 Jun 2022 14:04:31 -0700 (PDT) Received: from pps.filterd (m0148460.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 251EG7Sg011679 for ; Wed, 1 Jun 2022 14:04:30 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=facebook; bh=Yh7+qvp7wia1iDmc7QPLBPdsuYBbsRWXU5abdWcnXVM=; b=jQ95DVp5WTjKWyjOEONHEbsXt+MlD7J/7AFNFuwFuzsA13TA+CGZrmhHC7Ls2qL2Qoo4 aSCdYNQBPtRNwnxUbq+wzwrs4+oUajeZVGwQLE95t+C+fSvoQo+dIuWDvvFJqJe/P4ja jLHAP6trQntmXtT1UALL5So4zIXoZpu81zI= Received: from mail.thefacebook.com ([163.114.132.120]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 3gdv91xp0j-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Wed, 01 Jun 2022 14:04:30 -0700 Received: from twshared19572.14.frc2.facebook.com (2620:10d:c085:108::8) by mail.thefacebook.com (2620:10d:c085:11d::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.28; Wed, 1 Jun 2022 14:04:29 -0700 Received: by devvm225.atn0.facebook.com (Postfix, from userid 425415) id 0C52DFEB23AD; Wed, 1 Jun 2022 14:01:43 -0700 (PDT) From: Stefan Roesch To: , , , , CC: , , , , Subject: [PATCH v7 12/15] io_uring: Add support for async buffered writes Date: Wed, 1 Jun 2022 14:01:38 -0700 Message-ID: <20220601210141.3773402-13-shr@fb.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220601210141.3773402-1-shr@fb.com> References: <20220601210141.3773402-1-shr@fb.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-FB-Internal: Safe Content-Type: text/plain X-Proofpoint-GUID: 1bJC3U20G9wwa-gzudjVTSq-w-OxLCYZ X-Proofpoint-ORIG-GUID: 1bJC3U20G9wwa-gzudjVTSq-w-OxLCYZ X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.874,Hydra:6.0.517,FMLib:17.11.64.514 definitions=2022-06-01_08,2022-06-01_01,2022-02-23_01 Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org This enables the async buffered writes for the filesystems that support async buffered writes in io-uring. Buffered writes are enabled for blocks that are already in the page cache or can be acquired with noio. Signed-off-by: Stefan Roesch --- fs/io_uring.c | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/fs/io_uring.c b/fs/io_uring.c index 9f1c682d7caf..c0771e215669 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -4257,7 +4257,7 @@ static inline int io_iter_do_read(struct io_kiocb *= req, struct iov_iter *iter) return -EINVAL; } =20 -static bool need_read_all(struct io_kiocb *req) +static bool need_complete_io(struct io_kiocb *req) { return req->flags & REQ_F_ISREG || S_ISBLK(file_inode(req->file)->i_mode); @@ -4386,7 +4386,7 @@ static int io_read(struct io_kiocb *req, unsigned i= nt issue_flags) } else if (ret =3D=3D -EIOCBQUEUED) { goto out_free; } else if (ret =3D=3D req->cqe.res || ret <=3D 0 || !force_nonblock || - (req->flags & REQ_F_NOWAIT) || !need_read_all(req)) { + (req->flags & REQ_F_NOWAIT) || !need_complete_io(req)) { /* read all, failed, already did sync or don't want to retry */ goto done; } @@ -4482,9 +4482,10 @@ static int io_write(struct io_kiocb *req, unsigned= int issue_flags) if (unlikely(!io_file_supports_nowait(req))) goto copy_iov; =20 - /* file path doesn't support NOWAIT for non-direct_IO */ - if (force_nonblock && !(kiocb->ki_flags & IOCB_DIRECT) && - (req->flags & REQ_F_ISREG)) + /* File path supports NOWAIT for non-direct_IO only for block devices.= */ + if (!(kiocb->ki_flags & IOCB_DIRECT) && + !(kiocb->ki_filp->f_mode & FMODE_BUF_WASYNC) && + (req->flags & REQ_F_ISREG)) goto copy_iov; =20 kiocb->ki_flags |=3D IOCB_NOWAIT; @@ -4538,6 +4539,24 @@ static int io_write(struct io_kiocb *req, unsigned= int issue_flags) /* IOPOLL retry should happen for io-wq threads */ if (ret2 =3D=3D -EAGAIN && (req->ctx->flags & IORING_SETUP_IOPOLL)) goto copy_iov; + + if (ret2 !=3D req->cqe.res && ret2 >=3D 0 && need_complete_io(req)) { + struct io_async_rw *rw; + + /* This is a partial write. The file pos has already been + * updated, setup the async struct to complete the request + * in the worker. Also update bytes_done to account for + * the bytes already written. + */ + iov_iter_save_state(&s->iter, &s->iter_state); + ret =3D io_setup_async_rw(req, iovec, s, true); + + rw =3D req->async_data; + if (rw) + rw->bytes_done +=3D ret2; + + return ret ? ret : -EAGAIN; + } done: kiocb_done(req, ret2, issue_flags); } else { --=20 2.30.2