All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tejun Heo <tj@kernel.org>
To: Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Andrii Nakryiko <andrii@kernel.org>,
	Martin KaFai Lau <kafai@fb.com>, Ingo Molnar <mingo@redhat.com>,
	Peter Zijlstra <peterz@infradead.org>
Cc: bpf@vger.kernel.org, kernel-team@fb.com, linux-kernel@vger.kernel.org
Subject: [RFC] bpf: Implement prealloc for task_local_storage
Date: Wed, 20 Oct 2021 10:16:49 -1000	[thread overview]
Message-ID: <YXB5Mec4ahxXRx8K@slm.duckdns.org> (raw)

task_local_storage currently does not support pre-allocation and the memory
is allocated on demand using the GFP_ATOMIC mask. While atomic allocations
succeed most of the time and the occasional failures aren't a problem for
many use-cases, there are some which can benefit from reliable allocations -
e.g. tracking acquisitions and releases of specific resources to root cause
long-term reference leaks.

This patchset implements prealloc support for task_local_storage so that
once a map is created, it's guaranteed that the storage area is always
available for all tasks unless explicitly deleted.

The only tricky part is syncronizing against the fork path. Fortunately,
cgroup needs to do the same thing and is already using
cgroup_threadgroup_rwsem and we can use the same mechanism without adding
extra overhead. This patchset generalizes the rwsem and make cgroup and bpf
select it.

This patchset is on top of bpf-next 223f903e9c83 ("bpf: Rename BTF_KIND_TAG
to BTF_KIND_DECL_TAG") and contains the following patches:

 0001-cgroup-Drop-cgroup_-prefix-from-cgroup_threadgroup_r.patch
 0002-sched-cgroup-Generalize-threadgroup_rwsem.patch
 0003-bpf-Implement-prealloc-for-task_local_storage.patch

and also available in the following git branch:

 git://git.kernel.org/pub/scm/linux/kernel/git/tj/misc.git bpf-task-local-storage-prealloc

diffstat follows. Thanks.

 fs/exec.c                                                   |    7 +
 include/linux/bpf.h                                         |    6 +
 include/linux/bpf_local_storage.h                           |   12 +++
 include/linux/cgroup-defs.h                                 |   33 ---------
 include/linux/cgroup.h                                      |   11 +--
 include/linux/sched/threadgroup_rwsem.h                     |   46 ++++++++++++
 init/Kconfig                                                |    4 +
 kernel/bpf/Kconfig                                          |    1 
 kernel/bpf/bpf_local_storage.c                              |  112 ++++++++++++++++++++++--------
 kernel/bpf/bpf_task_storage.c                               |  138 +++++++++++++++++++++++++++++++++++++-
 kernel/cgroup/cgroup-internal.h                             |    4 -
 kernel/cgroup/cgroup-v1.c                                   |    9 +-
 kernel/cgroup/cgroup.c                                      |   74 ++++++++++++--------
 kernel/cgroup/pids.c                                        |    2 
 kernel/fork.c                                               |   16 ++++
 kernel/sched/core.c                                         |    4 +
 kernel/sched/sched.h                                        |    1 
 kernel/signal.c                                             |    7 +
 tools/testing/selftests/bpf/prog_tests/task_local_storage.c |  101 +++++++++++++++++++++++++++
 tools/testing/selftests/bpf/progs/task_ls_prealloc.c        |   15 ++++
 20 files changed, 489 insertions(+), 114 deletions(-)

--
tejun


             reply	other threads:[~2021-10-20 20:16 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-20 20:16 Tejun Heo [this message]
2021-10-20 20:17 ` [PATCH 1/3] cgroup: Drop cgroup_ prefix from cgroup_threadgroup_rwsem and friends Tejun Heo
2021-10-20 20:17 ` [PATCH 2/3] sched, cgroup: Generalize threadgroup_rwsem Tejun Heo
2021-10-20 20:18 ` [PATCH 3/3] bpf: Implement prealloc for task_local_storage Tejun Heo
2021-10-21  9:50   ` kernel test robot
2021-10-21  9:50     ` kernel test robot
2021-10-22 22:47   ` Martin KaFai Lau
2021-10-22 23:00     ` Tejun Heo
2021-10-22 17:01 ` [RFC] " Andrii Nakryiko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YXB5Mec4ahxXRx8K@slm.duckdns.org \
    --to=tj@kernel.org \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=kafai@fb.com \
    --cc=kernel-team@fb.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.