From: Jonathan Lemon <jonathan.lemon@gmail.com>
To: <netdev@vger.kernel.org>, <ast@kernel.org>,
<daniel@iogearbox.net>, <yhs@fb.com>, <bpf@vger.kernel.org>
Cc: <kernel-team@fb.com>
Subject: [PATCH 3/3 v4 bpf-next] bpf: optimize task iteration
Date: Fri, 18 Dec 2020 10:50:32 -0800 [thread overview]
Message-ID: <20201218185032.2464558-4-jonathan.lemon@gmail.com> (raw)
In-Reply-To: <20201218185032.2464558-1-jonathan.lemon@gmail.com>
From: Jonathan Lemon <bsd@fb.com>
Only obtain the task reference count at the end of the RCU section
instead of repeatedly obtaining/releasing it when iterating though
a thread group.
Jump to the correct branch when it is known that the task is NULL.
Signed-off-by: Jonathan Lemon <jonathan.lemon@gmail.com>
---
kernel/bpf/task_iter.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/kernel/bpf/task_iter.c b/kernel/bpf/task_iter.c
index dc4007f1843b..598a8d7da5bf 100644
--- a/kernel/bpf/task_iter.c
+++ b/kernel/bpf/task_iter.c
@@ -33,7 +33,7 @@ static struct task_struct *task_seq_get_next(struct pid_namespace *ns,
pid = find_ge_pid(*tid, ns);
if (pid) {
*tid = pid_nr_ns(pid, ns);
- task = get_pid_task(pid, PIDTYPE_PID);
+ task = pid_task(pid, PIDTYPE_PID);
if (!task) {
++*tid;
goto retry;
@@ -44,6 +44,7 @@ static struct task_struct *task_seq_get_next(struct pid_namespace *ns,
++*tid;
goto retry;
}
+ get_task_struct(task);
}
rcu_read_unlock();
@@ -148,12 +149,12 @@ task_file_seq_get_next(struct bpf_iter_seq_task_file_info *info)
* it held a reference to the task/files_struct/file.
* Otherwise, it does not hold any reference.
*/
-again:
if (info->task) {
curr_task = info->task;
curr_files = info->files;
curr_fd = info->fd;
} else {
+again:
curr_task = task_seq_get_next(ns, &curr_tid, true);
if (!curr_task) {
info->task = NULL;
--
2.24.1
next prev parent reply other threads:[~2020-12-18 18:51 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-18 18:50 [PATCH 0/3 v4 bpf-next] bpf: increment and use correct thread iterator Jonathan Lemon
2020-12-18 18:50 ` [PATCH 1/3 v4 bpf-next] bpf: save correct stopping point in file seq iteration Jonathan Lemon
2020-12-18 21:01 ` Andrii Nakryiko
2020-12-24 1:08 ` Daniel Borkmann
2020-12-18 18:50 ` [PATCH 2/3 v4 bpf-next] bpf: Use thread_group_leader() Jonathan Lemon
2020-12-18 21:02 ` Andrii Nakryiko
2020-12-18 18:50 ` Jonathan Lemon [this message]
2020-12-18 21:03 ` [PATCH 3/3 v4 bpf-next] bpf: optimize task iteration 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=20201218185032.2464558-4-jonathan.lemon@gmail.com \
--to=jonathan.lemon@gmail.com \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=kernel-team@fb.com \
--cc=netdev@vger.kernel.org \
--cc=yhs@fb.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).