From patchwork Mon Jul 4 15:23:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Fabio M. De Francesco" X-Patchwork-Id: 12905497 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9231BC433EF for ; Mon, 4 Jul 2022 15:23:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2A0396B0074; Mon, 4 Jul 2022 11:23:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 229266B0075; Mon, 4 Jul 2022 11:23:43 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0CA976B0078; Mon, 4 Jul 2022 11:23:43 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id F1B0B6B0074 for ; Mon, 4 Jul 2022 11:23:42 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id C2934488 for ; Mon, 4 Jul 2022 15:23:42 +0000 (UTC) X-FDA: 79649787084.15.7E864F4 Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.45]) by imf25.hostedemail.com (Postfix) with ESMTP id 76F9FA0018 for ; Mon, 4 Jul 2022 15:23:42 +0000 (UTC) Received: by mail-wm1-f45.google.com with SMTP id n185so5586511wmn.4 for ; Mon, 04 Jul 2022 08:23:42 -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=dqpZiR9EMoPoF97PAZqOh66fKxh4BpbCt/ICCQKrvF0=; b=HaytmN0zSS6r8LmkJZq70cytlyB5alsG72DRInTei3zZ6TR+IrKiZejsQ0NfuNfPcp PlTz8p5Q0AOlCQyK6OB+gCgXKJDF+Er6hCjuXVjgUV0iotSWmEDXiXfOTOJwXBgFHkIq mK7jEb7t03mgIFWp/Bbf+KFEntQ5Ll+0aT7rpPoALj5RyQ+rK2EZkm+3G91g36FUTlXR 1dxuu9Jq66ppJZwBErOLyD2n1ffggu95zZKVO43wLDL+PjceV8MN0gUbcEULEyUyNzMf 6Lvg9dt+YPOmD1/tzzT8HOpiTcYBFkx3IZGV/Ti3ECCqwaTFdalZbm8+8/YS3aMnsrFA SYiA== 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=dqpZiR9EMoPoF97PAZqOh66fKxh4BpbCt/ICCQKrvF0=; b=MdhG2sGEkRenxQ2jK6+K0oWnsWTAnnhxF6fwRqff/exsrG1izJJhyAA4HrNQOuXoH8 MGdi8OaaDbt/Awt0fhxjFxeqOrfW19jPY3V/7uL8fftwIQR2kw/WTLFbBp4ZtQVpkStQ ABo3B8CVDgYNlLr5IjEYK7oEOjSEvN2XC4McDjUEZrr5ckimqNE+ZHPhL4Vd/L9qG+Hu a0jJOjxi3gCe7OhKxMSnse5Xtkse/z2qEO+aiAJqrTUJLIDLdjCHpPD7sRcQYXR5DFko y00SOzTh4oG35V6Qxt4vEYlr8g+YGYZhL18uW+Z01uWLtQPGClQFB+3J1SeUu4tT0Ser FqUA== X-Gm-Message-State: AJIora+ZmgjzFVX2OsGK0C1GLC+t9LazimSAwgfPmchuXno/A1QirL8t ER0jw5vYvoT9uXUdSnsRlNU= X-Google-Smtp-Source: AGRyM1tQdcBc1Lj07OU8V4Z3ztHPVSogHdkYicU5Wg9dwV7uUcryGx8jYb43vi129HnZd9yAqtFIZw== X-Received: by 2002:a05:600c:2051:b0:3a0:3c58:6ff6 with SMTP id p17-20020a05600c205100b003a03c586ff6mr32713888wmg.98.1656948221471; Mon, 04 Jul 2022 08:23:41 -0700 (PDT) Received: from localhost.localdomain (host-79-53-109-127.retail.telecomitalia.it. [79.53.109.127]) by smtp.gmail.com with ESMTPSA id p28-20020a1c545c000000b003a02de5de80sm16089631wmi.4.2022.07.04.08.23.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Jul 2022 08:23:39 -0700 (PDT) From: "Fabio M. De Francesco" To: David Sterba , Chris Mason , Josef Bacik , Nick Terrell , linux-btrfs@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Ira Weiny , Andrew Morton , Matthew Wilcox , Kees Cook , Sebastian Andrzej Siewior , "James E. J. Bottomley" , Helge Deller , John David Anglin , linux-parisc@vger.kernel.org Cc: "Fabio M. De Francesco" , Filipe Manana Subject: [PATCH v5 2/2] btrfs: Replace kmap() with kmap_local_page() in zstd.c Date: Mon, 4 Jul 2022 17:23:22 +0200 Message-Id: <20220704152322.20955-3-fmdefrancesco@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220704152322.20955-1-fmdefrancesco@gmail.com> References: <20220704152322.20955-1-fmdefrancesco@gmail.com> MIME-Version: 1.0 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1656948222; a=rsa-sha256; cv=none; b=IMgbOvOKmgAYzpnWV84E3OGUXF8ckWm1OLMq9njYr/J+z1+ZFYBaQFPPfrfpSDYqXKmkH9 kfospZW6aeiVMohCqRONDxSrJ+x2jM+qarVaNqMAk0wGcyLztKkwIGdfiE9dMyaBZzUSVg CIYr1F6qQNGgIae8oVDmHk2S6BCDDUI= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=HaytmN0z; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf25.hostedemail.com: domain of fmdefrancesco@gmail.com designates 209.85.128.45 as permitted sender) smtp.mailfrom=fmdefrancesco@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1656948222; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=dqpZiR9EMoPoF97PAZqOh66fKxh4BpbCt/ICCQKrvF0=; b=SlD4q7FCMvsy928TOL4j7MjRqR8RzBdM74B5iLYUoZ4vhQEehyMaxUbSgpxjuiiZa0llLm YQVgAP1+bzcGlfy4WKIRnraTeLkiY1DBfch484whnJmiSr8+BLp5gCuu1V/DW9FYpvSy9o 2UPpA1nuliuWkRIrLUrKr0eWSMz3bz8= X-Rspam-User: X-Rspamd-Server: rspam07 Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=HaytmN0z; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf25.hostedemail.com: domain of fmdefrancesco@gmail.com designates 209.85.128.45 as permitted sender) smtp.mailfrom=fmdefrancesco@gmail.com X-Stat-Signature: dyaxmwtk66a86crbtc677r5bxxwz6prc X-Rspamd-Queue-Id: 76F9FA0018 X-HE-Tag: 1656948222-543821 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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 zstd.c because in this file the mappings are per thread and are not visible in other contexts. In the meanwhile use plain page_address() on pages allocated with the GFP_NOFS flag instead of calling kmap*() on them (since they are always allocated from ZONE_NORMAL). Tested with xfstests on QEMU + KVM 32 bits VM with 4GB of RAM and booting a kernel with HIGHMEM64G enabled. Cc: Filipe Manana Suggested-by: Ira Weiny Signed-off-by: Fabio M. De Francesco --- fs/btrfs/zstd.c | 34 ++++++++++++++-------------------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/fs/btrfs/zstd.c b/fs/btrfs/zstd.c index 0fe31a6f6e68..78e0272e770e 100644 --- a/fs/btrfs/zstd.c +++ b/fs/btrfs/zstd.c @@ -403,7 +403,7 @@ int zstd_compress_pages(struct list_head *ws, struct address_space *mapping, /* map in the first page of input data */ in_page = find_get_page(mapping, start >> PAGE_SHIFT); - workspace->in_buf.src = kmap(in_page); + workspace->in_buf.src = kmap_local_page(in_page); workspace->in_buf.pos = 0; workspace->in_buf.size = min_t(size_t, len, PAGE_SIZE); @@ -415,7 +415,7 @@ int zstd_compress_pages(struct list_head *ws, struct address_space *mapping, goto out; } pages[nr_pages++] = out_page; - workspace->out_buf.dst = kmap(out_page); + workspace->out_buf.dst = page_address(out_page); workspace->out_buf.pos = 0; workspace->out_buf.size = min_t(size_t, max_out, PAGE_SIZE); @@ -450,9 +450,7 @@ int zstd_compress_pages(struct list_head *ws, struct address_space *mapping, if (workspace->out_buf.pos == workspace->out_buf.size) { tot_out += PAGE_SIZE; max_out -= PAGE_SIZE; - kunmap(out_page); if (nr_pages == nr_dest_pages) { - out_page = NULL; ret = -E2BIG; goto out; } @@ -462,7 +460,7 @@ int zstd_compress_pages(struct list_head *ws, struct address_space *mapping, goto out; } pages[nr_pages++] = out_page; - workspace->out_buf.dst = kmap(out_page); + workspace->out_buf.dst = page_address(out_page); workspace->out_buf.pos = 0; workspace->out_buf.size = min_t(size_t, max_out, PAGE_SIZE); @@ -477,15 +475,15 @@ int zstd_compress_pages(struct list_head *ws, struct address_space *mapping, /* Check if we need more input */ if (workspace->in_buf.pos == workspace->in_buf.size) { tot_in += PAGE_SIZE; - kunmap(in_page); + kunmap_local(workspace->in_buf.src); put_page(in_page); - start += PAGE_SIZE; len -= PAGE_SIZE; in_page = find_get_page(mapping, start >> PAGE_SHIFT); - workspace->in_buf.src = kmap(in_page); + workspace->in_buf.src = kmap_local_page(in_page); workspace->in_buf.pos = 0; workspace->in_buf.size = min_t(size_t, len, PAGE_SIZE); + workspace->out_buf.dst = page_address(out_page); } } while (1) { @@ -510,9 +508,7 @@ int zstd_compress_pages(struct list_head *ws, struct address_space *mapping, tot_out += PAGE_SIZE; max_out -= PAGE_SIZE; - kunmap(out_page); if (nr_pages == nr_dest_pages) { - out_page = NULL; ret = -E2BIG; goto out; } @@ -522,7 +518,7 @@ int zstd_compress_pages(struct list_head *ws, struct address_space *mapping, goto out; } pages[nr_pages++] = out_page; - workspace->out_buf.dst = kmap(out_page); + workspace->out_buf.dst = page_address(out_page); workspace->out_buf.pos = 0; workspace->out_buf.size = min_t(size_t, max_out, PAGE_SIZE); } @@ -537,13 +533,10 @@ int zstd_compress_pages(struct list_head *ws, struct address_space *mapping, *total_out = tot_out; out: *out_pages = nr_pages; - /* Cleanup */ - if (in_page) { - kunmap(in_page); + if (workspace->in_buf.src) { + kunmap_local(workspace->in_buf.src); put_page(in_page); } - if (out_page) - kunmap(out_page); return ret; } @@ -567,7 +560,7 @@ int zstd_decompress_bio(struct list_head *ws, struct compressed_bio *cb) goto done; } - workspace->in_buf.src = kmap(pages_in[page_in_index]); + workspace->in_buf.src = kmap_local_page(pages_in[page_in_index]); workspace->in_buf.pos = 0; workspace->in_buf.size = min_t(size_t, srclen, PAGE_SIZE); @@ -603,14 +596,15 @@ int zstd_decompress_bio(struct list_head *ws, struct compressed_bio *cb) break; if (workspace->in_buf.pos == workspace->in_buf.size) { - kunmap(pages_in[page_in_index++]); + kunmap_local(workspace->in_buf.src); + page_in_index++; if (page_in_index >= total_pages_in) { workspace->in_buf.src = NULL; ret = -EIO; goto done; } srclen -= PAGE_SIZE; - workspace->in_buf.src = kmap(pages_in[page_in_index]); + workspace->in_buf.src = kmap_local_page(pages_in[page_in_index]); workspace->in_buf.pos = 0; workspace->in_buf.size = min_t(size_t, srclen, PAGE_SIZE); } @@ -619,7 +613,7 @@ int zstd_decompress_bio(struct list_head *ws, struct compressed_bio *cb) zero_fill_bio(cb->orig_bio); done: if (workspace->in_buf.src) - kunmap(pages_in[page_in_index]); + kunmap_local(workspace->in_buf.src); return ret; }