summaryrefslogtreecommitdiff
path: root/kernel/fork.c
diff options
context:
space:
mode:
authorHugh Dickins <hugh@veritas.com>2004-08-23 21:25:09 -0700
committerLinus Torvalds <torvalds@ppc970.osdl.org>2004-08-23 21:25:09 -0700
commit7dbb1d674cffcd849cd76116144aeff45a5f3f39 (patch)
tree86e1589b61284ec04a4ed7898840db17ce304cf3 /kernel/fork.c
parentc524e494f651156938ff2d76f22ad17231b77e20 (diff)
[PATCH] clarify get_task_mm (mmgrab)
Clarify mmgrab by collapsing it into get_task_mm (in fork.c not inline), and commenting on the special case it is guarding against: when use_mm in an AIO daemon temporarily adopts the mm while it's on its way out. Signed-off-by: Hugh Dickins <hugh@veritas.com> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'kernel/fork.c')
-rw-r--r--kernel/fork.c38
1 files changed, 26 insertions, 12 deletions
diff --git a/kernel/fork.c b/kernel/fork.c
index 9af20c8efbdc..477efdabe4f6 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -477,20 +477,34 @@ void mmput(struct mm_struct *mm)
}
}
-/*
- * Checks if the use count of an mm is non-zero and if so
- * returns a reference to it after bumping up the use count.
- * If the use count is zero, it means this mm is going away,
- * so return NULL.
+/**
+ * get_task_mm - acquire a reference to the task's mm
+ *
+ * Returns %NULL if the task has no mm. Checks if the use count
+ * of the mm is non-zero and if so returns a reference to it, after
+ * bumping up the use count. User must release the mm via mmput()
+ * after use. Typically used by /proc and ptrace.
+ *
+ * If the use count is zero, it means that this mm is going away,
+ * so return %NULL. This only happens in the case of an AIO daemon
+ * which has temporarily adopted an mm (see use_mm), in the course
+ * of its final mmput, before exit_aio has completed.
*/
-struct mm_struct *mmgrab(struct mm_struct *mm)
+struct mm_struct *get_task_mm(struct task_struct *task)
{
- spin_lock(&mmlist_lock);
- if (!atomic_read(&mm->mm_users))
- mm = NULL;
- else
- atomic_inc(&mm->mm_users);
- spin_unlock(&mmlist_lock);
+ struct mm_struct *mm;
+
+ task_lock(task);
+ mm = task->mm;
+ if (mm) {
+ spin_lock(&mmlist_lock);
+ if (!atomic_read(&mm->mm_users))
+ mm = NULL;
+ else
+ atomic_inc(&mm->mm_users);
+ spin_unlock(&mmlist_lock);
+ }
+ task_unlock(task);
return mm;
}