From: Christoph Lameter <clameter@sgi.com>
To: Andrea Arcangeli <andrea@qumranet.com>
Cc: Hugh Dickins <hugh@veritas.com>, Robin Holt <holt@sgi.com>,
Avi Kivity <avi@qumranet.com>, Izik Eidus <izike@qumranet.com>,
kvm-devel@lists.sourceforge.net,
Peter Zijlstra <a.p.zijlstra@chello.nl>,
general@lists.openfabrics.org,
Steve Wise <swise@opengridcomputing.com>,
Roland Dreier <rdreier@cisco.com>,
Kanoj Sarcar <kanojsarcar@yahoo.com>,
steiner@sgi.com, linux-kernel@vger.kernel.org,
linux-mm@kvack.org, daniel.blueman@quadrics.com,
Nick Piggin <npiggin@suse.de>
Subject: Re: [PATCH] mmu notifier #v11
Date: Fri, 4 Apr 2008 15:06:18 -0700 (PDT) [thread overview]
Message-ID: <Pine.LNX.4.64.0804041504310.12396@schroedinger.engr.sgi.com> (raw)
In-Reply-To: <20080404202055.GA14784@duo.random>
I am always the guy doing the cleanup after Andrea it seems. Sigh.
Here is the mm_lock/mm_unlock logic separated out for easier review.
Adds some comments. Still objectionable is the multiple ways of
invalidating pages in #v11. Callout now has similar locking to emm.
From: Christoph Lameter <clameter@sgi.com>
Subject: mm_lock: Lock a process against reclaim
Provide a way to lock an mm_struct against reclaim (try_to_unmap
etc). This is necessary for the invalidate notifier approaches so
that they can reliably add and remove a notifier.
Signed-off-by: Andrea Arcangeli <andrea@qumranet.com>
Signed-off-by: Christoph Lameter <clameter@sgi.com>
---
include/linux/mm.h | 10 ++++++++
mm/mmap.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 76 insertions(+)
Index: linux-2.6/include/linux/mm.h
===================================================================
--- linux-2.6.orig/include/linux/mm.h 2008-04-02 11:41:47.741678873 -0700
+++ linux-2.6/include/linux/mm.h 2008-04-04 15:02:17.660504756 -0700
@@ -1050,6 +1050,16 @@ extern int install_special_mapping(struc
unsigned long addr, unsigned long len,
unsigned long flags, struct page **pages);
+/*
+ * Locking and unlocking an mm against reclaim.
+ *
+ * mm_lock will take mmap_sem writably (to prevent additional vmas from being
+ * added) and then take all mapping locks of the existing vmas. With that
+ * reclaim is effectively stopped.
+ */
+extern void mm_lock(struct mm_struct *mm);
+extern void mm_unlock(struct mm_struct *mm);
+
extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
extern unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
Index: linux-2.6/mm/mmap.c
===================================================================
--- linux-2.6.orig/mm/mmap.c 2008-04-04 14:55:03.477593980 -0700
+++ linux-2.6/mm/mmap.c 2008-04-04 14:59:05.505395402 -0700
@@ -2242,3 +2242,69 @@ int install_special_mapping(struct mm_st
return 0;
}
+
+static void mm_lock_unlock(struct mm_struct *mm, int lock)
+{
+ struct vm_area_struct *vma;
+ spinlock_t *i_mmap_lock_last, *anon_vma_lock_last;
+
+ i_mmap_lock_last = NULL;
+ for (;;) {
+ spinlock_t *i_mmap_lock = (spinlock_t *) -1UL;
+ for (vma = mm->mmap; vma; vma = vma->vm_next)
+ if (vma->vm_file && vma->vm_file->f_mapping &&
+ (unsigned long) i_mmap_lock >
+ (unsigned long)
+ &vma->vm_file->f_mapping->i_mmap_lock &&
+ (unsigned long)
+ &vma->vm_file->f_mapping->i_mmap_lock >
+ (unsigned long) i_mmap_lock_last)
+ i_mmap_lock =
+ &vma->vm_file->f_mapping->i_mmap_lock;
+ if (i_mmap_lock == (spinlock_t *) -1UL)
+ break;
+ i_mmap_lock_last = i_mmap_lock;
+ if (lock)
+ spin_lock(i_mmap_lock);
+ else
+ spin_unlock(i_mmap_lock);
+ }
+
+ anon_vma_lock_last = NULL;
+ for (;;) {
+ spinlock_t *anon_vma_lock = (spinlock_t *) -1UL;
+ for (vma = mm->mmap; vma; vma = vma->vm_next)
+ if (vma->anon_vma &&
+ (unsigned long) anon_vma_lock >
+ (unsigned long) &vma->anon_vma->lock &&
+ (unsigned long) &vma->anon_vma->lock >
+ (unsigned long) anon_vma_lock_last)
+ anon_vma_lock = &vma->anon_vma->lock;
+ if (anon_vma_lock == (spinlock_t *) -1UL)
+ break;
+ anon_vma_lock_last = anon_vma_lock;
+ if (lock)
+ spin_lock(anon_vma_lock);
+ else
+ spin_unlock(anon_vma_lock);
+ }
+}
+
+/*
+ * This operation locks against the VM for all pte/vma/mm related
+ * operations that could ever happen on a certain mm. This includes
+ * vmtruncate, try_to_unmap, and all page faults. The holder
+ * must not hold any mm related lock. A single task can't take more
+ * than one mm lock in a row or it would deadlock.
+ */
+void mm_lock(struct mm_struct * mm)
+{
+ down_write(&mm->mmap_sem);
+ mm_lock_unlock(mm, 1);
+}
+
+void mm_unlock(struct mm_struct *mm)
+{
+ mm_lock_unlock(mm, 0);
+ up_write(&mm->mmap_sem);
+}
next prev parent reply other threads:[~2008-04-04 22:06 UTC|newest]
Thread overview: 51+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-04-01 20:55 [patch 0/9] [RFC] EMM Notifier V2 Christoph Lameter
2008-04-01 20:55 ` [patch 1/9] EMM Notifier: The notifier calls Christoph Lameter
2008-04-01 21:14 ` Peter Zijlstra
2008-04-01 21:38 ` Paul E. McKenney
2008-04-02 17:44 ` Christoph Lameter
2008-04-02 18:43 ` EMM: Fix rcu handling and spelling Christoph Lameter
2008-04-02 19:02 ` Paul E. McKenney
2008-04-02 6:49 ` [patch 1/9] EMM Notifier: The notifier calls Andrea Arcangeli
2008-04-02 10:59 ` Robin Holt
2008-04-02 11:16 ` Andrea Arcangeli
2008-04-02 14:26 ` Robin Holt
2008-04-02 17:59 ` Christoph Lameter
2008-04-02 19:03 ` EMM: Fixup return value handling of emm_notify() Christoph Lameter
2008-04-02 21:25 ` Andrea Arcangeli
2008-04-02 21:33 ` Christoph Lameter
2008-04-03 10:40 ` Peter Zijlstra
2008-04-03 15:00 ` Andrea Arcangeli
2008-04-03 19:14 ` Christoph Lameter
2008-04-02 21:05 ` EMM: Require single threadedness for registration Christoph Lameter
2008-04-02 22:01 ` Andrea Arcangeli
2008-04-02 22:06 ` Christoph Lameter
2008-04-02 22:17 ` Andrea Arcangeli
2008-04-02 22:41 ` Christoph Lameter
2008-04-03 1:24 ` EMM: disable other notifiers before register and unregister Christoph Lameter
2008-04-03 10:40 ` Peter Zijlstra
2008-04-03 15:29 ` Andrea Arcangeli
2008-04-03 19:20 ` Christoph Lameter
2008-04-03 20:23 ` Christoph Lameter
2008-04-04 12:30 ` Andrea Arcangeli
2008-04-04 20:20 ` [PATCH] mmu notifier #v11 Andrea Arcangeli
2008-04-04 22:06 ` Christoph Lameter [this message]
2008-04-05 0:23 ` Andrea Arcangeli
2008-04-07 5:45 ` Christoph Lameter
2008-04-07 6:02 ` Andrea Arcangeli
2008-04-02 21:53 ` [patch 1/9] EMM Notifier: The notifier calls Andrea Arcangeli
2008-04-02 21:54 ` Christoph Lameter
2008-04-02 22:09 ` Andrea Arcangeli
2008-04-02 23:04 ` Christoph Lameter
2008-04-01 20:55 ` [patch 2/9] Move tlb flushing into free_pgtables Christoph Lameter
2008-04-01 20:55 ` [patch 3/9] Convert i_mmap_lock to i_mmap_sem Christoph Lameter
2008-04-01 20:55 ` [patch 4/9] Remove tlb pointer from the parameters of unmap vmas Christoph Lameter
2008-04-01 20:55 ` [patch 5/9] Convert anon_vma lock to rw_sem and refcount Christoph Lameter
2008-04-02 17:50 ` Andrea Arcangeli
2008-04-02 18:15 ` Christoph Lameter
2008-04-02 21:56 ` Andrea Arcangeli
2008-04-02 21:56 ` Christoph Lameter
2008-04-02 22:12 ` Andrea Arcangeli
2008-04-01 20:55 ` [patch 6/9] This patch exports zap_page_range as it is needed by XPMEM Christoph Lameter
2008-04-01 20:55 ` [patch 7/9] Locking rules for taking multiple mmap_sem locks Christoph Lameter
2008-04-01 20:55 ` [patch 8/9] XPMEM: The device driver Christoph Lameter
2008-04-01 20:55 ` [patch 9/9] XPMEM: Simple example Christoph Lameter
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Pine.LNX.4.64.0804041504310.12396@schroedinger.engr.sgi.com \
--to=clameter@sgi.com \
--cc=a.p.zijlstra@chello.nl \
--cc=andrea@qumranet.com \
--cc=avi@qumranet.com \
--cc=daniel.blueman@quadrics.com \
--cc=general@lists.openfabrics.org \
--cc=holt@sgi.com \
--cc=hugh@veritas.com \
--cc=izike@qumranet.com \
--cc=kanojsarcar@yahoo.com \
--cc=kvm-devel@lists.sourceforge.net \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=npiggin@suse.de \
--cc=rdreier@cisco.com \
--cc=steiner@sgi.com \
--cc=swise@opengridcomputing.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®