Re: [PATCH 1/8] mm/memory-tiers: consolidate memory type dedup into mt_get_memory_type()

From: Gregory Price

Date: Mon Apr 13 2026 - 15:41:55 EST


On Mon, Apr 13, 2026 at 05:06:35PM +0200, David Hildenbrand (Arm) wrote:
> On 3/21/26 16:03, Gregory Price wrote:
> > Replace per-driver memory type list infrastructure with a single
> > mt_get_memory_type(adist) that deduplicates against the global
> > default_memory_types list under memory_tier_lock.
> >
> > The per-driver lists (mutex + list_head + find/put wrappers) provided
> > dedup within a single driver, but not across drivers or with the core.
> > Since the number of distinct adist values is bounded and types on
> > default_memory_types are never freed anyway, the per-driver cleanup
> > on module unload was not useful.
> >
> > Add MEMTIER_DEFAULT_LOWTIER_ADISTANCE to replace the default DAX
> > adistance, since it was really used as a standin for all kmem hotplugged
> > memory. This at least makes the default tier relationship clearer to
> > other drivers and they can see where to put their memory in relation to
> > the default lower tier.
>
> Very confusing code.
>
> What's the purpose of kref_get/kref_put if "the types on
> default_memory_types are never freed anyway" ?
>

Mostly trying to retain existing functionality rather than delete it.

I think the entire memory_type() infrastructure in memory-tiers.c is
generally very confusing and of dubious value - but i don't know who
out there still depends on it.

> IOW, couldn't init_node_memory_type()/clear_node_memory_type() just
> consume the "adist", and lookup the memory type itself?
>
> All you'd need is some way in the driver to verify that there is a
> memory type for the given adist, as some kind of prepare step.
>
> Alternatively, let init_node_memory_type() return an error to get a
> clean interface? :)
>

tl;dr: yes all of this is true and I will rework it.

~Gregory