From patchwork Mon Aug 15 18:54:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vishal Moola X-Patchwork-Id: 12943967 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 F0A72C00140 for ; Mon, 15 Aug 2022 18:56:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 358A28D0005; Mon, 15 Aug 2022 14:56:01 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 30D6B8D0001; Mon, 15 Aug 2022 14:56:01 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1352C8D0005; Mon, 15 Aug 2022 14:56:01 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 00A148D0001 for ; Mon, 15 Aug 2022 14:56:00 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id CC8801A0ECD for ; Mon, 15 Aug 2022 18:56:00 +0000 (UTC) X-FDA: 79802731680.08.32C42FA Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.174]) by imf09.hostedemail.com (Postfix) with ESMTP id 743F71401BA for ; Mon, 15 Aug 2022 18:56:00 +0000 (UTC) Received: by mail-pl1-f174.google.com with SMTP id z19so7137613plb.1 for ; Mon, 15 Aug 2022 11:56:00 -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=YNgoWYCY1lPrjzW0L6uvTUDhqO8Va4cbu+Lukza45Kk=; b=LLqk6nZx0CZaFFAKrYtayFNSQtFEufiNWAnBpPZzb6NuyTnfFHJ50yjihvOX09BnKM S47QhKHOD34cTFOPR6PhaMP7mmdaLrRYSmY3S08Yq78sPmyEiJxae5DQvOOdYruhjV2K VainybYqq60xbvb9Mjvhb2WTFrPUhyaHxn2OUAWwknzK883JGnUdbEkTFKzA/VFk6DlK U8j6FtQ9cjPFpqQ5YnVDfhVJc2COUwxSydLt+v/jUsytUL1hfqyDMVpnBKcHVytFmRqk lLrXpBUiei5hCA+Dw8+0AgZvhFxuDhaZTjwgI8a7Iu6XaMONbkJrwlTwh1AJurWNAhXM TeLQ== 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=YNgoWYCY1lPrjzW0L6uvTUDhqO8Va4cbu+Lukza45Kk=; b=t++5sFDj3v9p3cmcfv/XFBc51l4HXJTb9zHDhL2eN8ilrCR76yKOCL+wrv/u3p0+VF eulZjyBT0KcxBkO4+GbI7CDpxyR2TIdphEObpScjqRNAvPWWuffqQH/390YZPYwnd7qb Uy2wCTnnTNP+VT/+YUdB99ByCJp7lu8q50mx0PA2BzOMvW6GgZ5hNeE9vUA5i17SnIUv WhCIx/bRB4axS0NKlIB86eyITv2E4YMmUltdtpTQN7/G7RAc8Vw/3X+EvQq14ZrXBQz7 AxY2sszrzg4WhX0z+ax/RgcrcOGHi7FfQ3dZ7Iq05aqaZwFn2w8EYsW2bR0+nwehGV/4 6Z1w== X-Gm-Message-State: ACgBeo3Ge7zdETrYU2XNFHdhPv5+Q+poAa4PwjxtipPcwQMzJ3LM1ubE ar7yVPP+pgcQ2vbscJLTkT8= X-Google-Smtp-Source: AA6agR7Ao983jsJzFfh+XdeTEh3h2BJEmqP3wgZdEa6QB7GpFTZxxIDE7k3xHAwvuKwa7uOA/N5Omg== X-Received: by 2002:a17:902:ef81:b0:16d:cd36:7955 with SMTP id iz1-20020a170902ef8100b0016dcd367955mr17848496plb.24.1660589759453; Mon, 15 Aug 2022 11:55:59 -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.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Aug 2022 11:55:59 -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 2/7] btrfs: Convert __process_pages_contig() to use filemap_get_folios_contig() Date: Mon, 15 Aug 2022 11:54:47 -0700 Message-Id: <20220815185452.37447-3-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-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1660589760; a=rsa-sha256; cv=none; b=t9VmDd3CZiE3yXExrqS2IPItDr0GJmWYUm9toCfoocn4xRKzeC7g0vxTlQXFRmH5+L4l7a RpZN9f5CXJu/J/jDNheJN355bPA+Ta4GsgERmFRL/AgYgyy5ira+MOvVCtGi4b1Ji/dOus 8errclZl7pdnyb4xOBg3uT98OFioStU= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=LLqk6nZx; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf09.hostedemail.com: domain of vishal.moola@gmail.com designates 209.85.214.174 as permitted sender) smtp.mailfrom=vishal.moola@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1660589760; 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=YNgoWYCY1lPrjzW0L6uvTUDhqO8Va4cbu+Lukza45Kk=; b=ovXYM2N7lvUNQjSP4mk+apC+kKCtBBQ1mCjf0Mjg7hVjOhGrPWARGzGpmqvKg2qSAdvw0k t4B3ZM0BJl7RGBkU6A5V/6+tai/yhzGLDDksIeaJVuHvXl1Z0gHPxMm7HrFtSSlkxXJ2/u LcezL2umUsPV+5ONgMhmhLdWuggJFI4= X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 743F71401BA X-Rspam-User: Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=LLqk6nZx; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf09.hostedemail.com: domain of vishal.moola@gmail.com designates 209.85.214.174 as permitted sender) smtp.mailfrom=vishal.moola@gmail.com X-Stat-Signature: 31puf8k3q99imbpnaak1jc9h5g735taq X-HE-Tag: 1660589760-702612 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: Convert 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. Signed-off-by: Vishal Moola (Oracle) --- fs/btrfs/extent_io.c | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c index bfae67c593c5..2c2f0e281014 100644 --- a/fs/btrfs/extent_io.c +++ b/fs/btrfs/extent_io.c @@ -1900,9 +1900,8 @@ static int __process_pages_contig(struct address_space *mapping, pgoff_t start_index = start >> PAGE_SHIFT; pgoff_t end_index = end >> PAGE_SHIFT; pgoff_t index = start_index; - unsigned long nr_pages = end_index - start_index + 1; unsigned long pages_processed = 0; - struct page *pages[16]; + struct folio_batch fbatch; int err = 0; int i; @@ -1911,16 +1910,17 @@ static int __process_pages_contig(struct address_space *mapping, ASSERT(processed_end && *processed_end == start); } - if ((page_ops & PAGE_SET_ERROR) && nr_pages > 0) + if ((page_ops & PAGE_SET_ERROR) && start_index <= end_index) mapping_set_error(mapping, -EIO); - while (nr_pages > 0) { - int found_pages; + folio_batch_init(&fbatch); + while (index <= end_index) { + int found_folios; + + found_folios = filemap_get_folios_contig(mapping, &index, + end_index, &fbatch); - found_pages = find_get_pages_contig(mapping, index, - min_t(unsigned long, - nr_pages, ARRAY_SIZE(pages)), pages); - if (found_pages == 0) { + if (found_folios == 0) { /* * Only if we're going to lock these pages, we can find * nothing at @index. @@ -1930,23 +1930,20 @@ static int __process_pages_contig(struct address_space *mapping, goto out; } - for (i = 0; i < found_pages; i++) { + for (i = 0; i < found_folios; i++) { int process_ret; - + struct folio *folio = fbatch.folios[i]; process_ret = process_one_page(fs_info, mapping, - pages[i], locked_page, page_ops, + &folio->page, locked_page, page_ops, start, end); if (process_ret < 0) { - for (; i < found_pages; i++) - put_page(pages[i]); err = -EAGAIN; + folio_batch_release(&fbatch); goto out; } - put_page(pages[i]); - pages_processed++; + pages_processed += folio_nr_pages(folio); } - nr_pages -= found_pages; - index += found_pages; + folio_batch_release(&fbatch); cond_resched(); } out: