diff mbox series

mm/mempool: Use kmalloc_array_node to replace kmalloc_array

Message ID 20250207055213.141890-1-liuye@kylinos.cn (mailing list archive)
State New
Headers show
Series mm/mempool: Use kmalloc_array_node to replace kmalloc_array | expand

Commit Message

liuye Feb. 7, 2025, 5:52 a.m. UTC
The kmalloc_array call could be replaced with kmalloc_array_node
to allocate memory on a specific NUMA node.

Signed-off-by: Liu Ye <liuye@kylinos.cn>
---
 mm/mempool.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Hyeonggon Yoo Feb. 7, 2025, 6:47 a.m. UTC | #1
On Fri, Feb 07, 2025 at 01:52:13PM +0800, Liu Ye wrote:
> The kmalloc_array call could be replaced with kmalloc_array_node
> to allocate memory on a specific NUMA node.

Why is it useful to replace kmalloc_array() with kmalloc_array_node()
in the code?

> Signed-off-by: Liu Ye <liuye@kylinos.cn>
> ---
>  mm/mempool.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/mm/mempool.c b/mm/mempool.c
> index 3223337135d0..51eabcc87177 100644
> --- a/mm/mempool.c
> +++ b/mm/mempool.c
> @@ -328,8 +328,8 @@ int mempool_resize(mempool_t *pool, int new_min_nr)
>  	spin_unlock_irqrestore(&pool->lock, flags);
>  
>  	/* Grow the pool */
> -	new_elements = kmalloc_array(new_min_nr, sizeof(*new_elements),
> -				     GFP_KERNEL);
> +	new_elements = kmalloc_array_node(new_min_nr, sizeof(*new_elements),
> +				     GFP_KERNEL, NUMA_NO_NODE);

What do you mean by 'allocate memory on a specific NUMA node'
when you pass NUMA_NO_NODE?
It's essentially the same as what kmalloc_array() does.
liuye Feb. 7, 2025, 7:51 a.m. UTC | #2
在 2025/2/7 14:47, Harry (Hyeonggon) Yoo 写道:
> On Fri, Feb 07, 2025 at 01:52:13PM +0800, Liu Ye wrote:
>> The kmalloc_array call could be replaced with kmalloc_array_node
>> to allocate memory on a specific NUMA node.
> 
> Why is it useful to replace kmalloc_array() with kmalloc_array_node()
> in the code?
> 
>> Signed-off-by: Liu Ye <liuye@kylinos.cn>
>> ---
>>  mm/mempool.c | 4 ++--
>>  1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/mm/mempool.c b/mm/mempool.c
>> index 3223337135d0..51eabcc87177 100644
>> --- a/mm/mempool.c
>> +++ b/mm/mempool.c
>> @@ -328,8 +328,8 @@ int mempool_resize(mempool_t *pool, int new_min_nr)
>>  	spin_unlock_irqrestore(&pool->lock, flags);
>>  
>>  	/* Grow the pool */
>> -	new_elements = kmalloc_array(new_min_nr, sizeof(*new_elements),
>> -				     GFP_KERNEL);
>> +	new_elements = kmalloc_array_node(new_min_nr, sizeof(*new_elements),
>> +				     GFP_KERNEL, NUMA_NO_NODE);
> 
> What do you mean by 'allocate memory on a specific NUMA node'
> when you pass NUMA_NO_NODE?
> It's essentially the same as what kmalloc_array() does.
> 

Yeah, my brain short-circuited. Discard this patch.
diff mbox series

Patch

diff --git a/mm/mempool.c b/mm/mempool.c
index 3223337135d0..51eabcc87177 100644
--- a/mm/mempool.c
+++ b/mm/mempool.c
@@ -328,8 +328,8 @@  int mempool_resize(mempool_t *pool, int new_min_nr)
 	spin_unlock_irqrestore(&pool->lock, flags);
 
 	/* Grow the pool */
-	new_elements = kmalloc_array(new_min_nr, sizeof(*new_elements),
-				     GFP_KERNEL);
+	new_elements = kmalloc_array_node(new_min_nr, sizeof(*new_elements),
+				     GFP_KERNEL, NUMA_NO_NODE);
 	if (!new_elements)
 		return -ENOMEM;