~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/Documentation/mm/active_mm.rst

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 =========
  2 Active MM
  3 =========
  4 
  5 Note, the mm_count refcount may no longer include the "lazy" users
  6 (running tasks with ->active_mm == mm && ->mm == NULL) on kernels
  7 with CONFIG_MMU_LAZY_TLB_REFCOUNT=n. Taking and releasing these lazy
  8 references must be done with mmgrab_lazy_tlb() and mmdrop_lazy_tlb()
  9 helpers, which abstract this config option.
 10 
 11 ::
 12 
 13  List:       linux-kernel
 14  Subject:    Re: active_mm
 15  From:       Linus Torvalds <torvalds () transmeta ! com>
 16  Date:       1999-07-30 21:36:24
 17 
 18  Cc'd to linux-kernel, because I don't write explanations all that often,
 19  and when I do I feel better about more people reading them.
 20 
 21  On Fri, 30 Jul 1999, David Mosberger wrote:
 22  >
 23  > Is there a brief description someplace on how "mm" vs. "active_mm" in
 24  > the task_struct are supposed to be used?  (My apologies if this was
 25  > discussed on the mailing lists---I just returned from vacation and
 26  > wasn't able to follow linux-kernel for a while).
 27 
 28  Basically, the new setup is:
 29 
 30   - we have "real address spaces" and "anonymous address spaces". The
 31     difference is that an anonymous address space doesn't care about the
 32     user-level page tables at all, so when we do a context switch into an
 33     anonymous address space we just leave the previous address space
 34     active.
 35 
 36     The obvious use for a "anonymous address space" is any thread that
 37     doesn't need any user mappings - all kernel threads basically fall into
 38     this category, but even "real" threads can temporarily say that for
 39     some amount of time they are not going to be interested in user space,
 40     and that the scheduler might as well try to avoid wasting time on
 41     switching the VM state around. Currently only the old-style bdflush
 42     sync does that.
 43 
 44   - "tsk->mm" points to the "real address space". For an anonymous process,
 45     tsk->mm will be NULL, for the logical reason that an anonymous process
 46     really doesn't _have_ a real address space at all.
 47 
 48   - however, we obviously need to keep track of which address space we
 49     "stole" for such an anonymous user. For that, we have "tsk->active_mm",
 50     which shows what the currently active address space is.
 51 
 52     The rule is that for a process with a real address space (ie tsk->mm is
 53     non-NULL) the active_mm obviously always has to be the same as the real
 54     one.
 55 
 56     For a anonymous process, tsk->mm == NULL, and tsk->active_mm is the
 57     "borrowed" mm while the anonymous process is running. When the
 58     anonymous process gets scheduled away, the borrowed address space is
 59     returned and cleared.
 60 
 61  To support all that, the "struct mm_struct" now has two counters: a
 62  "mm_users" counter that is how many "real address space users" there are,
 63  and a "mm_count" counter that is the number of "lazy" users (ie anonymous
 64  users) plus one if there are any real users.
 65 
 66  Usually there is at least one real user, but it could be that the real
 67  user exited on another CPU while a lazy user was still active, so you do
 68  actually get cases where you have a address space that is _only_ used by
 69  lazy users. That is often a short-lived state, because once that thread
 70  gets scheduled away in favour of a real thread, the "zombie" mm gets
 71  released because "mm_count" becomes zero.
 72 
 73  Also, a new rule is that _nobody_ ever has "init_mm" as a real MM any
 74  more. "init_mm" should be considered just a "lazy context when no other
 75  context is available", and in fact it is mainly used just at bootup when
 76  no real VM has yet been created. So code that used to check
 77 
 78         if (current->mm == &init_mm)
 79 
 80  should generally just do
 81 
 82         if (!current->mm)
 83 
 84  instead (which makes more sense anyway - the test is basically one of "do
 85  we have a user context", and is generally done by the page fault handler
 86  and things like that).
 87 
 88  Anyway, I put a pre-patch-2.3.13-1 on ftp.kernel.org just a moment ago,
 89  because it slightly changes the interfaces to accommodate the alpha (who
 90  would have thought it, but the alpha actually ends up having one of the
 91  ugliest context switch codes - unlike the other architectures where the MM
 92  and register state is separate, the alpha PALcode joins the two, and you
 93  need to switch both together).
 94 
 95  (From http://marc.info/?l=linux-kernel&m=93337278602211&w=2)

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php