neighbour: Replace kvzalloc() with kzalloc() when GFP_ATOMIC is specified
Subsystems (2)
PATCH v2 1/1 neighbour: Replace kvzalloc() with kzalloc() when GFP_ATOMIC is specified
kzalloc() uses page allocator when size is larger than KMALLOC_MAX_CACHE_SIZE, so the intention of commit ab101c553bc1 ("neighbour: use kvzalloc()/kvfree()") can be achieved by using kzalloc().
When using GFP_ATOMIC, kvzalloc() only tries the kmalloc path, since the vmalloc path does not support the flag.
In this case, kvzalloc() is equivalent to kzalloc() in that neither try the vmalloc path, so this replacement brings no functional change. This is primarily a cleanup change, as the original code functions correctly.
This patch replaces kvzalloc() introduced by commit 41b3caa7c076 ("neighbour: Add hlist_node to struct neighbour"), which is called in the same context and with the same gfp flag as the aforementioned commit ab101c553bc1 ("neighbour: use kvzalloc()/kvfree()").
---
Notes:
One of the SLAB maintainers (Vlastimil Babka) looked at v1 patch and double-checked kzalloc() is clearer in this context:
https://lore.kernel.org/netdev/[email protected]/
Changes:
v1: https://lore.kernel.org/netdev/[email protected]/
v1->v2:
- Change commit message
- Remove the Fixes tag since there is no real bug now
--- net/core/neighbour.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
net/core/neighbour.c +2 -2
@@ -518,7 +518,7 @@ static struct neigh_hash_table *neigh_hash_alloc(unsigned int shift)if (!ret)return NULL ; - hash_heads =kvzalloc (size,GFP_ATOMIC ); + hash_heads =kzalloc (size,GFP_ATOMIC );if (!hash_heads) {kfree (ret);return NULL ;
@@ -536,7 +536,7 @@ static void neigh_hash_free_rcu(struct rcu_head *head) struct neigh_hash_table, rcu); -kvfree (nht->hash_heads); +kfree (nht->hash_heads);kfree (nht); }
Signature · 1 line
2.39.5 (Apple Git-154)
Quoted 11 lines · Kohei Enju
kzalloc()uses page allocator when size is larger thanKMALLOC_MAX_CACHE_SIZE, so the intention of commitab101c553bc1("neighbour: use kvzalloc()/kvfree()") can be achieved by usingkzalloc().When using
GFP_ATOMIC,kvzalloc()only tries the kmalloc path, since the vmalloc path does not support the flag.
In this case,kvzalloc()is equivalent tokzalloc()in that neither try the vmalloc path, so this replacement brings no functional change. This is primarily a cleanup change, as the original code functions correctly.
Quoted 6 lines
This patch replaces
kvzalloc()introduced by commit41b3caa7c076("neighbour: Addhlist_nodeto struct neighbour"), which is called in the same context and with the same gfp flag as the aforementioned commitab101c553bc1("neighbour: use kvzalloc()/kvfree()").Signed-off-by Kohei Enju <[email protected]>
Quoted 37 lines
---
Notes:
One of the SLAB maintainers (Vlastimil Babka) looked at v1 patch and double-checkedkzalloc()is clearer in this context:
https://lore.kernel.org/netdev/[email protected]/Changes:
v1: https://lore.kernel.org/netdev/[email protected]/
v1->v2:
- Change commit message
- Remove the Fixes tag since there is no real bug now--- net/core/neighbour.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)net/core/neighbour.c +2
-2@@ -518,7 +518,7 @@ static struct neigh_hash_table *neigh_hash_alloc(unsigned int shift)if (!ret)return NULL ; - hash_heads =kvzalloc (size,GFP_ATOMIC ); + hash_heads =kzalloc (size,GFP_ATOMIC );if (!hash_heads) {kfree (ret);return NULL ;@@ -536,7 +536,7 @@ static void neigh_hash_free_rcu(struct rcu_head *head) struct neigh_hash_table, rcu); -kvfree (nht->hash_heads); +kfree (nht->hash_heads);kfree (nht); }
…
Quoted 1 line
This patch replaces …
Thus replace?
Regards,
Markus
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Quoted 4 lines · On Wed, 19 Feb 2025 19:22:27 +0900 you wrote:
kzalloc()uses page allocator when size is larger thanKMALLOC_MAX_CACHE_SIZE, so the intention of commitab101c553bc1("neighbour: use kvzalloc()/kvfree()") can be achieved by usingkzalloc().
Quoted 8 lines
When using
GFP_ATOMIC,kvzalloc()only tries the kmalloc path, since the vmalloc path does not support the flag.
In this case,kvzalloc()is equivalent tokzalloc()in that neither try the vmalloc path, so this replacement brings no functional change. This is primarily a cleanup change, as the original code functions correctly.[...]
Here is the summary with links:
- [net-next,v2] neighbour: Replace kvzalloc() with kzalloc() when GFP_ATOMIC is specified
https://git.kernel.org/netdev/net-next/c/ef75d8343bc1
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html