From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on gnuweeb.org X-Spam-Level: X-Spam-Status: No, score=-0.1 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_PASS,SPF_SOFTFAIL,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 532B6C4167E for ; Fri, 20 May 2022 18:37:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344980AbiETShi (ORCPT ); Fri, 20 May 2022 14:37:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59284 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352929AbiETShe (ORCPT ); Fri, 20 May 2022 14:37:34 -0400 Received: from mx0a-00082601.pphosted.com (mx0b-00082601.pphosted.com [67.231.153.30]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 588F51666BD for ; Fri, 20 May 2022 11:37:33 -0700 (PDT) Received: from pps.filterd (m0001303.ppops.net [127.0.0.1]) by m0001303.ppops.net (8.17.1.5/8.17.1.5) with ESMTP id 24KHScIY008454 for ; Fri, 20 May 2022 11:37:32 -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=mtjtBSFBboij+dZeJUy8sfQn/qaPHn8tVpe9eVt5tec=; b=KEtuZFmnc7S13PpMRMlIu/rpwu7L3bcae8H0m3sa51fznvmCJ3fdBSAdtQ87LY2A+4ey /xvfmLgU4JaCvF7nN2C/Tof/yPAm07Yvu8tQpXHnlB4J82N4DUkWWFKtMtWyUnUr/dPq 5TA8/IiS5FWiFhs7HOwiXzJV5GEDVb7eqEw= Received: from maileast.thefacebook.com ([163.114.130.16]) by m0001303.ppops.net (PPS) with ESMTPS id 3g5wkre7my-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Fri, 20 May 2022 11:37:32 -0700 Received: from twshared4937.07.ash9.facebook.com (2620:10d:c0a8:1b::d) by mail.thefacebook.com (2620:10d:c0a8:83::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.28; Fri, 20 May 2022 11:37:30 -0700 Received: by devvm225.atn0.facebook.com (Postfix, from userid 425415) id 7D316F5E5B2B; Fri, 20 May 2022 11:37:16 -0700 (PDT) From: Stefan Roesch To: , , , , CC: , , , Subject: [RFC PATCH v4 06/17] iomap: Add async buffered write support Date: Fri, 20 May 2022 11:36:35 -0700 Message-ID: <20220520183646.2002023-7-shr@fb.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220520183646.2002023-1-shr@fb.com> References: <20220520183646.2002023-1-shr@fb.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-FB-Internal: Safe Content-Type: text/plain X-Proofpoint-GUID: 0GyFjaEAQz5CFeI7HHlGU3WSoBprmG1h X-Proofpoint-ORIG-GUID: 0GyFjaEAQz5CFeI7HHlGU3WSoBprmG1h X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.874,Hydra:6.0.486,FMLib:17.11.64.514 definitions=2022-05-20_06,2022-05-20_02,2022-02-23_01 Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org This adds async buffered write support to iomap. Signed-off-by: Stefan Roesch --- fs/iomap/buffered-io.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c index 27e67bfc64f5..187f4ddd7ba7 100644 --- a/fs/iomap/buffered-io.c +++ b/fs/iomap/buffered-io.c @@ -555,15 +555,21 @@ static int __iomap_write_begin(const struct iomap_i= ter *iter, loff_t pos, loff_t block_size =3D i_blocksize(iter->inode); loff_t block_start =3D round_down(pos, block_size); loff_t block_end =3D round_up(pos + len, block_size); + unsigned int nr_blocks =3D i_blocks_per_folio(iter->inode, folio); size_t from =3D offset_in_folio(folio, pos), to =3D from + len; size_t poff, plen; gfp_t gfp =3D GFP_NOFS | __GFP_NOFAIL; =20 + if (iter->flags & IOMAP_NOWAIT) + gfp =3D GFP_NOWAIT; + if (folio_test_uptodate(folio)) return 0; folio_clear_error(folio); =20 iop =3D iomap_page_create(iter->inode, folio, gfp); + if ((iter->flags & IOMAP_NOWAIT) && !iop && nr_blocks > 1) + return -EAGAIN; =20 do { iomap_adjust_read_range(iter->inode, folio, &block_start, @@ -581,7 +587,12 @@ static int __iomap_write_begin(const struct iomap_it= er *iter, loff_t pos, return -EIO; folio_zero_segments(folio, poff, from, to, poff + plen); } else { - int status =3D iomap_read_folio_sync(block_start, folio, + int status; + + if (iter->flags & IOMAP_NOWAIT) + return -EAGAIN; + + status =3D iomap_read_folio_sync(block_start, folio, poff, plen, srcmap); if (status) return status; @@ -610,6 +621,9 @@ static int iomap_write_begin(const struct iomap_iter = *iter, loff_t pos, unsigned fgp =3D FGP_LOCK | FGP_WRITE | FGP_CREAT | FGP_STABLE | FGP_NO= FS; int status =3D 0; =20 + if (iter->flags & IOMAP_NOWAIT) + fgp |=3D FGP_NOWAIT; + BUG_ON(pos + len > iter->iomap.offset + iter->iomap.length); if (srcmap !=3D &iter->iomap) BUG_ON(pos + len > srcmap->offset + srcmap->length); @@ -767,6 +781,10 @@ static loff_t iomap_write_iter(struct iomap_iter *it= er, struct iov_iter *i) * Otherwise there's a nasty deadlock on copying from the * same page as we're writing to, without it being marked * up-to-date. + * + * For async buffered writes the assumption is that the user + * page has already been faulted in. This can be optimized by + * faulting the user page in the prepare phase of io-uring. */ if (unlikely(fault_in_iov_iter_readable(i, bytes) =3D=3D bytes)) { status =3D -EFAULT; @@ -822,6 +840,9 @@ iomap_file_buffered_write(struct kiocb *iocb, struct = iov_iter *i, }; int ret; =20 + if (iocb->ki_flags & IOCB_NOWAIT) + iter.flags |=3D IOMAP_NOWAIT; + while ((ret =3D iomap_iter(&iter, ops)) > 0) iter.processed =3D iomap_write_iter(&iter, i); if (iter.pos =3D=3D iocb->ki_pos) --=20 2.30.2