is a task_struct vfork_done completion special only for kthreads?
(what is probably the first in a plethora of silly questions as i dig into the ugly details of various kernel features. you've been warned.) clawing my way through the kernel code for kthreads and i notice the following. in kernel/kthread.c, we have: === struct kthread { int should_stop; void *data; struct completion exited; }; #define to_kthread(tsk) \ container_of((tsk)->vfork_done, struct kthread, exited) === in other words, the kthread to associated "task_struct" mapping is based on the fact that this member field in task_struct: struct completion *vfork_done; /* for vfork() */ will point at the "exited" completion object in the corresponding "struct kthread". is the above construct only true for kthreads, in the sense of, unless you've specifically created a kthread, the vfork_done pointer in task_struct is to a simple completion. but if the task is a kthread, the vfork_done pointer is *still* to a completion, but it's a completion that's encapsulated in a larger structure that's meant to be manipulated by kthread routines, obviously. as a test, i did this: === $ grep -r "container_of.*vfork_done" * kernel/kthread.c: container_of((tsk)->vfork_done, struct kthread, exited) $ === so it appears that that vfork_done field is only ever "container_of"ed with respect to kthreads and nowhere else. thoughts? rday -- ======================================================================== Robert P. J. Day Ottawa, Ontario, CANADA http://crashcourse.ca Twitter: http://twitter.com/rpjday LinkedIn: http://ca.linkedin.com/in/rpjday ========================================================================
Hi Rob... On Thu, Jun 14, 2012 at 7:03 PM, Robert P. J. Day <rpjday@crashcourse.ca> wrote:
(what is probably the first in a plethora of silly questions as i dig into the ugly details of various kernel features. you've been warned.)
clawing my way through the kernel code for kthreads and i notice the following. in kernel/kthread.c, we have:
===
struct kthread { int should_stop; void *data; struct completion exited; };
#define to_kthread(tsk) \ container_of((tsk)->vfork_done, struct kthread, exited)
perhaps because somehow kernel thread in some ways are treated like normal vfork()? the way I see it is this: kernel thread borrows previously running mm_struct. In this scope, if somehow the real owner mm_struct is going to be destroyed, it must wait for the borrower (kernel thread) to finish first. Maybe this is where that vfork_done<-->exited correlation is used. -- regards, Mulyadi Santosa Freelance Linux trainer and consultant blog: the-hydra.blogspot.com training: mulyaditraining.blogspot.com
participants (2)
-
Mulyadi Santosa -
Robert P. J. Day