Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp667370iog; Thu, 30 Jun 2022 08:01:45 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uDQnian4vqL692x9FqyDh/hg2OMFlV/z0+W2D1Oo/yLHggTBJALaKIdPyG1+cHL9/+f434 X-Received: by 2002:a05:6a00:84d:b0:525:3ce6:9c33 with SMTP id q13-20020a056a00084d00b005253ce69c33mr15033050pfk.47.1656601305430; Thu, 30 Jun 2022 08:01:45 -0700 (PDT) Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q17-20020a63bc11000000b003ffafbc0463si25816549pge.369.2022.06.30.08.01.26; Thu, 30 Jun 2022 08:01:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=iuhtvLHP; arc=fail (signature failed); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234403AbiF3Ov2 (ORCPT + 99 others); Thu, 30 Jun 2022 10:51:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57682 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229966AbiF3Ov1 (ORCPT ); Thu, 30 Jun 2022 10:51:27 -0400 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6CEB41CFE6; Thu, 30 Jun 2022 07:51:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1656600686; x=1688136686; h=date:from:to:cc:subject:message-id:references: in-reply-to:mime-version; bh=PwLQS8rCsDFR4RJLA2H0Z3LljtFLcasNe+pYdF+2K/s=; b=iuhtvLHPVsqo92K7qIf6ZthBRHrXKxRNqN6pCNFD9E+iaHbsImjbnYek 1Z1SZUZElKHYc5eKJoQu5rhLlNF6mRA1a0gpt/LDK3yNPK59BYRtrjipg UZraBw7FVKmu9x/dq+nuKQXmTMEgnhBmh3zFnzZ+ft0rtoSMXkwjqDLg/ KJEW8Ha/yHdo5qXxC00QiO7IS2Vwam3+p63nuZs6KMJ8RTYOVK6NTcQA8 H1wFZUbqJ3JjQcvKlJkDDGzmofgtYF8yD/SDi+cMeVL+Td0NKjlN9WF0T vcVj0yLdsDWnHiyd+l90K+F5V4xk6FmA6tHKtvFPAPzHamamhx6KtYTmE w==; X-IronPort-AV: E=McAfee;i="6400,9594,10393"; a="262771613" X-IronPort-AV: E=Sophos;i="5.92,234,1650956400"; d="scan'208";a="262771613" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Jun 2022 07:51:26 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.92,234,1650956400"; d="scan'208";a="718243475" Received: from orsmsx603.amr.corp.intel.com ([10.22.229.16]) by orsmga004.jf.intel.com with ESMTP; 30 Jun 2022 07:51:25 -0700 Received: from orsmsx607.amr.corp.intel.com (10.22.229.20) by ORSMSX603.amr.corp.intel.com (10.22.229.16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.27; Thu, 30 Jun 2022 07:51:25 -0700 Received: from ORSEDG601.ED.cps.intel.com (10.7.248.6) by orsmsx607.amr.corp.intel.com (10.22.229.20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.27 via Frontend Transport; Thu, 30 Jun 2022 07:51:25 -0700 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (104.47.58.107) by edgegateway.intel.com (134.134.137.102) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2308.27; Thu, 30 Jun 2022 07:51:25 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=iZvgxtt996UlaMTAE6n/TrCH8kaVHpjAWZ32IPnnjNhAqb0lT6c0h/IrxPCyzDwY2A+s3Syo7/YVWbaJpWn7J19CzMRtUYam6dK909tvJjgGyCg0XP8xNF4EpKmBU9yXAzHywo4Zj3G5kl1FWKzXo1ZzaYTcbNW7z8OzbARgR0t7gqLuTn7l+F0SoeamYipqcapnZvQLpihbwJbdP3AdGKjACk5qKX0dp/4RqnEE9Twt44MrIPp3Xu6Blsc3XdT9itTLIrB3Jv44ZjfDBNF3HCERN7UZVdybx+6sxCAubzR9uiyVSMDYR0TPMz9HjuAPRUCnC8Kkd5/4OhkZ2Dz6NQ== 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=yACGtMcNmkD/YLSqgn3AQEWqhpfOZ9oj4G7S7D33EQ0=; b=QZRa9G4MfoE8uHcGhE7hyg0g8P4OtBysjQ+91k1/v5JabNRGG2HC0R2V/88gH+4N+E42AM0JcfOvy5odMc77YKXpwK8TkbT8KWuQDnM2DkYl8DODNDSyx7amFE53pyQTJZ5v4W7ptRmmPXw8uq+VIIy1byinOnkkEus2+xbK3N5+euLViNqu365amf67/ueBUxBFupx/NrgT1f7Pyqon7us3tp44csXcAZIkrEyeY/UqxbWvNk1IM91kJOQ2yuaW/wkEpZ0LpgIzq4zLFARIgUo6Zm0CWBUwl5XNs0BlywnPlLgASpv8hb5SRPe2DDSFNEjF7Mox4TwKTw8bPHXhNw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; Received: from DM4PR11MB6311.namprd11.prod.outlook.com (2603:10b6:8:a6::21) by CY4PR1101MB2165.namprd11.prod.outlook.com (2603:10b6:910:24::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5395.14; Thu, 30 Jun 2022 14:51:23 +0000 Received: from DM4PR11MB6311.namprd11.prod.outlook.com ([fe80::e912:6a38:4502:f207]) by DM4PR11MB6311.namprd11.prod.outlook.com ([fe80::e912:6a38:4502:f207%5]) with mapi id 15.20.5395.014; Thu, 30 Jun 2022 14:51:23 +0000 Date: Thu, 30 Jun 2022 07:51:14 -0700 From: Ira Weiny To: "Fabio M. De Francesco" CC: Chris Mason , Josef Bacik , David Sterba , Nick Terrell , Chris Down , Qu Wenruo , Filipe Manana , Gabriel Niebler , , Subject: Re: [PATCH] btrfs: Convert zlib_compress_pages() to use kmap_local_page() Message-ID: References: <20220627163305.24116-1-fmdefrancesco@gmail.com> Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: <20220627163305.24116-1-fmdefrancesco@gmail.com> X-ClientProxiedBy: BY5PR17CA0035.namprd17.prod.outlook.com (2603:10b6:a03:1b8::48) To DM4PR11MB6311.namprd11.prod.outlook.com (2603:10b6:8:a6::21) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 112261da-66f3-43ad-a952-08da5aa8000e X-MS-TrafficTypeDiagnostic: CY4PR1101MB2165:EE_ X-LD-Processed: 46c98d88-e344-4ed4-8496-4ed7712e255d,ExtAddr X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: SV8p+uybBAYhqO+HH2SgR0uOKg9mFTT/YB6iQHvTiVK9zCCsNWaZNZRn5N92bs7aeswOw5EyW6D9daSmpNs6v5yDjTFIVbuuj0A+JsFNAC+Xbb18mQ72M1qixCw1n+lDhbR5OIahArOWMhchlaW3sc2DU68GDg+bPUkf3j6sqp0ozr6RxgKfLBrMxw17StJityqNgKf2/CXu71tWB2Yv2U4VHJLPHn93SxQ01IGJoZBpCey+qfYNv4/ZuxuqP7t3Uos/yCio7o5UtAhCVsZxNkFEUQAceNqWgw8WCxTD98LkwJGBFy0EOQG/PSpqwg0Of9+iFEAY1YvZImZ+PpvAWertuULwr0UFR1a9U06nJjaTAJORnofrwnLH6SDNnTBvJSeAdBsmPREvYskLWmeK8LmtfDxtRypn2Fcj/asdCYLef7B2lF4aYYpScjyAwxY7B0savFJMVV3pnMD6hiyvJASlBlYOpNhazzYSR1ofZnxWUNYf4NEbsu34obv3hIhjJPDHbUlwUK+piRG7GYSbhaf+1i6/eJ9AVDg9xIvfhHXSaqiE43C7tg4kb9kwkSkCS8iT71azeFRxR/9vC8wGMwo/ws59bxWcTtvpFO57ha3lMjS73SsILmVwEwekx0ZZNk/X8DbAm7ia2IT2xHSdXS0bw1EdC7yiq6QdOP5akBQTwR7IMXT3jQpOhm4Tnaq/zW5G/1oBOsNJvtZs+0XQruWWuF0AJCydeeVAurPPnfbM27qNwLgEJTlN2wNQdvTHLEgfHwh5fZKmk7zyviXa8CMgnIBiMRFqHdXrZdiI4Sg= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM4PR11MB6311.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230016)(7916004)(39860400002)(346002)(136003)(396003)(376002)(366004)(7416002)(6512007)(5660300002)(478600001)(44832011)(6506007)(9686003)(6666004)(8936002)(66946007)(86362001)(2906002)(6486002)(82960400001)(33716001)(41300700001)(38100700002)(186003)(83380400001)(6916009)(4326008)(54906003)(8676002)(316002)(66476007)(66556008)(67856001);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?ZUGC7SDO1/txYAnzJNTnOuKQXq7/t3danzCKI2M7sJVjNF2ZG1CGXimjItJz?= =?us-ascii?Q?nKi+V4GcY0c/AxwTcEJV8mFB/xrctTNDynVT1w7zZ/qFqzxX0vM0Tyroa6/k?= =?us-ascii?Q?/ux+nsSbQyzT19gzY+nMx5qCj9Rf2piNN7EWO2NLfiz46/F2vjZURcCG7yuI?= =?us-ascii?Q?Uvg5Mklu1FH54zhX/C2O/JNF9eVTIiPrDsjqWVdHdqeBbMnoQv7TuEE8FcaV?= =?us-ascii?Q?4kyUspMVWP/l+BpohtqlahrFOvZ1dXxnsbQuFmxZd0JRDjCK19lu4A7Z8a8l?= =?us-ascii?Q?E3paGvFDU4ruHlxkZX+sMvs8G3hDXahY8MKK9vBpslNcg+WigfOLsIC26C9y?= =?us-ascii?Q?zKaitVxDEqVsbecZNElX+GaEm+1NmQRgTDn4z5LBEHB03qlylq5GedgMduD6?= =?us-ascii?Q?u4m5y9KQopCJbIBAsq2Hmvss5peImQCSt3TesYA4h4orC/wVsCaJHZDh4H1s?= =?us-ascii?Q?neCKjkAChaRu6M8yPxRWaB8SlRW00TXoyrPmoOu1hIpG6ykIWeZs+Gx2jBQs?= =?us-ascii?Q?16OQj2VtrSP8KHR/7rG8f9OZFH4G0kvbV60lzOHzQDtzD+g8ZHOHq3+h6E9H?= =?us-ascii?Q?0KwmovAOj940uyEbyduVGEeOUQs4VfxYf56x6mbx03Fv4tAmzVRhmQNO8Mm7?= =?us-ascii?Q?vFCCb2eGeK+AAQZxXbKlGodcIHWXDUIx6gXK35pdP8z2wMq6WL97k2XBvs9z?= =?us-ascii?Q?YMXKow3icmLXcN72x0Z9nV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us-ascii?Q?rg+xt02ZYMTyoQDNx6EuPBoPq1nd0rL1NA3br6uuC51f?= X-MS-Exchange-CrossTenant-Network-Message-Id: 112261da-66f3-43ad-a952-08da5aa8000e X-MS-Exchange-CrossTenant-AuthSource: DM4PR11MB6311.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Jun 2022 14:51:22.9406 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: ZDrdMD9b8H3ifEBZpzmyFDxnekLemGJaK83+WupMuDAT8UCN6fZPNS7xTVhR8zgdRJIbOAjI1QWmXVO5gWMHEg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR1101MB2165 X-OriginatorOrg: intel.com X-Spam-Status: No, score=-4.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jun 27, 2022 at 06:33:05PM +0200, Fabio M. De Francesco wrote: > The use of kmap() is being deprecated in favor of kmap_local_page(). With > kmap_local_page(), the mapping is per thread, CPU local and not globally > visible. > > Therefore, use kmap_local_page() / kunmap_local() in zlib_compress_pages() > because in this function the mappings are per thread and are not visible > in other contexts. Furthermore, drop the mappings of "out_page" which is > allocated within zlib_compress_pages() with alloc_page(GFP_NOFS) and use > page_address() (thanks to David Sterba). > > Tested with xfstests on a QEMU + KVM 32-bits VM with 4GB of RAM booting > a kernel with HIGHMEM64G enabled. This patch passes 26/26 tests of group > "compress". > > Cc: Qu Wenruo > Suggested-by: David Sterba > Suggested-by: Ira Weiny Reviewed-by: Ira Weiny > Signed-off-by: Fabio M. De Francesco > --- > fs/btrfs/zlib.c | 32 +++++++++++++------------------- > 1 file changed, 13 insertions(+), 19 deletions(-) > > diff --git a/fs/btrfs/zlib.c b/fs/btrfs/zlib.c > index 770c4c6bbaef..b4f44662cda7 100644 > --- a/fs/btrfs/zlib.c > +++ b/fs/btrfs/zlib.c > @@ -97,7 +97,7 @@ int zlib_compress_pages(struct list_head *ws, struct address_space *mapping, > { > struct workspace *workspace = list_entry(ws, struct workspace, list); > int ret; > - char *data_in; > + char *data_in = NULL; > char *cpage_out; > int nr_pages = 0; > struct page *in_page = NULL; > @@ -126,7 +126,7 @@ int zlib_compress_pages(struct list_head *ws, struct address_space *mapping, > ret = -ENOMEM; > goto out; > } > - cpage_out = kmap(out_page); > + cpage_out = page_address(out_page); > pages[0] = out_page; > nr_pages = 1; > > @@ -148,26 +148,26 @@ int zlib_compress_pages(struct list_head *ws, struct address_space *mapping, > int i; > > for (i = 0; i < in_buf_pages; i++) { > - if (in_page) { > - kunmap(in_page); > + if (data_in) { > + kunmap_local(data_in); > put_page(in_page); > } > in_page = find_get_page(mapping, > start >> PAGE_SHIFT); > - data_in = kmap(in_page); > + data_in = kmap_local_page(in_page); > memcpy(workspace->buf + i * PAGE_SIZE, > data_in, PAGE_SIZE); > start += PAGE_SIZE; > } > workspace->strm.next_in = workspace->buf; > } else { > - if (in_page) { > - kunmap(in_page); > + if (data_in) { > + kunmap_local(data_in); > put_page(in_page); > } > in_page = find_get_page(mapping, > start >> PAGE_SHIFT); > - data_in = kmap(in_page); > + data_in = kmap_local_page(in_page); > start += PAGE_SIZE; > workspace->strm.next_in = data_in; > } > @@ -196,9 +196,7 @@ int zlib_compress_pages(struct list_head *ws, struct address_space *mapping, > * the stream end if required > */ > if (workspace->strm.avail_out == 0) { > - kunmap(out_page); > if (nr_pages == nr_dest_pages) { > - out_page = NULL; > ret = -E2BIG; > goto out; > } > @@ -207,7 +205,7 @@ int zlib_compress_pages(struct list_head *ws, struct address_space *mapping, > ret = -ENOMEM; > goto out; > } > - cpage_out = kmap(out_page); > + cpage_out = page_address(out_page); > pages[nr_pages] = out_page; > nr_pages++; > workspace->strm.avail_out = PAGE_SIZE; > @@ -234,9 +232,7 @@ int zlib_compress_pages(struct list_head *ws, struct address_space *mapping, > goto out; > } else if (workspace->strm.avail_out == 0) { > /* get another page for the stream end */ > - kunmap(out_page); > if (nr_pages == nr_dest_pages) { > - out_page = NULL; > ret = -E2BIG; > goto out; > } > @@ -245,7 +241,7 @@ int zlib_compress_pages(struct list_head *ws, struct address_space *mapping, > ret = -ENOMEM; > goto out; > } > - cpage_out = kmap(out_page); > + cpage_out = page_address(out_page); > pages[nr_pages] = out_page; > nr_pages++; > workspace->strm.avail_out = PAGE_SIZE; > @@ -264,13 +260,11 @@ int zlib_compress_pages(struct list_head *ws, struct address_space *mapping, > *total_in = workspace->strm.total_in; > out: > *out_pages = nr_pages; > - if (out_page) > - kunmap(out_page); > - > - if (in_page) { > - kunmap(in_page); > + if (data_in) { > + kunmap_local(data_in); > put_page(in_page); > } > + > return ret; > } > > -- > 2.36.1 >