Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp1235675rwe; Thu, 1 Sep 2022 15:03:16 -0700 (PDT) X-Google-Smtp-Source: AA6agR50S2ig5bcO4/8iMYaugVk+mAeanqHkw5zx9EYeZtuhq+Z6LWrRQbnaatswdWrhp6L/yE4c X-Received: by 2002:a17:90a:94c7:b0:1fd:81a5:48fd with SMTP id j7-20020a17090a94c700b001fd81a548fdmr1239419pjw.97.1662069796470; Thu, 01 Sep 2022 15:03:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662069796; cv=none; d=google.com; s=arc-20160816; b=ZkQ8bjlfpEFhCvdXE53JVzlhc3KEc7dI0NLEQy2PPnm90g8r37GMnHtYOgo6NTnSZf 9moUZDMHsDN+C/A8fcHMilKfpIgx69aROZCKM1Wld4OJ61l0VhiHHyk+oL7m+qHnEMQ4 xNJk5P0HNNcItXDl2/l/TAKIETosqsMbRNjR32Vw2nP8yYT3mVty9oc/USGSsltMqldq pCZDg50YhLYsxw0G7dx6fxZbo9GgNnoo6d8avK5f820dGxsCd1/g2UGVhiG3epkG61DD QUIyNX7kW6uEdLORUbW+GEyOTITMUmY3NcStTkPoqhqdWq/X2ouSoaXOTSoeHxfi4gHZ S5tQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=CVjZRQRXjU7sjBLr6rHvAQKfUIl2rAWam+cMUVwdi8E=; b=U0tu7r/FA6SgaONLeO0Al2Qo0FxsLqYU/40plneHWpVhXCHmWqzPx0LIN8wu/fOtzn cEWKMqhmX3WJUb2vqoAvac2s69JhbTzYs0VlZH5n4baO0H1nr72xzTBwfpZsl5z5qjyc 7rK5WTaTz5+eBdBck1arJ+GrCYpm8tQ+lrQHmcO4bfd26QPto8xCwbVLkuQitVXW2uvf oG6WL+auTPq6X50lioarUhyK4frXMusHdXsbA4priCPvkf/8DgNaj7r+QRhZF2WovoTv kG5J4IbOFWZCQ8tLD8ScOZ2flDSuJgbT+0SOXXnnmHW4gCsL5G0yKXKF8ILp5VCHu/mU HP2g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=bv0LlXMB; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-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 r20-20020aa79634000000b00535fa14ffaasi214601pfg.116.2022.09.01.15.02.59; Thu, 01 Sep 2022 15:03:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-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=bv0LlXMB; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-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 S233501AbiIAWCm (ORCPT + 99 others); Thu, 1 Sep 2022 18:02:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38116 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233994AbiIAWCj (ORCPT ); Thu, 1 Sep 2022 18:02:39 -0400 Received: from mail-pf1-x435.google.com (mail-pf1-x435.google.com [IPv6:2607:f8b0:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 064034F671; Thu, 1 Sep 2022 15:02:38 -0700 (PDT) Received: by mail-pf1-x435.google.com with SMTP id l65so103773pfl.8; Thu, 01 Sep 2022 15:02:38 -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:subject:date; bh=CVjZRQRXjU7sjBLr6rHvAQKfUIl2rAWam+cMUVwdi8E=; b=bv0LlXMBz1E57HLrV0PxYhOttdXPLA9G/hmytg6Pe0rd+F6zlztjWzFwbENyiMaQWR F0y9cniRQ6tVYw7gWA96HxH7uvhLa7fAV6j9jf6hJKnH+nqTOa6IuccLgG2jeB4wnKbN dXNbKHhDCRc0KcSaeocdSfxm7jfTTYEBJlJdkL7KuMup4EyoA3sh9A1lYrEFkmC6fktZ zYtzraSEWM+6VBSfJSxJZMDmzsg1bohGoHF4buE8zyNN/Y+ges7udin1m1Ip09ANb1qi yx9Dumn8NExq4UnKeww1kfiOzJo2ul+62vzxa7uoxr+6j09KzXtjhQLvasVG7qC/0CUb sXvQ== 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 :subject:date; bh=CVjZRQRXjU7sjBLr6rHvAQKfUIl2rAWam+cMUVwdi8E=; b=yovhhEvdrqzSp954pT+KYK7g5BhrCtXvxqSi0K0xgDB8eOVgigDvwkyg/mtJjHL4Zd YeMv+2XLq3SOiy9RneWFkpcmWH4BuOdfIWkRPDpA1N/79C2Vd9aGQvqcMHVrmSTrtVWu S6Isgc7vwJb0PGm21+lN7jy/fh4PBeqfKVrPLgT8AHfqjKSkokb/rYEmWh7qoWlXItpM RtXPUCi7V2WS0sx3CxYe7+0vrKSPFx+3SXBc57MFCHqJqjBawBDZ4QtaVhrgQMZyoZNR EH7knkyH3p7KHQkviZfeYPvtlkfz15kiXc7pj9ILLMfNOYIwHhgiLEGWXJCcxILn9DZa tZhw== X-Gm-Message-State: ACgBeo2j9ePa8YRK1KkvMyQtLagVyqSvE29ypmAtRUqlbauGPeVhTMVO V9WOfuyJylVTPju3FbleF0JBV+5c6seaSA== X-Received: by 2002:a63:6cc4:0:b0:41a:ff04:661f with SMTP id h187-20020a636cc4000000b0041aff04661fmr27931509pgc.600.1662069757234; Thu, 01 Sep 2022 15:02:37 -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 fv4-20020a17090b0e8400b001fb350026f1sm128894pjb.4.2022.09.01.15.02.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Sep 2022 15:02:36 -0700 (PDT) From: "Vishal Moola (Oracle)" To: linux-fsdevel@vger.kernel.org Cc: linux-afs@lists.infradead.org, linux-kernel@vger.kernel.org, linux-btrfs@vger.kernel.org, ceph-devel@vger.kernel.org, linux-cifs@vger.kernel.org, linux-ext4@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, cluster-devel@redhat.com, linux-nilfs@vger.kernel.org, linux-mm@kvack.org, "Vishal Moola (Oracle)" Subject: [PATCH 02/23] filemap: Added filemap_get_folios_tag() Date: Thu, 1 Sep 2022 15:01:17 -0700 Message-Id: <20220901220138.182896-3-vishal.moola@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220901220138.182896-1-vishal.moola@gmail.com> References: <20220901220138.182896-1-vishal.moola@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 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,T_SCC_BODY_TEXT_LINE autolearn=ham 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-ext4@vger.kernel.org This is the equivalent of find_get_pages_range_tag(), except for folios instead of pages. One noteable difference is filemap_get_folios_tag() does not take in a maximum pages argument. It instead tries to fill a folio batch and stops either once full (15 folios) or reaching the end of the search range. The new function supports large folios, the initial function did not since all callers don't use large folios. Signed-off-by: Vishal Moola (Oracle) --- include/linux/pagemap.h | 2 ++ mm/filemap.c | 53 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h index 4d3092d6b2c0..85cc96c82c2c 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -740,6 +740,8 @@ unsigned filemap_get_folios(struct address_space *mapping, pgoff_t *start, pgoff_t end, struct folio_batch *fbatch); unsigned find_get_pages_contig(struct address_space *mapping, pgoff_t start, unsigned int nr_pages, struct page **pages); +unsigned filemap_get_folios_tag(struct address_space *mapping, pgoff_t *start, + pgoff_t end, xa_mark_t tag, struct folio_batch *fbatch); unsigned find_get_pages_range_tag(struct address_space *mapping, pgoff_t *index, pgoff_t end, xa_mark_t tag, unsigned int nr_pages, struct page **pages); diff --git a/mm/filemap.c b/mm/filemap.c index 15800334147b..3ded72a65668 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -2254,6 +2254,59 @@ unsigned find_get_pages_contig(struct address_space *mapping, pgoff_t index, } EXPORT_SYMBOL(find_get_pages_contig); +/** + * filemap_get_folios_tag - Get a batch of folios matching @tag. + * @mapping: The address_space to search + * @start: The starting page index + * @end: The final page index (inclusive) + * @tag: The tag index + * @fbatch: The batch to fill + * + * Same as filemap_get_folios, but only returning folios tagged with @tag + * + * Return: The number of folios found + * Also update @start to index the next folio for traversal + */ +unsigned filemap_get_folios_tag(struct address_space *mapping, pgoff_t *start, + pgoff_t end, xa_mark_t tag, struct folio_batch *fbatch) +{ + XA_STATE(xas, &mapping->i_pages, *start); + struct folio *folio; + + rcu_read_lock(); + while ((folio = find_get_entry(&xas, end, tag)) != NULL) { + /* Shadow entries should never be tagged, but this iteration + * is lockless so there is a window for page reclaim to evict + * a page we saw tagged. Skip over it. + */ + if (xa_is_value(folio)) + continue; + if (!folio_batch_add(fbatch, folio)) { + unsigned long nr = folio_nr_pages(folio); + + if (folio_test_hugetlb(folio)) + nr = 1; + *start = folio->index + nr; + goto out; + } + } + /* + * We come here when there is no page beyond @end. We take care to not + * overflow the index @start as it confuses some of the callers. This + * breaks the iteration when there is a page at index -1 but that is + * already broke anyway. + */ + if (end == (pgoff_t)-1) + *start = (pgoff_t)-1; + else + *start = end + 1; +out: + rcu_read_unlock(); + + return folio_batch_count(fbatch); +} +EXPORT_SYMBOL(filemap_get_folios_tag); + /** * find_get_pages_range_tag - Find and return head pages matching @tag. * @mapping: the address_space to search -- 2.36.1