Discussion:
active_mm versus mm
Roy Smith
2005-08-07 14:40:14 UTC
Permalink
Hi,

I fail to understand the difference between task->mm and task->active_mm.
I've noticed that upon forking a task, both mm and active_mm get the same
memory descriptor.
when will the active mm be different the the task's mm ? even kernel threads,
who obviously don't have any user address space, use the previous
mm/active_mm as a way to reach kernel memory areas. so why have two
different pointers ?

thanks a lot,
Roy.

--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive: http://mail.nl.linux.org/kernelnewbies/
FAQ: http://kernelnewbies.org/faq/
Mulyadi Santosa
2005-08-08 02:36:58 UTC
Permalink
Hello Roy
Post by Roy Smith
I fail to understand the difference between task->mm and
task->active_mm. I've noticed that upon forking a task, both mm and
active_mm get the same memory descriptor.
Well, here is my understanding. task_struct->mm points to memory
descriptor which is unique to each process (unless they are on the same
thread group, forked with CLONE_VM). active_mm points to the *actual*
memory descriptor used by the process when it is executed.

So why it is separated? IMHO the reason is to identify which process is
kernel thread (doesn't own a process address space) and which one is
normal process (owns a process address space). As you can see on
functions related with context switching, by checking task_struct->mm,
the scheduler can decide whether it is going to switch onto kernel
thread or not. if

it is NULL, then the process doesn't have process address space, in
other word this is a kernel thread. But you also aware that even kernel
threads don't acess user space memory, it still needs to access kernel
space. because kernel space is 100% identical for every process, kernel
thread can freely use memory descriptor (mm) owned by previously
running process. All the kernel thread needed is page tables
referencing toward virtual address bigger than PAGE_OFFSET, other are
simply ignored by it is assumed that kernel thread doesn't need to
access user space (perhaps it is somehow can be abused?)

Hope it helps answering your question

regards

Mulyadi


--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive: http://mail.nl.linux.org/kernelnewbies/
FAQ: http://kernelnewbies.org/faq/
Thomas Petazzoni
2005-08-08 08:05:32 UTC
Permalink
Hi,
Post by Mulyadi Santosa
So why it is separated? IMHO the reason is to identify which process is
kernel thread (doesn't own a process address space) and which one is
normal process (owns a process address space). As you can see on
functions related with context switching, by checking task_struct->mm,
the scheduler can decide whether it is going to switch onto kernel
thread or not. if
There's one other reason for having both task->mm and task->active_mm:
in some cases, you might be executing a process without being in the
address space of that process. This is possible because during the
execution of a syscall, you're in kernel mode, so you don't necessarily
need to be in the correct address space. This avoids some costly TLB
switches.

For more information, read section 4.3 of Mel Gorman's book at
http://www.phptr.com/content/images/0131453483/downloads/gorman_book.pdf.

Sincerly,

Thomas
--
Thomas Petazzoni
***@enix.org

--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive: http://mail.nl.linux.org/kernelnewbies/
FAQ: http://kernelnewbies.org/faq/
Roy Smith
2005-08-08 10:02:12 UTC
Permalink
Thanks !!
Post by Thomas Petazzoni
Hi,
Post by Mulyadi Santosa
So why it is separated? IMHO the reason is to identify which process is
kernel thread (doesn't own a process address space) and which one is
normal process (owns a process address space). As you can see on
functions related with context switching, by checking task_struct->mm,
the scheduler can decide whether it is going to switch onto kernel
thread or not. if
in some cases, you might be executing a process without being in the
address space of that process. This is possible because during the
execution of a syscall, you're in kernel mode, so you don't necessarily
need to be in the correct address space. This avoids some costly TLB
switches.
For more information, read section 4.3 of Mel Gorman's book at
http://www.phptr.com/content/images/0131453483/downloads/gorman_book.pdf.
Sincerly,
Thomas
--
Thomas Petazzoni
--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive: http://mail.nl.linux.org/kernelnewbies/
FAQ: http://kernelnewbies.org/faq/
--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive: http://mail.nl.linux.org/kernelnewbies/
FAQ: http://kernelnewbies.org/faq/

Loading...