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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id CC0F6C433FE for ; Tue, 26 Apr 2022 17:43:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 56F6F6B007B; Tue, 26 Apr 2022 13:43:56 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4F4B36B007E; Tue, 26 Apr 2022 13:43:56 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3980F6B0080; Tue, 26 Apr 2022 13:43:56 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.26]) by kanga.kvack.org (Postfix) with ESMTP id 207A36B007B for ; Tue, 26 Apr 2022 13:43:56 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id EB50B27009 for ; Tue, 26 Apr 2022 17:43:55 +0000 (UTC) X-FDA: 79399753230.14.3196B64 Received: from mx0b-00082601.pphosted.com (mx0b-00082601.pphosted.com [67.231.153.30]) by imf28.hostedemail.com (Postfix) with ESMTP id 6B897C0040 for ; Tue, 26 Apr 2022 17:43:48 +0000 (UTC) Received: from pps.filterd (m0109331.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 23QGQduV023418 for ; Tue, 26 Apr 2022 10:43:54 -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=sVaCe7n8PQWmshIX6gLNdmwvF5amYzdsvPLOsBIpxFY=; b=de9wCTDnCaO3DYx4UvPg8EdhK9JTmC0DM6dcTNRpEa5JRxkKBZRTDMTMFAy9zZKKtEmE i3AGjhSaKCN5V4vsFI3dA8evAEFWJ2GCFOnGr94i5z2ylQ1SuVUcZ3NiWghG0pOOE3FM IYNIb+/fUaAQ9SOLNftdiNW4U3IWQUfnDPk= Received: from maileast.thefacebook.com ([163.114.130.16]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 3fp9qhv8n2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Tue, 26 Apr 2022 10:43:54 -0700 Received: from twshared29473.14.frc2.facebook.com (2620:10d:c0a8:1b::d) by mail.thefacebook.com (2620:10d:c0a8:82::c) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Tue, 26 Apr 2022 10:43:54 -0700 Received: by devvm225.atn0.facebook.com (Postfix, from userid 425415) id 8EE03E2D485D; Tue, 26 Apr 2022 10:43:40 -0700 (PDT) From: Stefan Roesch To: , , , , CC: , Subject: [RFC PATCH v1 05/18] iomap: add async buffered write support Date: Tue, 26 Apr 2022 10:43:22 -0700 Message-ID: <20220426174335.4004987-6-shr@fb.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220426174335.4004987-1-shr@fb.com> References: <20220426174335.4004987-1-shr@fb.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-FB-Internal: Safe Content-Type: text/plain X-Proofpoint-ORIG-GUID: fEAjw04xoEHSDy0w1WpvH-vhoOOnh40_ X-Proofpoint-GUID: fEAjw04xoEHSDy0w1WpvH-vhoOOnh40_ X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.858,Hydra:6.0.486,FMLib:17.11.64.514 definitions=2022-04-26_05,2022-04-26_02,2022-02-23_01 X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 6B897C0040 X-Stat-Signature: 9rbit43wxhi54bo1h6pkc1p9y3uodzsf X-Rspam-User: Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=fb.com header.s=facebook header.b=de9wCTDn; spf=none (imf28.hostedemail.com: domain of "prvs=5115329de3=shr@fb.com" has no SPF policy when checking 67.231.153.30) smtp.mailfrom="prvs=5115329de3=shr@fb.com"; dmarc=pass (policy=reject) header.from=fb.com X-HE-Tag: 1650995028-849132 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: This adds async buffered write support to iomap. The support is focused on the changes necessary to support XFS with iomap. Support for other filesystems might require additional changes. Signed-off-by: Stefan Roesch --- fs/iomap/buffered-io.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c index 1ffdc7078e7d..5c53a5715c85 100644 --- a/fs/iomap/buffered-io.c +++ b/fs/iomap/buffered-io.c @@ -580,13 +580,20 @@ static int __iomap_write_begin(const struct iomap_i= ter *iter, loff_t pos, 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; + bool no_wait =3D (iter->flags & IOMAP_NOWAIT); + + if (no_wait) + gfp =3D GFP_NOIO | GFP_ATOMIC; =20 if (folio_test_uptodate(folio)) return 0; folio_clear_error(folio); =20 - if (!iop && nr_blocks > 1) + if (!iop && nr_blocks > 1) { iop =3D iomap_page_create_gfp(iter->inode, folio, nr_blocks, gfp); + if (no_wait && !iop) + return -EAGAIN; + } =20 do { iomap_adjust_read_range(iter->inode, folio, &block_start, @@ -603,6 +610,8 @@ static int __iomap_write_begin(const struct iomap_ite= r *iter, loff_t pos, if (WARN_ON_ONCE(iter->flags & IOMAP_UNSHARE)) return -EIO; folio_zero_segments(folio, poff, from, to, poff + plen); + } else if (no_wait) { + return -EAGAIN; } else { int status =3D iomap_read_folio_sync(block_start, folio, poff, plen, srcmap); @@ -633,6 +642,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 | FGP_ATOMIC; + BUG_ON(pos + len > iter->iomap.offset + iter->iomap.length); if (srcmap !=3D &iter->iomap) BUG_ON(pos + len > srcmap->offset + srcmap->length); @@ -790,6 +802,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; @@ -845,6 +861,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