lkml.org 
[lkml]   [2022]   [Jul]   [15]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
SubjectRe: [PATCH v9 4/8] mm/demotion: Add hotplug callbacks to handle new numa node onlined
Date

"Aneesh Kumar K.V" <aneesh.kumar@linux.ibm.com> writes:

> If the new NUMA node onlined doesn't have a memory tier assigned,
> the kernel adds the NUMA node to default memory tier.
>
> Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com>
> ---
> mm/memory-tiers.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 68 insertions(+)
>
> diff --git a/mm/memory-tiers.c b/mm/memory-tiers.c
> index 79347d4ab05e..5706ad647136 100644
> --- a/mm/memory-tiers.c
> +++ b/mm/memory-tiers.c
> @@ -5,6 +5,7 @@
> #include <linux/slab.h>
> #include <linux/lockdep.h>
> #include <linux/moduleparam.h>
> +#include <linux/memory.h>
> #include <linux/memory-tiers.h>
>
> struct memory_tier {
> @@ -130,8 +131,73 @@ int node_create_and_set_memory_tier(int node, int tier)
> }
> EXPORT_SYMBOL_GPL(node_create_and_set_memory_tier);
>
> +static int __node_set_memory_tier(int node, int tier)
> +{
> + int ret = 0;
> + struct memory_tier *memtier;
> +
> + memtier = __get_memory_tier_from_id(tier);
> + if (!memtier) {
> + ret = -EINVAL;
> + goto out;
> + }
> + node_set(node, memtier->nodelist);
> +out:
> + return ret;
> +}
> +
> +static int node_set_memory_tier(int node, int tier)

Minor comment, but I don't like the name of this function as it doesn't
always set the node to the given tier.

Something like this would make it clearer the tier value is only used if
the node isn't already assigned to a tier:

static int init_node_memory_tier(int node, int default_tier)

> +{
> + struct memory_tier *memtier;
> + int ret = 0;
> +
> + mutex_lock(&memory_tier_lock);
> + memtier = __node_get_memory_tier(node);
> + if (!memtier)
> + ret = __node_set_memory_tier(node, tier);
> +
> + mutex_unlock(&memory_tier_lock);
> +
> + return ret;
> +}
> +
> static unsigned int default_memtier = DEFAULT_MEMORY_TIER;
> core_param(default_memory_tier, default_memtier, uint, 0644);
> +/*
> + * This runs whether reclaim-based migration is enabled or not,
> + * which ensures that the user can turn reclaim-based migration
> + * at any time without needing to recalculate migration targets.
> + */
> +static int __meminit migrate_on_reclaim_callback(struct notifier_block *self,
> + unsigned long action, void *_arg)
> +{
> + struct memory_notify *arg = _arg;
> +
> + /*
> + * Only update the node migration order when a node is
> + * changing status, like online->offline.
> + */
> + if (arg->status_change_nid < 0)
> + return notifier_from_errno(0);
> +
> + switch (action) {
> + case MEM_ONLINE:
> + /*
> + * We ignore the error here, if the node already have the tier
> + * registered, we will continue to use that for the new memory
> + * we are adding here.
> + */
> + node_set_memory_tier(arg->status_change_nid, default_memtier);
> + break;
> + }
> +
> + return notifier_from_errno(0);
> +}
> +
> +static void __init migrate_on_reclaim_init(void)
> +{
> + hotplug_memory_notifier(migrate_on_reclaim_callback, 100);
> +}
>
> static int __init memory_tier_init(void)
> {
> @@ -153,6 +219,8 @@ static int __init memory_tier_init(void)
> /* CPU only nodes are not part of memory tiers. */
> memtier->nodelist = node_states[N_MEMORY];
> mutex_unlock(&memory_tier_lock);
> +
> + migrate_on_reclaim_init();
> return 0;
> }
> subsys_initcall(memory_tier_init);

\
 
 \ /
  Last update: 2022-07-15 07:59    [W:0.581 / U:0.624 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site