Back to home page

OSCL-LXR

 
 

    


0001 .. _active_mm:
0002 
0003 =========
0004 Active MM
0005 =========
0006 
0007 ::
0008 
0009  List:       linux-kernel
0010  Subject:    Re: active_mm
0011  From:       Linus Torvalds <torvalds () transmeta ! com>
0012  Date:       1999-07-30 21:36:24
0013 
0014  Cc'd to linux-kernel, because I don't write explanations all that often,
0015  and when I do I feel better about more people reading them.
0016 
0017  On Fri, 30 Jul 1999, David Mosberger wrote:
0018  >
0019  > Is there a brief description someplace on how "mm" vs. "active_mm" in
0020  > the task_struct are supposed to be used?  (My apologies if this was
0021  > discussed on the mailing lists---I just returned from vacation and
0022  > wasn't able to follow linux-kernel for a while).
0023 
0024  Basically, the new setup is:
0025 
0026   - we have "real address spaces" and "anonymous address spaces". The
0027     difference is that an anonymous address space doesn't care about the
0028     user-level page tables at all, so when we do a context switch into an
0029     anonymous address space we just leave the previous address space
0030     active.
0031 
0032     The obvious use for a "anonymous address space" is any thread that
0033     doesn't need any user mappings - all kernel threads basically fall into
0034     this category, but even "real" threads can temporarily say that for
0035     some amount of time they are not going to be interested in user space,
0036     and that the scheduler might as well try to avoid wasting time on
0037     switching the VM state around. Currently only the old-style bdflush
0038     sync does that.
0039 
0040   - "tsk->mm" points to the "real address space". For an anonymous process,
0041     tsk->mm will be NULL, for the logical reason that an anonymous process
0042     really doesn't _have_ a real address space at all.
0043 
0044   - however, we obviously need to keep track of which address space we
0045     "stole" for such an anonymous user. For that, we have "tsk->active_mm",
0046     which shows what the currently active address space is.
0047 
0048     The rule is that for a process with a real address space (ie tsk->mm is
0049     non-NULL) the active_mm obviously always has to be the same as the real
0050     one.
0051 
0052     For a anonymous process, tsk->mm == NULL, and tsk->active_mm is the
0053     "borrowed" mm while the anonymous process is running. When the
0054     anonymous process gets scheduled away, the borrowed address space is
0055     returned and cleared.
0056 
0057  To support all that, the "struct mm_struct" now has two counters: a
0058  "mm_users" counter that is how many "real address space users" there are,
0059  and a "mm_count" counter that is the number of "lazy" users (ie anonymous
0060  users) plus one if there are any real users.
0061 
0062  Usually there is at least one real user, but it could be that the real
0063  user exited on another CPU while a lazy user was still active, so you do
0064  actually get cases where you have a address space that is _only_ used by
0065  lazy users. That is often a short-lived state, because once that thread
0066  gets scheduled away in favour of a real thread, the "zombie" mm gets
0067  released because "mm_count" becomes zero.
0068 
0069  Also, a new rule is that _nobody_ ever has "init_mm" as a real MM any
0070  more. "init_mm" should be considered just a "lazy context when no other
0071  context is available", and in fact it is mainly used just at bootup when
0072  no real VM has yet been created. So code that used to check
0073 
0074         if (current->mm == &init_mm)
0075 
0076  should generally just do
0077 
0078         if (!current->mm)
0079 
0080  instead (which makes more sense anyway - the test is basically one of "do
0081  we have a user context", and is generally done by the page fault handler
0082  and things like that).
0083 
0084  Anyway, I put a pre-patch-2.3.13-1 on ftp.kernel.org just a moment ago,
0085  because it slightly changes the interfaces to accommodate the alpha (who
0086  would have thought it, but the alpha actually ends up having one of the
0087  ugliest context switch codes - unlike the other architectures where the MM
0088  and register state is separate, the alpha PALcode joins the two, and you
0089  need to switch both together).
0090 
0091  (From http://marc.info/?l=linux-kernel&m=93337278602211&w=2)