From patchwork Tue Aug 16 17:52:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vishal Moola X-Patchwork-Id: 12945137 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 19732C2BB41 for ; Tue, 16 Aug 2022 17:53:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6BB778D0006; Tue, 16 Aug 2022 13:53:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 66BE98D0001; Tue, 16 Aug 2022 13:53:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 533AF8D0006; Tue, 16 Aug 2022 13:53:29 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 4512E8D0001 for ; Tue, 16 Aug 2022 13:53:29 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 0C5CB8139C for ; Tue, 16 Aug 2022 17:53:29 +0000 (UTC) X-FDA: 79806202938.01.02BBC1C Received: from mail-pf1-f175.google.com (mail-pf1-f175.google.com [209.85.210.175]) by imf13.hostedemail.com (Postfix) with ESMTP id A420B201CF for ; Tue, 16 Aug 2022 17:53:28 +0000 (UTC) Received: by mail-pf1-f175.google.com with SMTP id d20so9962761pfq.5 for ; Tue, 16 Aug 2022 10:53:28 -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=seovf7hiIocC7KrgUovFX1N/tGF31/3t5G8CMyD0zNk=; b=A0QG8rMJwgPAuWRxPlxnmh0emyQWQHjQkk9hr6ZxAF1b/UlBzE2vwG6yDS6Onat/T1 nRdTln1m+yYp5YakV3snbMptSKhwuNZzSDdp+NESr/ni9xiSwgMDPWEEifb5m0ZosUSV 9sHCH+S1LknyJ/6Tl+mQPkMXI351gqUZSkqiEPyrq0vLFwuzTIVb8cRw4rdotfCRibYp RnT8Uco4OInEnU/NOs8Bxepr+KJ5ngBTyRUVkb2BB3TNyBoiNHJ22I2XvB3SLeWnaXDA Tp3f6UUxkmtH/JSg8yZtpECHMchQJlJVuq9dRAuUXMqoOgIXk5bosl31og54wQVNkTFS l2UA== 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=seovf7hiIocC7KrgUovFX1N/tGF31/3t5G8CMyD0zNk=; b=ZlknJkys7pca859xh+YHmKlaRFJrgzT1VgWAbT7XQJPNlmwQjVEiEO+nIskMUPV3Fg 4F0eOOF2S7IhG8olHwyBBFORYTFimPOfX61L4YJ3csEQOJpYek0pTsqPIAtssFR94SDx tgvXVYc/Cuksk4kJVEIBwmstZCj8i9diBBis9iD3SR8e5zVBoO+tvo9qHDRIOHM2JB8/ yN1fVkl1pnCIBOl69m4OjvvRpNkveRgOmEhcnVZUBO9ySba1By3ucwi00QQTQYdLR5ug levRbWL0XSOnIWdHQEjre7MWfvCBQd5PPH8Ni0NzP8Na9mZiv1KPZLW8pNhoPbCfeUg7 HpwQ== X-Gm-Message-State: ACgBeo3dfCOImN5gYQp/z500E0WkJozaisvjC9mchlyLROcwQm40Ic6o lInHn3EUg1TfSRDm1S29tN8= X-Google-Smtp-Source: AA6agR5OMPr2DofSZD/3VZBz9h2pJym/U+Ew2vFlF94lnjZe3JsI+ZihdlS1+zjNBbNg0ylOVu34Fg== X-Received: by 2002:a63:88c7:0:b0:429:a566:e534 with SMTP id l190-20020a6388c7000000b00429a566e534mr3304481pgd.517.1660672407707; Tue, 16 Aug 2022 10:53:27 -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 mi4-20020a17090b4b4400b001f52fa1704csm3379963pjb.3.2022.08.16.10.53.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Aug 2022 10:53:27 -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 v2 3/7] btrfs: Convert end_compressed_writeback() to use filemap_get_folios() Date: Tue, 16 Aug 2022 10:52:42 -0700 Message-Id: <20220816175246.42401-4-vishal.moola@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220816175246.42401-1-vishal.moola@gmail.com> References: <20220816175246.42401-1-vishal.moola@gmail.com> MIME-Version: 1.0 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1660672408; a=rsa-sha256; cv=none; b=6VPR70uzxHzhCnPGvB0VJgcBuFUvsUdwFzfW9DMk4JBsQviCdnRcvkmgEasmvaPLg2dqF6 Fjo1RgkIESsozmlaxIeU+9BCTg0aCOPHN7/Q+po11Ea7Wgdma1BcGmGCYHNMHIsJDJeuEn 8va87jNgW9+GRGSBDJFxXidD5qrU1oQ= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=A0QG8rMJ; spf=pass (imf13.hostedemail.com: domain of vishal.moola@gmail.com designates 209.85.210.175 as permitted sender) smtp.mailfrom=vishal.moola@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1660672408; 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=seovf7hiIocC7KrgUovFX1N/tGF31/3t5G8CMyD0zNk=; b=5fMY2P3ovzv2o4oXVNYMcV8uoy+PlG2/+BKPM0QkAfP23uV85KbG7UIvh9AMhjbIgynbtx wnZi0ti8Ys3TZ08Tc+mm+Zy1KEeAlcR0oPzA/fejajLQqnje1B/4VkP1JRypfA8z2I0bAM OOSX508zu6iC1nNlLtyCtaDp840a11c= Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=A0QG8rMJ; spf=pass (imf13.hostedemail.com: domain of vishal.moola@gmail.com designates 209.85.210.175 as permitted sender) smtp.mailfrom=vishal.moola@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Rspam-User: X-Stat-Signature: msib85ptuto3kn866bjkndnuknrk1aeu X-Rspamd-Queue-Id: A420B201CF X-Rspamd-Server: rspam06 X-HE-Tag: 1660672408-258889 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) Acked-by: David Sterba --- 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 f4564f32f6d9..3dcd5006cfb4 100644 --- a/fs/btrfs/compression.c +++ b/fs/btrfs/compression.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -339,8 +340,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; @@ -348,24 +348,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 */ }