Hi Adil, First the disclaimer. This is based on my understanding ... may not be correct ... will appreciate if someone can please CMIIW.
As per my understanding mm_struct represent the process's address space (i.e. 0-3GB area).
Correct ... it will contain VMAs only for those memory areas that are accessible by user space.
Some of the points mentioned in the Linux kernel Development (by Robert Love) book about mm_struct and kernel thread are : "Kernel threads do not have a process address space and therefore do not have an associated memory descriptor. Thus, the mm field of a kernel thread's process descriptor is NULL. " "Because kernel threads do not have any pages in user-space, they do not really deserve their own memory descriptor and page tables (page tables are discussed later in the chapter). Despite this, kernel threads need some of the data, such as the page tables, even to access kernel memory." "Kernel threads do not have an address space and mm is NULL. Therefore, when a kernel thread is scheduled, the kernel notices that mm is NULL and keeps the previous process's address space loaded. The kernel then updates the active_mm field of the kernel thread's process descriptor to refer to the previous process's memory descriptor. The kernel thread can then use the previous process's page tables as needed." Now my queries are: 1. First it is mentioned that the kernel threads dont have any page in user space and hence they dont deserve memory desriptor and page tables and in the next line it says it needs some data such as page tables to access kernel memory. What page table it is referring here?? Every process has its own page table for mapping the virtual to physical address, why kernel thread requires that?
The mm_struct is there only for representing user space memory (The memory that can be accessed in user space). Since by definition, a kernel_thread never goes into userspace, hence it does not have user space memory - thus no need for mm_struct. However, the kernel_thread certainly accesses kernel data structures that are stored in kernel space memory. So it needs an access to this memory, which is facilitated by page tables. Page tables contain virtual-to-physical address mappings for both user space memory (all of VMAs) and kernel space memory (kernel spacer mappings same for all processes). So to access these page tables, the trick described by you is used.
2. does kernel thread run in a process context? I mean it says when a kernel thread is scheduled, it keeps the previous process's address space loaded.
Yes.
3. Further it is mentioned in the same book as "Because kernel threads do not access user-space memory, they make use of only the information in the address space pertaining to kernel memory, which is the same for all processes.". That means the process's mm_struct or the page table contains the information about kernel memory?
The page tables, IMHO.
Please someone could clarify my doubts.
Please someone could confirm my reply :-) Thanks, Rajat -- To unsubscribe from this list: send an email with "unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx Please read the FAQ at http://kernelnewbies.org/FAQ