From: Gregory Price <gourry@gourry.net>
To: Shakeel Butt <shakeel.butt@linux.dev>
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
Date: Mon, 28 Oct 2024 10:39:31 -0400 [thread overview]
Message-ID: <Zx-iI33-I4YYOEbB@PC2K9PVX.TheFacebook.com> (raw)
In-Reply-To: <mjfsmy5naqj2oimgelvual6zpfinbugmbqy7kmbs2c2f7ll5jr@z4rl5zzdvrat>
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 <gourry@gourry.net>
> > Fixes: 26aa2d199d6f2 ("mm/migrate: demote pages during reclaim")
> > Cc: stable@vger.kernel.org
>
> Reviewed-by: Shakeel Butt <shakeel.butt@linux.dev>
>
> 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
> >
next prev parent reply other threads:[~2024-10-28 14:39 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-25 14:17 Gregory Price
2024-10-28 4:39 ` Huang, Ying
2024-10-28 5:24 ` Shakeel Butt
2024-10-28 14:39 ` Gregory Price [this message]
2024-10-29 0:16 ` Huang, Ying
2024-10-28 16:05 ` Davidlohr Bueso
2024-10-28 20:45 ` Yang Shi
2024-10-28 21:25 ` Gregory Price
2024-10-29 0:34 ` Huang, Ying
2024-10-29 13:14 ` Gregory Price
2024-10-29 8:40 ` Oscar Salvador
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Zx-iI33-I4YYOEbB@PC2K9PVX.TheFacebook.com \
--to=gourry@gourry.net \
--cc=akpm@linux-foundation.org \
--cc=dave.hansen@linux.intel.com \
--cc=kernel-team@meta.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=osalvador@suse.de \
--cc=shakeel.butt@linux.dev \
--cc=shy828301@gmail.com \
--cc=stable@vger.kernel.org \
--cc=weixugc@google.com \
--cc=ying.huang@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox