Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp393892iog; Fri, 17 Jun 2022 05:42:39 -0700 (PDT) X-Google-Smtp-Source: AGRyM1u4UvL1EzyacQ6iS7i5CfoXmnKMsUgYL1WSEmyQbPJanJFDrmLDHfznGcLcpeFRwyXqc5nx X-Received: by 2002:a17:903:1105:b0:168:9cac:a0a5 with SMTP id n5-20020a170903110500b001689caca0a5mr9678331plh.59.1655469759656; Fri, 17 Jun 2022 05:42:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655469759; cv=none; d=google.com; s=arc-20160816; b=NO9FUC4XXfJnVvdNqFyZ4UI4BXtL7HjU+4hj/Oh4o3UpajZvq30fTgKdHeVlAVhxE0 Bht6JP1fjftPhVzV5NqHYnqgdTVSDC6DYazhhoSEleLPGrLzJPqnVycd7AjHOiX/FUZm 7o4XgyeqvEkQAXGfCgwGky/2RQZrzM1XTGi//FwzsaLk2ZjZ/wuTgVxwqNxfiiXExAaq t3e0AH3B/ESqRJLefIzhC9AasUZquaqu9CIeFPA1CJeHDtDc9tpB8iYdxdLubTOAVynC Ab0c82QuxDQt0SryHR/GlLpPYxcEcueaimWsXafUt5pCLup/lv40OEwC0dYiQRoWRVXi EcvQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=N+ZalsdEns5XWVe5XTgPvObVhbj/edy5N7yIyAU1hcY=; b=Y7Ph9A8kgBx/c7h7mOlbS1nBlI5WNk8qAN9TeOqBmzgrVUIiHLHqnJpi7UqeQY9F9P D1qJQj1oWrWJ87Lfym904FLleMTZxwiYtSykXkKF6ReO98xDTM1caWP20Pcl/5Nfxb0U HruyTpq75MhtyUv7O1FUXgTDhiaiUurPMaCh53N0Teq5C7ecLMzY2QdP+Q5SE0jm69Sb nUvxO83nys9ZiLdZmfx3Ljc0DNLeUYrvHFGuzcHtz5nxyojAnTl4SOtHemFDLY69hPss DoB11HHHagvsoDei/S4dQFJdOo/vGNJRBkmqQd6tGKXNWtaruBvuE+uEI9t1byLPIeQr kZog== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=bLCSOMhH; 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 e10-20020a170903240a00b0015682b8c0b3si5845829plo.469.2022.06.17.05.42.25; Fri, 17 Jun 2022 05:42:39 -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=bLCSOMhH; 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 S1382308AbiFQMF6 (ORCPT + 99 others); Fri, 17 Jun 2022 08:05:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60280 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1382176AbiFQMFx (ORCPT ); Fri, 17 Jun 2022 08:05:53 -0400 Received: from mail-ej1-x635.google.com (mail-ej1-x635.google.com [IPv6:2a00:1450:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 547BE6B7CD; Fri, 17 Jun 2022 05:05:52 -0700 (PDT) Received: by mail-ej1-x635.google.com with SMTP id h23so8334467ejj.12; Fri, 17 Jun 2022 05:05:52 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=N+ZalsdEns5XWVe5XTgPvObVhbj/edy5N7yIyAU1hcY=; b=bLCSOMhHE1gx3vXnzBZSlvOsYN71L/kr9xcKjvvZbEFkrBBSd/Q8N40o4xjX4xcMde TpyqV4SCShJzDQYncz7IB3ZNx4eBEk6AaWJHY/Rodk62kGUW9dADY0Em0mtqbOUa013p 2scD0xPxS4puge1MPrD5KCb4u+NPDJAA7ovEFTy2AhXfh9jOL040OfjZ6q5jTo9odDoA CzOnndAwZZwN6rKv6dvg8ogOV9vpHXmXfEbag2hn8WlhcXnXANE0D2VQnwmrOMHFP9RM eWJM53aFamxiZo0FZL+9CX/WhUcEPHLqLKLT9NPtEVW+9Zqyc4zGbGDmwkc4p2mFVkBI vOOA== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=N+ZalsdEns5XWVe5XTgPvObVhbj/edy5N7yIyAU1hcY=; b=lFcSBNzQOBIdkk3PrmsG75CEjiPI2u1v6veRir85fDEgAy54sVkP3mu97Y3kjHxOFV jmqb3TMSk5gRs8oEDChg3ekkM4GcF4CT1SMLikTSFpD5UyzhCyUj6IlHVWnpsr/RkEUi P7jW1Ey6oCKwfO3a2FL7xoGD3mJIkr4+Yj22MvaVFSQSu1d/gurprtSdV0yi077mTYHa CeZ2UrK8z1GyP9+rq5L6Vke/fyYmcgMpyMmt9njnL8Dx3sVs8fWnTEDVV9ugD0uPeHH5 8DEZK2KUWJb1UHEhLJGZlAC6Or6FrPMaXOpfX5MWr9bH3IhtiilEFzkPFZiXxaKWvR6r Zmiw== X-Gm-Message-State: AJIora/l4IaRJXocs+BqgcGdBR8V9oYkHG9lFuLMHQ2oK9l5jZVJ/dFU TRXp+Es4x2R12cMGH6/4siU= X-Received: by 2002:a17:906:77da:b0:712:2241:2c3e with SMTP id m26-20020a17090677da00b0071222412c3emr8818742ejn.405.1655467550889; Fri, 17 Jun 2022 05:05:50 -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 kw2-20020a170907770200b007121361d54asm2135179ejc.25.2022.06.17.05.05.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Jun 2022 05:05:49 -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 , Ira Weiny , linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org Cc: "Fabio M. De Francesco" Subject: [RFC PATCH v2 2/3] btrfs: Use kmap_local_page() on "out_page" in zlib_compress_pages() Date: Fri, 17 Jun 2022 14:05:37 +0200 Message-Id: <20220617120538.18091-3-fmdefrancesco@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220617120538.18091-1-fmdefrancesco@gmail.com> References: <20220617120538.18091-1-fmdefrancesco@gmail.com> 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() for "out_page" 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 bits VM with 4GB of RAM and HIGHMEM64G enabled. This patch passes 26/26 tests of group "compress". Suggested-by: Ira Weiny Signed-off-by: Fabio M. De Francesco --- fs/btrfs/zlib.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/fs/btrfs/zlib.c b/fs/btrfs/zlib.c index 770c4c6bbaef..c7c69ce4a1a9 100644 --- a/fs/btrfs/zlib.c +++ b/fs/btrfs/zlib.c @@ -97,8 +97,8 @@ 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 *cpage_out; + char *data_in = NULL; + char *cpage_out = NULL; int nr_pages = 0; struct page *in_page = NULL; struct page *out_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 = kmap_local_page(out_page); pages[0] = out_page; nr_pages = 1; @@ -196,7 +196,8 @@ 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); + cpage_out = NULL; if (nr_pages == nr_dest_pages) { out_page = NULL; ret = -E2BIG; @@ -207,7 +208,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; @@ -234,7 +235,8 @@ 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); + cpage_out = NULL; if (nr_pages == nr_dest_pages) { out_page = NULL; ret = -E2BIG; @@ -245,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; @@ -264,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); if (in_page) { kunmap(in_page); -- 2.36.1