Re: [PATCH RFC 3/3] mm: use non-temporal stores for demotion

Yiannis Nikolakopoulos <[email protected]> Thu, 30 Jul 2026 16:11:38 +0300
Newsgroups org.kernel.vger.linux-nfs,org.kernel.vger.linux-kernel,org.kernel.vger.linux-trace-kernel,org.kvack.linux-mm
Message-ID <CAOi6=wQ7CxHf8QMFXm5oyHZFc9n6BQecL45rBud=hMubmayCnA@mail.gmail.com>
On Tue, May 26, 2026 at 6:25=E2=80=AFPM Gregory Price <[email protected]> w=
rote:
>
> On Tue, May 26, 2026 at 01:37:04PM +0200, Yiannis Nikolakopoulos wrote:
> > From: Alirad Malek <[email protected]>
> >
> > Memory demoted to a lower tier is assumed to be cold and most likely ou=
t of
> > the CPU's last level cache. Additionally, in certain demotion targets (=
e.g.
> > CXL devices with compressed memory) the bandwidth can be negatively
> > impacted by the eviction patterns of the last level cache when standard
> > memcpy is used. When the feature is enabled, use the
> > MIGRATE_ASYNC_NON_TEMPORAL_STORES flag in demotions to trigger the foli=
o
> > copy path using non-temporal stores.
> >
> > Signed-off-by: Alirad Malek <[email protected]>
> > Co-developed-by: Yiannis Nikolakopoulos <[email protected]>
> > Signed-off-by: Yiannis Nikolakopoulos <[email protected]>
> > ---
> >  mm/Kconfig   | 8 ++++++++
> >  mm/migrate.c | 9 ++++++++-
> >  2 files changed, 16 insertions(+), 1 deletion(-)
> >
> > diff --git a/mm/Kconfig b/mm/Kconfig
> > index ebd8ea353687..4b7a75b57f6e 100644
> > --- a/mm/Kconfig
> > +++ b/mm/Kconfig
> > @@ -645,6 +645,14 @@ config MIGRATION
> >         pages as migration can relocate pages to satisfy a huge page
> >         allocation instead of reclaiming.
> >
> > +config DEMOTION_WITH_NON_TEMPORAL_STORES
> > +     bool "Use non-temporal stores for demotion"
> > +     default n
> > +     depends on MIGRATION
> > +     help
> > +       Enable non-temporal stores when migrating pages due to demotion=
.
> > +       If disabled, demotion uses regular migration copy paths.
> > +
>
> Do we actually need this config flag or should we just default to this
> (if the arch supports NT stores)?
As discussed in the sync call, I was just being defensive :).
In fact the non-temporal instructions should be in all x86_64 afaict.
So I've removed this in the next version (landing soon).

/Yiannis
>
> >  config DEVICE_MIGRATION
> >       def_bool MIGRATION && ZONE_DEVICE
> >
> > diff --git a/mm/migrate.c b/mm/migrate.c
> > index ff6cf50e7b0b..368d40dc8772 100644
> > --- a/mm/migrate.c
> > +++ b/mm/migrate.c
> > @@ -862,7 +862,10 @@ static int __migrate_folio(struct address_space *m=
apping, struct folio *dst,
> >       if (folio_ref_count(src) !=3D expected_count)
> >               return -EAGAIN;
> >
> > -     rc =3D folio_mc_copy(dst, src);
> > +     if (mode =3D=3D MIGRATE_ASYNC_NON_TEMPORAL_STORES)
> > +             rc =3D folio_mc_copy_nt(dst, src);
> > +     else
> > +             rc =3D folio_mc_copy(dst, src);
> >       if (unlikely(rc))
> >               return rc;
> >
> > @@ -2081,6 +2084,10 @@ int migrate_pages(struct list_head *from, new_fo=
lio_t get_new_folio,
> >       LIST_HEAD(split_folios);
> >       struct migrate_pages_stats stats;
> >
> > +     if (IS_ENABLED(CONFIG_DEMOTION_WITH_NON_TEMPORAL_STORES) &&
> > +             reason =3D=3D MR_DEMOTION && mode =3D=3D MIGRATE_ASYNC)
> > +             mode =3D MIGRATE_ASYNC_NON_TEMPORAL_STORES;
> > +
> >       trace_mm_migrate_pages_start(mode, reason);
> >
> >       memset(&stats, 0, sizeof(stats));
> >
> > --
> > 2.43.0
> >