* Re: [PATCH] mm: migrate: restore the nmask after successfully allocating on the target node
@ 2025-03-26 5:54 Simon Wang (王传国)
2025-03-28 13:41 ` Oscar Salvador
0 siblings, 1 reply; 7+ messages in thread
From: Simon Wang (王传国) @ 2025-03-26 5:54 UTC (permalink / raw)
To: Matthew Wilcox; +Cc: akpm, mhiramat, linux-mm, linux-kernel
> On Wed, Mar 26, 2025 at 11:12:18AM +0800, wangchuanguo wrote:
> > If memory is successfully allocated on the target node and the
> > function directly returns without value restore for nmask, non-first
> > migration operations in migrate_pages() by again label may ignore the
> > nmask settings, thereby allowing new memory allocations for migration
> > on any node.
>
> I have no opinion on whether this is the right thing to do or not, but if it is
>
I don't think so. When memory allocation fails on the target node, there is already a recovery operation for the nmask value below. Therefore, the nmask value should only be restored when memory allocation is successfully completed on the target node.
> > +++ b/mm/vmscan.c
> > @@ -1026,8 +1026,10 @@ struct folio *alloc_migrate_folio(struct folio *src,
> unsigned long private)
> > mtc->nmask = NULL;
> > mtc->gfp_mask |= __GFP_THISNODE;
> > dst = alloc_migration_target(src, (unsigned long)mtc);
> > - if (dst)
> > + if (dst) {
> > + mtc->nmask = allowed_mask;
> > return dst;
> > + }
> >
> > mtc->gfp_mask &= ~__GFP_THISNODE;
> > mtc->nmask = allowed_mask;
>
> this should be:
>
> dst = alloc_migration_target(src, (unsigned long)mtc);
> + mtc->nmask = allowed_mask;
> if (dst)
> return dst;
>
> mtc->gfp_mask &= ~__GFP_THISNODE;
> - mtc->nmask = allowed_mask;
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH] mm: migrate: restore the nmask after successfully allocating on the target node
2025-03-26 5:54 [PATCH] mm: migrate: restore the nmask after successfully allocating on the target node Simon Wang (王传国)
@ 2025-03-28 13:41 ` Oscar Salvador
0 siblings, 0 replies; 7+ messages in thread
From: Oscar Salvador @ 2025-03-28 13:41 UTC (permalink / raw)
To: Simon Wang (王传国)
Cc: Matthew Wilcox, akpm, mhiramat, linux-mm, linux-kernel
On Wed, Mar 26, 2025 at 05:54:35AM +0000, Simon Wang (王传国) wrote:
>
> > On Wed, Mar 26, 2025 at 11:12:18AM +0800, wangchuanguo wrote:
> > > If memory is successfully allocated on the target node and the
> > > function directly returns without value restore for nmask, non-first
> > > migration operations in migrate_pages() by again label may ignore the
> > > nmask settings, thereby allowing new memory allocations for migration
> > > on any node.
> >
> > I have no opinion on whether this is the right thing to do or not, but if it is
> >
>
> I don't think so. When memory allocation fails on the target node, there is already a recovery operation for the nmask value below. Therefore, the nmask value should only be restored when memory allocation is successfully completed on the target node.
But that is not what the code is doing, is it? With the changes applied I mean.
You are restoring mtc->nmask in case you managed to allocate for __GFP_THISNODE
and after you clear the flag, so we might as well do it just once at the beginning
after calling alloc_migration_target for the first time.
--
Oscar Salvador
SUSE Labs
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] mm: migrate: restore the nmask after successfully allocating on the target node
@ 2025-04-01 1:06 Simon Wang (王传国)
0 siblings, 0 replies; 7+ messages in thread
From: Simon Wang (王传国) @ 2025-04-01 1:06 UTC (permalink / raw)
To: Oscar Salvador; +Cc: akpm, mhiramat, linux-mm, linux-kernel
>
> On Wed, Mar 26, 2025 at 11:12:18AM +0800, wangchuanguo wrote:
> > If memory is successfully allocated on the target node and the
> > function directly returns without value restore for nmask, non-first
> > migration operations in migrate_pages() by again label may ignore the
> > nmask settings, thereby allowing new memory allocations for migration
> > on any node.
> >
> > Signed-off-by: wangchuanguo <wangchuanguo@inspur.com>
>
> Unless I am missing something this looks reasonable, but I whonder why
> nobody noticed it before.
> It is a path that should be pretty exercised.
>
>
> --
> Oscar Salvador
> SUSE Labs
I tested it, and even when the nmask is set to all zeros, memory allocation still occurs on other nodes.
I suspect this is because the bug expands the range of eligible nodes for memory allocation instead of causing allocation failures, which is why it has gone unnoticed.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] mm: migrate: restore the nmask after successfully allocating on the target node
@ 2025-04-01 0:48 Simon Wang (王传国)
0 siblings, 0 replies; 7+ messages in thread
From: Simon Wang (王传国) @ 2025-04-01 0:48 UTC (permalink / raw)
To: Oscar Salvador; +Cc: Matthew Wilcox, akpm, mhiramat, linux-mm, linux-kernel
> >
> > > On Wed, Mar 26, 2025 at 11:12:18AM +0800, wangchuanguo wrote:
> > > > If memory is successfully allocated on the target node and the
> > > > function directly returns without value restore for nmask,
> > > > non-first migration operations in migrate_pages() by again label
> > > > may ignore the nmask settings, thereby allowing new memory
> > > > allocations for migration on any node.
> > >
> > > I have no opinion on whether this is the right thing to do or not,
> > > but if it is
> > >
> >
> > I don't think so. When memory allocation fails on the target node, there is
> already a recovery operation for the nmask value below. Therefore, the nmask
> value should only be restored when memory allocation is successfully
> completed on the target node.
>
> But that is not what the code is doing, is it? With the changes applied I mean.
> You are restoring mtc->nmask in case you managed to allocate for
> __GFP_THISNODE and after you clear the flag, so we might as well do it just
> once at the beginning after calling alloc_migration_target for the first time.
>
>
> --
> Oscar Salvador
> SUSE Labs
Yes, you're right. My apologies—I overlooked a line of code earlier.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH] mm: migrate: restore the nmask after successfully allocating on the target node
@ 2025-03-26 3:12 wangchuanguo
2025-03-26 3:28 ` Matthew Wilcox
2025-03-28 13:44 ` Oscar Salvador
0 siblings, 2 replies; 7+ messages in thread
From: wangchuanguo @ 2025-03-26 3:12 UTC (permalink / raw)
To: akpm; +Cc: mhiramat, linux-mm, linux-kernel, wangchuanguo
If memory is successfully allocated on the target node and the
function directly returns without value restore for nmask,
non-first migration operations in migrate_pages() by again label
may ignore the nmask settings, thereby allowing new memory
allocations for migration on any node.
Signed-off-by: wangchuanguo <wangchuanguo@inspur.com>
---
mm/vmscan.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/mm/vmscan.c b/mm/vmscan.c
index b620d74b0f66..9467b2acef28 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -1026,8 +1026,10 @@ struct folio *alloc_migrate_folio(struct folio *src, unsigned long private)
mtc->nmask = NULL;
mtc->gfp_mask |= __GFP_THISNODE;
dst = alloc_migration_target(src, (unsigned long)mtc);
- if (dst)
+ if (dst) {
+ mtc->nmask = allowed_mask;
return dst;
+ }
mtc->gfp_mask &= ~__GFP_THISNODE;
mtc->nmask = allowed_mask;
--
2.39.3
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH] mm: migrate: restore the nmask after successfully allocating on the target node
2025-03-26 3:12 wangchuanguo
@ 2025-03-26 3:28 ` Matthew Wilcox
2025-03-28 13:44 ` Oscar Salvador
1 sibling, 0 replies; 7+ messages in thread
From: Matthew Wilcox @ 2025-03-26 3:28 UTC (permalink / raw)
To: wangchuanguo; +Cc: akpm, mhiramat, linux-mm, linux-kernel
On Wed, Mar 26, 2025 at 11:12:18AM +0800, wangchuanguo wrote:
> If memory is successfully allocated on the target node and the
> function directly returns without value restore for nmask,
> non-first migration operations in migrate_pages() by again label
> may ignore the nmask settings, thereby allowing new memory
> allocations for migration on any node.
I have no opinion on whether this is the right thing to do or not, but
if it is:
> +++ b/mm/vmscan.c
> @@ -1026,8 +1026,10 @@ struct folio *alloc_migrate_folio(struct folio *src, unsigned long private)
> mtc->nmask = NULL;
> mtc->gfp_mask |= __GFP_THISNODE;
> dst = alloc_migration_target(src, (unsigned long)mtc);
> - if (dst)
> + if (dst) {
> + mtc->nmask = allowed_mask;
> return dst;
> + }
>
> mtc->gfp_mask &= ~__GFP_THISNODE;
> mtc->nmask = allowed_mask;
this should be:
dst = alloc_migration_target(src, (unsigned long)mtc);
+ mtc->nmask = allowed_mask;
if (dst)
return dst;
mtc->gfp_mask &= ~__GFP_THISNODE;
- mtc->nmask = allowed_mask;
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH] mm: migrate: restore the nmask after successfully allocating on the target node
2025-03-26 3:12 wangchuanguo
2025-03-26 3:28 ` Matthew Wilcox
@ 2025-03-28 13:44 ` Oscar Salvador
1 sibling, 0 replies; 7+ messages in thread
From: Oscar Salvador @ 2025-03-28 13:44 UTC (permalink / raw)
To: wangchuanguo; +Cc: akpm, mhiramat, linux-mm, linux-kernel
On Wed, Mar 26, 2025 at 11:12:18AM +0800, wangchuanguo wrote:
> If memory is successfully allocated on the target node and the
> function directly returns without value restore for nmask,
> non-first migration operations in migrate_pages() by again label
> may ignore the nmask settings, thereby allowing new memory
> allocations for migration on any node.
>
> Signed-off-by: wangchuanguo <wangchuanguo@inspur.com>
Unless I am missing something this looks reasonable, but I whonder why nobody
noticed it before.
It is a path that should be pretty exercised.
--
Oscar Salvador
SUSE Labs
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2025-04-01 1:06 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-03-26 5:54 [PATCH] mm: migrate: restore the nmask after successfully allocating on the target node Simon Wang (王传国)
2025-03-28 13:41 ` Oscar Salvador
-- strict thread matches above, loose matches on Subject: below --
2025-04-01 1:06 Simon Wang (王传国)
2025-04-01 0:48 Simon Wang (王传国)
2025-03-26 3:12 wangchuanguo
2025-03-26 3:28 ` Matthew Wilcox
2025-03-28 13:44 ` Oscar Salvador
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox