Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp110125rwr; Tue, 2 May 2023 16:59:05 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7BLhLHy78ICnUcQFAOZ0nQsJSCicTp4ibYfQC+kmZywBMc5Ysv3+6rMfAXFZBv92l2fnCD X-Received: by 2002:a17:90a:4685:b0:233:fb7d:845a with SMTP id z5-20020a17090a468500b00233fb7d845amr19967900pjf.4.1683071945532; Tue, 02 May 2023 16:59:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683071945; cv=none; d=google.com; s=arc-20160816; b=hT1EPaPZetbramQ2tG83ckUd31VxwMegUhiW5B3co3YtGPq8cFHNGNWt/i75cEJWal DgpPJgAjuOuEiVgZmS4RawY/OazB1l+mybKCMnkWexKkUyw9IFPmY2Nrw3Oa8r5aAZup eecqh/CefFVEvCZWRidIrjEJjZ81AkhZfTUrv9PSvM2Af8j30wxeSJG86LhRx/qK0iyn wMT0YKlb6BBo9J87jGBMHkayzhZA0iFYfjWkJKl4eFLTIp9k/1ojuFErdiU7cdEyf0E+ hF9LWBhSTQMZHFwkVXMMYz85yCu7fl2DLlEvcBri6H37TL7xYN1NNYgzBUdFP2Pjqw/5 TGdw== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 126-20020a630484000000b004fb95253a18si32766761pge.376.2023.05.02.16.58.31; Tue, 02 May 2023 16:59:05 -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 S229768AbjEBX4N (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 Content-Type: text/plain; charset="UTF-8" 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 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 -- 2.40.1.495.gc816e09b53d-goog