diff mbox series

[2/4] perf/core: convert call_rcu(free_ctx) to kfree_rcu()

Message ID 20241120064716.3361211-3-ranxiaokai627@163.com (mailing list archive)
State New
Headers show
Series Convert some simple call_rcu() to kfree_rcu()/kvfree_rcu() | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Guessed tree name to be net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 3 this patch: 3
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers warning 8 maintainers not CCed: acme@kernel.org jolsa@kernel.org irogers@google.com alexander.shishkin@linux.intel.com mark.rutland@arm.com namhyung@kernel.org kan.liang@linux.intel.com adrian.hunter@intel.com
netdev/build_clang success Errors and warnings before: 3 this patch: 3
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 48 this patch: 48
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 22 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 5 this patch: 5
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2024-11-20--15-00 (tests: 789)

Commit Message

Ran Xiaokai Nov. 20, 2024, 6:47 a.m. UTC
From: Ran Xiaokai <ran.xiaokai@zte.com.cn>

The rcu callback free_ctx() simply calls kfree().
It's better to directly call kfree_rcu().

Signed-off-by: Ran Xiaokai <ran.xiaokai@zte.com.cn>
---
 kernel/events/core.c | 10 +---------
 1 file changed, 1 insertion(+), 9 deletions(-)

Comments

Peter Zijlstra Nov. 20, 2024, 9:12 a.m. UTC | #1
On Wed, Nov 20, 2024 at 06:47:14AM +0000, Ran Xiaokai wrote:
> From: Ran Xiaokai <ran.xiaokai@zte.com.cn>
> 
> The rcu callback free_ctx() simply calls kfree().
> It's better to directly call kfree_rcu().

Why is it better? 

> Signed-off-by: Ran Xiaokai <ran.xiaokai@zte.com.cn>
> ---
>  kernel/events/core.c | 10 +---------
>  1 file changed, 1 insertion(+), 9 deletions(-)
> 
> diff --git a/kernel/events/core.c b/kernel/events/core.c
> index 065f9188b44a..7f4cc9c41bbe 100644
> --- a/kernel/events/core.c
> +++ b/kernel/events/core.c
> @@ -1210,14 +1210,6 @@ static void free_task_ctx_data(struct pmu *pmu, void *task_ctx_data)
>  		kmem_cache_free(pmu->task_ctx_cache, task_ctx_data);
>  }
>  
> -static void free_ctx(struct rcu_head *head)
> -{
> -	struct perf_event_context *ctx;
> -
> -	ctx = container_of(head, struct perf_event_context, rcu_head);
> -	kfree(ctx);
> -}
> -
>  static void put_ctx(struct perf_event_context *ctx)
>  {
>  	if (refcount_dec_and_test(&ctx->refcount)) {
> @@ -1225,7 +1217,7 @@ static void put_ctx(struct perf_event_context *ctx)
>  			put_ctx(ctx->parent_ctx);
>  		if (ctx->task && ctx->task != TASK_TOMBSTONE)
>  			put_task_struct(ctx->task);
> -		call_rcu(&ctx->rcu_head, free_ctx);
> +		kfree_rcu(ctx, rcu_head);
>  	}
>  }
>  
> -- 
> 2.17.1
> 
>
Peter Zijlstra Nov. 20, 2024, 9:16 a.m. UTC | #2
On Wed, Nov 20, 2024 at 10:12:15AM +0100, Peter Zijlstra wrote:
> On Wed, Nov 20, 2024 at 06:47:14AM +0000, Ran Xiaokai wrote:
> > From: Ran Xiaokai <ran.xiaokai@zte.com.cn>
> > 
> > The rcu callback free_ctx() simply calls kfree().
> > It's better to directly call kfree_rcu().
> 
> Why is it better? 

*sigh*, also please don't cross post with a moderated list :-(
diff mbox series

Patch

diff --git a/kernel/events/core.c b/kernel/events/core.c
index 065f9188b44a..7f4cc9c41bbe 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -1210,14 +1210,6 @@  static void free_task_ctx_data(struct pmu *pmu, void *task_ctx_data)
 		kmem_cache_free(pmu->task_ctx_cache, task_ctx_data);
 }
 
-static void free_ctx(struct rcu_head *head)
-{
-	struct perf_event_context *ctx;
-
-	ctx = container_of(head, struct perf_event_context, rcu_head);
-	kfree(ctx);
-}
-
 static void put_ctx(struct perf_event_context *ctx)
 {
 	if (refcount_dec_and_test(&ctx->refcount)) {
@@ -1225,7 +1217,7 @@  static void put_ctx(struct perf_event_context *ctx)
 			put_ctx(ctx->parent_ctx);
 		if (ctx->task && ctx->task != TASK_TOMBSTONE)
 			put_task_struct(ctx->task);
-		call_rcu(&ctx->rcu_head, free_ctx);
+		kfree_rcu(ctx, rcu_head);
 	}
 }