Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp1166360iog; Sat, 18 Jun 2022 02:29:53 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sWPPfCqQf5sq60gtqxLZYBOKOi3n4jJ6v3vv0HmtTTxftiZDrVw7xFCt6SrTQZ4Zu65ejQ X-Received: by 2002:a17:903:11c9:b0:154:be2d:eb9 with SMTP id q9-20020a17090311c900b00154be2d0eb9mr13708700plh.91.1655544593761; Sat, 18 Jun 2022 02:29:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655544593; cv=none; d=google.com; s=arc-20160816; b=BHQDm5PBe6wdaHTLw7WeScKEiWmYOOgdcEbseDDQOsSA1rCutChQppGHelVVusFpjS dkKDoDaLRgoXi5G15x2qDPXvEHKJ2GdMM7t4/QMkGDMKc3pKA8GFxXjEAgkbfcIa96CM 8NLDAL10q1m9kCFMakguqlXllqO6yG9+L6hj3Fvr7t8ZDqZvPozmnjjZ9IgFgfbXNy2w AmBADfbyd7vzypVeZ5BNQva691o6YSrwAecFoT8X9X6KudBnVYI21EneZMY/uq+HgcpY NGYRgSLydzGQBiwuCVYJ4DT8cGfm+FCqDSmwCvrkVak6cKLd0SMYILm2V0ZPVCOTohXY vmJQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=zurrbWODzCL1ddkbl6NdnzpZxtPzyETq04wfptwh7DM=; b=Dty0ayEAPL9C90G9MCZCRVEnxyZ94+oALe/UrVe1uKp8Mx9R4/xZsL8mYjsMr5ivFv PwWgPuXPlHl/33u6jJxirufh5qgKrpvbUn9zIMx/Wsy0EXzR6kYSbNQg6+21wP3hzBhl FRMit8g2UTGi0bv+LzV7dvL8OD4d1uX33nXcDkmN7i6mIK0CeAy/ageJNUglZhQ/8amu UaamOTwwZe0gt44aHlqzKEZmTwsiN/JvN96sJKX55UuFWuiCjszpgWWZxTTAJQOv0Tol +GuIFlXJxFsxi+Jw1IsVdjkbm659e/Jqndv+V6Y5u/O4TkwGCXW4g3E+OUTkxIzMLQAd nh1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=c4bHkLgZ; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p19-20020a63f453000000b003db947d50fcsi8967134pgk.174.2022.06.18.02.29.40; Sat, 18 Jun 2022 02:29:53 -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=@gmail.com header.s=20210112 header.b=c4bHkLgZ; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233929AbiFRJ2D (ORCPT + 99 others); Sat, 18 Jun 2022 05:28:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34108 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233859AbiFRJ2A (ORCPT ); Sat, 18 Jun 2022 05:28:00 -0400 Received: from mail-ed1-x534.google.com (mail-ed1-x534.google.com [IPv6:2a00:1450:4864:20::534]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 93A42F598; Sat, 18 Jun 2022 02:27:58 -0700 (PDT) Received: by mail-ed1-x534.google.com with SMTP id o10so9023754edi.1; Sat, 18 Jun 2022 02:27:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=zurrbWODzCL1ddkbl6NdnzpZxtPzyETq04wfptwh7DM=; b=c4bHkLgZzc7iiVTDpB9d7SGvdmSsUTaqFyiLR1x9r4firz6ghgHY21dMIaDiVT+zCv cpmnb+O9pdmSpf37NF1LNoia/nXzdhSZUxXgdXEVGHmK7Bk9Gz8vZj7fKTkn18GhwjYL Ng1C1Y1pYDh2yuoENrTDHa8rX/JVEYoHznMtHqARyZU9lmZUvewuu11qCb2HelPxxKIF i3pOMt8FRxRLNSsOzjaynnzZBLVxRzFHr1Feqei/KdPeY1OCA9/N2bj+8qa7dFVX6IO+ 9RzvVt4oUgQFwWY6nrGgyc7tbI1lwoSmgq/mrKK+Z4SswfwotF9VhZo3KDMMFspJFve2 Cm3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=zurrbWODzCL1ddkbl6NdnzpZxtPzyETq04wfptwh7DM=; b=7DQjwUaIy93+FjOaeLkW2YjTlwV51TU6E05uyBucBHs6BgLh29FC8E3tYmZbDitHX3 pWthoakVr+ENZESVO8Y5yw3FBWFUWlFEJQEYH3/B0piEY7Tij1P81f3mdCdccKavFx3+ 4CVh7j/hJUGszJmeTF2rJHRlb4yHkNnvhfl9Sro74NzsebH/NJ7gyXlyk4eQ5p0pOi1v P9rWF7g9xqsTjUzHrE+mFQMEndBM3Desw8BKSTORjK31aayODBh6Sik/sAgMOKZ5rvYc YJ3LA9lkHIgYm3GNxOAHDjvmzVhAGKPSR8dlC9WTC/ZuCiwhohFerHaD5yrE3YEFjuEQ 0NYA== X-Gm-Message-State: AJIora/f9fY8zabSGKqucIhM/jD1UzThu4r04tOMtI9mxDGzy/6CRujJ mDSeqVhoHfPfiwvl/a5mxIs= X-Received: by 2002:a05:6402:e87:b0:435:5dda:9428 with SMTP id h7-20020a0564020e8700b004355dda9428mr9285608eda.6.1655544476984; Sat, 18 Jun 2022 02:27:56 -0700 (PDT) Received: from localhost.localdomain (host-87-6-98-182.retail.telecomitalia.it. [87.6.98.182]) by smtp.gmail.com with ESMTPSA id s18-20020a170906169200b00705976bcd01sm3132209ejd.206.2022.06.18.02.27.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Jun 2022 02:27:55 -0700 (PDT) From: "Fabio M. De Francesco" To: Chris Mason , Josef Bacik , David Sterba , Nick Terrell , Chris Down , Filipe Manana , Qu Wenruo , Nikolay Borisov , Gabriel Niebler , linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org Cc: "Fabio M. De Francesco" , Ira Weiny Subject: [PATCH] btrfs: Convert zlib_compress_pages() to use kmap_local_page() Date: Sat, 18 Jun 2022 11:27:52 +0200 Message-Id: <20220618092752.25153-1-fmdefrancesco@gmail.com> X-Mailer: git-send-email 2.36.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,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 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. Tested with xfstests on QEMU + KVM 32-bit VM with 4GB of RAM and HIGHMEM64G enabled. This patch passes 26/26 tests of group "compress". Cc: Qu Wenruo Suggested-by: Ira Weiny Signed-off-by: Fabio M. De Francesco --- This patch builds only on top of "[PATCH] btrfs: zlib: refactor how we prepare the input buffer" by Qu Wenruo". https://lore.kernel.org/linux-btrfs/d0bfc791b5509df7b9ad44e41ada197d1b3149b3.1655519730.git.wqu@suse.com/ fs/btrfs/zlib.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/fs/btrfs/zlib.c b/fs/btrfs/zlib.c index 966e17cea981..4496dd30bd71 100644 --- a/fs/btrfs/zlib.c +++ b/fs/btrfs/zlib.c @@ -160,7 +160,7 @@ int zlib_compress_pages(struct list_head *ws, struct address_space *mapping, ret = -ENOMEM; goto out; } - cpage_out = kmap(out_page); + cpage_out = kmap_local_page(out_page); pages[0] = out_page; nr_pages = 1; @@ -198,9 +198,9 @@ 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); + kunmap_local(cpage_out); if (nr_pages == nr_dest_pages) { - out_page = NULL; + cpage_out = NULL; ret = -E2BIG; goto out; } @@ -209,7 +209,7 @@ int zlib_compress_pages(struct list_head *ws, struct address_space *mapping, ret = -ENOMEM; goto out; } - cpage_out = kmap(out_page); + cpage_out = kmap_local_page(out_page); pages[nr_pages] = out_page; nr_pages++; workspace->strm.avail_out = PAGE_SIZE; @@ -236,9 +236,9 @@ 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); + kunmap_local(cpage_out); if (nr_pages == nr_dest_pages) { - out_page = NULL; + cpage_out = NULL; ret = -E2BIG; goto out; } @@ -247,7 +247,7 @@ int zlib_compress_pages(struct list_head *ws, struct address_space *mapping, ret = -ENOMEM; goto out; } - cpage_out = kmap(out_page); + cpage_out = kmap_local_page(out_page); pages[nr_pages] = out_page; nr_pages++; workspace->strm.avail_out = PAGE_SIZE; @@ -266,8 +266,8 @@ 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 (cpage_out) + kunmap_local(cpage_out); return ret; } -- 2.36.1