Skip to content

Commit c114d10

Browse files
Hou Taochantra
authored andcommitted
bpf: Use rcu_trace_implies_rcu_gp() in bpf memory allocator
The memory free logic in bpf memory allocator chains a RCU Tasks Trace grace period and a normal RCU grace period one after the other, so it can ensure that both sleepable and non-sleepable programs have finished. With the introduction of rcu_trace_implies_rcu_gp(), __free_rcu_tasks_trace() can check whether or not a normal RCU grace period has also passed after a RCU Tasks Trace grace period has passed. If it is true, freeing these elements directly, else freeing through call_rcu(). Signed-off-by: Hou Tao <[email protected]>
1 parent 7b25c1a commit c114d10

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

kernel/bpf/memalloc.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -222,9 +222,13 @@ static void __free_rcu(struct rcu_head *head)
222222

223223
static void __free_rcu_tasks_trace(struct rcu_head *head)
224224
{
225-
struct bpf_mem_cache *c = container_of(head, struct bpf_mem_cache, rcu);
226-
227-
call_rcu(&c->rcu, __free_rcu);
225+
/* If RCU Tasks Trace grace period implies RCU grace period,
226+
* there is no need to invoke call_rcu().
227+
*/
228+
if (rcu_trace_implies_rcu_gp())
229+
__free_rcu(head);
230+
else
231+
call_rcu(head, __free_rcu);
228232
}
229233

230234
static void enque_to_free(struct bpf_mem_cache *c, void *obj)
@@ -253,8 +257,9 @@ static void do_call_rcu(struct bpf_mem_cache *c)
253257
*/
254258
__llist_add(llnode, &c->waiting_for_gp);
255259
/* Use call_rcu_tasks_trace() to wait for sleepable progs to finish.
256-
* Then use call_rcu() to wait for normal progs to finish
257-
* and finally do free_one() on each element.
260+
* If RCU Tasks Trace grace period implies RCU grace period, free
261+
* these elements directly, else use call_rcu() to wait for normal
262+
* progs to finish and finally do free_one() on each element.
258263
*/
259264
call_rcu_tasks_trace(&c->rcu, __free_rcu_tasks_trace);
260265
}

0 commit comments

Comments
 (0)