From patchwork Mon Feb 27 17:57:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 62078 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp2563718wrd; Mon, 27 Feb 2023 10:03:38 -0800 (PST) X-Google-Smtp-Source: AK7set+rKlGrhm7f+Aylr++hKR0cokvml+kcSVnVF3x0mY5YDJLr8npSJMj2eAUOr7QeVmVJmh6d X-Received: by 2002:a05:6a20:431f:b0:cb:c276:5873 with SMTP id h31-20020a056a20431f00b000cbc2765873mr375744pzk.22.1677521018308; Mon, 27 Feb 2023 10:03:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677521018; cv=none; d=google.com; s=arc-20160816; b=wIsspWPjvjPRPkFaAL5IBnb/E9Q0CmrvItonnLUCgSS+wfuC6IgsWmxB0/RL3CVjeM lM6Pa5eaL+fKfeY6bmuwWDUSaBxxeSBC6QNMl1gEeN7cG3eXxLddDTqa833pQjvok1Jj okivAPG+JLJSFF8zycI8egKYSVBDDkfFLrXS3838gSQyQUUYqgzApmgp0X1NoGlLQWUa G6B6Uvemg58J4NenwSeSwzrR/dmZazNLyx4RfwNIpW7vZftZ+7aBKyUUY0t2jc1FZMtP +HkeRCYBObZtzTvDwAP25xWZL3sRjqTsbhs8SbNNJvrb7wJywA62Ys6aWpK8M8FiRkMd xTlA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=aaXlbA2/BvRg6HHDAadnVZCwlkGxkg/4CEs3FrmdfUo=; b=h/ev5nEDAk6nVWpXCjUVHHM1sZMKzZfW44fqJF92VmWeIczZfcv1i02bXGZOX+wDT8 kZozLXfdmLIMg5z0OPkJoOUEasgf36DVkOo1vxS4Y2R/Na0sH8fdaipERaYQNKVecl8Z D0PS4l6Mcs2oN6B1o6bFGTd/SaWgswPgu0q8CVGPxK7/zUxWUshSOC0sBoTkN9IDRZGs rYL7XsX3SodDBE4dabwL9Z07Qdf969ERBOUOgmiyp6bAhNiKgGE3ElAxAScksqNfznR8 /O3gs4I/bO/O9BqF951hZ+lsLBnKQ5poBF7cXpkFruzqMQftDJhfXwWD6OEiFKSXUADQ DQww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=HXN9VHt2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t128-20020a635f86000000b004fbd53187ecsi7468434pgb.258.2023.02.27.10.03.25; Mon, 27 Feb 2023 10:03:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=HXN9VHt2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230527AbjB0R7W (ORCPT + 99 others); Mon, 27 Feb 2023 12:59:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49266 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230258AbjB0R6W (ORCPT ); Mon, 27 Feb 2023 12:58:22 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 138F844B1; Mon, 27 Feb 2023 09:57:54 -0800 (PST) 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=aaXlbA2/BvRg6HHDAadnVZCwlkGxkg/4CEs3FrmdfUo=; b=HXN9VHt2EFXUIhhFmEnV3MVjKc W8bimZyhdFaayUqTL0aWIlWF4u8HSlrCZsPP6sAgvIwuQhK9Xu6jYzgV7d8u496T7uVOMbbb7lKs2 DiMor3aKe0pkza1VKFtk5sS4gi0rR8DzvDgOvfd+wGjAUOw1XZ3HutdOhQgQHoIB51MWYkybo0Mhy EPb4RTDx8bELqsN7hhScXf6q+G0xfo0BODTUyYYkw+Jzst9swDFfIaImLaFI07iafp0gD5Sh/CUdj NjVT0AXThjTjSN7OuG3+iOmCQUo+eSPJvGLcNaowabymnfQKN0Ul+3Xlfew5Gx285pk6Lsj1fXtFk OabJICJg==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1pWhkt-000IWt-9T; Mon, 27 Feb 2023 17:57:43 +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 v2 03/30] mm: Add folio_flush_mapping() Date: Mon, 27 Feb 2023 17:57:14 +0000 Message-Id: <20230227175741.71216-4-willy@infradead.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20230227175741.71216-1-willy@infradead.org> References: <20230227175741.71216-1-willy@infradead.org> MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759008278915449459?= X-GMAIL-MSGID: =?utf-8?q?1759008278915449459?= 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..647c5a036a97 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 swapcache_mapping(folio); + + return folio->mapping; +} + 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)); } /**