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 8823FC54EE9 for ; Thu, 8 Sep 2022 18:33:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229583AbiIHSdv (ORCPT ); Thu, 8 Sep 2022 14:33:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52916 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229700AbiIHSdt (ORCPT ); Thu, 8 Sep 2022 14:33:49 -0400 Received: from mx0a-00082601.pphosted.com (mx0b-00082601.pphosted.com [67.231.153.30]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D32C7F22CD; Thu, 8 Sep 2022 11:33:47 -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 288IJ8KL019918; Thu, 8 Sep 2022 11:33:44 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=message-id : date : subject : to : cc : references : from : in-reply-to : mime-version : content-type : content-transfer-encoding; s=facebook; bh=l/nHA+VmiWviEqsaL2iKhKxR27g/BcydhTNJ68Z7bpo=; b=PbDgTJ/KSEnyGfXH+fOPxKGGTAIPkN5YlB/aZ6KeIew5xQ5mnxi8EyDnMLmTQZRiqoBz o4gKc2DvxWf4IAqoTMTJMKjzOU4weBEozRirQTRZpcaRbWN3g1SP3X/qi90IrjCmyVw/ 9amh7wQQmPcjDPBXxqCpS4GuVA1BMhhgQ7g= Received: from nam11-dm6-obe.outbound.protection.outlook.com (mail-dm6nam11lp2168.outbound.protection.outlook.com [104.47.57.168]) by m0001303.ppops.net (PPS) with ESMTPS id 3jevdaj0p4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 08 Sep 2022 11:33:43 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QiIwnQfBN2QzA+m0deCac2i4TRIb3czuFZ6sxFGN0P/rtzwO9ftORPoTT7ecQVIpliarMEVs8kzkrIb2Af0QZh3dZOAldgEEfFDQDspGdmgvaTMR3tdqXzh3Sz65T7gqKHTr4pBgCR4xitiF2tiyr5/okRoQbNYLwuIdCPG+cwv8W/RUVKcKcf672CuMxGS+ls8/0jvW7keMG7+jxtAbBJFea5/wEi13T9bKySanzcrLtNrxfBsOofd6BsFs4aWt3EJvWsFmHc3U3cuNAr/wnmNXiCMYovG1ty8guBdXUeEhe4/G0CGRQhMUzQzInGNh9qHLsYMfGpVETMCbqrmDGw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=nUvvn96bD/roa0JaKPRr6MfhRt1TJH6+qVHDal3KM3o=; b=IAtoASuuWhAWsQrHvcDmrs6uiBc4g2eh6fQJ+odmnkmsy5BOQNKfdmsaXiBiE0BwACRubGOUQkvofIx9S+cKdnvHgURsUbVIJT3GgytWsRggR5BipidStsoqVjI/HBuF0OgSc0hSFZYoo2weMd4hZGvgsRtVVfUiEx9XrZbHol8dU/s2oPAU1VFyIlkqujuX8oUdXtLdT/ipMGG7KPNaGbpWJ6aH88k69PC7R+TUiV24KeBljb78f2HclF8lvp54RqExVhSDE72hHIt3jDUqnARdEbvnj+l2yk8D6BK7k8a05o3MkMTZZQmmFrTYPgv8x2qudGlMdBGtJivhhE38uw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=fb.com; dmarc=pass action=none header.from=fb.com; dkim=pass header.d=fb.com; arc=none Received: from DM6PR15MB2316.namprd15.prod.outlook.com (2603:10b6:5:8d::10) by SN6PR1501MB1984.namprd15.prod.outlook.com (2603:10b6:805:f::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5588.18; Thu, 8 Sep 2022 18:33:37 +0000 Received: from DM6PR15MB2316.namprd15.prod.outlook.com ([fe80::c052:c6b9:41f8:e5ae]) by DM6PR15MB2316.namprd15.prod.outlook.com ([fe80::c052:c6b9:41f8:e5ae%3]) with mapi id 15.20.5612.014; Thu, 8 Sep 2022 18:33:37 +0000 Message-ID: <53c625e9-5dc0-5fc6-c30c-7483bcc468a7@fb.com> Date: Thu, 8 Sep 2022 11:33:34 -0700 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:91.0) Gecko/20100101 Thunderbird/91.13.0 Subject: Re: [PATCH v2 07/12] btrfs: make prepare_pages nowait compatible Content-Language: en-US To: Filipe Manana Cc: kernel-team@fb.com, io-uring@vger.kernel.org, linux-btrfs@vger.kernel.org, axboe@kernel.dk, josef@toxicpanda.com References: <20220908002616.3189675-1-shr@fb.com> <20220908002616.3189675-8-shr@fb.com> From: Stefan Roesch In-Reply-To: X-ClientProxiedBy: BYAPR08CA0023.namprd08.prod.outlook.com (2603:10b6:a03:100::36) To DM6PR15MB2316.namprd15.prod.outlook.com (2603:10b6:5:8d::10) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR15MB2316:EE_|SN6PR1501MB1984:EE_ X-MS-Office365-Filtering-Correlation-Id: 7546d956-9b60-4fd9-66d3-08da91c8a49a X-FB-Source: Internal X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: JW8Kr9Ds4iSXTAXnnEybmdLPOM6FMawVpzGNpnkri1Br/OdenViE8l0zVcRMAtqYmTvaVB9VGg5uX2R3lWex3pkBq58PIrujGz6Jw8kBDXOVWnLBI6mImywIY+WqShF2GS1vHzU+zFAW+/KQ0Yk527I+I3ghJBFZd3TbifRYA7TR1gSQWGkWOap/oz55egnXBBCGRjmH0Lfo0g+lPlLY3XCxtaW4JxhQSOZ3v5FlqA1nd7bxCn47pcjzicCsJIZVJ1ojIFunj4zM6dSf04t7m72985LHonRhBzuBHomDNClxzzXAu+d/zJceR4HrE791us9bAId/sKykT+STdnPVaTnjccebAawkCY4Bj9PYysg+rr4d1wd6lZyl9Gxa8hPf/ipvpBdCDVs0N0hDHatCkdbw7wHZHXzrj2wE9h5icgbrHp5E9Qt57nQgjIxv3OyrZilZejtisrluUu/aN717mbIODTRdlP5FWl2ToJvAkoCNwnyAAZ3OCZiIjtGzWqtZclNfPk1b+wamYZtt1M5f4ewVHOFY/ENeQ4gu4jGHCmL4kxWdkfz/yq5zZMQ6PhJ+gUAIHP8iybriIZYjXSQKVYub1P81PdZ9MGQkvgqHLS5XhOeClEAnEYifyo+Z1EN94msOMwfFAggrSE/xr0B0lDqA1CtrLzk31rl9jUNJ911jiSjtZxY/zL5S1LDNrfYUTkmz+bOJ/+sGooWLKf8kQ6BAWpwCArtUxmZrrT4P1oFFc1WrX+hQRRzqirmdU2WQVG02ThozrpdsprtoncGpFpLBvVVm5ez39OZSknjseD4= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR15MB2316.namprd15.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230016)(4636009)(366004)(39860400002)(346002)(376002)(136003)(396003)(38100700002)(86362001)(6666004)(478600001)(4326008)(66556008)(66946007)(8676002)(66476007)(8936002)(5660300002)(41300700001)(31696002)(6916009)(316002)(186003)(83380400001)(53546011)(6512007)(2906002)(2616005)(6506007)(31686004)(6486002)(36756003)(45980500001)(43740500002);DIR:OUT;SFP:1102; X-M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Yvc01EZUk5ejlS?= =?utf-8?B?NVdvUjhNU3UvNTZwYWtXMDFPS05ocVNUSnkwWk1uMnoxczBzTDAxN0VCNU1Q?= =?utf-8?B?Y2RoRlF6ZFd3SXlVbUcvUElISXdWZzBnZnl4M3FEMlVLZDNzT1VtRDhuemJh?= =?utf-8?B?U3NZUzRYY2l6TWN5QkRINFcvRm4xNjI4NlRRQmJub3ZFL1ZHc05oeVNoVERs?= =?utf-8?B?TC9IZGlhQ0RjbWZ2UVFQMzRkenJkaFpDVVFSRTJnSjFWRTBadGZpRHc1NFZa?= =?utf-8?B?NXJ0Z3JoQWpGYkJDL1hJR24xbTEwemRIYmFvYk1WRk00ZGdHUGxTRTU3bEVT?= =?utf-8?B?OUgrN0tBNUgzNkpCazFXSE1McHRMUDlFMDQxWk1BNDRZM3FWY2laZ0tNWlZ3?= =?utf-8?Q?dVXjZiZ0+ZkQNaUpV8AvccLw1?= X-OriginatorOrg: fb.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7546d956-9b60-4fd9-66d3-08da91c8a49a X-MS-Exchange-CrossTenant-AuthSource: DM6PR15MB2316.namprd15.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Sep 2022 18:33:36.8821 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 8ae927fe-1255-47a7-a2af-5f3a069daaa2 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: K/lMFDRYv8UBEjnY7NqPYbrgcv7lFI5Ds+LOtyqpXgKWAdXo6v3AfDjoH9/fs7j9 X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR1501MB1984 X-Proofpoint-GUID: H2Cm_e5tMqf5RcqrWbZwSPXgmKk0bDFW X-Proofpoint-ORIG-GUID: H2Cm_e5tMqf5RcqrWbZwSPXgmKk0bDFW Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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-08_10,2022-09-08_01,2022-06-22_01 Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org On 9/8/22 3:17 AM, Filipe Manana wrote: > >=20 > On Thu, Sep 8, 2022 at 1:26 AM Stefan Roesch wrote: >> >> 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 | 43 ++++++++++++++++++++++++++++++++++++------- >> 1 file changed, 36 insertions(+), 7 deletions(-) >> >> diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c >> index cf19d381ead6..a154a3cec44b 100644 >> --- a/fs/btrfs/file.c >> +++ b/fs/btrfs/file.c >> @@ -1339,26 +1339,55 @@ static int prepare_uptodate_page(struct inode *i= node, >> return 0; >> } >> >> +static int get_prepare_fgp_flags(bool nowait) >> +{ >> + int fgp_flags; >> + >> + fgp_flags =3D FGP_LOCK|FGP_ACCESSED|FGP_CREAT; >=20 > Please follow the existing code style and add a space before and after > each bitwise or operator. > Not only does it conform to the btrfs style, it's also easier to read. >=20 > The assignment could also be done when declaring the variable, since > it's short and simple. >=20 > Thanks. I added the space and moved the assignment to the definition. >=20 >> + if (nowait) >> + fgp_flags |=3D FGP_NOWAIT; >> + >> + return fgp_flags; >> +} >> + >> +static gfp_t get_prepare_gfp_flags(struct inode *inode, bool nowait) >> +{ >> + gfp_t gfp; >> + >> + gfp =3D btrfs_alloc_write_mask(inode->i_mapping); >> + if (nowait) { >> + gfp &=3D ~__GFP_DIRECT_RECLAIM; >> + gfp |=3D 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 **pa= ges, >> size_t num_pages, loff_t pos, >> - size_t write_bytes, bool force_uptodat= e) >> + size_t write_bytes, bool force_uptodat= e, >> + bool nowait) >> { >> int i; >> unsigned long index =3D pos >> PAGE_SHIFT; >> - gfp_t mask =3D btrfs_alloc_write_mask(inode->i_mapping); >> + gfp_t mask =3D get_prepare_gfp_flags(inode, nowait); >> + int fgp_flags =3D get_prepare_fgp_flags(nowait); >> int err =3D 0; >> int faili; >> >> for (i =3D 0; i < num_pages; i++) { >> again: >> - pages[i] =3D find_or_create_page(inode->i_mapping, index= + i, >> - mask | __GFP_WRITE); >> + pages[i] =3D pagecache_get_page(inode->i_mapping, index = + i, >> + fgp_flags, mask | __GFP_WRITE); >> if (!pages[i]) { >> faili =3D i - 1; >> - err =3D -ENOMEM; >> + if (nowait) >> + err =3D -EAGAIN; >> + else >> + err =3D -ENOMEM; >> goto fail; >> } >> >> @@ -1376,7 +1405,7 @@ static noinline int prepare_pages(struct inode *in= ode, struct page **pages, >> pos + write_bytes, f= alse); >> if (err) { >> put_page(pages[i]); >> - if (err =3D=3D -EAGAIN) { >> + if (!nowait && err =3D=3D -EAGAIN) { >> err =3D 0; >> goto again; >> } >> @@ -1716,7 +1745,7 @@ static noinline ssize_t btrfs_buffered_write(struc= t kiocb *iocb, >> */ >> ret =3D 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); >> -- >> 2.30.2 >>