-
Notifications
You must be signed in to change notification settings - Fork 78
Remove superfluous {get|put}_task_struct() calls when iterating over tasks #365
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove superfluous {get|put}_task_struct() calls when iterating over tasks #365
Conversation
Thanks @kerneltoast for that PR. I looked at the code and I think that we can drop get/put_task_struct because we are under RCU lock. p_iterate_process() is only executed when we do initialization, and we do it when all the processes are frozen (we call freeze_processes()). I'm wondering, maybe it is worth adding Thanks, |
Kthreads aren't frozen though, and all tasks in the system are iterated upon, so there is still a double-free possibility from p_iterate_processes()... or so I thought, but there's no double-free at all (see below).
This is only true for
Turns out I'm wrong about the potential double-free because a task_struct pointer which is obtained under RCU read lock is guaranteed to have a refcount of >=1 within that same RCU read-side critical section. This guarantee was introduced by this old commit from 2006. So the commit message can be simplified to say that it's just removing superfluous {get|put}_task_struct() calls. |
A bikeshed: regarding the commit message, we no longer use the CI/ED designation since LKRG 0.8 (released years ago). This change was described as follows:
We've more recently started to reuse the CI acronym to mean Continuous Integration. We still have plenty of |
Seems reasonable. Nevertheless, I'm curious if we should add |
Could you elaborate on this? I'm not seeing any race in the database creation that would be fixed by read_{un}lock(&tasklist_lock) protection. |
e53a694
to
88921b2
Compare
…tasks Since the memory for a task_struct pointer obtained via one of the task list loop macros is protected via RCU, and RCU read lock protection already encapsulates LKRG's task iterations, the {get|put}_task_struct() calls are superfluous. Even if LKRG were to need each task_struct's refcount to be nonzero during the task iteration, this is already guaranteed by the RCU protection. This guarantee was added into the kernel in an old commit from 2006: 8c7904a00b06 ("[PATCH] task: RCU protect task->usage"). As such, drop the {get|put}_task_struct() calls entirely. Signed-off-by: Sultan Alsawaf <sultan@ciq.com>
88921b2
to
175a0cc
Compare
Sure. RCU does not prevent the |
If you're referring to If you're referring to I think RCU protection is sufficient, and |
Thank you Adam and Sultan for this additional review/discussion, and I'm sorry I didn't get around to looking into that. I think this PR is ready to merge, correct? |
@kerneltoast when I refer to database creation in that context I meant ED database through |
If we do this, it'd need to be a separate commit anyhow, so not necessarily in this PR. |
@Adam-pi3 freezing is a cooperative process—it is not possible for a task to be preempted and then frozen while executing arbitrary code in the kernel. It's similarly not possible for a task to be frozen while it is sleeping somewhere inside the kernel in a non-freezable state; e.g., if a task is in the middle of Frozen tasks are parked in the aptly-named The process creation/exit code in the kernel doesn't call into the refrigerator anywhere, so there is no possibility for a task to be frozen midway through process creation/exit. |
I think I found the answer. @kerneltoast thanks for more details, although the same problem which I described may appear during process freeze. However, the logic of the
Because of that, the problem does not apply for freezing and since we are executing our logic after, we're safe (otherwise we would need to acquire |
@solardiz That's true, although I don't think is needed (please take a look at my comment #365 (comment)). I just merged the PR. |
No description provided.