From: Hugh Dickins <hugh.dickins@tiscali.co.uk>
To: Izik Eidus <ieidus@redhat.com>
Cc: Andrea Arcangeli <aarcange@redhat.com>,
Rik van Riel <riel@redhat.com>, Chris Wright <chrisw@redhat.com>,
Nick Piggin <nickpiggin@yahoo.com.au>,
Andrew Morton <akpm@linux-foundation.org>,
linux-kernel@vger.kernel.org, linux-mm@kvack.org
Subject: [PATCH 8/12] ksm: distribute remove_mm_from_lists
Date: Mon, 3 Aug 2009 13:17:15 +0100 (BST) [thread overview]
Message-ID: <Pine.LNX.4.64.0908031316180.16754@sister.anvils> (raw)
In-Reply-To: <Pine.LNX.4.64.0908031304430.16449@sister.anvils>
Do some housekeeping in ksm.c, to help make the next patch easier
to understand: remove the function remove_mm_from_lists, distributing
its code to its callsites scan_get_next_rmap_item and __ksm_exit.
That turns out to be a win in scan_get_next_rmap_item: move its
remove_trailing_rmap_items and cursor advancement up, and it becomes
simpler than before. __ksm_exit becomes messier, but will change
again; and moving its remove_trailing_rmap_items up lets us strengthen
the unstable tree item's age condition in remove_rmap_item_from_tree.
Signed-off-by: Hugh Dickins <hugh.dickins@tiscali.co.uk>
---
mm/ksm.c | 97 ++++++++++++++++++++++-------------------------------
1 file changed, 42 insertions(+), 55 deletions(-)
--- ksm7/mm/ksm.c 2009-08-02 13:50:25.000000000 +0100
+++ ksm8/mm/ksm.c 2009-08-02 13:50:32.000000000 +0100
@@ -444,14 +444,9 @@ static void remove_rmap_item_from_tree(s
* But __ksm_exit has to be careful: do the rb_erase
* if it's interrupting a scan, and this rmap_item was
* inserted by this scan rather than left from before.
- *
- * Because of the case in which remove_mm_from_lists
- * increments seqnr before removing rmaps, unstable_nr
- * may even be 2 behind seqnr, but should never be
- * further behind. Yes, I did have trouble with this!
*/
age = (unsigned char)(ksm_scan.seqnr - rmap_item->address);
- BUG_ON(age > 2);
+ BUG_ON(age > 1);
if (!age)
rb_erase(&rmap_item->node, &root_unstable_tree);
ksm_pages_unshared--;
@@ -546,37 +541,6 @@ out:
return err;
}
-static void remove_mm_from_lists(struct mm_struct *mm)
-{
- struct mm_slot *mm_slot;
-
- spin_lock(&ksm_mmlist_lock);
- mm_slot = get_mm_slot(mm);
-
- /*
- * This mm_slot is always at the scanning cursor when we're
- * called from scan_get_next_rmap_item; but it's a special
- * case when we're called from __ksm_exit.
- */
- if (ksm_scan.mm_slot == mm_slot) {
- ksm_scan.mm_slot = list_entry(
- mm_slot->mm_list.next, struct mm_slot, mm_list);
- ksm_scan.address = 0;
- ksm_scan.rmap_item = list_entry(
- &ksm_scan.mm_slot->rmap_list, struct rmap_item, link);
- if (ksm_scan.mm_slot == &ksm_mm_head)
- ksm_scan.seqnr++;
- }
-
- hlist_del(&mm_slot->link);
- list_del(&mm_slot->mm_list);
- spin_unlock(&ksm_mmlist_lock);
-
- remove_trailing_rmap_items(mm_slot, mm_slot->rmap_list.next);
- free_mm_slot(mm_slot);
- clear_bit(MMF_VM_MERGEABLE, &mm->flags);
-}
-
static u32 calc_checksum(struct page *page)
{
u32 checksum;
@@ -1248,33 +1212,31 @@ next_mm:
}
}
- if (!ksm_scan.address) {
- /*
- * We've completed a full scan of all vmas, holding mmap_sem
- * throughout, and found no VM_MERGEABLE: so do the same as
- * __ksm_exit does to remove this mm from all our lists now.
- */
- remove_mm_from_lists(mm);
- up_read(&mm->mmap_sem);
- slot = ksm_scan.mm_slot;
- if (slot != &ksm_mm_head)
- goto next_mm;
- return NULL;
- }
-
/*
* Nuke all the rmap_items that are above this current rmap:
* because there were no VM_MERGEABLE vmas with such addresses.
*/
remove_trailing_rmap_items(slot, ksm_scan.rmap_item->link.next);
- up_read(&mm->mmap_sem);
spin_lock(&ksm_mmlist_lock);
- slot = list_entry(slot->mm_list.next, struct mm_slot, mm_list);
- ksm_scan.mm_slot = slot;
+ ksm_scan.mm_slot = list_entry(slot->mm_list.next,
+ struct mm_slot, mm_list);
+ if (ksm_scan.address == 0) {
+ /*
+ * We've completed a full scan of all vmas, holding mmap_sem
+ * throughout, and found no VM_MERGEABLE: so do the same as
+ * __ksm_exit does to remove this mm from all our lists now.
+ */
+ hlist_del(&slot->link);
+ list_del(&slot->mm_list);
+ free_mm_slot(slot);
+ clear_bit(MMF_VM_MERGEABLE, &mm->flags);
+ }
spin_unlock(&ksm_mmlist_lock);
+ up_read(&mm->mmap_sem);
/* Repeat until we've completed scanning the whole list */
+ slot = ksm_scan.mm_slot;
if (slot != &ksm_mm_head)
goto next_mm;
@@ -1415,13 +1377,38 @@ int __ksm_enter(struct mm_struct *mm)
void __ksm_exit(struct mm_struct *mm)
{
+ struct mm_slot *mm_slot;
+
/*
* This process is exiting: doesn't hold and doesn't need mmap_sem;
* but we do need to exclude ksmd and other exiters while we modify
* the various lists and trees.
*/
mutex_lock(&ksm_thread_mutex);
- remove_mm_from_lists(mm);
+ spin_lock(&ksm_mmlist_lock);
+ mm_slot = get_mm_slot(mm);
+ if (!list_empty(&mm_slot->rmap_list)) {
+ spin_unlock(&ksm_mmlist_lock);
+ remove_trailing_rmap_items(mm_slot, mm_slot->rmap_list.next);
+ spin_lock(&ksm_mmlist_lock);
+ }
+
+ if (ksm_scan.mm_slot == mm_slot) {
+ ksm_scan.mm_slot = list_entry(
+ mm_slot->mm_list.next, struct mm_slot, mm_list);
+ ksm_scan.address = 0;
+ ksm_scan.rmap_item = list_entry(
+ &ksm_scan.mm_slot->rmap_list, struct rmap_item, link);
+ if (ksm_scan.mm_slot == &ksm_mm_head)
+ ksm_scan.seqnr++;
+ }
+
+ hlist_del(&mm_slot->link);
+ list_del(&mm_slot->mm_list);
+ spin_unlock(&ksm_mmlist_lock);
+
+ free_mm_slot(mm_slot);
+ clear_bit(MMF_VM_MERGEABLE, &mm->flags);
mutex_unlock(&ksm_thread_mutex);
}
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next prev parent reply other threads:[~2009-08-03 11:57 UTC|newest]
Thread overview: 53+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-08-03 12:08 [PATCH 0/12] ksm: stats, oom, doc, misc Hugh Dickins
2009-08-03 12:10 ` [PATCH 1/12] ksm: rename kernel_pages_allocated Hugh Dickins
2009-08-03 14:21 ` Izik Eidus
2009-08-03 16:48 ` Andrea Arcangeli
2009-08-03 12:11 ` [PATCH 2/12] ksm: move pages_sharing updates Hugh Dickins
2009-08-03 14:34 ` Izik Eidus
2009-08-03 16:53 ` Andrea Arcangeli
2009-08-03 17:34 ` Hugh Dickins
2009-08-03 12:11 ` [PATCH 3/12] ksm: pages_unshared and pages_volatile Hugh Dickins
2009-08-03 14:54 ` Izik Eidus
2009-08-04 21:49 ` Andrew Morton
2009-08-05 11:39 ` Hugh Dickins
2009-08-05 15:11 ` Andrea Arcangeli
2009-08-03 12:12 ` [PATCH 4/12] ksm: break cow once unshared Hugh Dickins
2009-08-03 16:00 ` Izik Eidus
2009-08-03 12:14 ` [PATCH 5/12] ksm: keep quiet while list empty Hugh Dickins
2009-08-03 16:55 ` Izik Eidus
2009-08-04 21:59 ` Andrew Morton
2009-08-05 11:54 ` Hugh Dickins
2009-08-03 12:15 ` [PATCH 6/12] ksm: five little cleanups Hugh Dickins
2009-08-04 12:41 ` Izik Eidus
2009-08-03 12:16 ` [PATCH 7/12] ksm: fix endless loop on oom Hugh Dickins
2009-08-04 12:55 ` Izik Eidus
2009-08-03 12:17 ` Hugh Dickins [this message]
2009-08-04 13:03 ` [PATCH 8/12] ksm: distribute remove_mm_from_lists Izik Eidus
2009-08-03 12:18 ` [PATCH 9/12] ksm: fix oom deadlock Hugh Dickins
2009-08-04 19:32 ` Izik Eidus
2009-08-25 14:58 ` Andrea Arcangeli
2009-08-25 15:22 ` [PATCH 13/12] ksm: fix munlock during exit_mmap deadlock Andrea Arcangeli
2009-08-25 17:49 ` Hugh Dickins
2009-08-25 18:10 ` Andrea Arcangeli
2009-08-25 18:58 ` Hugh Dickins
2009-08-25 19:45 ` Andrea Arcangeli
2009-08-26 16:18 ` Justin M. Forbes
2009-08-26 19:17 ` Hugh Dickins
2009-08-26 19:44 ` Andrea Arcangeli
2009-08-26 19:57 ` Hugh Dickins
2009-08-26 20:28 ` Andrea Arcangeli
2009-08-26 20:54 ` Izik Eidus
2009-08-26 21:14 ` Andrea Arcangeli
2009-08-26 21:49 ` Izik Eidus
2009-08-27 19:11 ` Hugh Dickins
2009-08-27 19:35 ` Izik Eidus
2009-08-26 22:00 ` David Rientjes
2009-08-26 20:29 ` Hugh Dickins
2009-08-25 17:35 ` [PATCH 9/12] ksm: fix oom deadlock Hugh Dickins
2009-08-25 17:47 ` Andrea Arcangeli
2009-08-03 12:19 ` [PATCH 10/12] ksm: sysfs and defaults Hugh Dickins
2009-08-04 19:34 ` Izik Eidus
2009-08-03 12:21 ` [PATCH 11/12] ksm: add some documentation Hugh Dickins
2009-08-04 19:35 ` Izik Eidus
2009-08-03 12:22 ` [PATCH 12/12] ksm: remove VM_MERGEABLE_FLAGS Hugh Dickins
2009-08-04 19:35 ` Izik Eidus
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.0908031316180.16754@sister.anvils \
--to=hugh.dickins@tiscali.co.uk \
--cc=aarcange@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=chrisw@redhat.com \
--cc=ieidus@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=nickpiggin@yahoo.com.au \
--cc=riel@redhat.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