Skip to content

bpf, mm: introduce cgroup.memory=nobpf

Yafang Shao bpf cgroups linux-mm 2 versions – Applied

Status from this message: This series was applied to bpf/bpf-next.git (master)

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest4 patches 0 repliesApplied 4/4
  2. v15 patches 5 repliesSuperseded

Changes in v2 from the cover letter

- squash patches (Roman)
- commit log improvement in patch #2. (Johannes)

Patches in v2 All 4 applied

#Subject and filesSizeRepliesApplied
1/4mm: memcontrol: add new kernel parameter cgroup.memory=nobpfDocumentation/admin-guide/kernel-parameters.txt include/linux/memcontrol.h mm/memcontrol.c+30 -00 repliesApplied
2/4bpf: use bpf_map_kvcalloc in bpf_local_storageinclude/linux/bpf.h kernel/bpf/bpf_local_storage.c kernel/bpf/syscall.c+25 -20 repliesApplied
3/4bpf: allow to disable bpf map memory accountinginclude/linux/bpf.h kernel/bpf/memalloc.c kernel/bpf/syscall.c+13 -30 repliesApplied
4/4bpf: allow to disable bpf prog memory accountingkernel/bpf/core.c+7 -60 repliesApplied

Reviews trailers per patch

All 4 patches have a Reviewed-by or Acked-by.

PatchJohannes WeinerRoman Gushchin
1/4A-b A-b
2/4A-b A-b
3/4A-b A-b
4/4A-b A-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v2 thread

Cover letter [PATCH bpf-next v2 0/4] bpf, mm: introduce cgroup.memory=nobpf

The bpf memory accouting has some known problems in contianer environment,

- The container memory usage is not consistent if there's pinned bpf program
After the container restart, the leftover bpf programs won't account to the new generation, so the memory usage of the container is not consistent. This issue can be resolved by introducing selectable memcg, but we don't have an agreement on the solution yet. See also the discussions at https://lwn.net/Articles/905150/ .

- The leftover non-preallocated bpf map can't be limited
The leftover bpf map will be reparented, and thus it will be limited by the parent, rather than the container itself. Furthermore, if the parent is destroyed, it be will limited by its parent's parent, and so on. It can also be resolved by introducing selectable memcg.

- The memory dynamically allocated in bpf prog is charged into root memcg only
Nowdays the bpf prog can dynamically allocate memory, for example via bpf_obj_new(), but it only allocate from the global bpf_mem_alloc pool, so it will charge into root memcg only. That needs to be addressed by a new proposal.

So let's give the container user an option to disable bpf memory accouting.

The idea of "cgroup.memory=nobpf" is originally by Tejun[1].

[1]. https://lwn.net/ml/linux-mm/YxjOawzlgE458ezL-NiLfg/[email protected]/

Changes,
v1->v2:
- squash patches (Roman)
- commit log improvement in patch #2. (Johannes)

Yafang Shao (4):
mm: memcontrol: add new kernel parameter cgroup.memory=nobpf
bpf: use bpf_map_kvcalloc in bpf_local_storage
bpf: allow to disable bpf map memory accounting
bpf: allow to disable bpf prog memory accounting

 Documentation/admin-guide/kernel-parameters.txt |  1 +
 include/linux/bpf.h                             | 16 ++++++++++++++++
 include/linux/memcontrol.h                      | 11 +++++++++++
 kernel/bpf/bpf_local_storage.c                  |  4 ++--
 kernel/bpf/core.c                               | 13 +++++++------
 kernel/bpf/memalloc.c                           |  3 ++-
 kernel/bpf/syscall.c                            | 20 ++++++++++++++++++--
 mm/memcontrol.c                                 | 18 ++++++++++++++++++
 8 files changed, 75 insertions(+), 11 deletions(-)
Signature · 1 line
1.8.3.1