[PATCH v5 04/10] mm,slub: Use node-notifier instead of memory-notifier

Oscar Salvador posted 10 patches 6 months, 2 weeks ago
There is a newer version of this series
[PATCH v5 04/10] mm,slub: Use node-notifier instead of memory-notifier
Posted by Oscar Salvador 6 months, 2 weeks ago
slub is only concerned when a numa node changes its memory state,
so stop using the memory notifier and use the new numa node notifer
instead.

Signed-off-by: Oscar Salvador <osalvador@suse.de>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Reviewed-by: Harry Yoo <harry.yoo@oracle.com>
Reviewed-by: Vlastimil Babka <vbabka@suse.cz>
---
 mm/slub.c | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)

diff --git a/mm/slub.c b/mm/slub.c
index f92b43d36adc..b8b5b81bfd1a 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -6164,8 +6164,8 @@ static int slab_mem_going_online_callback(void *arg)
 {
 	struct kmem_cache_node *n;
 	struct kmem_cache *s;
-	struct memory_notify *marg = arg;
-	int nid = marg->status_change_nid;
+	struct node_notify *narg = arg;
+	int nid = narg->nid;
 	int ret = 0;
 
 	/*
@@ -6217,15 +6217,12 @@ static int slab_memory_callback(struct notifier_block *self,
 	int ret = 0;
 
 	switch (action) {
-	case MEM_GOING_ONLINE:
+	case NODE_ADDING_FIRST_MEMORY:
 		ret = slab_mem_going_online_callback(arg);
 		break;
-	case MEM_GOING_OFFLINE:
+	case NODE_REMOVING_LAST_MEMORY:
 		ret = slab_mem_going_offline_callback(arg);
 		break;
-	case MEM_ONLINE:
-	case MEM_CANCEL_OFFLINE:
-		break;
 	}
 	if (ret)
 		ret = notifier_from_errno(ret);
@@ -6300,7 +6297,7 @@ void __init kmem_cache_init(void)
 			sizeof(struct kmem_cache_node),
 			SLAB_HWCACHE_ALIGN | SLAB_NO_OBJ_EXT, 0, 0);
 
-	hotplug_memory_notifier(slab_memory_callback, SLAB_CALLBACK_PRI);
+	hotplug_node_notifier(slab_memory_callback, SLAB_CALLBACK_PRI);
 
 	/* Able to allocate the per node structures */
 	slab_state = PARTIAL;
-- 
2.49.0
Re: [PATCH v5 04/10] mm,slub: Use node-notifier instead of memory-notifier
Posted by David Hildenbrand 6 months, 2 weeks ago
On 05.06.25 16:22, Oscar Salvador wrote:
> slub is only concerned when a numa node changes its memory state,
> so stop using the memory notifier and use the new numa node notifer
> instead.
> 
> Signed-off-by: Oscar Salvador <osalvador@suse.de>
> Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> Reviewed-by: Harry Yoo <harry.yoo@oracle.com>
> Reviewed-by: Vlastimil Babka <vbabka@suse.cz>
> ---
>   mm/slub.c | 13 +++++--------
>   1 file changed, 5 insertions(+), 8 deletions(-)
> 
> diff --git a/mm/slub.c b/mm/slub.c
> index f92b43d36adc..b8b5b81bfd1a 100644
> --- a/mm/slub.c
> +++ b/mm/slub.c
> @@ -6164,8 +6164,8 @@ static int slab_mem_going_online_callback(void *arg)
>   {
>   	struct kmem_cache_node *n;
>   	struct kmem_cache *s;
> -	struct memory_notify *marg = arg;
> -	int nid = marg->status_change_nid;
> +	struct node_notify *narg = arg;
> +	int nid = narg->nid;
>   	int ret = 0;
>   
>   	/*
> @@ -6217,15 +6217,12 @@ static int slab_memory_callback(struct notifier_block *self,
>   	int ret = 0;
>   
>   	switch (action) {
> -	case MEM_GOING_ONLINE:
> +	case NODE_ADDING_FIRST_MEMORY:
>   		ret = slab_mem_going_online_callback(arg);

In slab_mem_going_online_callback we will cast arg to "struct 
memory_notify", no?

Probably needs to get fixed.

... and probably best to pass marg directly.

>   		break;
> -	case MEM_GOING_OFFLINE:
> +	case NODE_REMOVING_LAST_MEMORY:
>   		ret = slab_mem_going_offline_callback(arg);

slab_mem_going_offline_callback() doesn't even look at arg, so likely we 
can drop that parameter?


-- 
Cheers,

David / dhildenb
Re: [PATCH v5 04/10] mm,slub: Use node-notifier instead of memory-notifier
Posted by Oscar Salvador 6 months, 2 weeks ago
On Fri, Jun 06, 2025 at 01:56:15PM +0200, David Hildenbrand wrote:
> > @@ -6217,15 +6217,12 @@ static int slab_memory_callback(struct notifier_block *self,
> >   	int ret = 0;
> >   	switch (action) {
> > -	case MEM_GOING_ONLINE:
> > +	case NODE_ADDING_FIRST_MEMORY:
> >   		ret = slab_mem_going_online_callback(arg);
> 
> In slab_mem_going_online_callback we will cast arg to "struct
> memory_notify", no?

Uhm... not sure if I understood this correctly but slab_mem_going_online_callback looks
like this:

 static int slab_mem_going_online_callback(void *arg)
 {
         struct kmem_cache_node *n;
         struct kmem_cache *s;
         struct node_notify *narg = arg;
         int nid = narg->nid;
         int ret = 0;



> Probably needs to get fixed.
> 
> ... and probably best to pass marg directly.

You mean to cast it directly in slab_memory_callback and pass 'narg'
to slab_mem_going_online_callback?


> >   		break;
> > -	case MEM_GOING_OFFLINE:
> > +	case NODE_REMOVING_LAST_MEMORY:
> >   		ret = slab_mem_going_offline_callback(arg);
> 
> slab_mem_going_offline_callback() doesn't even look at arg, so likely we can
> drop that parameter?

Sure.

Thanks for the feedback!

 

-- 
Oscar Salvador
SUSE Labs
Re: [PATCH v5 04/10] mm,slub: Use node-notifier instead of memory-notifier
Posted by David Hildenbrand 6 months, 2 weeks ago
On 06.06.25 14:28, Oscar Salvador wrote:
> On Fri, Jun 06, 2025 at 01:56:15PM +0200, David Hildenbrand wrote:
>>> @@ -6217,15 +6217,12 @@ static int slab_memory_callback(struct notifier_block *self,
>>>    	int ret = 0;
>>>    	switch (action) {
>>> -	case MEM_GOING_ONLINE:
>>> +	case NODE_ADDING_FIRST_MEMORY:
>>>    		ret = slab_mem_going_online_callback(arg);
>>
>> In slab_mem_going_online_callback we will cast arg to "struct
>> memory_notify", no?
> 
> Uhm... not sure if I understood this correctly but slab_mem_going_online_callback looks
> like this:
> 
>   static int slab_mem_going_online_callback(void *arg)
>   {
>           struct kmem_cache_node *n;
>           struct kmem_cache *s;
>           struct node_notify *narg = arg;
>           int nid = narg->nid;
>           int ret = 0;
> 

I'm stupid and missed that hunk, sorry.

> 
> 
>> Probably needs to get fixed.
>>
>> ... and probably best to pass marg directly.
> 
> You mean to cast it directly in slab_memory_callback and pass 'narg'
> to slab_mem_going_online_callback?

Yes :)



-- 
Cheers,

David / dhildenb
Re: [PATCH v5 04/10] mm,slub: Use node-notifier instead of memory-notifier
Posted by kernel test robot 6 months, 2 weeks ago
Hi Oscar,

kernel test robot noticed the following build errors:

[auto build test ERROR on driver-core/driver-core-testing]
[also build test ERROR on driver-core/driver-core-next driver-core/driver-core-linus rafael-pm/linux-next rafael-pm/bleeding-edge tj-cgroup/for-next linus/master v6.15 next-20250605]
[cannot apply to akpm-mm/mm-everything vbabka-slab/for-next]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Oscar-Salvador/mm-memory_hotplug-Remove-status_change_nid_normal-and-update-documentation/20250605-232305
base:   driver-core/driver-core-testing
patch link:    https://lore.kernel.org/r/20250605142305.244465-5-osalvador%40suse.de
patch subject: [PATCH v5 04/10] mm,slub: Use node-notifier instead of memory-notifier
config: riscv-randconfig-001-20250606 (https://download.01.org/0day-ci/archive/20250606/202506060918.HDCPogq9-lkp@intel.com/config)
compiler: riscv64-linux-gcc (GCC) 11.5.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250606/202506060918.HDCPogq9-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202506060918.HDCPogq9-lkp@intel.com/

All errors (new ones prefixed by >>):

   mm/slub.c: In function 'slab_mem_going_online_callback':
>> mm/slub.c:6168:23: error: invalid use of undefined type 'struct node_notify'
    6168 |         int nid = narg->nid;
         |                       ^~
   mm/slub.c: In function 'slab_memory_callback':
   mm/slub.c:6220:14: error: 'NODE_ADDING_FIRST_MEMORY' undeclared (first use in this function)
    6220 |         case NODE_ADDING_FIRST_MEMORY:
         |              ^~~~~~~~~~~~~~~~~~~~~~~~
   mm/slub.c:6220:14: note: each undeclared identifier is reported only once for each function it appears in
   mm/slub.c:6223:14: error: 'NODE_REMOVING_LAST_MEMORY' undeclared (first use in this function)
    6223 |         case NODE_REMOVING_LAST_MEMORY:
         |              ^~~~~~~~~~~~~~~~~~~~~~~~~
   mm/slub.c: In function 'kmem_cache_init':
   mm/slub.c:6300:9: error: implicit declaration of function 'hotplug_node_notifier'; did you mean 'hotplug_memory_notifier'? [-Werror=implicit-function-declaration]
    6300 |         hotplug_node_notifier(slab_memory_callback, SLAB_CALLBACK_PRI);
         |         ^~~~~~~~~~~~~~~~~~~~~
         |         hotplug_memory_notifier
   cc1: some warnings being treated as errors


vim +6168 mm/slub.c

  6162	
  6163	static int slab_mem_going_online_callback(void *arg)
  6164	{
  6165		struct kmem_cache_node *n;
  6166		struct kmem_cache *s;
  6167		struct node_notify *narg = arg;
> 6168		int nid = narg->nid;
  6169		int ret = 0;
  6170	
  6171		/*
  6172		 * If the node's memory is already available, then kmem_cache_node is
  6173		 * already created. Nothing to do.
  6174		 */
  6175		if (nid < 0)
  6176			return 0;
  6177	
  6178		/*
  6179		 * We are bringing a node online. No memory is available yet. We must
  6180		 * allocate a kmem_cache_node structure in order to bring the node
  6181		 * online.
  6182		 */
  6183		mutex_lock(&slab_mutex);
  6184		list_for_each_entry(s, &slab_caches, list) {
  6185			/*
  6186			 * The structure may already exist if the node was previously
  6187			 * onlined and offlined.
  6188			 */
  6189			if (get_node(s, nid))
  6190				continue;
  6191			/*
  6192			 * XXX: kmem_cache_alloc_node will fallback to other nodes
  6193			 *      since memory is not yet available from the node that
  6194			 *      is brought up.
  6195			 */
  6196			n = kmem_cache_alloc(kmem_cache_node, GFP_KERNEL);
  6197			if (!n) {
  6198				ret = -ENOMEM;
  6199				goto out;
  6200			}
  6201			init_kmem_cache_node(n);
  6202			s->node[nid] = n;
  6203		}
  6204		/*
  6205		 * Any cache created after this point will also have kmem_cache_node
  6206		 * initialized for the new node.
  6207		 */
  6208		node_set(nid, slab_nodes);
  6209	out:
  6210		mutex_unlock(&slab_mutex);
  6211		return ret;
  6212	}
  6213	

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
Re: [PATCH v5 04/10] mm,slub: Use node-notifier instead of memory-notifier
Posted by Oscar Salvador 6 months, 2 weeks ago
On Fri, Jun 06, 2025 at 09:50:39AM +0800, kernel test robot wrote:
> Hi Oscar,
> 
> kernel test robot noticed the following build errors:

Fixed, see:

https://lore.kernel.org/linux-mm/aEKdvc8IWgSXSF8Q@localhost.localdomain/T/#mb3acf8bc17463f621f2b85d688817acd65cef042

Thanks

-- 
Oscar Salvador
SUSE Labs