Discussion:
daemonize() in kernel?
NAHieu
2005-07-25 05:40:51 UTC
Permalink
Hello,

Anybody here could tell me what is the purpose of daemonize() function
in kernel? In wich case should we use it?

Thank you,
NAH

--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive: http://mail.nl.linux.org/kernelnewbies/
FAQ: http://kernelnewbies.org/faq/
Bhanu Kalyan Chetlapalli
2005-07-25 06:27:51 UTC
Permalink
daemonize() function is generally used to convert ordinary processes
into kernel threads - like kswapd, ksoftirqd etc - which do not have
an associated user-space (mm_struct). These kernel threads execute
completely in kernel-space. For processes like this check out the
/proc/<pid>/maps file - it will be empty - since they have no
associated mm_struct.

The daemonize() function reduces the reference count of the struct_mm
structure by calling exit_mm().

Note: kswapd, ksoftirqd etc are especially coded for such a switch
into the kernel, do NOT assume that an ordinary process can be
converted into a kernel thread by calling the daemonize() through a
system call or whatever.

An interesting fact about kernel threads is that since, they do NOT
have access to user space, they dont need the user space page-tables.
So, during a process switch, the TLB (Translation Lookaside Buffer) of
the previous process is not flushed (flushing is a costly operation).
This concept is called Lazy TLB Flushing.
Post by NAHieu
Hello,
Anybody here could tell me what is the purpose of daemonize() function
in kernel? In wich case should we use it?
Thank you,
NAH
--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive: http://mail.nl.linux.org/kernelnewbies/
FAQ: http://kernelnewbies.org/faq/
--
The difference between Theory and Practice is more so in Practice than
in Theory.

--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive: http://mail.nl.linux.org/kernelnewbies/
FAQ: http://kernelnewbies.org/faq/
NAHieu
2005-07-25 08:37:18 UTC
Permalink
Post by Bhanu Kalyan Chetlapalli
daemonize() function is generally used to convert ordinary processes
into kernel threads - like kswapd, ksoftirqd etc - which do not have
an associated user-space (mm_struct). These kernel threads execute
completely in kernel-space. For processes like this check out the
/proc/<pid>/maps file - it will be empty - since they have no
associated mm_struct.
Great. But what is the advantage of "converting" a current kernel
process into a kernel thread? Is that better to use kernel thread API
to create a thread?

Thank you a lot, Bhanu.
NAH

--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive: http://mail.nl.linux.org/kernelnewbies/
FAQ: http://kernelnewbies.org/faq/
Bhanu Kalyan Chetlapalli
2005-07-25 09:10:19 UTC
Permalink
The reason for implementing the entire thing (kswapd/ksoftirqd etc) in
kernel space is that, these processes must deal with the kernel stuff
so much (paging, swapping, executing bottom halves etc) that it makes
no sense to have any part of them in the user space.

AFAIK, Since the processes do not have ANY use for user space -
(working completely in the kernel) - an unused struct_mm is just a
waste of precious memory (struct_mm, pg table & the executable's code
which loaded it). So by calling daemonize they free up all the
unneeded user-space resources. (also the lazyTLB flush optimizes
things)

Does that answer your question?
Post by NAHieu
Post by Bhanu Kalyan Chetlapalli
daemonize() function is generally used to convert ordinary processes
into kernel threads - like kswapd, ksoftirqd etc - which do not have
an associated user-space (mm_struct). These kernel threads execute
completely in kernel-space. For processes like this check out the
/proc/<pid>/maps file - it will be empty - since they have no
associated mm_struct.
Great. But what is the advantage of "converting" a current kernel
process into a kernel thread? Is that better to use kernel thread API
to create a thread?
Thank you a lot, Bhanu.
NAH
--
The difference between Theory and Practice is more so in Practice than
in Theory.

--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive: http://mail.nl.linux.org/kernelnewbies/
FAQ: http://kernelnewbies.org/faq/
Loading...