From patchwork Mon Aug 15 18:54:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vishal Moola X-Patchwork-Id: 12943968 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 75E01C25B08 for ; Mon, 15 Aug 2022 18:56:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 382DA8D0006; Mon, 15 Aug 2022 14:56:02 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 332738D0001; Mon, 15 Aug 2022 14:56:02 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1A9B98D0006; Mon, 15 Aug 2022 14:56:02 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 0D42C8D0001 for ; Mon, 15 Aug 2022 14:56:02 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id E0ACD1A0EFF for ; Mon, 15 Aug 2022 18:56:01 +0000 (UTC) X-FDA: 79802731722.17.085DF0C Received: from mail-pj1-f43.google.com (mail-pj1-f43.google.com [209.85.216.43]) by imf15.hostedemail.com (Postfix) with ESMTP id 75BA0A01C8 for ; Mon, 15 Aug 2022 18:56:01 +0000 (UTC) Received: by mail-pj1-f43.google.com with SMTP id q7-20020a17090a7a8700b001f300db8677so7529756pjf.5 for ; Mon, 15 Aug 2022 11:56:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=/3WdeuCJ7GOu9Di/kxGE5ZGCTP43O1pORgSps3IpIM0=; b=pzhH71/RORsENTBh74vzN5tqqZUKFr4QVYLeRWr9RocyL7OZKiodwsp21TGAG95MnP dsuAJ49JcqdqnfiQ/krxHAJW/NtnLndMog8nxsvyC2oA20RPu4/6P6mDM4v7uuHosvVH pT5ae4HmStn9CqdvdQtc2KGE6WbjIPCG3FCvuooEIPPs6GLaeOdlD3rRWGmVbQl6FVff Nzqo8PGtzrW7EDcHQrvUe2tpoWaUa6xYETFR7d9fAzFnv7Bbq3TYbrJwUFNVcLqbYKyj NC6RjlEpmZ5pJ/nLcPtKXXEhsDM9I9HkAYhAFnuJgZuL9w1mjMSt+T8E7NreD5qk8oS0 AZrQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=/3WdeuCJ7GOu9Di/kxGE5ZGCTP43O1pORgSps3IpIM0=; b=PkVPWGl/+7GlFq6vVif7ISzzlbkdIeFBS9MfnrL4WWJTGUu1k2OHkYTZA3r/teL/VH 0IR0EPUKWTjvcI9FHiGIR0mbOSVseUTW1XWDEzTEO2FlgZ0yUR8lFxZh5aKwC9M2/sQb DaB4wXnBLjV+V+OC0KBeAexn9djHL16SX0KQld7oOz4kggXfF/VJleefv1nOwq2gfvAE NthODbxaIWxvJoRNMtfpFp39W/UOV4smZ9Zr20U5XBAYsDF/dwv0e88xqx2lESiGM9qx c+qTHLoA4k/wOm6gKISuCEkJShqOF3VhqMUnx2D2XtIGvp6DuznPbnrhIXc4w9Ao98Ds Qc1A== X-Gm-Message-State: ACgBeo0EOWby6mvFfnqUkUSkTHcjsQjD1OiKYJ4CTApmxPUehbVg7QfR HiU48oKLl4XLc3dXXZSr0ms= X-Google-Smtp-Source: AA6agR4ivgKsW1nGK+NgnkoWRxp99CaZs3EHTMf/igrghYYz2Hbi4Z0NHcfQ+u7S31hvnU6vrpxPBQ== X-Received: by 2002:a17:90b:1bcf:b0:1f5:53cf:c01d with SMTP id oa15-20020a17090b1bcf00b001f553cfc01dmr30056226pjb.37.1660589760532; Mon, 15 Aug 2022 11:56:00 -0700 (PDT) Received: from vmfolio.. (c-73-189-111-8.hsd1.ca.comcast.net. [73.189.111.8]) by smtp.googlemail.com with ESMTPSA id x190-20020a6231c7000000b0052def2e20dasm6858174pfx.167.2022.08.15.11.55.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Aug 2022 11:56:00 -0700 (PDT) From: "Vishal Moola (Oracle)" To: linux-fsdevel@vger.kernel.org Cc: linux-btrfs@vger.kernel.org, linux-nilfs@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, "Vishal Moola (Oracle)" Subject: [PATCH 3/7] btrfs: Convert end_compressed_writeback() to use filemap_get_folios() Date: Mon, 15 Aug 2022 11:54:48 -0700 Message-Id: <20220815185452.37447-4-vishal.moola@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220815185452.37447-1-vishal.moola@gmail.com> References: <20220815185452.37447-1-vishal.moola@gmail.com> MIME-Version: 1.0 ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b="pzhH71/R"; spf=pass (imf15.hostedemail.com: domain of vishal.moola@gmail.com designates 209.85.216.43 as permitted sender) smtp.mailfrom=vishal.moola@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1660589761; a=rsa-sha256; cv=none; b=6/hdHoxIra0BbdqBvQTs4YtG88GJdCO9B96LsYXU0oOLT5GlNMSePmhM4x4n2KzPgG/D9j sKl0Y5bJysGQMMRgxyXf0VBUScoMkaYdHjieJbskJvJq5JPQBie9ZxSeQ9QA5RPhXJL1s2 HSLEvHUhTqqvqzkYMtoEdXWy6DzDRos= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1660589761; 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=/3WdeuCJ7GOu9Di/kxGE5ZGCTP43O1pORgSps3IpIM0=; b=oLrxHLKtR3AOElDL/J0/ksPyGooS9c0UEBdquiPI1/0yWnyk3w8xis3+f3ANk09aWvK4v2 CgQfyQusrQcWhbN2BLTScKiKYfu/l2sAbajC8Yu2lQBneqIoAHr1QV2iTVUKR+Ed5o78UO Tev60JTTh1HKZy7zSKYitFfVIi8fzmw= Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b="pzhH71/R"; spf=pass (imf15.hostedemail.com: domain of vishal.moola@gmail.com designates 209.85.216.43 as permitted sender) smtp.mailfrom=vishal.moola@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Stat-Signature: 3nwdi5fxbrex1q4xkfipzwg9rmotyfh9 X-Rspamd-Server: rspam09 X-Rspam-User: X-Rspamd-Queue-Id: 75BA0A01C8 X-HE-Tag: 1660589761-888036 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: Converted function to use folios throughout. This is in preparation for the removal of find_get_pages_contig(). Now also supports large folios. Since we may receive more than nr_pages pages, nr_pages may underflow. Since nr_pages > 0 is equivalent to index <= end_index, we replaced it with this check instead. Also this function does not care about the pages being contiguous so we can just use filemap_get_folios() to be more efficient. Signed-off-by: Vishal Moola (Oracle) --- fs/btrfs/compression.c | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/fs/btrfs/compression.c b/fs/btrfs/compression.c index e84d22c5c6a8..d4ebef60b3ce 100644 --- a/fs/btrfs/compression.c +++ b/fs/btrfs/compression.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -222,8 +223,7 @@ static noinline void end_compressed_writeback(struct inode *inode, struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb); unsigned long index = cb->start >> PAGE_SHIFT; unsigned long end_index = (cb->start + cb->len - 1) >> PAGE_SHIFT; - struct page *pages[16]; - unsigned long nr_pages = end_index - index + 1; + struct folio_batch fbatch; const int errno = blk_status_to_errno(cb->status); int i; int ret; @@ -231,24 +231,22 @@ static noinline void end_compressed_writeback(struct inode *inode, if (errno) mapping_set_error(inode->i_mapping, errno); - while (nr_pages > 0) { - ret = find_get_pages_contig(inode->i_mapping, index, - min_t(unsigned long, - nr_pages, ARRAY_SIZE(pages)), pages); + folio_batch_init(&fbatch); + while (index <= end_index) { + ret = filemap_get_folios(inode->i_mapping, &index, end_index, + &fbatch); + if (ret == 0) { - nr_pages -= 1; - index += 1; - continue; + return; } for (i = 0; i < ret; i++) { + struct folio *folio = fbatch.folios[i]; if (errno) - SetPageError(pages[i]); - btrfs_page_clamp_clear_writeback(fs_info, pages[i], + folio_set_error(folio); + btrfs_page_clamp_clear_writeback(fs_info, &folio->page, cb->start, cb->len); - put_page(pages[i]); } - nr_pages -= ret; - index += ret; + folio_batch_release(&fbatch); } /* the inode may be gone now */ }