From patchwork Mon Feb 19 06:27:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13562207 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 8F319C5475B for ; Mon, 19 Feb 2024 06:27:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A63628D000A; Mon, 19 Feb 2024 01:27:42 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 9ECD28D0008; Mon, 19 Feb 2024 01:27:42 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7A3C38D000A; Mon, 19 Feb 2024 01:27:42 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 610518D0008 for ; Mon, 19 Feb 2024 01:27:42 -0500 (EST) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 085104023D for ; Mon, 19 Feb 2024 06:27:42 +0000 (UTC) X-FDA: 81807572364.14.2B39EB8 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf07.hostedemail.com (Postfix) with ESMTP id 525E74000C for ; Mon, 19 Feb 2024 06:27:40 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=wCSCFJdh; dmarc=none; spf=none (imf07.hostedemail.com: domain of BATV+994827af29a55d2021e7+7484+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+994827af29a55d2021e7+7484+infradead.org+hch@bombadil.srs.infradead.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1708324060; 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=PKxPHKzpQ4kwpuIEhYrsnVzQ37Gdt6u06KSfR24TJS0=; b=vnkPM6TV34H4AycsJjIJHlb8CYnRFluE0WY5wnm5mrdxcCD79UYYoNExXymnlCMrn38g3W 1tzVTkB+n2WnpSLln8eG2c9g6ugJeVqc/Rk33+r1IGXh0geWrAARLC50S3nMlTvOPf6hEP uN+tpYHX1AwriUKjWYBdU9ivscHS2JU= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=wCSCFJdh; dmarc=none; spf=none (imf07.hostedemail.com: domain of BATV+994827af29a55d2021e7+7484+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+994827af29a55d2021e7+7484+infradead.org+hch@bombadil.srs.infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708324060; a=rsa-sha256; cv=none; b=thKdt+oIDSxgXSs14g6IoYUzWodVJPFA4jQX2mBOl+Yw0MS1bH+SsE9kA2byPUhD+OpQK1 NA3Ul42KqlfRkolWTsYy65cfgb3bp8XYe5lSLzjXdMRNYK9OumUMP1M/llZVtKBf7WwOoh itoa2WWoqXbIgZYr0LI+YbeApD+7Wl0= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=PKxPHKzpQ4kwpuIEhYrsnVzQ37Gdt6u06KSfR24TJS0=; b=wCSCFJdhZ+pJGYDDB2gcwfsxyv DtHYc5mwCOcHLH6FBHeIpogSXZLO5pgQmclOZKqEof3kUHtHsfClwuGjkwXSSMADZ6vm1mDQ6LEGn ux1rXGEaynPi8UjoiYBcMmvRodaNcrtkLAwrv3omOM1tCDyB8aT5Y3h+LqEQSus9JZCjqBctqUrv2 2+UGwLkTs7qEbBVZ4GrW+JdNQTzjJdpDMgDK3QDDasrwxOhNgSLNGRJM3xVfQKi3n6rxkhYf5CDv2 6b1YubOqwKG2nX3KbvEWgkKQOIo3wbx6BE8TXo0XOj5buU17oLKM+MgtV/+r+QozoaoHw0NfhoQbf wygPpU9w==; Received: from 2a02-8389-2341-5b80-39d3-4735-9a3c-88d8.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:39d3:4735:9a3c:88d8] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1rbx7p-00000009F79-0oF6; Mon, 19 Feb 2024 06:27:37 +0000 From: Christoph Hellwig To: Chandan Babu R , "Darrick J. Wong" , Hugh Dickins , Andrew Morton Cc: Hui Su , linux-xfs@vger.kernel.org, linux-mm@kvack.org, Matthew Wilcox Subject: [PATCH 05/22] shmem: export shmem_get_folio Date: Mon, 19 Feb 2024 07:27:13 +0100 Message-Id: <20240219062730.3031391-6-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240219062730.3031391-1-hch@lst.de> References: <20240219062730.3031391-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 525E74000C X-Stat-Signature: uqa7hiksz3cd7z3fimmoyb9jn8p7ad7k X-Rspam-User: X-HE-Tag: 1708324060-377066 X-HE-Meta: U2FsdGVkX1/xSpoc8bCy/V2nENxnkOb/KyS5hZyQ6P5fWEaxfq515HGBlbViTSqZnYnad06nLXI+29aoO5uuMqOh5rChR4/OQuZQw7ZbBiJYGMUdTuOHiPn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WfOuDK01ilB2EoqQ+ovEpdmtOGr/BYD8vbFk+rKszLdqQJUsOgkHLH07ubnTI5CUYg2ALRhSBYoQg9OgcIYtyC3zmJ6+BoNl1J5pRJgV9VJi3Yc3Ps+IRO/sqELTLfGiT2v5jNVJOHaJxLI8j06Hy1oFSTMAgq0NM+NdZ36Y3xySdFaZmdJvWYxReNSBv9qYo+qamd43W4DJe3GGoDy0lmDia/+MWlVC18n6BcB7dAPccPfZyOdicbCdvAiNJqcTBLPogZwJmmlfYRnWIaNks57/LyDgR5nVjqGb+ANO9X3iKUgxUZgNguFdb7PLdCh3rn1Le+moqChlZsVog8l1MT92dbHoU5gO3rXXJ8naM2iHX4HDOlkWc3/OcBWn4Y= 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: List-Subscribe: List-Unsubscribe: Export shmem_get_folio as a slightly lower-level variant of shmem_read_folio_gfp. This will be useful for XFS xfile use cases that want to pass SGP_NOALLOC or get a locked page, which the thin shmem_read_folio_gfp wrapper can't provide. Signed-off-by: Christoph Hellwig Reviewed-by: Matthew Wilcox (Oracle) Reviewed-by: Darrick J. Wong --- mm/shmem.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/mm/shmem.c b/mm/shmem.c index ad533b2f0721a7..aeb1fd19ea3f72 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -2137,12 +2137,32 @@ static int shmem_get_folio_gfp(struct inode *inode, pgoff_t index, return error; } +/** + * shmem_get_folio - find, and lock a shmem folio. + * @inode: inode to search + * @index: the page index. + * @foliop: pointer to the folio if found + * @sgp: SGP_* flags to control behavior + * + * Looks up the page cache entry at @inode & @index. If a folio is + * present, it is returned locked with an increased refcount. + * + * When no folio is found, the behavior depends on @sgp: + * - for SGP_READ, *foliop is %NULL and 0 is returned + * - for SGP_NOALLOC, *foliop is %NULL and -ENOENT is returned + * - for all other flags a new folio is allocated, inserted into the + * page cache and returned locked in @foliop. + * + * Context: May sleep. + * Return: 0 if successful, else a negative error code. + */ int shmem_get_folio(struct inode *inode, pgoff_t index, struct folio **foliop, enum sgp_type sgp) { return shmem_get_folio_gfp(inode, index, foliop, sgp, mapping_gfp_mask(inode->i_mapping), NULL, NULL); } +EXPORT_SYMBOL_GPL(shmem_get_folio); /* * This is like autoremove_wake_function, but it removes the wait queue