From patchwork Tue May 2 23:56:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ackerley Tng X-Patchwork-Id: 89525 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp980051vqo; Tue, 2 May 2023 17:17:25 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4vupow+6b0KxwwQNtzB8pcMbJN8fyUhVrkdVSfgUgDOsOyqKg6PkIBz8LjgtoiExAErXfv X-Received: by 2002:a17:90b:315:b0:24d:f597:346c with SMTP id ay21-20020a17090b031500b0024df597346cmr10284098pjb.6.1683073045293; Tue, 02 May 2023 17:17:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683073045; cv=none; d=google.com; s=arc-20160816; b=ADGZ/s5yYMtH93Sj0VwiBWtiXWZqWf690l4j4Bg1mTbqvZURlOHSrMx8YiURvnI5/u IgcIEappT/tw5HvbvxHvI9C3XP5g0hT6d6Dsy93RuLrL8BXLpm98dpk7ubFzoX8S8Qrd 6RwbABmFwhJ0Gg/R49KPVhu3RGdZYAjgFxHGFYNZLcfZSI3f/F+czf21/wa3F1M4i7+z nm8myYovSLmKm/EqWUHo1mzRQWTKx5n4zwVU774YYiKp1cJBq2g9yU2jc4iksapJfSSb zgIWDGsX8hIl61HquV42els/5oxjJ3vIz/+fbIteUT0dqz7T2J81ORB5sIt01+vfnYAb I2kA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=TIxhAVAgYS5mapIdI8ZTL33+hofUrDA3Fj2JnyUnXTo=; b=qlaBRsWx8YezhUZA/TtF0N2ODbGdPQM/2S7C7oDnPt/HXNa9+nqh1gEPvUShzomJJ/ PjKBAr6NVfaGNZxsnJsfD4TNpz28gvSWRn1ApkkVqavN81W/ubGvR0HhG2fu7XP2bjqn ywVjfI4KlbfetwVA89ypgTKmeba+Pj+suZht3c8UehjlNqUGDZEMBTvcO+mHzL9We6HF wwpIK4dWJwCe0+10DyzpVMOAC4We1wxPs42vodflubIt4217xWtupUOonl26mHBhxvMA cv6PiHuw2xe35IlcysJhuiH1gb4g60Xa7jfxU8KRyMEWJEYg1pes/l4as28TKQWyUGmg jPdQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=dNZZa0Le; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p18-20020a17090ad31200b00246b1a9630csi228904pju.130.2023.05.02.17.17.09; Tue, 02 May 2023 17:17:25 -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=@google.com header.s=20221208 header.b=dNZZa0Le; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229806AbjEBX4N (ORCPT + 99 others); Tue, 2 May 2023 19:56:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41222 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229576AbjEBX4J (ORCPT ); Tue, 2 May 2023 19:56:09 -0400 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2FDD330CD for ; Tue, 2 May 2023 16:56:08 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-55a9614c154so25505037b3.2 for ; Tue, 02 May 2023 16:56:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1683071767; x=1685663767; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=TIxhAVAgYS5mapIdI8ZTL33+hofUrDA3Fj2JnyUnXTo=; b=dNZZa0LeBYDZrFKtDX5qs0Huzpekye+DGENcdzJGQDDEmBIXmSv36HWyWunH74mYvv IYPkV9Yol53BLGWLbst9q5taC4QG822qYbdKdjNOZLs5p2TJmEPhbjh66IcJTvBUA5SP kUPBtZngsyGsJXYWzbuqy/qAcQIPsfW6qYuE6xxKyYqL6ThrIh2fNwHEeRKouUsYon2A mRtSyLBzArQDmBie63b74T6C2w2V0kJcF5RAHMQ5ytpNzPR7bzzivdKenxaQveRH8kfk 76sucra8VLmAZHJqkCPmWEHri4ZaUVqTJhTvZT50Xvoa8ThsdZG2UvcJP9ETia91jzUg aWFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683071767; x=1685663767; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=TIxhAVAgYS5mapIdI8ZTL33+hofUrDA3Fj2JnyUnXTo=; b=CLKgGkztkhYoWe2r/n7WDU6UoCGEfO/YmCbk54ewaABNu/V1N48INOcgCBYiqy4dfz STx6DGKTVALXjn3pWfNJlOOcJ7NVuVic4NROPrHYq2cvnvxl+aIZNwgh038PVupX9K5F QnU1L1FjLdhfxDNFe5p6a9NpZ9kv0AsX7TPgdvoesX4wt5zMQflvDXKuZmSmMlEXBRup MQTxy5ome1W5Nhv77OUV1Bbqtw2dW0NQ0fJjia+Zqvum2hdE0UQLpVLGQYF/r1VCyfzv MlkcKrp/m3CMNmCHC0d52BlT3JODV4sXhoMro1q2TdFXyiPlzu6QfRrdyYgfzmnofOlM 0Wig== X-Gm-Message-State: AC+VfDzbD9JtMKoukm3+Viev5ae8S1bT1cshpHc8VT53rp3xtNlVOKC2 yUh533HJr2+k85GkOFXlibHJDC2JnYPqC5Zwsg== X-Received: from ackerleytng-ctop.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:13f8]) (user=ackerleytng job=sendgmr) by 2002:a81:7653:0:b0:54f:a60c:12eb with SMTP id j19-20020a817653000000b0054fa60c12ebmr10693783ywk.1.1683071767464; Tue, 02 May 2023 16:56:07 -0700 (PDT) Date: Tue, 2 May 2023 23:56:02 +0000 In-Reply-To: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.40.1.495.gc816e09b53d-goog Message-ID: <98624c2f481966492b4eb8272aef747790229b73.1683069252.git.ackerleytng@google.com> Subject: [PATCH 1/2] mm: filemap: Add filemap_has_folio function From: Ackerley Tng To: akpm@linux-foundation.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, mike.kravetz@oracle.com, muchun.song@linux.dev, willy@infradead.org, sidhartha.kumar@oracle.com, jhubbard@nvidia.com Cc: vannapurve@google.com, erdemaktas@google.com, Ackerley Tng X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL 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-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1764830001650426889?= X-GMAIL-MSGID: =?utf-8?q?1764830001650426889?= filemap_has_folio() will return whether there is a folio at a given index in a mapping. This function does not affect the folio refcount. Signed-off-by: Ackerley Tng --- include/linux/pagemap.h | 1 + mm/filemap.c | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h index a56308a9d1a4..e49f07cdbff7 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -508,6 +508,7 @@ pgoff_t page_cache_prev_miss(struct address_space *mapping, #define FGP_WRITEBEGIN (FGP_LOCK | FGP_WRITE | FGP_CREAT | FGP_STABLE) +bool filemap_has_folio(struct address_space *mapping, pgoff_t index); void *filemap_get_entry(struct address_space *mapping, pgoff_t index); struct folio *__filemap_get_folio(struct address_space *mapping, pgoff_t index, int fgp_flags, gfp_t gfp); diff --git a/mm/filemap.c b/mm/filemap.c index a34abfe8c654..a7a6e229e33d 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -1835,6 +1835,23 @@ EXPORT_SYMBOL(page_cache_prev_miss); * folio_put(). */ +/** + * filemap_has_folio - Check if filemap has a folio at given index + * @mapping: The address_space to search. + * @index: The page index. + * + * Unlike filemap_get_entry, this does not increment refcount of the folio. + * + * Return: true if folio exists else false. + */ +bool filemap_has_folio(struct address_space *mapping, pgoff_t index) +{ + void *entry = xa_load(&mapping->i_pages, index); + + return entry && !xa_is_value(entry); +} +EXPORT_SYMBOL(filemap_has_folio); + /* * filemap_get_entry - Get a page cache entry. * @mapping: the address_space to search