From patchwork Mon Sep 12 19:27:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roesch X-Patchwork-Id: 12974057 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 DA28EC6FA8D for ; Mon, 12 Sep 2022 19:28:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229939AbiILT2V (ORCPT ); Mon, 12 Sep 2022 15:28:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50586 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229865AbiILT2T (ORCPT ); Mon, 12 Sep 2022 15:28:19 -0400 Received: from mx0a-00082601.pphosted.com (mx0a-00082601.pphosted.com [67.231.145.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DAF3546220 for ; Mon, 12 Sep 2022 12:28:16 -0700 (PDT) Received: from pps.filterd (m0109334.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 28CIEppd022502 for ; Mon, 12 Sep 2022 12:28:16 -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=8RVRQ6/cQX6qNy5uU4Kh4lX2fZOOQ9gq7/Aw+KIXpjA=; b=XRbmhapx5q387X5gok3qOUaceqcy5ZmlZXPOIt2VKkhfje2A0uCU0CcR5RvK/BG/vmQU 4zTzi3giUVTCrJhzHRmHCWoYOL5r/4ihGoIlfFLax+bGgG/eOgznzsy1Dctv1M/ndNH4 AGwcQocHNG1CKh8Y54jvmyhLycJuLQEazyk= Received: from maileast.thefacebook.com ([163.114.130.16]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 3jgsw4ccjw-5 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Mon, 12 Sep 2022 12:28:16 -0700 Received: from twshared15978.04.prn5.facebook.com (2620:10d:c0a8:1b::d) by mail.thefacebook.com (2620:10d:c0a8:83::4) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Mon, 12 Sep 2022 12:28:12 -0700 Received: by dev1180.prn1.facebook.com (Postfix, from userid 425415) id 162392085234; Mon, 12 Sep 2022 12:27:54 -0700 (PDT) From: Stefan Roesch To: , , , CC: , , , Subject: [PATCH v3 07/12] btrfs: make prepare_pages nowait compatible Date: Mon, 12 Sep 2022 12:27:47 -0700 Message-ID: <20220912192752.3785061-8-shr@fb.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220912192752.3785061-1-shr@fb.com> References: <20220912192752.3785061-1-shr@fb.com> MIME-Version: 1.0 X-FB-Internal: Safe X-Proofpoint-ORIG-GUID: OB2AqnbZWOnQvV0IVJ9OoyVex1fLiMN7 X-Proofpoint-GUID: OB2AqnbZWOnQvV0IVJ9OoyVex1fLiMN7 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.528,FMLib:17.11.122.1 definitions=2022-09-12_12,2022-09-12_02,2022-06-22_01 Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org Add nowait parameter to the prepare_pages function. In case nowait is specified for an async buffered write request, do a nowait allocation or return -EAGAIN. Signed-off-by: Stefan Roesch --- fs/btrfs/file.c | 42 +++++++++++++++++++++++++++++++++++------- 1 file changed, 35 insertions(+), 7 deletions(-) diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c index f18efd9f2bc3..d4362ee7e09e 100644 --- a/fs/btrfs/file.c +++ b/fs/btrfs/file.c @@ -1339,26 +1339,54 @@ static int prepare_uptodate_page(struct inode *inode, return 0; } +static int get_prepare_fgp_flags(bool nowait) +{ + int fgp_flags = FGP_LOCK | FGP_ACCESSED | FGP_CREAT; + + if (nowait) + fgp_flags |= FGP_NOWAIT; + + return fgp_flags; +} + +static gfp_t get_prepare_gfp_flags(struct inode *inode, bool nowait) +{ + gfp_t gfp; + + gfp = btrfs_alloc_write_mask(inode->i_mapping); + if (nowait) { + gfp &= ~__GFP_DIRECT_RECLAIM; + gfp |= GFP_NOWAIT; + } + + return gfp; +} + /* * this just gets pages into the page cache and locks them down. */ static noinline int prepare_pages(struct inode *inode, struct page **pages, size_t num_pages, loff_t pos, - size_t write_bytes, bool force_uptodate) + size_t write_bytes, bool force_uptodate, + bool nowait) { int i; unsigned long index = pos >> PAGE_SHIFT; - gfp_t mask = btrfs_alloc_write_mask(inode->i_mapping); + gfp_t mask = get_prepare_gfp_flags(inode, nowait); + int fgp_flags = get_prepare_fgp_flags(nowait); int err = 0; int faili; for (i = 0; i < num_pages; i++) { again: - pages[i] = find_or_create_page(inode->i_mapping, index + i, - mask | __GFP_WRITE); + pages[i] = pagecache_get_page(inode->i_mapping, index + i, + fgp_flags, mask | __GFP_WRITE); if (!pages[i]) { faili = i - 1; - err = -ENOMEM; + if (nowait) + err = -EAGAIN; + else + err = -ENOMEM; goto fail; } @@ -1376,7 +1404,7 @@ static noinline int prepare_pages(struct inode *inode, struct page **pages, pos + write_bytes, false); if (err) { put_page(pages[i]); - if (err == -EAGAIN) { + if (!nowait && err == -EAGAIN) { err = 0; goto again; } @@ -1716,7 +1744,7 @@ static noinline ssize_t btrfs_buffered_write(struct kiocb *iocb, */ ret = prepare_pages(inode, pages, num_pages, pos, write_bytes, - force_page_uptodate); + force_page_uptodate, false); if (ret) { btrfs_delalloc_release_extents(BTRFS_I(inode), reserve_bytes);