Skip to content

Commit 9fc8e80

Browse files
Yonghong SongAlexei Starovoitov
authored andcommitted
bpf: Add objcg to bpf_mem_alloc
The objcg is a bpf_mem_alloc level property since all bpf_mem_cache's are with the same objcg. This patch made such a property explicit. The next patch will use this property to save and restore objcg for percpu unit allocator. Acked-by: Hou Tao <[email protected]> Signed-off-by: Yonghong Song <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent 9beda16 commit 9fc8e80

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

include/linux/bpf_mem_alloc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ struct bpf_mem_caches;
1111
struct bpf_mem_alloc {
1212
struct bpf_mem_caches __percpu *caches;
1313
struct bpf_mem_cache __percpu *cache;
14+
struct obj_cgroup *objcg;
1415
bool percpu;
1516
struct work_struct work;
1617
};

kernel/bpf/memalloc.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,7 @@ int bpf_mem_alloc_init(struct bpf_mem_alloc *ma, int size, bool percpu)
523523
if (memcg_bpf_enabled())
524524
objcg = get_obj_cgroup_from_current();
525525
#endif
526+
ma->objcg = objcg;
526527
for_each_possible_cpu(cpu) {
527528
c = per_cpu_ptr(pc, cpu);
528529
c->unit_size = unit_size;
@@ -542,6 +543,7 @@ int bpf_mem_alloc_init(struct bpf_mem_alloc *ma, int size, bool percpu)
542543
#ifdef CONFIG_MEMCG_KMEM
543544
objcg = get_obj_cgroup_from_current();
544545
#endif
546+
ma->objcg = objcg;
545547
for_each_possible_cpu(cpu) {
546548
cc = per_cpu_ptr(pcc, cpu);
547549
for (i = 0; i < NUM_CACHES; i++) {
@@ -691,9 +693,8 @@ void bpf_mem_alloc_destroy(struct bpf_mem_alloc *ma)
691693
rcu_in_progress += atomic_read(&c->call_rcu_ttrace_in_progress);
692694
rcu_in_progress += atomic_read(&c->call_rcu_in_progress);
693695
}
694-
/* objcg is the same across cpus */
695-
if (c->objcg)
696-
obj_cgroup_put(c->objcg);
696+
if (ma->objcg)
697+
obj_cgroup_put(ma->objcg);
697698
destroy_mem_alloc(ma, rcu_in_progress);
698699
}
699700
if (ma->caches) {
@@ -709,8 +710,8 @@ void bpf_mem_alloc_destroy(struct bpf_mem_alloc *ma)
709710
rcu_in_progress += atomic_read(&c->call_rcu_in_progress);
710711
}
711712
}
712-
if (c->objcg)
713-
obj_cgroup_put(c->objcg);
713+
if (ma->objcg)
714+
obj_cgroup_put(ma->objcg);
714715
destroy_mem_alloc(ma, rcu_in_progress);
715716
}
716717
}

0 commit comments

Comments
 (0)