perf/core: Using kfree_rcu() to simplify the code in put_ctx()
PATCH 1/1 perf/core: Using kfree_rcu() to simplify the code in put_ctx()
After commit 983bd8543b5a ("perf: Rewrite core context handling"), the callback function of call_rcu() just calls a kfree(), so we can use kfree_rcu() instead of call_rcu() + callback function.
--- kernel/events/core.c | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-)
kernel/events/core.c +1 -9
@@ -1157,14 +1157,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)) {
@@ -1172,7 +1164,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); } }
Signature · 1 line
2.25.1
Peter Zijlstra
maintainerQuoted 29 lines · Yang Yingliang
After commit
983bd8543b5a("perf: Rewrite core context handling"), the callback function ofcall_rcu()just calls akfree(), so we can usekfree_rcu()instead ofcall_rcu()+ callback function.Signed-off-by Yang Yingliang <[email protected]>--- kernel/events/core.c | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-)kernel/events/core.c +0
-8@@ -1157,14 +1157,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)) {
kernel/events/core.c static void put_ctx(struct perf_event_context *ctx) · line 1169
Quoted 7 lines
kernel/events/core.c +1
-1@@ -1172,7 +1164,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); } }
While valid; I think I prefer the explicit form. This makes it much easier to add some debug code for example.
Hi,
Quoted 31 lines · Peter Zijlstra
Quoted 30 lines · Yang Yingliang
After commit
983bd8543b5a("perf: Rewrite core context handling"), the callback function ofcall_rcu()just calls akfree(), so we can usekfree_rcu()instead ofcall_rcu()+ callback function.Signed-off-by Yang Yingliang <[email protected]>--- kernel/events/core.c | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-)kernel/events/core.c +0
-8@@ -1157,14 +1157,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)) {@@ -1172,7 +1164,7 @@ static void put_ctx(struct perf_event_context *ctx)put_ctx (ctx->parent_ctx);
Quoted 8 lines
kernel/events/core.c static void put_ctx(struct perf_event_context *ctx) · line 1169
Quoted 6 lines
kernel/events/core.c +1
-1if (ctx->task && ctx->task !=TASK_TOMBSTONE )put_task_struct (ctx->task); -call_rcu (&ctx->rcu_head, free_ctx); +kfree_rcu (ctx, rcu_head); } }While valid; I think I prefer the explicit form. This makes it much easier to add some debug code for example.
Good point, thanks for replying.
Yang
Quoted 2 lines
.