active_mm.rst 4.1 KB

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