Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp4388737rwb; Tue, 16 Aug 2022 21:44:59 -0700 (PDT) X-Google-Smtp-Source: AA6agR7FF+XxBvit3/ng6/eCtmevwlQEUJ5werBo6/9DEUoUPRk/Y1RYPd1YeONjVGL6OOVc5D5a X-Received: by 2002:a17:90a:ab14:b0:1fa:b97f:c28b with SMTP id m20-20020a17090aab1400b001fab97fc28bmr397135pjq.71.1660711499391; Tue, 16 Aug 2022 21:44:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660711499; cv=none; d=google.com; s=arc-20160816; b=cujT7qQQVyAyqdo9EfDqPXXsA4OVnvy9MEApvxLxOG3NBCAKvufr0IN0Be8O1ISJn6 kHLCz31QlY+zI7+BFqylLFi8PobmstN0m/fEMdbIc4R7hqFl3l8yLeFRvnalWrwBK7DE DvGpPSr2x1rNVjrtSOLlUB6uMkYPOZ/IWfrb6cyPQiD/Khy6bjwmgaIuO9jGiAwZsH8V u0NPjm3C1jlN+nqmI27eVZEGG4lB6oUI2c0ZNY5P1uIDV4qlzrzr7fMf+VVLHYXr7uXW 4im6qUKoFFkKUTAI0xUfkkECa3ZsevWK9cOVqafVV44ViUoxa7kjF5SvDzkH/aEyynRg RhwQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=nOdb6n13ohDqgquF5+hz9jSYLtO6Hr9UX14Xr/YTGlM=; b=OOAYJyP8LB2A4N0j7FLGn9mLe85rELHYNGoIK/K8JHY0KGxrSvci5gDkz14HBzZ8rW w8NmKLqM346SJ0OR5rO88g8/SurDypJsdZxl9R5cwkRNmslsbWMTNEPerzuGmLSh76xw ra2agQ+PAOzMiX1XdBBLXkzmZA1m4rhKWFENduIFUKijJizIRslePaqO2AchClLZdnsS /7EVTuOOPM562Mzyk2iLjQ1joqhdYoUlDuNYpGfk5Np7R725AJ2ryfF0D+3MLD7z7Z+D iKnRR0aWXfzAYZkuUT+bGOew1aT4gJW7mJ3qgdCyFndhQ99auRSjgdysDetwA0A/jTKF uT1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=dMkCJ8Qc; 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 b20-20020a63eb54000000b0041ba9bc9bdfsi16283739pgk.16.2022.08.16.21.44.48; Tue, 16 Aug 2022 21:44:59 -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=dMkCJ8Qc; 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 S231561AbiHQEds (ORCPT + 99 others); Wed, 17 Aug 2022 00:33:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54220 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229448AbiHQEdr (ORCPT ); Wed, 17 Aug 2022 00:33:47 -0400 Received: from mail-lf1-x12b.google.com (mail-lf1-x12b.google.com [IPv6:2a00:1450:4864:20::12b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9458171725; Tue, 16 Aug 2022 21:33:46 -0700 (PDT) Received: by mail-lf1-x12b.google.com with SMTP id e15so17614283lfs.0; Tue, 16 Aug 2022 21:33:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc; bh=nOdb6n13ohDqgquF5+hz9jSYLtO6Hr9UX14Xr/YTGlM=; b=dMkCJ8QcXk8CCKs+JMzTMBHDLD4h16lKjhPfa818z1aMbkmqmpn4lSJ/hn0QuEWAWS OdymGqhTo4Pn/bNpk8llqrNNi6dl8VAXbfkDlgq0LGsfqFbAcRfU/QkVvvQTJ7XjPdlo G+V2u884J/ZowvVBoBep11BxqGF+P30pLFDrYUsxDKLvHcyrL3YTPIhXXvypH5+ZedHM Q6nLlNLv4ELt/1W812op/++Q7j7T/KiIOBtNGNFaXYckan6OxeLrFHGSmGqS9Sv/ONIM vOholq/pwx6EFwcprMgfhLQiGkgA1WhOigSaEZYsgkNRN8sM2DbUANkpN8czCaKsVb/N LnWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc; bh=nOdb6n13ohDqgquF5+hz9jSYLtO6Hr9UX14Xr/YTGlM=; b=OsWWGCltHbq4mCPfNKmMeUnoPo8nL2aWSTpUCULgcJ6uHA1/MkzE0mhb9MdNLvMrbR qzJy8VYknUaVoqKpuaUYK0YttVY1loZub+QFigT5CaEOktrZFtuG+eB9Uxu60/MBZna5 0kEn/mGZjyQVf72103GM8mBtaOJEyhyvF4oLRKzOLZLcOV+ywCQBwRP/ZnY1tEAgiKf8 9zWvy6G02rWI3AcEwvwRRMY/R+bpGXNA58X92i3WBQOwGkwnVmLBrW4Dd4Q2zF3ldM4w HDTRBeQv+kUSnVWAuS2CNOjetpxmDq34hvxPdpEZSYhQqu8mOd+qt/ll6gH5ajXNHRpp 5FuA== X-Gm-Message-State: ACgBeo0sr+qfR+HvFg7/OL6DrgeUfAUgjrvLSJ2g99h330+DtXvN9VPz D4M9qwj3uif0rpaLFAb4XgAjO7Td4TyXHoPar3Lh1sVmggeuVA== X-Received: by 2002:a05:6512:12c7:b0:48b:3bc4:10f4 with SMTP id p7-20020a05651212c700b0048b3bc410f4mr7766818lfg.411.1660710824597; Tue, 16 Aug 2022 21:33:44 -0700 (PDT) MIME-Version: 1.0 References: <20220816175246.42401-1-vishal.moola@gmail.com> <20220816175246.42401-6-vishal.moola@gmail.com> In-Reply-To: <20220816175246.42401-6-vishal.moola@gmail.com> From: Ryusuke Konishi Date: Wed, 17 Aug 2022 13:33:27 +0900 Message-ID: Subject: Re: [PATCH v2 5/7] nilfs2: Convert nilfs_find_uncommited_extent() to use filemap_get_folios_contig() To: "Vishal Moola (Oracle)" Cc: linux-fsdevel@vger.kernel.org, linux-btrfs@vger.kernel.org, linux-nilfs@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=0.4 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,SUSPICIOUS_RECIPS, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=no 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 On Wed, Aug 17, 2022 at 2:54 AM Vishal Moola (Oracle) wrote: > > Converted function to use folios throughout. This is in preparation for > the removal of find_get_pages_contig(). Now also supports large folios. > > Also cleaned up an unnecessary if statement - pvec.pages[0]->index > index > will always evaluate to false, and filemap_get_folios_contig() returns 0 if > there is no folio found at index. > > Signed-off-by: Vishal Moola (Oracle) > --- > > v2: > - Fixed a warning regarding a now unused label "out" > - Reported-by: kernel test robot > --- > fs/nilfs2/page.c | 39 +++++++++++++++++---------------------- > 1 file changed, 17 insertions(+), 22 deletions(-) > > diff --git a/fs/nilfs2/page.c b/fs/nilfs2/page.c > index 3267e96c256c..14629e03d0da 100644 > --- a/fs/nilfs2/page.c > +++ b/fs/nilfs2/page.c > @@ -480,13 +480,13 @@ unsigned long nilfs_find_uncommitted_extent(struct inode *inode, > sector_t start_blk, > sector_t *blkoff) > { > - unsigned int i; > + unsigned int i, nr; > pgoff_t index; > unsigned int nblocks_in_page; > unsigned long length = 0; > sector_t b; > - struct pagevec pvec; > - struct page *page; > + struct folio_batch fbatch; > + struct folio *folio; > > if (inode->i_mapping->nrpages == 0) > return 0; > @@ -494,27 +494,24 @@ unsigned long nilfs_find_uncommitted_extent(struct inode *inode, > index = start_blk >> (PAGE_SHIFT - inode->i_blkbits); > nblocks_in_page = 1U << (PAGE_SHIFT - inode->i_blkbits); > > - pagevec_init(&pvec); > + folio_batch_init(&fbatch); > > repeat: > - pvec.nr = find_get_pages_contig(inode->i_mapping, index, PAGEVEC_SIZE, > - pvec.pages); > - if (pvec.nr == 0) > + nr = filemap_get_folios_contig(inode->i_mapping, &index, ULONG_MAX, > + &fbatch); > + if (nr == 0) > return length; > > - if (length > 0 && pvec.pages[0]->index > index) > - goto out; > - > - b = pvec.pages[0]->index << (PAGE_SHIFT - inode->i_blkbits); > + b = fbatch.folios[0]->index << (PAGE_SHIFT - inode->i_blkbits); > i = 0; > do { > - page = pvec.pages[i]; > + folio = fbatch.folios[i]; > > - lock_page(page); > - if (page_has_buffers(page)) { > + folio_lock(folio); > + if (folio_buffers(folio)) { > struct buffer_head *bh, *head; > > - bh = head = page_buffers(page); > + bh = head = folio_buffers(folio); > do { > if (b < start_blk) > continue; > @@ -532,18 +529,16 @@ unsigned long nilfs_find_uncommitted_extent(struct inode *inode, > > b += nblocks_in_page; Here, It looks like the block index "b" should be updated with the number of blocks in the folio because the loop is now per folio, not per page. Instead of replacing it with a calculation that uses folio_size(folio) or folio_shift(folio), I think it would be better to move the calculation of "b" inside the branch where the folio has buffers as follows: if (folio_buffers(folio)) { struct buffer_head *bh, *head; sector_t b; b = folio->index << (PAGE_SHIFT - inode->i_blkbits); bh = head = folio_buffers(folio); ... } else if (length > 0) { goto out_locked; } This way, we can remove calculations for the block index "b" outside the above part and the variable "nblocks_in_page" as well. Thanks, Ryusuke Konishi > } > - unlock_page(page); > + folio_unlock(folio); > > - } while (++i < pagevec_count(&pvec)); > + } while (++i < nr); > > - index = page->index + 1; > - pagevec_release(&pvec); > + folio_batch_release(&fbatch); > cond_resched(); > goto repeat; > > out_locked: > - unlock_page(page); > -out: > - pagevec_release(&pvec); > + folio_unlock(folio); > + folio_batch_release(&fbatch); > return length; > } > -- > 2.36.1 >