From patchwork Thu Apr 11 15:32:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zi Yan X-Patchwork-Id: 13626161 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 5134AC4345F for ; Thu, 11 Apr 2024 15:32:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C35266B007B; Thu, 11 Apr 2024 11:32:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BE5596B0082; Thu, 11 Apr 2024 11:32:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AACB46B0083; Thu, 11 Apr 2024 11:32:40 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 8E2CA6B007B for ; Thu, 11 Apr 2024 11:32:40 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 31B8A160C26 for ; Thu, 11 Apr 2024 15:32:40 +0000 (UTC) X-FDA: 81997643280.01.ECD2E0B Received: from wfout2-smtp.messagingengine.com (wfout2-smtp.messagingengine.com [64.147.123.145]) by imf18.hostedemail.com (Postfix) with ESMTP id CBE8C1C001E for ; Thu, 11 Apr 2024 15:32:37 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=sent.com header.s=fm2 header.b="Q HJ0LVR"; dkim=pass header.d=messagingengine.com header.s=fm2 header.b="rrDlv/VD"; dmarc=pass (policy=none) header.from=sent.com; spf=pass (imf18.hostedemail.com: domain of zi.yan@sent.com designates 64.147.123.145 as permitted sender) smtp.mailfrom=zi.yan@sent.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712849558; h=from:from:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:in-reply-to: references:dkim-signature; bh=KdSkiWAB+vDwE4VKWUPrvuNlR/TihrAEV6L79eFI5ZQ=; b=LWhZNthyXq3qtInrsKvS+H7vd1+x0M+3jIM7oub8mQE4u9grIyWDgDNK9/hT/2ERe7eEu+ PIUdTFTY3g5trTXK/TIhodQMMrOllTRVAvrS0QNwgZorK+eQ7lN2tXsZKmofQxh5k0/47S 3YDRQ4SGqJqFWQkgbMEWB2+1ZfF5T6I= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=sent.com header.s=fm2 header.b="Q HJ0LVR"; dkim=pass header.d=messagingengine.com header.s=fm2 header.b="rrDlv/VD"; dmarc=pass (policy=none) header.from=sent.com; spf=pass (imf18.hostedemail.com: domain of zi.yan@sent.com designates 64.147.123.145 as permitted sender) smtp.mailfrom=zi.yan@sent.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712849558; a=rsa-sha256; cv=none; b=hJanmOJxCrBxN91yX70241zuZeulqV6aeBOSkFLqSK7xywffHVKvWK9lZ/pf26iqI1DN0V K1thPemwGLRKPhe+03CG6bQAr3yvB3Y2jhL/TX3MGQCIQTEIsS66spIT0i44Rpf6AgCE7M hFdqFLv/w8MdJCw74HyHDq7qrAqhsVY= Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailfout.west.internal (Postfix) with ESMTP id 752081C000CD; Thu, 11 Apr 2024 11:32:35 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Thu, 11 Apr 2024 11:32:36 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sent.com; h=cc :cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:message-id:mime-version:reply-to :reply-to:subject:subject:to:to; s=fm2; t=1712849554; x= 1712935954; bh=KdSkiWAB+vDwE4VKWUPrvuNlR/TihrAEV6L79eFI5ZQ=; b=Q HJ0LVRusDCl9WofJUn1onmqrSqUqAMyw6HqF03WQEacpYIj67+33AMlN0HrdCkuC 4i+X20NidtzFpZJQ8xCoKsMxrM/zthuBpjU1EGANz5jqLZCOBLORpeFK0K+N+o+g WPAUvMwN+KYFrTuO51rkHQ3ys4OwYFVXBvydgWrgJDJgdOTeDNFXRN3cs/Y8vfMT AW9ou+8jGS5jl5uaqGrtNZ04Len01wUtFTaHoKkD0wItPviV92d5hjc3cCbubm0H K5I0gD7I2NCH94E5iOLaPCCMR8CT0HD+pmbuoD8S49D794j2JdLW+sH9NZ7sL1GX UwmAnnS8ZQowvZM8WsYfw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:message-id:mime-version:reply-to:reply-to :subject:subject:to:to:x-me-proxy:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm2; t=1712849554; x=1712935954; bh=K dSkiWAB+vDwE4VKWUPrvuNlR/TihrAEV6L79eFI5ZQ=; b=rrDlv/VDEMK6irLfP 0s8x+W7HbkF4lRMYw6Ry7bWTRbodWBHDMzfDBjLe9rvJv4KBp8C0Ae5LK3XxNVEy TyoPFiJUiRML9vwpT2Bs4bJrCFueytwcEr7wIgFEAQiUJdwzvHGpZUPXQoDhRwSr CAtcONha58r3B3chAXA5SZ2pbGYm683KrHZkgxxWjgWi+2Dr6VMA2ZRJ8Z77agnx lXuQI2c50PfK5D402SHgKosZEkBoaE4KWP8QKIMtD8gZxyDbjwbdaOKeqYYhe9uD TQ0LunFJOXJLcABuWcgZJAzzC6PBp7n5RXSA6h6gHH6t6pPKDazgkNTqOj8F6RKs w8HlA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrudehkedgkeelucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvvefufffkofhrgggtgfesthekredtredtjeenucfhrhhomhepkghiucgj rghnuceoiihirdihrghnsehsvghnthdrtghomheqnecuggftrfgrthhtvghrnhepueevte ehveduudffveetfeehueekheeutdeuheeiheeileevgeevueffieelfffhnecuvehluhhs thgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepiihirdihrghnsehsvg hnthdrtghomh X-ME-Proxy: Feedback-ID: iccd040f4:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 11 Apr 2024 11:32:34 -0400 (EDT) From: Zi Yan To: linux-mm@kvack.org Cc: Zi Yan , Andrew Morton , "Matthew Wilcox (Oracle)" , Yang Shi , Ryan Roberts , Barry Song <21cnbao@gmail.com>, David Hildenbrand , linux-kernel@vger.kernel.org Subject: [PATCH] mm/rmap: do not add fully unmapped large folio to deferred split list Date: Thu, 11 Apr 2024 11:32:32 -0400 Message-ID: <20240411153232.169560-1-zi.yan@sent.com> X-Mailer: git-send-email 2.43.0 Reply-To: Zi Yan MIME-Version: 1.0 X-Rspamd-Queue-Id: CBE8C1C001E X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: hucdum39uadmwehxhriihmirye19krs5 X-HE-Tag: 1712849557-381406 X-HE-Meta: U2FsdGVkX1/I/C5C/SUZt34FYMgd47OUau2aSaF8sJtzsviRd8r3puZ9PUeOstqsUsTDzbB9WXZa5j72dFYnTTSsZEkpDDCUFQFii7PZS3kkVXWSyYxCBD0lprQXiIrlbJgtbUV5Q7UmZ5LlfBCGUkIko6vwPuXwVF7SS6vTzejBJRc0+fV8Ysz8VqzL2ZYo+vi3nbemgATiWrxAK5udtPUwSg67ic3O6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okOArEIBYfsJMWgJrERqqh8r0lW6/BPRsyeS53YxheMzJKVGsSLtCZWmsrfvYchhsG6tmNyt28B1n/EQMCfZO4b5x1/x3GNunisVU4QtTTYFXete/HH2vkB/hdLdIEeXRYAl/lqoLOSiFUQjKtJqy1SL8A= 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: List-Subscribe: List-Unsubscribe: From: Zi Yan In __folio_remove_rmap(), a large folio is added to deferred split list if any page in a folio loses its final mapping. It is possible that the folio is unmapped fully, but it is unnecessary to add the folio to deferred split list at all. Fix it by checking folio mapcount before adding a folio to deferred split list. Signed-off-by: Zi Yan --- mm/rmap.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) base-commit: ed7c95c95397baff9b40ba9b0919933eee2d7960 diff --git a/mm/rmap.c b/mm/rmap.c index 2608c40dffad..d599a772e282 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -1494,7 +1494,7 @@ static __always_inline void __folio_remove_rmap(struct folio *folio, enum rmap_level level) { atomic_t *mapped = &folio->_nr_pages_mapped; - int last, nr = 0, nr_pmdmapped = 0; + int last, nr = 0, nr_pmdmapped = 0, mapcount = 0; enum node_stat_item idx; __folio_rmap_sanity_checks(folio, page, nr_pages, level); @@ -1506,7 +1506,8 @@ static __always_inline void __folio_remove_rmap(struct folio *folio, break; } - atomic_sub(nr_pages, &folio->_large_mapcount); + mapcount = atomic_sub_return(nr_pages, + &folio->_large_mapcount) + 1; do { last = atomic_add_negative(-1, &page->_mapcount); if (last) { @@ -1554,7 +1555,9 @@ static __always_inline void __folio_remove_rmap(struct folio *folio, * is still mapped. */ if (folio_test_large(folio) && folio_test_anon(folio)) - if (level == RMAP_LEVEL_PTE || nr < nr_pmdmapped) + if ((level == RMAP_LEVEL_PTE && + mapcount != 0) || + (level == RMAP_LEVEL_PMD && nr < nr_pmdmapped)) deferred_split_folio(folio); }