From nobody Mon Apr 27 03:24:00 2026 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 B5F40CCA479 for ; Fri, 17 Jun 2022 12:05:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1382255AbiFQMF5 (ORCPT ); Fri, 17 Jun 2022 08:05:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60256 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379829AbiFQMFv (ORCPT ); Fri, 17 Jun 2022 08:05:51 -0400 Received: from mail-ej1-x636.google.com (mail-ej1-x636.google.com [IPv6:2a00:1450:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 546F16B7CD; Fri, 17 Jun 2022 05:05:50 -0700 (PDT) Received: by mail-ej1-x636.google.com with SMTP id kq6so8333448ejb.11; Fri, 17 Jun 2022 05:05:50 -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=KnN24k9bVkHEuK5wqwj88tJd2kUsuq85Wnf8cEQ0fjA=; b=k3jYGlLxfV7mO9FY1IxOxNtTFHO5QdM7tcjuPJjU8Y7FrlN6yDdBAngPXpORjDAfpw 6jinETykgTOxqSLSF/bVFLQe3xnb7szXyPl0M1F1qKHXIvmQptuUt8ZaG10vtVa4aOJU +kMcFD7ATDd5R2uFnopGJomK8j8f0+fY+ngWo0gbTKqnHmB9+cST0yyunwfThxs+0RFD a+Aj65wCHFw3T4hZdHCSldfzJhnbZ8g/5F+f1IVHfwMsiWH9gjo+6gxnDl5/rTBPTbnv yevwX2iskpjdHBE/9hiYFw4TrTL+mJCTKCCYzXBa5BkOtV6eU3ksmYCBrYkdbbZpRLd1 MmWA== 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=KnN24k9bVkHEuK5wqwj88tJd2kUsuq85Wnf8cEQ0fjA=; b=zJwCaqSoDYhxUvfEByf1Y313b6EXvsNimXldC3pQNKqmgz4xUKXYtuV0FA7HvXV2Eh jViR6fsQTJNtJx2QG2IggNQSigoXadBJTHveRAgndy2VWU9kUzNWbMdAUZxhL4oOE6kv VN2U0mkTmXnw2CraK3HntufdZJGro6GGgZ/jy5RfVXvnN5BEyaohMz/XvGFq98fOJkC+ gDxKAsM22dq3BlBbfFBXeIHS79nef2RIhH/JJcmk/C6mGPPvWkWOQm2r1GJI/jyjOOBO 0xH3qPiloQSwEkCTcDYwAUYz2vDU86lDz8Ce8K53sx/ThHEnjqOh2sB3cmoPT7w7/gk4 tKPQ== X-Gm-Message-State: AJIora/eI4TSGUSCxQDsdK3uCd0QnTLQkIrAZki5wC74RXgznBLS6REi WnapV+02QnZDzfzByNA+l6MMiSYCP5g= X-Google-Smtp-Source: AGRyM1tjlOy6g3acRJ2FTwt2II0C6scynPXeVvNaWAwNwMDX2pN4Xc0MrXf0U08jY/dwDDT6B9VASQ== X-Received: by 2002:a17:907:8195:b0:710:b40:95d2 with SMTP id iy21-20020a170907819500b007100b4095d2mr9017211ejc.604.1655467548861; Fri, 17 Jun 2022 05:05:48 -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.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Jun 2022 05:05:47 -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 1/3] btrfs: Convert zlib_decompress_bio() to use kmap_local_page() Date: Fri, 17 Jun 2022 14:05:36 +0200 Message-Id: <20220617120538.18091-2-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: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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_decompress_bio() 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 Reviewed-by: Qu Wenruo --- fs/btrfs/zlib.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/fs/btrfs/zlib.c b/fs/btrfs/zlib.c index 767a0c6c9694..770c4c6bbaef 100644 --- a/fs/btrfs/zlib.c +++ b/fs/btrfs/zlib.c @@ -287,7 +287,7 @@ int zlib_decompress_bio(struct list_head *ws, struct co= mpressed_bio *cb) unsigned long buf_start; struct page **pages_in =3D cb->compressed_pages; =20 - data_in =3D kmap(pages_in[page_in_index]); + data_in =3D kmap_local_page(pages_in[page_in_index]); workspace->strm.next_in =3D data_in; workspace->strm.avail_in =3D min_t(size_t, srclen, PAGE_SIZE); workspace->strm.total_in =3D 0; @@ -309,7 +309,7 @@ int zlib_decompress_bio(struct list_head *ws, struct co= mpressed_bio *cb) =20 if (Z_OK !=3D zlib_inflateInit2(&workspace->strm, wbits)) { pr_warn("BTRFS: inflateInit failed\n"); - kunmap(pages_in[page_in_index]); + kunmap_local(data_in); return -EIO; } while (workspace->strm.total_in < srclen) { @@ -336,13 +336,13 @@ int zlib_decompress_bio(struct list_head *ws, struct = compressed_bio *cb) =20 if (workspace->strm.avail_in =3D=3D 0) { unsigned long tmp; - kunmap(pages_in[page_in_index]); + kunmap_local(data_in); page_in_index++; if (page_in_index >=3D total_pages_in) { data_in =3D NULL; break; } - data_in =3D kmap(pages_in[page_in_index]); + data_in =3D kmap_local_page(pages_in[page_in_index]); workspace->strm.next_in =3D data_in; tmp =3D srclen - workspace->strm.total_in; workspace->strm.avail_in =3D min(tmp, PAGE_SIZE); @@ -355,7 +355,7 @@ int zlib_decompress_bio(struct list_head *ws, struct co= mpressed_bio *cb) done: zlib_inflateEnd(&workspace->strm); if (data_in) - kunmap(pages_in[page_in_index]); + kunmap_local(data_in); if (!ret) zero_fill_bio(cb->orig_bio); return ret; --=20 2.36.1 From nobody Mon Apr 27 03:24:00 2026 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 55244C433EF for ; Fri, 17 Jun 2022 12:06:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1382315AbiFQMGA (ORCPT ); Fri, 17 Jun 2022 08:06:00 -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-Google-Smtp-Source: AGRyM1u5DNIC4xaqXuwV9mvbfEKMka1G18Jwrkh/vP/CiojfW3FcYmmNVcehUpM14Qv/nsm54Uhuxw== 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: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Qu Wenruo --- 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 addr= ess_space *mapping, { struct workspace *workspace =3D list_entry(ws, struct workspace, list); int ret; - char *data_in; - char *cpage_out; + char *data_in =3D NULL; + char *cpage_out =3D NULL; int nr_pages =3D 0; struct page *in_page =3D NULL; struct page *out_page =3D NULL; @@ -126,7 +126,7 @@ int zlib_compress_pages(struct list_head *ws, struct ad= dress_space *mapping, ret =3D -ENOMEM; goto out; } - cpage_out =3D kmap(out_page); + cpage_out =3D kmap_local_page(out_page); pages[0] =3D out_page; nr_pages =3D 1; =20 @@ -196,7 +196,8 @@ int zlib_compress_pages(struct list_head *ws, struct ad= dress_space *mapping, * the stream end if required */ if (workspace->strm.avail_out =3D=3D 0) { - kunmap(out_page); + kunmap_local(cpage_out); + cpage_out =3D NULL; if (nr_pages =3D=3D nr_dest_pages) { out_page =3D NULL; ret =3D -E2BIG; @@ -207,7 +208,7 @@ int zlib_compress_pages(struct list_head *ws, struct ad= dress_space *mapping, ret =3D -ENOMEM; goto out; } - cpage_out =3D kmap(out_page); + cpage_out =3D kmap_local_page(out_page); pages[nr_pages] =3D out_page; nr_pages++; workspace->strm.avail_out =3D PAGE_SIZE; @@ -234,7 +235,8 @@ int zlib_compress_pages(struct list_head *ws, struct ad= dress_space *mapping, goto out; } else if (workspace->strm.avail_out =3D=3D 0) { /* get another page for the stream end */ - kunmap(out_page); + kunmap_local(cpage_out); + cpage_out =3D NULL; if (nr_pages =3D=3D nr_dest_pages) { out_page =3D NULL; ret =3D -E2BIG; @@ -245,7 +247,7 @@ int zlib_compress_pages(struct list_head *ws, struct ad= dress_space *mapping, ret =3D -ENOMEM; goto out; } - cpage_out =3D kmap(out_page); + cpage_out =3D kmap_local_page(out_page); pages[nr_pages] =3D out_page; nr_pages++; workspace->strm.avail_out =3D PAGE_SIZE; @@ -264,8 +266,8 @@ int zlib_compress_pages(struct list_head *ws, struct ad= dress_space *mapping, *total_in =3D workspace->strm.total_in; out: *out_pages =3D nr_pages; - if (out_page) - kunmap(out_page); + if (cpage_out) + kunmap_local(cpage_out); =20 if (in_page) { kunmap(in_page); --=20 2.36.1 From nobody Mon Apr 27 03:24:00 2026 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 EA199C433EF for ; Fri, 17 Jun 2022 12:06:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1382336AbiFQMGD (ORCPT ); Fri, 17 Jun 2022 08:06:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60296 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1382214AbiFQMFz (ORCPT ); Fri, 17 Jun 2022 08:05:55 -0400 Received: from mail-ej1-x631.google.com (mail-ej1-x631.google.com [IPv6:2a00:1450:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 678766B7CD; Fri, 17 Jun 2022 05:05:54 -0700 (PDT) Received: by mail-ej1-x631.google.com with SMTP id me5so8390094ejb.2; Fri, 17 Jun 2022 05:05:54 -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=An4VqlbV85lFxIwTKixxFZWGiBTSsqtaMQNOxgii35g=; b=E8NhQjtf3V5xxVM/puZlkNVsq/WnHH46QoEAkyGYxPh9eRM+RpvMQgusQIS+tzBteG bQ+c3M0+UV0TAL/at3SeV5qcaezmv8wGdazzZ7cfd0G4ds+JZXhKMn3ay74Y1wcwZwyZ yruQrJAlgez1XgAbH9lCGzI9RkAG6xxKfBe4SPqRmllUbuAksKzw0JFzHmkGfVKkLhSB o2RXGs6Wd/+3ye+WVxQBhGtchWVzztMipZBQ8FE89s+tKzjW6s2dEJuOCloO71ce9wBp wbQqvzwNulaM5oiyV/yqzMoSoEzhtKx84UxfxVIqdxAyhltPydf9xDfUBJcQS5qeFFPe mx1w== 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=An4VqlbV85lFxIwTKixxFZWGiBTSsqtaMQNOxgii35g=; b=KvV3SR6g5OdzT3DNLJN+Rjik9deL+eT0KixpFjGFknctQMAgfS2A08sXwWctxA3BA5 wI6tHGs+Jnsot05eCWutO0iQteFryMQ9QKe/tHxtSoS9cRZAMyFG9ECkXUXpaSjiFY0P u2Zzf3RH6McI/jMZyX8YeURu4iUvalG+IlKvXIXtni6bJj8lpJukd5vPoRTkHqhq3Kof sv4Kyrt7vnDEwZlZ5fY7dEq0tCVjmaluIc4xlg7T5Wzhu6mYKxz9Dnw7WmG3wXhuzxjz Vm20ume+pWChDh/m2cx67tfUx1zzk/8TYK0b9FTkA6FqSRhgWV/zB8fYJkbdexBsl4o6 yfPg== X-Gm-Message-State: AJIora/1VHfxur/2VRhw74+DppHuzFnBu6dCMw3he6NDQ+uw79j0ddJB 74nl3h328448iF05kMW6b9LU+DAxQHk= X-Google-Smtp-Source: AGRyM1upGBjBu4f3AX1HjebEDy6OWQ9rPP1SDaYiCLaIq14AZU3ea98jPecg0S5wHVUeuxoQFeG8Rw== X-Received: by 2002:a17:907:7245:b0:711:d1ff:2ca4 with SMTP id ds5-20020a170907724500b00711d1ff2ca4mr9092563ejc.753.1655467552905; Fri, 17 Jun 2022 05:05:52 -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.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Jun 2022 05:05:51 -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 3/3] btrfs: Use kmap_local_page() on "in_page" in zlib_compress_pages() Date: Fri, 17 Jun 2022 14:05:38 +0200 Message-Id: <20220617120538.18091-4-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: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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() on "in_page" in zlib_compress_pages() because in this function the mappings are per thread and are not visible in other contexts. Use an array based stack in order to take note of the order of mappings and un-mappings to comply to the rules of nesting local mappings. 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 | 65 ++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 53 insertions(+), 12 deletions(-) diff --git a/fs/btrfs/zlib.c b/fs/btrfs/zlib.c index c7c69ce4a1a9..1f16014e8ff3 100644 --- a/fs/btrfs/zlib.c +++ b/fs/btrfs/zlib.c @@ -99,6 +99,8 @@ int zlib_compress_pages(struct list_head *ws, struct addr= ess_space *mapping, int ret; char *data_in =3D NULL; char *cpage_out =3D NULL; + char mstack[2]; + int sind =3D 0; int nr_pages =3D 0; struct page *in_page =3D NULL; struct page *out_page =3D NULL; @@ -126,6 +128,8 @@ int zlib_compress_pages(struct list_head *ws, struct ad= dress_space *mapping, ret =3D -ENOMEM; goto out; } + mstack[sind] =3D 'A'; + sind++; cpage_out =3D kmap_local_page(out_page); pages[0] =3D out_page; nr_pages =3D 1; @@ -148,26 +152,32 @@ int zlib_compress_pages(struct list_head *ws, struct = address_space *mapping, int i; =20 for (i =3D 0; i < in_buf_pages; i++) { - if (in_page) { - kunmap(in_page); + if (data_in) { + sind--; + kunmap_local(data_in); put_page(in_page); } in_page =3D find_get_page(mapping, start >> PAGE_SHIFT); - data_in =3D kmap(in_page); + mstack[sind] =3D 'B'; + sind++; + data_in =3D kmap_local_page(in_page); memcpy(workspace->buf + i * PAGE_SIZE, data_in, PAGE_SIZE); start +=3D PAGE_SIZE; } workspace->strm.next_in =3D workspace->buf; } else { - if (in_page) { - kunmap(in_page); + if (data_in) { + sind--; + kunmap_local(data_in); put_page(in_page); } in_page =3D find_get_page(mapping, start >> PAGE_SHIFT); - data_in =3D kmap(in_page); + mstack[sind] =3D 'B'; + sind++; + data_in =3D kmap_local_page(in_page); start +=3D PAGE_SIZE; workspace->strm.next_in =3D data_in; } @@ -196,23 +206,39 @@ int zlib_compress_pages(struct list_head *ws, struct = address_space *mapping, * the stream end if required */ if (workspace->strm.avail_out =3D=3D 0) { + sind--; + kunmap_local(data_in); + data_in =3D NULL; + + sind--; kunmap_local(cpage_out); cpage_out =3D NULL; + if (nr_pages =3D=3D nr_dest_pages) { out_page =3D NULL; + put_page(in_page); ret =3D -E2BIG; goto out; } + out_page =3D alloc_page(GFP_NOFS); if (out_page =3D=3D NULL) { + put_page(in_page); ret =3D -ENOMEM; goto out; } + + mstack[sind] =3D 'A'; + sind++; cpage_out =3D kmap_local_page(out_page); pages[nr_pages] =3D out_page; nr_pages++; workspace->strm.avail_out =3D PAGE_SIZE; workspace->strm.next_out =3D cpage_out; + + mstack[sind] =3D 'B'; + sind++; + data_in =3D kmap_local_page(in_page); } /* we're all done */ if (workspace->strm.total_in >=3D len) @@ -235,10 +261,16 @@ int zlib_compress_pages(struct list_head *ws, struct = address_space *mapping, goto out; } else if (workspace->strm.avail_out =3D=3D 0) { /* get another page for the stream end */ + sind--; + kunmap_local(data_in); + data_in =3D NULL; + + sind--; kunmap_local(cpage_out); cpage_out =3D NULL; if (nr_pages =3D=3D nr_dest_pages) { out_page =3D NULL; + put_page(in_page); ret =3D -E2BIG; goto out; } @@ -247,11 +279,18 @@ int zlib_compress_pages(struct list_head *ws, struct = address_space *mapping, ret =3D -ENOMEM; goto out; } + + mstack[sind] =3D 'A'; + sind++; cpage_out =3D kmap_local_page(out_page); pages[nr_pages] =3D out_page; nr_pages++; workspace->strm.avail_out =3D PAGE_SIZE; workspace->strm.next_out =3D cpage_out; + + mstack[sind] =3D 'B'; + sind++; + data_in =3D kmap_local_page(in_page); } } zlib_deflateEnd(&workspace->strm); @@ -266,13 +305,15 @@ int zlib_compress_pages(struct list_head *ws, struct = address_space *mapping, *total_in =3D workspace->strm.total_in; out: *out_pages =3D nr_pages; - if (cpage_out) - kunmap_local(cpage_out); - - if (in_page) { - kunmap(in_page); - put_page(in_page); + while (--sind >=3D 0) { + if (mstack[sind] =3D=3D 'B') { + kunmap_local(data_in); + put_page(in_page); + } else { + kunmap_local(cpage_out); + } } + return ret; } =20 --=20 2.36.1