OpenCloudOS-Kernel/kernel/cgroup
Roman Gushchin 4bfc0bb2c6 bpf: decouple the lifetime of cgroup_bpf from cgroup itself
Currently the lifetime of bpf programs attached to a cgroup is bound
to the lifetime of the cgroup itself. It means that if a user
forgets (or intentionally avoids) to detach a bpf program before
removing the cgroup, it will stay attached up to the release of the
cgroup. Since the cgroup can stay in the dying state (the state
between being rmdir()'ed and being released) for a very long time, it
leads to a waste of memory. Also, it blocks a possibility to implement
the memcg-based memory accounting for bpf objects, because a circular
reference dependency will occur. Charged memory pages are pinning the
corresponding memory cgroup, and if the memory cgroup is pinning
the attached bpf program, nothing will be ever released.

A dying cgroup can not contain any processes, so the only chance for
an attached bpf program to be executed is a live socket associated
with the cgroup. So in order to release all bpf data early, let's
count associated sockets using a new percpu refcounter. On cgroup
removal the counter is transitioned to the atomic mode, and as soon
as it reaches 0, all bpf programs are detached.

Because cgroup_bpf_release() can block, it can't be called from
the percpu ref counter callback directly, so instead an asynchronous
work is scheduled.

The reference counter is not socket specific, and can be used for any
other types of programs, which can be executed from a cgroup-bpf hook
outside of the process context, had such a need arise in the future.

Signed-off-by: Roman Gushchin <guro@fb.com>
Cc: jolsa@redhat.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2019-05-28 09:30:02 -07:00
..
Makefile cgroup: cgroup v2 freezer 2019-04-19 11:26:48 -07:00
cgroup-internal.h cgroup: make TRACE_CGROUP_PATH irq-safe 2019-04-19 11:26:49 -07:00
cgroup-v1.c treewide: Add SPDX license identifier for missed files 2019-05-21 10:50:45 +02:00
cgroup.c bpf: decouple the lifetime of cgroup_bpf from cgroup itself 2019-05-28 09:30:02 -07:00
cpuset.c cgroup/cpuset: Update stale generate_sched_domains() comments 2019-04-19 19:44:14 +02:00
debug.c kernel: cgroup: fix misuse of %x 2019-05-06 08:47:48 -07:00
freezer.c cgroup: get rid of cgroup_freezer_frozen_exit() 2019-05-06 08:39:11 -07:00
legacy_freezer.c cgroup: rename freezer.c into legacy_freezer.c 2019-04-19 11:26:48 -07:00
namespace.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
pids.c cgroup/pids: turn cgroup_subsys->free() into cgroup_subsys->release() to fix the accounting 2019-01-31 06:55:57 -08:00
rdma.c IB/core: Simplify rdma cgroup registration 2019-01-18 13:43:10 -07:00
rstat.c treewide: Add SPDX license identifier for missed files 2019-05-21 10:50:45 +02:00