Received: by 2002:a05:7412:5112:b0:fa:6e18:a558 with SMTP id fm18csp1750916rdb; Thu, 25 Jan 2024 05:16:15 -0800 (PST) X-Google-Smtp-Source: AGHT+IFuMdcrsV2thGytbq2XHqiIaYOeJc/Nusc3Ru3+moYAvER31MX7R5l2qvF+kxD4BxwWcXMv X-Received: by 2002:a92:280e:0:b0:361:9911:f2ee with SMTP id l14-20020a92280e000000b003619911f2eemr1031649ilf.45.1706188575383; Thu, 25 Jan 2024 05:16:15 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706188575; cv=pass; d=google.com; s=arc-20160816; b=n9xJKCy51nItA1X3wYzaMc23HnWo9GuMwP3RRHU1TbLi+PVrNpRb7B7PRh69Mb1fKp YPfA1aBCN5qtplv7LGFWgzBU6yXi3XQym6oV7OziD88yjymAjHwLmRZAf56lx3EfDfR0 JInxZd6zU7zq/V8JaoJ3ouCx4JTDzUU6TAFHnLNV0wB5zhs1gD+QMpxKkwXBGv5kHWEn uA/96dQ59TDvpSCBgBpq0Bv2ojpdWJNHyUr8A0Ygx7G/ayvjGO0nUKevAiM45ek7yc+7 wg6yygPchx2nngg8jrHARcjR4AVynxyNMzjAhl6yKSGVUCL11y8oGhAOQJGWqhwAwW6g NjZg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=O4bxFIxTxliAhbxcpp9TKWKH4jIswUEZlfCRJGbzDmk=; fh=TMLyVqPlfAK50oxQKnRZLy5V8GKcWC7IJTIuGNsGS1I=; b=bvt3nA5qRsMq8LPSDo9T2JtWxyjH2UXatZ9IJdNRxVthYBCAVZ0B9smNnqM6Yuyywx ez+Wx3kTHXMX5I0ODI0jLp1gAh6T9OCvl+WR5cb1yTyN9HgfqAxCAzANvXdakBjBaHzv W4bazlfoSK0zpvZAALZEhOXbHTmi+9oJaP56LqyINPAQ/xoSVNWYfsfiIP92w0n2Xoxi S4v4EilY0RTjEOzuzxz+iYb4j6LoiDZcLo6CDdTxN4akws1I5upSwUKnfowrcDzwRRWJ zaYNsnLnnYaB6A41/6wnR49p987I62zBMH3Nnm+jRkOoXhYVpHotQevwPwN7y9nucFp2 dIdg== ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=omp.ru); spf=pass (google.com: domain of linux-kernel+bounces-38626-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-38626-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id q20-20020a635054000000b005ced5bbfcb3si13147262pgl.392.2024.01.25.05.16.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Jan 2024 05:16:15 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-38626-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=omp.ru); spf=pass (google.com: domain of linux-kernel+bounces-38626-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-38626-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 5CC13B26216 for ; Thu, 25 Jan 2024 13:10:50 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 943DD50A96; Thu, 25 Jan 2024 13:10:18 +0000 (UTC) Received: from mx01.omp.ru (mx01.omp.ru [90.154.21.10]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B2B344F61E; Thu, 25 Jan 2024 13:10:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.154.21.10 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706188218; cv=none; b=TvvYqUfJdwME54kjjmMPDCutjlBK73bqpKDcuwA6NMgz+h236r586o/r4QPp+L0jND4zfwdCYLcsjyZlx9P3daUrSp22DWHwak2ndXJ2weO4/BQVUk8kQyVx5KBDl+ReNfdqiE7FDBMpIiC6J9SeleLxj9+sAaAFASz32csan+4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706188218; c=relaxed/simple; bh=LQFpv4X1hT+QUG0VEtK7cRc54lvNGdJoRVXIOPkgluo=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=bb6nHZwfngV3LqmR00dt9fewtLqZ/MwMhjfGlCL1nRZdkx/dbpnpwFksDDjRfefruPUhOlI8txGt3p3dys+R4+OWQG85ZAMMs9KFv/NSkB41XVwQTyfgeDvxAm1aZXBVhnCZJAcnOEqCfcd4ucctQ2Qlfx7yRTXOvZvKVB8ENLU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=omp.ru; spf=pass smtp.mailfrom=omp.ru; arc=none smtp.client-ip=90.154.21.10 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=omp.ru Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=omp.ru Received: from r.smirnovsmtp.omp.ru (10.189.215.22) by msexch01.omp.ru (10.188.4.12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.2.1258.12; Thu, 25 Jan 2024 16:10:05 +0300 From: Roman Smirnov To: , Greg Kroah-Hartman CC: Roman Smirnov , "Matthew Wilcox (Oracle)" , Andrew Morton , Alexey Khoroshilov , Sergey Shtylyov , Karina Yankevich , , , , Subject: [PATCH 5.10/5.15 v2 1/1 RFC] mm/truncate: Replace page_mapped() call in invalidate_inode_page() Date: Thu, 25 Jan 2024 13:09:47 +0000 Message-ID: <20240125130947.600632-2-r.smirnov@omp.ru> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240125130947.600632-1-r.smirnov@omp.ru> References: <20240125130947.600632-1-r.smirnov@omp.ru> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: msexch02.omp.ru (10.188.4.13) To msexch01.omp.ru (10.188.4.12) X-KSE-ServerInfo: msexch01.omp.ru, 9 X-KSE-AntiSpam-Interceptor-Info: scan successful X-KSE-AntiSpam-Version: 6.1.0, Database issued on: 01/25/2024 12:50:25 X-KSE-AntiSpam-Status: KAS_STATUS_NOT_DETECTED X-KSE-AntiSpam-Method: none X-KSE-AntiSpam-Rate: 0 X-KSE-AntiSpam-Info: Lua profiles 182932 [Jan 25 2024] X-KSE-AntiSpam-Info: Version: 6.1.0.3 X-KSE-AntiSpam-Info: Envelope from: r.smirnov@omp.ru X-KSE-AntiSpam-Info: LuaCore: 7 0.3.7 6d6bf5bd8eea7373134f756a2fd73e9456bb7d1a X-KSE-AntiSpam-Info: {Tracking_from_domain_doesnt_match_to} X-KSE-AntiSpam-Info: 127.0.0.199:7.1.2;omp.ru:7.1.1;r.smirnovsmtp.omp.ru:7.1.1;d41d8cd98f00b204e9800998ecf8427e.com:7.1.1 X-KSE-AntiSpam-Info: FromAlignment: s X-KSE-AntiSpam-Info: Rate: 0 X-KSE-AntiSpam-Info: Status: not_detected X-KSE-AntiSpam-Info: Method: none X-KSE-AntiSpam-Info: Auth:dkim=none X-KSE-Antiphishing-Info: Clean X-KSE-Antiphishing-ScanningType: Heuristic X-KSE-Antiphishing-Method: None X-KSE-Antiphishing-Bases: 01/25/2024 12:53:00 X-KSE-Antivirus-Interceptor-Info: scan successful X-KSE-Antivirus-Info: Clean, bases: 1/25/2024 10:40:00 AM X-KSE-Attachment-Filter-Triggered-Rules: Clean X-KSE-Attachment-Filter-Triggered-Filters: Clean X-KSE-BulkMessagesFiltering-Scan-Result: InTheLimit From: "Matthew Wilcox (Oracle)" commit e41c81d0d30e1a6ebf408feaf561f80cac4457dc upstream. folio_mapped() is expensive because it has to check each page's mapcount field. A cheaper check is whether there are any extra references to the page, other than the one we own, one from the page private data and the ones held by the page cache. The call to remove_mapping() will fail in any case if it cannot freeze the refcount, but failing here avoids cycling the i_pages spinlock. Signed-off-by: Matthew Wilcox (Oracle) Reviewed-by: Miaohe Lin [Roman: replaced folio_ref_count() call with page_ref_count(), folio_nr_pages() call with compound_nr(), and folio_has_private() call with page_has_private()] Signed-off-by: Roman Smirnov --- mm/truncate.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mm/truncate.c b/mm/truncate.c index 8914ca4ce4b1..989bc7785d55 100644 --- a/mm/truncate.c +++ b/mm/truncate.c @@ -256,7 +256,9 @@ int invalidate_inode_page(struct page *page) return 0; if (PageDirty(page) || PageWriteback(page)) return 0; - if (page_mapped(page)) + /* The refcount will be elevated if the page is used by the system */ + if (page_ref_count(page) > + compound_nr(page) + page_has_private(page) + 1) return 0; return invalidate_complete_page(mapping, page); } -- 2.34.1