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 7BCE6D5B845 for ; Tue, 29 Oct 2024 00:20:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D16436B00A7; Mon, 28 Oct 2024 20:20:49 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CC4E26B00AA; Mon, 28 Oct 2024 20:20:49 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B65896B00AC; Mon, 28 Oct 2024 20:20:49 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 97F4E6B00A7 for ; Mon, 28 Oct 2024 20:20:49 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 16EB31607F7 for ; Tue, 29 Oct 2024 00:20:49 +0000 (UTC) X-FDA: 82724733126.19.88E68BF Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.9]) by imf06.hostedemail.com (Postfix) with ESMTP id 28A4F180006 for ; Tue, 29 Oct 2024 00:20:28 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=mNSvH2IK; spf=pass (imf06.hostedemail.com: domain of ying.huang@intel.com designates 198.175.65.9 as permitted sender) smtp.mailfrom=ying.huang@intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1730161166; a=rsa-sha256; cv=none; b=CwwBkMsOizS1Wz2wM8gTtUawbF3bEzjiWagVt4W0PkMsjSTtybpF8VfESIlpmJmpS5iU4f QOSfshjmv5jvJK1k9B4iql3HNFctrWtGXgKvpjVjS8f8Qhn3Iz3w238A+32FtLfUVE9nu9 tDREM4iZSlNWnhY1oTCXJnJ8dVwRzdA= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=mNSvH2IK; spf=pass (imf06.hostedemail.com: domain of ying.huang@intel.com designates 198.175.65.9 as permitted sender) smtp.mailfrom=ying.huang@intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1730161166; h=from:from:sender: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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=n2DARhqX4GYcxzVQvIQwrBfYvcwriRhNc2zDU0QSs1Y=; b=g3BUgUp87Tb92Ce/dX2549tnQbr5Z1aqSofoM8+K4gFkSHJtPilnsD25uHQwy09wfmIvfs IYiNtqpTMdCDFF0LGho9x0QF/hLpzi1ZJ4f8WEWTGnVxgfoo6T6SxS/6xtL4YlqZKgC7Hx uBzIpgX2QwkVgX5Qq/YNVwg8ZLGR9qc= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730161247; x=1761697247; h=from:to:cc:subject:in-reply-to:references:date: message-id:mime-version; bh=eDYQTz0cUxiILv3RQ0GED/Yvh8CRPXEqZcmH1uCJ/p0=; b=mNSvH2IKHpjA10hejHDCnHaOeec4KqrjVdqouuOUYzM7XrzVR0TBxvBz hJ2IsK7I8iDuzJlKGiJ3tg2k1ziKdwNAzKpKSetSvA9+fR2LVcjb6ikGd YNB0pBQ0IoKVV9yXaVIhh3iWamsLeqJ+aAFyBrIjyQjGECAwbLh1lcUW0 /TJ4I5rmZuW1/9m5qyt445vpVRkWaOHuvBaxV3K2GHF1j4HJcG/idos3v ShzWGvXYnjzybNliBanLFPInIzWqJ4XxXcmYc6WJ0aagOcTlIsyhXwUEl KF+n482lB+nZDC7Z5m3CRvqAw8VTtQELCtFEKrrWlTxM7V+stQwfBF+Xi Q==; X-CSE-ConnectionGUID: q3hJIBKWQxSSz3VmsW+G5Q== X-CSE-MsgGUID: TE05NThCSuK9uSfkBAdFOA== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="52336906" X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="52336906" Received: from orviesa006.jf.intel.com ([10.64.159.146]) by orvoesa101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Oct 2024 17:20:18 -0700 X-CSE-ConnectionGUID: FJcDQSIrTDCWYFnwoHfEow== X-CSE-MsgGUID: pbsMikqGQr6/BMZFA+A5Og== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,240,1725346800"; d="scan'208";a="81932934" Received: from yhuang6-desk2.sh.intel.com (HELO yhuang6-desk2.ccr.corp.intel.com) ([10.238.208.55]) by orviesa006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Oct 2024 17:20:15 -0700 From: "Huang, Ying" To: Gregory Price Cc: Shakeel Butt , linux-kernel@vger.kernel.org, linux-mm@kvack.org, kernel-team@meta.com, akpm@linux-foundation.org, weixugc@google.com, dave.hansen@linux.intel.com, osalvador@suse.de, shy828301@gmail.com, stable@vger.kernel.org Subject: Re: [PATCH] vmscan,migrate: fix double-decrement on node stats when demoting pages In-Reply-To: (Gregory Price's message of "Mon, 28 Oct 2024 10:39:31 -0400") References: <20241025141724.17927-1-gourry@gourry.net> Date: Tue, 29 Oct 2024 08:16:41 +0800 Message-ID: <87r07zwyom.fsf@yhuang6-desk2.ccr.corp.intel.com> User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain; charset=ascii X-Stat-Signature: thocrq3ytxwnhagrk91o9j4tmc5df61m X-Rspamd-Queue-Id: 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+Nx36WnbQIYXWQy3woj+vcCKujjqSaOEBO4uXnnHqYnnbEhPxWuD8e7EfTdOkr2FVa119Fjn3tqjy1zGz98/Wk69jNnL9bXAiGRFE0Xrmn2ySgLi/buq2MWVi0BhHyPDCEqkreklZho+4jQo+H5n3s/qxGyk13utScxahK9v1h6FQEmhPUOBDoduWMCV22tLHtGp+txLRp6jNjzknJfip8Wlb5Gi7PbfH+9VV 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: Gregory Price writes: > On Sun, Oct 27, 2024 at 10:24:10PM -0700, Shakeel Butt wrote: >> On Fri, Oct 25, 2024 at 10:17:24AM GMT, Gregory Price wrote: >> > When numa balancing is enabled with demotion, vmscan will call >> > migrate_pages when shrinking LRUs. Successful demotions will >> > cause node vmstat numbers to double-decrement, leading to an >> > imbalanced page count. The result is dmesg output like such: >> > >> > $ cat /proc/sys/vm/stat_refresh >> > >> > [77383.088417] vmstat_refresh: nr_isolated_anon -103212 >> > [77383.088417] vmstat_refresh: nr_isolated_file -899642 >> > >> > This negative value may impact compaction and reclaim throttling. >> > >> > The double-decrement occurs in the migrate_pages path: >> > >> > caller to shrink_folio_list decrements the count >> > shrink_folio_list >> > demote_folio_list >> > migrate_pages >> > migrate_pages_batch >> > migrate_folio_move >> > migrate_folio_done >> > mod_node_page_state(-ve) <- second decrement >> > >> > This path happens for SUCCESSFUL migrations, not failures. Typically >> > callers to migrate_pages are required to handle putback/accounting for >> > failures, but this is already handled in the shrink code. >> > >> > When accounting for migrations, instead do not decrement the count >> > when the migration reason is MR_DEMOTION. As of v6.11, this demotion >> > logic is the only source of MR_DEMOTION. >> > >> > Signed-off-by: Gregory Price >> > Fixes: 26aa2d199d6f2 ("mm/migrate: demote pages during reclaim") >> > Cc: stable@vger.kernel.org >> >> Reviewed-by: Shakeel Butt >> >> This patch looks good for stable backports. For future I wonder if >> instead of migrate_pages(), the caller providing the isolated folios, >> manages the isolated stats (increments and decrements) similar to how >> reclaim does it. >> > > Note that even if you provided the folios, you'd likely still end up in > migrate_pages_batch/migrate_folio_move and subsequently the same accounting > path. Probably there's some refactoring we can do to make the accounting > more obvious - it is very subtle here. I agree with Shakeel here. It's better for the caller who isolates the folios to increase and decrease the isolation counter. And yes, some refactoring is required. -- Best Regards, Huang, Ying >> > --- >> > mm/migrate.c | 2 +- >> > 1 file changed, 1 insertion(+), 1 deletion(-) >> > >> > diff --git a/mm/migrate.c b/mm/migrate.c >> > index 923ea80ba744..e3aac274cf16 100644 >> > --- a/mm/migrate.c >> > +++ b/mm/migrate.c >> > @@ -1099,7 +1099,7 @@ static void migrate_folio_done(struct folio *src, >> > * not accounted to NR_ISOLATED_*. They can be recognized >> > * as __folio_test_movable >> > */ >> > - if (likely(!__folio_test_movable(src))) >> > + if (likely(!__folio_test_movable(src)) && reason != MR_DEMOTION) >> > mod_node_page_state(folio_pgdat(src), NR_ISOLATED_ANON + >> > folio_is_file_lru(src), -folio_nr_pages(src)); >> > >> > -- >> > 2.43.0 >> >