From mboxrd@z Thu Jan 1 00:00:00 1970 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 11C0BC433EF for ; Fri, 25 Mar 2022 01:09:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9A6FE6B0071; Thu, 24 Mar 2022 21:09:56 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 957226B0074; Thu, 24 Mar 2022 21:09:56 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 81EA96B0075; Thu, 24 Mar 2022 21:09:56 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.28]) by kanga.kvack.org (Postfix) with ESMTP id 6FBE36B0071 for ; Thu, 24 Mar 2022 21:09:56 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 1E92324A4A for ; Fri, 25 Mar 2022 01:09:56 +0000 (UTC) X-FDA: 79281126792.05.6FE4031 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by imf09.hostedemail.com (Postfix) with ESMTP id A7CFA140008 for ; Fri, 25 Mar 2022 01:09:55 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 78556B81DE2; Fri, 25 Mar 2022 01:09:54 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 25AF1C340EC; Fri, 25 Mar 2022 01:09:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1648170593; bh=ScfNCgSDD6pedCbQrNdSqkDjkRn4PGxjSfzYW38zyu8=; h=Date:To:From:In-Reply-To:Subject:From; b=ME5XJuqNdtRNxpyTqyXPwaigsRpJfLz/OY6ZQZyQ8ELJWN6h+HYH6srxnJkv3RMYX tUPC0QxonVrI0z/LZLfHK6Zmhuf4gzcdlyEb+EZxd3T8wOUqPpN11SJBqIhrmpjoVQ AtzWLIKrWfKpKATY5+tBiG1dmxdyqGGDcZ7Em2Fo= Date: Thu, 24 Mar 2022 18:09:52 -0700 To: willy@infradead.org,hughd@google.com,akpm@linux-foundation.org,patches@lists.linux.dev,linux-mm@kvack.org,mm-commits@vger.kernel.org,torvalds@linux-foundation.org,akpm@linux-foundation.org From: Andrew Morton In-Reply-To: <20220324180758.96b1ac7e17675d6bc474485e@linux-foundation.org> Subject: [patch 026/114] mm: filemap_unaccount_folio() large skip mapcount fixup Message-Id: <20220325010953.25AF1C340EC@smtp.kernel.org> X-Rspam-User: X-Stat-Signature: y7efeizgtdwgsobumd3mna38e75f8j1d Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=ME5XJuqN; spf=pass (imf09.hostedemail.com: domain of akpm@linux-foundation.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org; dmarc=none X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: A7CFA140008 X-HE-Tag: 1648170595-4400 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: From: Hugh Dickins Subject: mm: filemap_unaccount_folio() large skip mapcount fixup The page_mapcount_reset() when folio_mapped() while mapping_exiting() was devised long before there were huge or compound pages in the cache. It is still valid for small pages, but not at all clear what's right to check and reset on large pages. Just don't try when folio_test_large(). Link: https://lkml.kernel.org/r/879c4426-4122-da9c-1a86-697f2c9a083@google.com Signed-off-by: Hugh Dickins Cc: Matthew Wilcox Signed-off-by: Andrew Morton --- mm/filemap.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) --- a/mm/filemap.c~mm-filemap_unaccount_folio-large-skip-mapcount-fixup +++ a/mm/filemap.c @@ -152,25 +152,25 @@ static void filemap_unaccount_folio(stru VM_BUG_ON_FOLIO(folio_mapped(folio), folio); if (!IS_ENABLED(CONFIG_DEBUG_VM) && unlikely(folio_mapped(folio))) { - int mapcount; - pr_alert("BUG: Bad page cache in process %s pfn:%05lx\n", current->comm, folio_pfn(folio)); dump_page(&folio->page, "still mapped when deleted"); dump_stack(); add_taint(TAINT_BAD_PAGE, LOCKDEP_NOW_UNRELIABLE); - mapcount = page_mapcount(&folio->page); - if (mapping_exiting(mapping) && - folio_ref_count(folio) >= mapcount + 2) { - /* - * All vmas have already been torn down, so it's - * a good bet that actually the folio is unmapped, - * and we'd prefer not to leak it: if we're wrong, - * some other bad page check should catch it later. - */ - page_mapcount_reset(&folio->page); - folio_ref_sub(folio, mapcount); + if (mapping_exiting(mapping) && !folio_test_large(folio)) { + int mapcount = page_mapcount(&folio->page); + + if (folio_ref_count(folio) >= mapcount + 2) { + /* + * All vmas have already been torn down, so it's + * a good bet that actually the page is unmapped + * and we'd rather not leak it: if we're wrong, + * another bad page check should catch it later. + */ + page_mapcount_reset(&folio->page); + folio_ref_sub(folio, mapcount); + } } } _