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 04354D33990 for ; Mon, 28 Oct 2024 14:39:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8552C6B0085; Mon, 28 Oct 2024 10:39:30 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8059D6B0089; Mon, 28 Oct 2024 10:39:30 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6CD6D6B008A; Mon, 28 Oct 2024 10:39:30 -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 4B7486B0085 for ; Mon, 28 Oct 2024 10:39:30 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id E8E7340274 for ; Mon, 28 Oct 2024 14:39:29 +0000 (UTC) X-FDA: 82723268796.16.1391F66 Received: from mail-qk1-f181.google.com (mail-qk1-f181.google.com [209.85.222.181]) by imf30.hostedemail.com (Postfix) with ESMTP id BC6C280019 for ; Mon, 28 Oct 2024 14:38:43 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=gourry.net header.s=google header.b=Gj4+DS+c; dmarc=none; spf=pass (imf30.hostedemail.com: domain of gourry@gourry.net designates 209.85.222.181 as permitted sender) smtp.mailfrom=gourry@gourry.net ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1730126314; a=rsa-sha256; cv=none; b=zDSk9L9BC8ljDO2EI7Rs0uWYiEB7UDKBhEAjLVZRUN1y3OTIFgxgDN5FxxMIf82uukFc+N /F36qBn6cI75vvLuOYBxGsFlogM5aNY1Jwti/RRU/bQo/ZX6Xt5oC/0akt3KKQqULm4K7D MZ+kHUS08cGXmtwgyurYdHwZw6HbWXo= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=gourry.net header.s=google header.b=Gj4+DS+c; dmarc=none; spf=pass (imf30.hostedemail.com: domain of gourry@gourry.net designates 209.85.222.181 as permitted sender) smtp.mailfrom=gourry@gourry.net ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1730126314; 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=ugG/qQ91MoDgp/XfSym9AwO2ZJCFXAJqXvA7n9+izLE=; b=nEV1odd/C9nTl/dfreV138dtfoQGGCDLYd3lm7VkGzd5fcWUJzIYP+XTp8DqDQZPWa+7hQ PmUlaXMclPLWdS/DDL1ue7ixdwparSntqkLenlZrNwsrzGvLOKeyIku1LbMbrq5HD0fu3O 0rVHZlLgYM70eDg4B0eQgmowQjm+bPM= Received: by mail-qk1-f181.google.com with SMTP id af79cd13be357-7b1418058bbso326317485a.3 for ; Mon, 28 Oct 2024 07:39:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gourry.net; s=google; t=1730126367; x=1730731167; darn=kvack.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=ugG/qQ91MoDgp/XfSym9AwO2ZJCFXAJqXvA7n9+izLE=; b=Gj4+DS+cxzs7Inay+FtKzZs4hkgGFhUSPyXplii9q0+cSutX4YT/5ZuFHe+m6LBmLq EdsdlF8CvJOB6QHEkQ4YfY/GAFEE3WSDrWDyAPNFAxoObwdFaj3m+3PtqHcgsVSK28jG NwX/iNdsFVPiHVXKIalxUgtOXqHhTbR2ugvaivG6MFfkn7r/M/okrdmUptR0Te15hXPM 7RW/4bqIqQEIAWk/GBgilH1/URh1C6tPPJvyjDfWj9O3PZKtFHTLpJmf8cd3Gwf0lKGm PyJImY0K+A/ckFU9h7yGcvK97Mw7Rlw+oQ8n2enx2YYJ50IpOWBEZwHn+pvvezOu5jFi EXXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730126367; x=1730731167; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=ugG/qQ91MoDgp/XfSym9AwO2ZJCFXAJqXvA7n9+izLE=; b=rTID5CcOPwKChd8SROkV9BBSOLlYvZLsVeI6Jqna2nxYK1eSfGQp2KctMQAU8j4J5e /nYTGSZWGEjo0O9YtqIsE4bXLoMBjMzWY76j4QZb0B9/5rsMJ/Cyz2Z5aX3qzA6y6BND GoevjGYj6joMkiKjm3m1gQP8PBYW0ac0chVsjQoU+H+1fKD2bc7MWSokFCIUMN8PusG+ at3G3U1nEAxlDq3SCZ+tO0F2cWVfIySlu4U5xV0t/whhjGqMnUm0ZnrCq0Hztz/wGjyn Y/Byu2OA61rEcM9WaBBb0q9Z4YnSQdexFLlLmh1IdheKVDMFoxVNzo/2M2gHrIyxHzU7 tfnQ== X-Forwarded-Encrypted: i=1; AJvYcCUGTUZkVpElNeIOwQH0APv2vN1LXc5XCrd6jMn8KSs+3vjFqC1oCp61g0iYPvbAMlUaaNc9qWEtRA==@kvack.org X-Gm-Message-State: AOJu0YxeKQ7WpoLR903VYxRsgaKrN6judb8PBsvw0pZfdZ4YLFBlE8s3 /45sKWhEELxW4gM+i/f9lhwD5H/JQB9F1qXqv9e0JGUCYQK2Bx0u+hMnqa4mxDY= X-Google-Smtp-Source: AGHT+IEK686cLan9wZ/Ri6zx93A/eMAWg77IfwvrBwtwRpqtwNCNZxaNf/uMbabpGOd/ZmNyFfpvxA== X-Received: by 2002:a05:620a:4249:b0:7b1:35f4:fe19 with SMTP id af79cd13be357-7b193f5d7ccmr1171250485a.58.1730126367131; Mon, 28 Oct 2024 07:39:27 -0700 (PDT) Received: from PC2K9PVX.TheFacebook.com (pool-173-79-56-208.washdc.fios.verizon.net. [173.79.56.208]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7b18d27a555sm325528685a.14.2024.10.28.07.39.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Oct 2024 07:39:26 -0700 (PDT) Date: Mon, 28 Oct 2024 10:39:31 -0400 From: Gregory Price To: Shakeel Butt Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, kernel-team@meta.com, akpm@linux-foundation.org, ying.huang@intel.com, 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 Message-ID: References: <20241025141724.17927-1-gourry@gourry.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspam-User: X-Rspamd-Queue-Id: BC6C280019 X-Rspamd-Server: rspam01 X-Stat-Signature: afhh1fooretwnm4mbh73orqx348ddegz X-HE-Tag: 1730126323-707126 X-HE-Meta: U2FsdGVkX1+rYqy6FWDJbKINi5YSK4pUob476B7J01o7sbReVeAEoagHWwRFG/G4a5z6J9UZ+NDaClpgYMMkGCyHRSBzxPdbwUzVSoIGXOirll0xl5+jfB/3YXVDucM2BH1ZB36SqSrULu3kMfYh3T44reOKKwyA7ltMju67m3IJ72GSXHB6afZiq30FsRN6cEn2BhhIPbo4bcq2SPPXKPQdZAn081YHEGAO8jhqmSh8HUpgLlKQZV37kk0piHXktrWb+vFfkz92rzyCxyUMoPqraHylB9lDtJGuooDmKjYsqrRq9NeacQl+YEcXER/dQTb/NL7antSFx4G68phZ4mJoVvyO+L+Pmn4rt7+RKJnCwR0hwzKDWg22TU6DfP6Z8olxADH/S+QkfuKJKPLDCGHBlx3fzi7WilNOYwJcKbY4MAB8pnj6PP9B6jQMk0G+/CWjO5fA9r1GHN134Uk1eeAmMVKEfdMFK+Ang4yddJY2JIG3jaW/DVG40RO3Ak440YD5WNGPmTcoLd1chVhtBYBq2ksxkoJPx6n1Uijap2M8zoif87mLWFQyTbEYS92YhJQGjMKmAbmtqGoptBt6lWxkyZMd7kkwI0w0Xv9287yTfGpyQpZl/ewihJLtY+XqvCXn2TwpuzVMbvQ6BNKzfDGniP6WZUHU381MvwXQK+wliabQU9G3gVMlf8Aw4Zn2jYa8fq6Q13NKQ+SNe4owjawoqNBfxzItryxQcbq3sts55mR6TXRDZLSpymiFyiebt2rmFSOF4Cet4c8twvqAWbiW0qDZ7gsfI7J5BzzsvpTfbxGihDmvzWsqA7S7dqVfXrrvDTQEKR9SDdZ/WKCr33dGcXeDVGUIF1EkpAtVPVDhjWC2a1Wxwj15SArQJ1JXku6gftYWOqW6N9PLjstAofpvqOSb7oHahxtspxFoHx8z2pK1qV+SortRAvzi+jxe9xsqMhBJAnPX/tZ+M/y KRusqCs3 TGK+57czW6UkgmetQrIuN0uY6SqJKCLzhNNvEoGh6F6zEuKAQa4cDpFPkTeN7X8629SXFjwPz4hsMdqc5hTp00SwCDONiMYizq3YEbfLLtJdgMDcOM/gogsYmKKBfFYGMbpCJD85wJMaPl1chn3E8YUAom3KvzA0u2Go50HaYxoqQWEFtNc7cmnycHrcsLADND75h03SxiBJ75OomCQ+qZhlKnzMIkVJavbvyh22R3WPzMCsvoA0hdMU/p/pdMDHkQmHkoHieN3dzTKbSe13u0IPYX8aoMeyCUfY/uoUikESK1jaYf9JmqBOYP8gNEH/qKlYsYOP7slIOp8Me/C/VVtnaFMosVjSxVRe19ZPgFSkDwBGK8uODEfDRBg== 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: 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. > > --- > > 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 > >