From patchwork Wed Aug 2 15:13:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13338355 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 E94BCC001DF for ; Wed, 2 Aug 2023 15:14:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B17C02801A4; Wed, 2 Aug 2023 11:14:19 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A56EA2801A3; Wed, 2 Aug 2023 11:14:19 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8C9EB2801A2; Wed, 2 Aug 2023 11:14:19 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 5C9AB2801A1 for ; Wed, 2 Aug 2023 11:14:19 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 0DE89C0FB2 for ; Wed, 2 Aug 2023 15:14:19 +0000 (UTC) X-FDA: 81079510638.28.7E2E53F Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf16.hostedemail.com (Postfix) with ESMTP id 39E31180026 for ; Wed, 2 Aug 2023 15:14:16 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=QrowCvRJ; spf=none (imf16.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=1690989257; 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=uh/dLU05HXiEbSg20w2LmQ0wgPaOMm+owDlujvnA+nk=; b=yvRNPcfyv4jx4YizdOjt9P92RWmIplCZ9I32Xp56cIpqp/UlewXssalQk0TA7T7qnuqIoB lhFlA8/s4fmS+LVcnjz1FkoUl/Dv5AxKzrevimnZqEuPgpdIJAtzteXT61M2hapx92R5e7 SGNLH0HLqiuunYvU5y8MbRqBtgH8gik= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=QrowCvRJ; spf=none (imf16.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=1690989257; a=rsa-sha256; cv=none; b=jGZS+mTpZ76/3RX9giXHVKGRKzMm6YhNYbBbMRlOhfEudwt00Gd2YrPSay2GzN3J7MdKu0 ptnvG9qGg3oVsVZu/2UVRtNiu1CYQzhk5xScRq7aPpC02XawG7Rxhecdh1TPpRFm5jSxWD Kf9BP2iN3jxc1JK8fD0V0/NRhzEMAFU= 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=uh/dLU05HXiEbSg20w2LmQ0wgPaOMm+owDlujvnA+nk=; b=QrowCvRJ89eB18rNesY1xCrndt rfqJLhx5g6XpNfP22H0oocN9EwYAt5Cc/PboODlXqt5QzyjwDBQ4fNwyoj2aOxATvpaVYYMCyBgY7 pbAc5FwRFbjtQjrjik2+JD0c2FKxNpzRCCd3DyfuGGmTSM0uWCI49O5ay5Ct3tiU+ej0DDpA210mW NaXwpRVsrFDP4Bqmmt3B25hCYTfT9WMn2KmAhvlTIxF2Ygc7nqIQDJdylwaaiGy7Hjk980g/7FROT 3VrkiMbsI2pQK5PRdr/dMlwNzV6g5TlCp6B+t1Q6AKz/YjdV6yszP1j0tRuRrRPg3Pnvf9BktFT/T QV2/NySw==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qRDY8-00Ffii-AF; Wed, 02 Aug 2023 15:14:08 +0000 From: "Matthew Wilcox (Oracle)" To: Andrew Morton Cc: "Matthew Wilcox (Oracle)" , linux-arch@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Mike Rapoport , Anshuman Khandual Subject: [PATCH v6 04/38] mm: Add folio_flush_mapping() Date: Wed, 2 Aug 2023 16:13:32 +0100 Message-Id: <20230802151406.3735276-5-willy@infradead.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20230802151406.3735276-1-willy@infradead.org> References: <20230802151406.3735276-1-willy@infradead.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 39E31180026 X-Rspam-User: X-Stat-Signature: tzrdtascfemkdki1qooknshuhezz39qf X-Rspamd-Server: rspam01 X-HE-Tag: 1690989256-62260 X-HE-Meta: U2FsdGVkX184F7YlExhf2BkLBG1fgAqbNAbL590SLS5PEVyEZ7o4rarbBHlgMvEbwR53osyH8PcMwo3dlhZ+USaM1HlkmpqeHbGJXj2LtCkUf5AQBSfAfrMh+d96TJeoHT5Y7JrMVO7l+SwgjYHPz+fc/LMvRMzStMFmRqVbhDH8YK6qT8TDWFBD4NX9Hrbw5A2Ium6e+zlAQLWElbCz2CtYzUVJn5RsrLe5UhF4xiv/DuaKRWfvkWqtpgrgmZeFuCcXCXbUvTxcq/PZBjfxdibwHq7H+NGKMDfIlZk4E1t+ptys58tctDBACWT/KaQ2d6hHdhFKn1Ijjtj52Ja7cZx+f9SWev+jA0dYbt4TJ5bzyyStWz26wnz3/d7YIBBwzSPHS4Vew27AXGQXgcYdGFvW8hA1FSqA2EktJ/XqvbuLPl6/LPIIXjrwWYLZUt8X5VjFRo9f3PKFsYUVBazf+BZadp/7cSandCha0EnLBEALmawtDLvS4r9TNo1GyxtK4RFnRkme0i/xVHYkdYcanRSvrTFqznN+f1/WaViSAcbB81nT8GBB60Swmo5yGFL2M7et+6k3vdUFHSZZydyoWntReYRppC6id+lBS5KPyDZ7BvynPVLOuERjxOx3iWHriZzdKhmo5phH2f2qvtjgHXrSw5hZu9zD0+Cvd4I27vRqYH546GmzJiXZRheed38rIruhUxi7Uy7ibtN0r1axOkeWa5jHP3xwuC+3x1AmcVl8JcGd2RyYYtuN2W0PwmFoZt01WfpkvMStv5izS+v4PVtKc24iESyU0e2AjT38OsDrIVPQv6Q/vBDz5y+zZhierc6vA9vmHmxyRNpxdsd1/iE0Qw88ILqSe2J4SYxxQzmaV8t7KzQMuDaCPcuq+8a/sz5fd/qCE8vmfhHLaOrYVPmbq5r8SMAuPESseU/iGDbTO9amUXoB2hGdmfTqhKMb2Z4VB1RcGXv91RXQl7e S12sfewp 2dgxWLbAplVx2Nt0SZCGZyBE7NQANuFvG6KTblfkyXCe2VXKPRUTwQ+LhwQHtWgm6M5oKUh15wiQOG+/f4wEonFprrWmCVN1SOuAFl43Kl76TbXUqeYNH8sWTPxdm3/Xl+D97xfvldT9t+2+3VA05EOI+7x+3N3I1gkNvvJ4moDmqi+jxMslo5+ytYXVHFqr67SiHm+Xp74hCHl6kK6IN29LAPJUo8ZrwVBqnDVCjU2dpd4XDx1foQ7low/Ptc2A4bxzy2gpfj8vsypFrRH2zwV8kM3qMB4x9dHWomppZR1emKdGoT2ilbq2LtL6yuT/Agn35Y8rZGY00wKXowSJ5yVOU3Q== 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) Acked-by: Mike Rapoport (IBM) Reviewed-by: Anshuman Khandual --- 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 04c0fc6f81b3..bd522a64b714 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -389,6 +389,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)); @@ -399,11 +419,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)); } /**