All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] add a knob to control whether to use other nodes at the same tier of the target node in DAMON
@ 2025-05-28 11:10 wangchuanguo
  2025-05-28 11:10 ` [PATCH 1/2] mm: migrate: restore the nmask after successfully allocating on the target node wangchuanguo
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: wangchuanguo @ 2025-05-28 11:10 UTC (permalink / raw)
  To: akpm, hannes, sj
  Cc: david, mhocko, zhengqi.arch, shakeel.butt, lorenzo.stoakes,
	linux-mm, linux-kernel, damon, wangchuanguo

In DAMON's migrate_hot and migrate_cold features, the code was
intended to migrate pages ​​only to the node specified by target_nid​​.
However, during testing, it was observed that memory allocation
and migration could occur on ​​any nodes​​, which is a BUG.
The first patch in this PR fix this issue.

A use_nodes_of_tier file has been added under the directory /sys/kernel/mm/damon/admin/kdamonds/<N>/contexts/<N>/schemes/<N>/
to control whether to ​​use other nodes in the same tier as
the target node​​ for migration.

wangchuanguo (2):
  mm: migrate: restore the nmask after successfully allocating on the 
    target node
  mm/damon/sysfs-schemes: add use_nodes_of_tier on sysfs-schemes

 include/linux/damon.h        |  9 ++++++++-
 include/linux/memory-tiers.h |  5 +++++
 mm/damon/core.c              |  6 ++++--
 mm/damon/lru_sort.c          |  3 ++-
 mm/damon/paddr.c             | 19 ++++++++++++-------
 mm/damon/reclaim.c           |  3 ++-
 mm/damon/sysfs-schemes.c     | 31 ++++++++++++++++++++++++++++++-
 mm/memory-tiers.c            | 13 +++++++++++++
 mm/vmscan.c                  |  2 +-
 samples/damon/mtier.c        |  3 ++-
 samples/damon/prcl.c         |  3 ++-
 11 files changed, 81 insertions(+), 16 deletions(-)

-- 
2.39.3


^ permalink raw reply	[flat|nested] 9+ messages in thread
* Re: [PATCH 1/2] mm: migrate: restore the nmask after successfully allocating on the  target node
@ 2025-05-29  3:03 Simon Wang (王传国)
  0 siblings, 0 replies; 9+ messages in thread
From: Simon Wang (王传国) @ 2025-05-29  3:03 UTC (permalink / raw)
  To: SeongJae Park
  Cc: akpm@linux-foundation.org, hannes@cmpxchg.org, david@redhat.com,
	mhocko@kernel.org, zhengqi.arch@bytedance.com,
	shakeel.butt@linux.dev, lorenzo.stoakes@oracle.com,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	damon@lists.linux.dev, Jagdish Gediya


> + Jagdish, since seems the behavior that this patch tries to change is
> apparently made by Jagdish's commit 320080272892 ("mm/demotion:
> demote pages according to allocation fallback order").
> 
> On Wed, 28 May 2025 19:10:37 +0800 wangchuanguo
> <wangchuanguo@inspur.com> 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,
> 
> Nice finding!
> 
> > thereby allowing new memory
> > allocations for migration on any node.
> 
> But, isn't the consequence of this behavior is the opposite?  That is, I think
> this behavior restricts to use only the specified node (mtc->nid) in the case,
> ignoring more allowed fallback nodes (mtc->nmask)?
> 
> Anyway, to me, this seems not an intended behavior but a bug.  Cc-ing
> Jagdish, who authored the commit 320080272892 ("mm/demotion: demote
> pages according to allocation fallback order"), which apparently made this
> behavior initially, though, since I may misreading the original author's
> intention.
> 

Under the original logic, the alloc_migrate_folio function would attempt to allocate new memory ​​sequentially across all nodes based on distance​​, even for nodes at the same tier, which is nonsensical. For example, if nodes 0 and 1 are DRAM nodes and nodes 2 and 3 are CXL nodes, attempting to promote a hot page from node 2 to node 0 would ​​erroneously fall back to nodes 2 and 3​​ (the same tier as the source node) if nodes 0 and 1 are out of space. This is a BUG.In ​​Patch 1​​, I fix this BUG. 

In ​​Patch 2​​, I extend the target node range from node 0 to nodes 0 and 1. To accommodate users who require strict migration (e.g., migrating only to node 0 and aborting if it is full), I added a ​​sysfs toggle​​ in Patch 2.
​​Question​​: Should this sysfs toggle default to true (allow fallback to other nodes) or false (strict mode: migrate only to node 0, abort if full)? I would appreciate your advice on the default value, considering backward compatibility and use cases.

> >
> > Signed-off-by: wangchuanguo <wangchuanguo@inspur.com>
> > ---
> >  mm/vmscan.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/mm/vmscan.c b/mm/vmscan.c index
> > f8dfd2864bbf..e13f17244279 100644
> > --- a/mm/vmscan.c
> > +++ b/mm/vmscan.c
> > @@ -1035,11 +1035,11 @@ 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);
> > +	mtc->nmask = allowed_mask;
> >  	if (dst)
> >  		return dst;
> 
> Restoring ->nmask looks right behavior to me.  But, if so, shouldn't we also
> restore ->gfp_mask?

Yes, it's a good idea. I will do it.
 

> >
> >  	mtc->gfp_mask &= ~__GFP_THISNODE;
> > -	mtc->nmask = allowed_mask;
> >
> >  	return alloc_migration_target(src, (unsigned long)mtc);  }
> > --
> > 2.39.3
> 
> 
> Thanks,
> SJ

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2025-06-09 12:30 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-28 11:10 [PATCH 0/2] add a knob to control whether to use other nodes at the same tier of the target node in DAMON wangchuanguo
2025-05-28 11:10 ` [PATCH 1/2] mm: migrate: restore the nmask after successfully allocating on the target node wangchuanguo
2025-05-28 22:09   ` SeongJae Park
2025-05-28 11:10 ` [PATCH 2/2] mm/damon/sysfs-schemes: add use_nodes_of_tier on sysfs-schemes wangchuanguo
2025-05-28 21:33   ` kernel test robot
2025-05-28 22:31   ` SeongJae Park
2025-06-09 12:30   ` Honggyu Kim
2025-05-28 22:39 ` [PATCH 0/2] add a knob to control whether to use other nodes at the same tier of the target node in DAMON SeongJae Park
  -- strict thread matches above, loose matches on Subject: below --
2025-05-29  3:03 [PATCH 1/2] mm: migrate: restore the nmask after successfully allocating on the target node Simon Wang (王传国)

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.