From patchwork Wed Jan 4 21:14:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vishal Moola X-Patchwork-Id: 13088951 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 0C578C54EBD for ; Wed, 4 Jan 2023 21:15:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6AF808E0006; Wed, 4 Jan 2023 16:15:01 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 5EA238E0001; Wed, 4 Jan 2023 16:15:01 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 48A8C8E0006; Wed, 4 Jan 2023 16:15:01 -0500 (EST) 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 3BB4B8E0001 for ; Wed, 4 Jan 2023 16:15:01 -0500 (EST) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 1480D1A06AB for ; Wed, 4 Jan 2023 21:15:01 +0000 (UTC) X-FDA: 80318371602.18.0F50308 Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.170]) by imf04.hostedemail.com (Postfix) with ESMTP id 7173D40008 for ; Wed, 4 Jan 2023 21:14:59 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b="X+JhwQB/"; spf=pass (imf04.hostedemail.com: domain of vishal.moola@gmail.com designates 209.85.214.170 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=1672866899; 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=KWc2oMWZrabUsNL93YYBg0xBgzl7UJM5P4FHRP4dszA=; b=XF/1sksl2OUbjWnQbYrJ1V3B1tbm0KeYcB9ajBRDEOV7ydGiE2lXm9YCOZMJzJD+W5ryF8 9U0vgIOzlEMt3DvCzmmElH1fUM8bMIw36Ci4UB4QFQgmeuGVSV9ISaogoFefP9zXiJrzeu CIhX21nIQTk0c7J7mtkFObL6s81nKtA= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b="X+JhwQB/"; spf=pass (imf04.hostedemail.com: domain of vishal.moola@gmail.com designates 209.85.214.170 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=1672866899; a=rsa-sha256; cv=none; b=CpZ4gl6b5Sz4pPzf3vYKp22O8Zk8UsHa6O33WuemCMX+CdYxUqmKW7bc41jM5Ki7Mypr7A jzBUr6aSUEV0S5EXj0F611o0gcoilxozqruyT7Fqj/LfO+bW2lIph5zfa7INVAiH8mF2Az 0e1M9+qVzqvxt95ycwWnmB/F8BbrtsY= Received: by mail-pl1-f170.google.com with SMTP id d3so37194071plr.10 for ; Wed, 04 Jan 2023 13:14:59 -0800 (PST) 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 :message-id:reply-to; bh=KWc2oMWZrabUsNL93YYBg0xBgzl7UJM5P4FHRP4dszA=; b=X+JhwQB/YFpkv9O3Sz2RIqehaNfUYePllMKYDSfYMVmQ80S+7Znm3qUhQQutUgGzcL 0uq/hVoyBfqjmkDpyVZm/VIPt68FQqEGQ82Nd+zz6E+E98NXjR4XSpPj/MXztZhY0W/5 2SnakvGDdpx0xcZLQD7UZxy8cVZY3oo6XDRKLX6rp+1lZ5XfYRhOxIIbBxK+QOE0O7oY mvbbq1JpLOKHZ6D7c98chruQCpXs68i4ZX3rFltoX/XuVJPECIsdkN1cooENDtzYQJT2 bRwgzwaxOKhTwxGYYDaTYxmm4WsaqrwCXgLa3BEJo54/4GqC8mZRZtI56zwUYC6qebL9 Oo2w== 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:message-id:reply-to; bh=KWc2oMWZrabUsNL93YYBg0xBgzl7UJM5P4FHRP4dszA=; b=rj/cXstDlCIxmwwKJR9p1B32Qx99R2MLIukeULwTGLX+mi+QFz81eoGTqLeoeVJK3y 03u6aCHZmd5gcDA4wRY/9yrp3YmrGHAKIQInmS99ifXN0g/lhoPswyoSH53nVCzXPGqR 5jYHLinVZ321q7JV8RWVzhyQWV6WZGb1z6aZfAaSa96OunUmWbY4aTAH6/ITfiVyngAb Tk3lIlcHBKcib9wLOm4clMV+L3Esl8gvvLNKQ30uB9Qek2jMIAxNZKgVj98vM9qgD9y2 Q6Yp6fG7w2mX098GJijmddCGL6w68XeeKQPYWKZEenGObVCVcqMRCkEvcdVo7+kQlkHT r2TQ== X-Gm-Message-State: AFqh2kqFVeyu0rokX9dGnPiJR6D8UB9HqK7V4VOg7rfsAbfol1PzvO4O irrHknZFtY9zYsydDxrfMX4= X-Google-Smtp-Source: AMrXdXsQLnyc09jFT7hjT2KR1nJMp1M067OD5YrApEuRuIFS+9J6bRUAVKGRrDQmj0MgbIV/5rlsug== X-Received: by 2002:a17:90a:cc2:b0:219:9973:2746 with SMTP id 2-20020a17090a0cc200b0021999732746mr65437761pjt.0.1672866898346; Wed, 04 Jan 2023 13:14:58 -0800 (PST) Received: from fedora.hsd1.ca.comcast.net ([2601:644:8002:1c20::a55d]) by smtp.googlemail.com with ESMTPSA id i8-20020a17090a138800b00226369149cesm6408pja.21.2023.01.04.13.14.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Jan 2023 13:14:58 -0800 (PST) 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)" , Matthew Wilcow Subject: [PATCH v5 02/23] filemap: Added filemap_get_folios_tag() Date: Wed, 4 Jan 2023 13:14:27 -0800 Message-Id: <20230104211448.4804-3-vishal.moola@gmail.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230104211448.4804-1-vishal.moola@gmail.com> References: <20230104211448.4804-1-vishal.moola@gmail.com> MIME-Version: 1.0 X-Stat-Signature: 11i1b37higgyt6osai4e7db1jjeiej5n X-Rspam-User: X-Rspamd-Queue-Id: 7173D40008 X-Rspamd-Server: rspam06 X-HE-Tag: 1672866899-468021 X-HE-Meta: U2FsdGVkX18CiCG0v/xd35ySElXOmJtvFzPN8ZgQN+pFaCmp2gdgkfcRgMaSSNP8dSUwx22icghVZ6FNjAG7rnGxB/jpYGTS6Yv8SBeJj1PAlNsBiDMF2GT4GtZiULY+9NJW3MTkTGrz2KA0/cm2/jBfRAWylmzm60pajvlRWxQNFf9ozzlaKwAbmZsFuxCsTQU8nEMKOprhOrc5BcOmWHAcluUueOcI8Bix7KYYAUhmuEUTKaXgzwGyVqtOiAMhkyTbxx4JCnzBDJXasSmGMLiEM8ovJHcRUBD42b7STY9ptcATBROR3GPTTgHkCooGKoYiSoXV03qbe76JVyO1MAU9J06KlI2dqA2A++fjME7Q+LMFMmQm4ThUAy9DWQdnuIEiWR3BXY+9dUejkYtf2+Rh5i7GzBqAm+HUycU/nVzortb/x5yatxDSMwHJxbzoFZFX7YpjVOzupbFrNQBkjkoB99xQrRDoOsXEsiz5ozywmgt+QvlgOIK3JpV+5QIDijAh9w/2p8GJCsXYP8upQKu02SmfGNznIHK12EsGTsD0ZRiBOPAhnjqCLwgOSTUCt0GOMQU/thTywWnKNKTqqMAI5z4M0pMejJ37AXTL4GCkRqJGKVOZjjN9n7TQkzGcN+GFyK3h8KHi5cbeL4XRXfkL2DRKo221xhumvkfiWRwEFYPBra2NK4BnCLM+k2snXlw5Ud8NuQL+tLjK8inqzQjU/1p1I2q7JozO0H4T7ksxHZvV3Yw7ax00plQl8piNZbccv0ESyJjFidR+woqfq3vNJg1lAelLK1xJieWOP5CS6ls54UH3BNRyzYTEWg3FZ2R1Py7j/f73ecKpHUePf53fIdFC4m3VVKGcJIJxardPeD8+ZdF21+APhN+ty3qAZl4/OimcGPUjkDoGWl2LNeKwOJCPyagA1iudPhq4XIMClIQtG4EAsiOBND2RkzxLARLcyeCW6MCIvLlt8lg 6UNrzv5B rN12lWCHTVAKz+avKaw2BisN7bCa0KNSfsvsaL4Oooi0mZLrn2d8WU7doJrdNxdlawo4dAAro01AShSHLB8g1xFwu1e0xxMadazBmShhH5sugFq7BYCrXuDteD1WQFeS6lixbNoioyVeG7YhFLkJ1QAAG1yaINCMqBTP1KhQoHnT7xxAuiAK3/2q1sPNLLAqLc9TUIKr4Pb+al5P+k/8faNkoa5kpl7L841Qzq3nVjYQz5SG6Zr+Do1cpx3vkfOoY6KEVq5INIW7v+6Ip4b94yVcmMBO3bG4RZIGd 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: 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) Reviewed-by: Matthew Wilcow (Oracle) --- include/linux/pagemap.h | 2 ++ mm/filemap.c | 54 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h index 468183be67be..bb3c1d51b1cb 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -739,6 +739,8 @@ unsigned filemap_get_folios(struct address_space *mapping, pgoff_t *start, pgoff_t end, struct folio_batch *fbatch); unsigned filemap_get_folios_contig(struct address_space *mapping, pgoff_t *start, pgoff_t end, struct folio_batch *fbatch); +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 c4d4ace9cc70..291bb3e0957a 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -2281,6 +2281,60 @@ unsigned filemap_get_folios_contig(struct address_space *mapping, } EXPORT_SYMBOL(filemap_get_folios_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