From patchwork Mon Jul 10 20:43:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13307608 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 991A1EB64DC for ; Mon, 10 Jul 2023 20:44:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CFF458E0001; Mon, 10 Jul 2023 16:43:48 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A3B538E000A; Mon, 10 Jul 2023 16:43:48 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DE48D8E0006; Mon, 10 Jul 2023 16:43:47 -0400 (EDT) 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 C81FD8E0009 for ; Mon, 10 Jul 2023 16:43:47 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id A342A1A0248 for ; Mon, 10 Jul 2023 20:43:47 +0000 (UTC) X-FDA: 80996878494.20.5453DFA Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf16.hostedemail.com (Postfix) with ESMTP id 4D74118000F for ; Mon, 10 Jul 2023 20:43:45 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=hnJ+NuJo; 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=1689021826; 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=aGQ2GHttWzJ+Nk3XqgE1qMHvrVsWPVFdkiJHip5axuY=; b=Lv3fTIl9/E8fwbPZ0BN/rUsqHomd9w9PqCze6PC2tbZzk0tz2zQlH6nhx4KJmdm/h6mtpT y/IYtVCMp2uzE9XXaQPxB0LzJ8+7j0MbX3upwFwsk2m7oYOGuozuz/aG8OwPbmhbrDg148 ZI/wmbuhoY3DA+j+GC5XWesa7xdavtY= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1689021826; a=rsa-sha256; cv=none; b=JceugOt6T5xtYQSXMoS9sZTn/YHtZ1l+hObT4xfyzn1KLt41K4u1j62CzHaeCPzxce/y+Q ZgMHBPs1/7ZrJMplEl4//pH/4Rr8bFdzC6SEd4tfKN/Wz5kkzay/jGClvLYuke16u7im26 N0OHUGw87OQ4DPmvqCahAwoy61MHE0c= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=hnJ+NuJo; 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 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=aGQ2GHttWzJ+Nk3XqgE1qMHvrVsWPVFdkiJHip5axuY=; b=hnJ+NuJoHrGWnFQIHj5mwikc3Y f+ynvhq+4B/aEwy8FCPsgFshOQWVrWerLCxpuQBbeUnTyyz1X0U1Nqmo5shKPFaE2oMcX+P2NwLlm Hx6TYojYAi/XeM3hRmgQle7OUe0P4VkJ/Tt345eZQ34NwKAAmjbTCS8gD+17k8LCVxA5Uw2bKNxGK 2pBd5RYRhgtJ8EnVR9p6jVnQj2YQK6aJ3WeDQX+ZdDJGeDEqNezcYGk0XiuPM9EbIuKOpAhQmmDC0 VsWF9mJJKPpNAkiMNKSDiBc99gmwms10qIVtaqz0HiRd1zfD+6eV29vnvCGa1faKf7Aum+Nodg8wh gzQnfLWQ==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qIxjR-00EuoL-Fj; Mon, 10 Jul 2023 20:43:41 +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 v5 04/38] mm: Add folio_flush_mapping() Date: Mon, 10 Jul 2023 21:43:05 +0100 Message-Id: <20230710204339.3554919-5-willy@infradead.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20230710204339.3554919-1-willy@infradead.org> References: <20230710204339.3554919-1-willy@infradead.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 4D74118000F X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: 7n5s3za9cinz6qpiufjwnwnmkpb7y3cz X-HE-Tag: 1689021825-824120 X-HE-Meta: U2FsdGVkX19yVVXJwCHfLX8VIb+N/2sXNT7Znq6Uh32PL0yG4DLeiqqu7EnuynHGWcm3TJZsRZqWLA7koR0D9vgR5DywOdQCs0LtcId+W+v5f2SZoTpxyDikyeVWOaDuxY+tgICkNh+UD+0+59uvIO/oib8ZyCREX2qaU9TVN6JnZHu3Ik07uUEpBdcq5ADm3RkUvraeDdmhWfhK2AE8Vrtw5EMp+VV6qNPNKZkFHGMkINcqZkg/k49EvseJg57Yps0/h9B79EP3xQvD4WDj84sXbAMcLnbWTTnjgfTwFXlyZJxD/RaX0BLgxbW/9UYR4BQpnqULPzzw0GDj/shMmM59tYHFAAKJhyRG5t3ep1nBjwg0bwF4LoSSfhrRKRclordincSuGzgNBIP1i9d78HrqrEP+jh3ggb4iNA2gJYC18b78lx1AnjkQfwAvKp3723TMh6IKHLM8bWWh+7uBCyUy8s0doVpvXTKvZPK8elgrABmwRRm5CDWlsgpdu2bIADYF8gGUKbCW6UcfNIqkonM2mFEEG/1eIbOBYqkca8Zsi4CVp3TfNk+YwTK8ymnInmewCKmusoUxipbkbo8ub1i/QtWfxXRHoBhtlmIgs1+yFmYCN+YDzZwamTrjc06lw6tqjVgMMVEvR811txbdsm4hRt2QmH5WGZ6ZtcUkvGPBiuqQzIQRyiPnIUpLFLD5MoIorlIS3p377icwIAifnO7gboii1kxL9RBBvfWvFxXzgdisdjmLmddmnjXy93zWMGl8MuSSh+rnPktNDXeXg8Pa+YO2Sh6BGloDGnlTg2af7MZt8ZjeYQ8s80IluVamnxD2bCC1DmEk9m5qCQ6HPMrEzUXgKu4eb8HGql+KV5qpCPzaKOmX5j+IrfEckgRqu1oKnymFHJCRIHW7duHZH/Gi4rTbNUYw7StfNlW2EyUDo1ZifA73q41es8XsHXnOVO2WxVsJ8emTsgEn3av xNwFxVuY qnGBtjzbzBQ5+Crz0eE9yfA63PtiOT4u4sls3pFXxELfMFPV9MbHQKymeTGElnihmdRTM5bNZB2GnsmfH7k71wUHh+1ANm3mAWRwD1G2LRtsQqS7r7+c9IkTHbLyWfTvvwv1/MxlFnjCd+tG6cBLuR6567opzh9pKivQXBQYn9ZzYA/D5oKq0LObgK2siPj+6xMezvvU0jEPFGX5T7zzwP1WzsQ4UfQTwwsizAfOqQBdfbq1P3ONld8RD42DsdhhevE3Ep0WjEayG/ZAeC1TjdfIjEhD+V/KIGahEhZl3JRaQFgz+YZcxKKXNGOrRnpKCc6JCc5A3fAv0s77AAE+SqJNAWA== 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 69b99b61ed72..794e4e55dc38 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)); } /**