From patchwork Thu Jan 11 14:37:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Smirnov X-Patchwork-Id: 187403 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2411:b0:101:2151:f287 with SMTP id m17csp1491936dyi; Thu, 11 Jan 2024 06:39:42 -0800 (PST) X-Google-Smtp-Source: AGHT+IF8N7CAC5slMGgBzslcWLAShMB3ycOKCuL7wyRyhvhMB/W1lofaZxSSb+aInM/eD2ziu/hv X-Received: by 2002:a05:6214:20ec:b0:67f:ad04:871f with SMTP id 12-20020a05621420ec00b0067fad04871fmr1215228qvk.114.1704983981667; Thu, 11 Jan 2024 06:39:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704983981; cv=none; d=google.com; s=arc-20160816; b=EcRKP/o4Hope+o2gyM1/PKdJV4jc6Oos5mi3BF7GzULb/KeqHFTTgLKg0l5C1mpO4l v4qpeJe1pIrhbGt8WD6SwNrEUXV82de8JXp52wUIU/JoMFem8XKTT064IkiU5u98DNlv hI7tvHhbX3UF5/6/O1Gh1lP1rkYgfVQMIvL8rNHzYcEgdV+DIPXuNXd7wrzchxnoIefQ jrVMN37uKIxpraxpzjHU5eHa5nzje2MW2KVw3rksdIXBVMOQ2tGbmcukn5eLZEffRZZY oc9N6D+1fQmIP/NMjsoHoGUBfThBydz//nsK/KM2qJqQqrDwCHnqwtHNiff5q30u3hU5 Mhig== ARC-Message-Signature: i=1; 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=286O+sPTZMWddfKTsyMrO89j21hyKTRv693tpd0bq1k=; fh=btMxYaoVVQU/OzYJMEKvBvCH51RczG4+ciHI0bq78e0=; b=D76iwRAYMMp0if6/WvoG11I+qZC05Lp5emcGxUxNmQcEmPG29zh5ZrDNEyy155f0mA wXZ9H4QQfoffQzw9FQZRvtwb9kyrtikwO6CWiwDuI/LMdjlJrVOCv3NzjXWESPzPHJ5I VqWLOKDm0Rdeo8j784bhr5eDuFD3dEfwVbwA96RgSuTv9/GY7PfKTExMrUyL/s06rI0j Ta/KNGWzylHULKFMB+8f7UmU+AopTBkC8vAjauZOnJwWvpOG32zV/CxLEX3D0O1tPHKI 9RsS8X2Bxb3EzLpjQFZANRAQPpupnDFpzahygp1pGEmG+3674y+TfJ1qD/draSplkAmN HwKA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-23717-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-23717-ouuuleilei=gmail.com@vger.kernel.org" Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id 22-20020ac84e96000000b00429c17dcce3si1034804qtp.173.2024.01.11.06.39.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jan 2024 06:39:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-23717-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-23717-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-23717-ouuuleilei=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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 740AB1C233D5 for ; Thu, 11 Jan 2024 14:39:41 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 158124D5BC; Thu, 11 Jan 2024 14:38:54 +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 6F5D64C3C4; Thu, 11 Jan 2024 14:38:49 +0000 (UTC) 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, 11 Jan 2024 17:38:39 +0300 From: Roman Smirnov To: , Greg Kroah-Hartman CC: Roman Smirnov , "Matthew Wilcox (Oracle)" , Andrew Morton , Alexey Khoroshilov , Sergey Shtylyov , Karina Yankevich , , , , , Miaohe Lin Subject: [PATCH 5.10 2/2] mm/truncate: Replace page_mapped() call in invalidate_inode_page() Date: Thu, 11 Jan 2024 14:37:47 +0000 Message-ID: <20240111143747.4418-3-r.smirnov@omp.ru> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240111143747.4418-1-r.smirnov@omp.ru> References: <20240111143747.4418-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 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/11/2024 14:25:57 X-KSE-AntiSpam-Status: KAS_STATUS_NOT_DETECTED X-KSE-AntiSpam-Method: none X-KSE-AntiSpam-Rate: 0 X-KSE-AntiSpam-Info: Lua profiles 182570 [Jan 11 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;r.smirnovsmtp.omp.ru:7.1.1;d41d8cd98f00b204e9800998ecf8427e.com:7.1.1;omp.ru: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/11/2024 14:31:00 X-KSE-Antivirus-Interceptor-Info: scan successful X-KSE-Antivirus-Info: Clean, bases: 1/11/2024 1:37:00 PM X-KSE-Attachment-Filter-Triggered-Rules: Clean X-KSE-Attachment-Filter-Triggered-Filters: Clean X-KSE-BulkMessagesFiltering-Scan-Result: InTheLimit X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787805283847971194 X-GMAIL-MSGID: 1787805283847971194 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. [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: Matthew Wilcox (Oracle) Reviewed-by: Miaohe Lin Signed-off-by: Roman Smirnov --- mm/truncate.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mm/truncate.c b/mm/truncate.c index 03998fd86e4a..72d6c62756fd 100644 --- a/mm/truncate.c +++ b/mm/truncate.c @@ -232,7 +232,8 @@ int invalidate_inode_page(struct page *page) return 0; if (PageDirty(page) || PageWriteback(page)) return 0; - if (page_mapped(page)) + if (page_ref_count(page) > + compound_nr(page) + page_has_private(page) + 1) return 0; if (page_has_private(page) && !try_to_release_page(page, 0)) return 0;