From patchwork Tue Feb 28 21:37:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Matthew Wilcox (Oracle)" X-Patchwork-Id: 13155234 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 44E13C7EE31 for ; Tue, 28 Feb 2023 21:37:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EE6A06B007B; Tue, 28 Feb 2023 16:37:45 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id BD68F6B0082; Tue, 28 Feb 2023 16:37:45 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 657E66B0083; Tue, 28 Feb 2023 16:37:45 -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 48CF96B0080 for ; Tue, 28 Feb 2023 16:37:45 -0500 (EST) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id F2B5E1C655A for ; Tue, 28 Feb 2023 21:37:44 +0000 (UTC) X-FDA: 80518012848.18.EF9BC54 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf13.hostedemail.com (Postfix) with ESMTP id 5D2A620012 for ; Tue, 28 Feb 2023 21:37:42 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=V7oeXdyW; spf=none (imf13.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1677620262; 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=4/i61ZL50yz6ye25FSWBiGacTMwROTdk2fb5bLUdjZQ=; b=kBm4bJcdAOiYSVRk9SJHBRWGFdBEmAcJG1ySCjAziMGgRJzjG7FUXS1kStuDlkC6miIfNF 6w/TWxWsVZRwXDcyCuD8FN4syqu+E/aavBSMnxC+wGtPoXVF+3HhWHoNC04gc9BzbKwRSv 8V+NYGZcnP2DMAnx5AIjYqFmzVXxPvM= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=V7oeXdyW; spf=none (imf13.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1677620262; a=rsa-sha256; cv=none; b=q1Z1TJgPpR+8fHxTYJBDgLuICENDy1oTQKxSbluD5bYVMz/AZs2MDq6A3+VQLI96s43Ql0 G/Js9oGMC5jzwSbGCgC7DUIUOHlncFrhXL69exjD8VO9g5ahP4ZYK5iUpVnEHgnQpIu+2a LztkxnoLBsUdFQ1ZBLRrRnGxwAqkrXo= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; 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=4/i61ZL50yz6ye25FSWBiGacTMwROTdk2fb5bLUdjZQ=; b=V7oeXdyWrSBQgRuryxvAjDdmK/ PmEA/0paMrtQ6HBE6tePsYJZz6k8Eh2IV/Cduw5PCatHygY5uf1HHh9QXAJPpxd+2Gt1XNNJ38oBs 7jgK2jLi0kEqTGbXcVMBwUjbU8B8InVRi5eVhNtY/7bIXj5PQ0pDmofSBVZsUlt31MoRZzGWn21xe ShtzNNaoqjpLDJEoZAQx6SbSpLUGkzQUxHAln8/TjK2Ab5c/gDiu2+elc2SGxedi70Wnn4dR15nyK UfY0ANK45Jvq1+6mUEFQF1tYFeZx/1od4+UoclrTdV+pqDp7Fq4FbeDqoDP2CwXIOnaiRJmBGcjTR 1cStI3qg==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1pX7fH-0018oY-P6; Tue, 28 Feb 2023 21:37:39 +0000 From: "Matthew Wilcox (Oracle)" To: linux-mm@kvack.org, linux-arch@vger.kernel.org Cc: "Matthew Wilcox (Oracle)" , linux-kernel@vger.kernel.org Subject: [PATCH v3 03/34] mm: Add folio_flush_mapping() Date: Tue, 28 Feb 2023 21:37:06 +0000 Message-Id: <20230228213738.272178-4-willy@infradead.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20230228213738.272178-1-willy@infradead.org> References: <20230228213738.272178-1-willy@infradead.org> MIME-Version: 1.0 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 5D2A620012 X-Stat-Signature: 5in3xeh4t5hmmhjwnbkr6rjjrzookt7h X-Rspam-User: X-HE-Tag: 1677620262-296620 X-HE-Meta: U2FsdGVkX1+NK9KvlQO5Wm34B3TcYkA6RiaZeCN8zCOuNo4pvdtAp6xb/nzu+XQSjG1HZzIi44vUgMPApLtEfOQYXx2UppZSVn3QvY9aXZO2DNzhQMIs4f4KYrR8MJMREcn8BuJ1csS5bM138VFmjqEQmMG9Dxk97GaR7Ehfdk0iM5Drg9BgCtRMXz8p/VyjYbr6bpVpHPTW2rJUk3MGpBrPhF6Me0HgTXrdHb2Zj97qs/s3fUwC+pBXzgRTfQUwOazY5IQHLTz5F6H1j6EmKkYK0LnuToYpjiqA9oqT092HMb9/4/4SYRo36Ic4uTLwosvO4/SywGUFcPp6YCdLgn6uUFBbSITMH1CmFLGBti3Is7AW+uY99aQV3brGaDgwKDrouQe7nB85lQDtv8+eBJFMaUBhHyRyz70xIxyiDYIzAwJvza38fhgk0rJB38uPdxYnDdRaMXNsyGyqE7ovtpzaB+TVhcpD+WOpGeFSzUEwEe6BqWy8YrV0s0vnxCgGxn81+ehvc943jezEFYY5NezKYO6RnOawhri6nBheMKADfbZj8syetZUGjXADhgOaVCsjmko52QM3YpR5qOXeH7k3U7EC5nnSfGC7zTapO6XfR1y5AjDWeKX7CazIaFT1dNCuCNDPZDZcVbwiouY1IDS71/XWaGu/ysuS4W9f48upzzT8GPWZ23BxgwOkw297FX9OtFPd3+O10S0W9cYFrCQibtcAcwZ//uQnvXTkpq0XprdBw6Xc3UHQBMmZT2vKykb5R+5Eziq311VC24NlCRyhCdoFQ6r5Vb0ldNj1XfiEwirZ+94StBQSx9S0cnmUXZRJBwlN4M6P8MqEJ7kucp+frRK4W/JB2v8YcMtHOrQtwH/ZrNQRIjW1Rgss07DLDCDU9rPWfdHDcVDTOY7MpxfGmhM9MyaAUdmbKbKQ/XVkxzRP54BN2A/Rn7BLLKAvHakLaKXVLNXvm5PuB66 VtlXOveH nYfDFpmPLP2rleztzclNVYSaNElkv8G2uIFGnSmcqlRtfxTHVbpVExPVsQW4aIR9Sioha2VAZc810+oxqNAIVhwrFthdBk04j94YEFd4JmFTZSLOPcAAUir3Y2YJVb/BEB4FXl6WqjEQA2MZLV8QdFTzXRC+/soQLUjj18T03DVx9l9u7zjqphqwWCisTgk+h17Ahdz8AF4Nfimd97UOqZ7QC/zU2XGJy7sja0UByIXUoznNkOgWsoib7iA== 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 folio equivalent of page_mapping_file(), but rename it to make it clear that it's very different from page_file_mapping(). Theoretically, there's nothing flush-only about it, but there are no other users today, and I doubt there will be; it's almost always more useful to know the swapfile's mapping or the swapcache's mapping. Signed-off-by: Matthew Wilcox (Oracle) --- include/linux/pagemap.h | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h index 51b75b89730e..1b1ba3d5100d 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -369,6 +369,26 @@ static inline struct address_space *folio_file_mapping(struct folio *folio) return folio->mapping; } +/** + * folio_flush_mapping - Find the file mapping this folio belongs to. + * @folio: The folio. + * + * For folios which are in the page cache, return the mapping that this + * page belongs to. Anonymous folios return NULL, even if they're in + * the swap cache. Other kinds of folio also return NULL. + * + * This is ONLY used by architecture cache flushing code. If you aren't + * writing cache flushing code, you want either folio_mapping() or + * folio_file_mapping(). + */ +static inline struct address_space *folio_flush_mapping(struct folio *folio) +{ + if (unlikely(folio_test_swapcache(folio))) + return NULL; + + return folio_mapping(folio); +} + static inline struct address_space *page_file_mapping(struct page *page) { return folio_file_mapping(page_folio(page)); @@ -379,11 +399,7 @@ static inline struct address_space *page_file_mapping(struct page *page) */ static inline struct address_space *page_mapping_file(struct page *page) { - struct folio *folio = page_folio(page); - - if (unlikely(folio_test_swapcache(folio))) - return NULL; - return folio_mapping(folio); + return folio_flush_mapping(page_folio(page)); } /**