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: 13229393 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 84BD5C77B75 for ; Tue, 2 May 2023 23:56:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 24AD56B0072; Tue, 2 May 2023 19:56:08 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1AC486B0074; Tue, 2 May 2023 19:56:08 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F3EFB6B0075; Tue, 2 May 2023 19:56:07 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) by kanga.kvack.org (Postfix) with ESMTP id D6F676B0072 for ; Tue, 2 May 2023 19:56:07 -0400 (EDT) Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-556011695d1so75245277b3.1 for ; Tue, 02 May 2023 16:56:07 -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=Y2IO2GFqH5SzwUZQtWoL4l4XzGw2kMPS2zoZHwiS2G9TOV2GGRyrU7PmxZGERlI4GQ CX+2CGkwDdJ40gs7/a1VBrUAMes6lG7lGwmMrwL2i/irrwRl4hBqoxTPrMTipb0C51kb s+c9a3zbCOOkvJIPETVVBqmqfHoPu7WK3DRiuErfed9IXoiisKDKeq/yZ9vvlYez38hk NGLdl+Z9TGM9JMt0LGJVk5pFk2QGMGfkFPUH3+uj5fj+sKuiBEqKEbAWiAiX1tSQw3dj YlphHaXIORY1izjYQsFKFydxfLN5RcqUcJv16Nyn/V0IeMf0qsHm40Hxpvs03BUNIrld f3AQ== X-Gm-Message-State: AC+VfDwP9h3SicKA+5jy4WB8Di9MMR+SacoRFWoRajkJz7MsbQ3T+Dq1 0wzQJUV2yo05yyUAHvxhoAExLAdiEOKGdRXZ7Q== X-Google-Smtp-Source: ACHHUZ4q9/YhcCBGN0gQnRI8Ol1Z4ZZs3Rm5jmAnbsCWwCheFAJAc64ACgZuO2mDTRSg0K7U9fnxqYL2vTo7g2S1Ng== 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-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: 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