diff mbox series

[net-next] net/sysctl: avoid two synchronize_rcu() calls

Message ID 20220225161855.489923-1-eric.dumazet@gmail.com (mailing list archive)
State Accepted
Commit b3483bc7a1f2673b35331e60668104ba2be46510
Delegated to: Netdev Maintainers
Headers show
Series [net-next] net/sysctl: avoid two synchronize_rcu() calls | expand

Checks

Context Check Description
netdev/tree_selection success Clearly marked for net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix success Link
netdev/cover_letter success Single patches do not need cover letters
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 2 this patch: 2
netdev/cc_maintainers warning 3 maintainers not CCed: dvyukov@google.com ast@kernel.org hmukos@yandex-team.ru
netdev/build_clang success Errors and warnings before: 18 this patch: 18
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 7 this patch: 7
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 18 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Eric Dumazet Feb. 25, 2022, 4:18 p.m. UTC
From: Eric Dumazet <edumazet@google.com>

Both rps_sock_flow_sysctl() and flow_limit_cpu_sysctl()
are using synchronize_rcu() right before freeing memory
either by vfree() or kfree()

They can switch to kvfree_rcu(ptr) and kfree_rcu(ptr) to benefit
from asynchronous mode, instead of blocking the current thread.

Note that kvfree_rcu(ptr) and kfree_rcu(ptr) eventually can
have to use synchronize_rcu() in some memory pressure cases.

Signed-off-by: Eric Dumazet <edumazet@google.com>
---
 net/core/sysctl_net_core.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

Comments

patchwork-bot+netdevbpf@kernel.org Feb. 28, 2022, 11:50 a.m. UTC | #1
Hello:

This patch was applied to netdev/net-next.git (master)
by David S. Miller <davem@davemloft.net>:

On Fri, 25 Feb 2022 08:18:55 -0800 you wrote:
> From: Eric Dumazet <edumazet@google.com>
> 
> Both rps_sock_flow_sysctl() and flow_limit_cpu_sysctl()
> are using synchronize_rcu() right before freeing memory
> either by vfree() or kfree()
> 
> They can switch to kvfree_rcu(ptr) and kfree_rcu(ptr) to benefit
> from asynchronous mode, instead of blocking the current thread.
> 
> [...]

Here is the summary with links:
  - [net-next] net/sysctl: avoid two synchronize_rcu() calls
    https://git.kernel.org/netdev/net-next/c/b3483bc7a1f2

You are awesome, thank you!
diff mbox series

Patch

diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c
index dbeb8ecbcd98f0aa6c02c650f925b05faf23ecad..7123fe7feeac634023d4e73247db0a20e3fcc383 100644
--- a/net/core/sysctl_net_core.c
+++ b/net/core/sysctl_net_core.c
@@ -103,8 +103,7 @@  static int rps_sock_flow_sysctl(struct ctl_table *table, int write,
 			if (orig_sock_table) {
 				static_branch_dec(&rps_needed);
 				static_branch_dec(&rfs_needed);
-				synchronize_rcu();
-				vfree(orig_sock_table);
+				kvfree_rcu(orig_sock_table);
 			}
 		}
 	}
@@ -142,8 +141,7 @@  static int flow_limit_cpu_sysctl(struct ctl_table *table, int write,
 				     lockdep_is_held(&flow_limit_update_mutex));
 			if (cur && !cpumask_test_cpu(i, mask)) {
 				RCU_INIT_POINTER(sd->flow_limit, NULL);
-				synchronize_rcu();
-				kfree(cur);
+				kfree_rcu(cur);
 			} else if (!cur && cpumask_test_cpu(i, mask)) {
 				cur = kzalloc_node(len, GFP_KERNEL,
 						   cpu_to_node(i));