lkml.org 
[lkml]   [2010]   [Nov]   [3]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Subject[PATCH 43 of 66] don't leave orhpaned swap cache after ksm merging
Date
From
From: Andrea Arcangeli <aarcange@redhat.com>

When swapcache is replaced by a ksm page don't leave orhpaned swap cache.

Signed-off-by: Andrea Arcangeli <aarcange@redhat.com>
Reviewed-by: Rik van Riel <riel@redhat.com>
---

diff --git a/mm/ksm.c b/mm/ksm.c
--- a/mm/ksm.c
+++ b/mm/ksm.c
@@ -800,7 +800,7 @@ static int replace_page(struct vm_area_s
set_pte_at_notify(mm, addr, ptep, mk_pte(kpage, vma->vm_page_prot));

page_remove_rmap(page);
- put_page(page);
+ free_page_and_swap_cache(page);

pte_unmap_unlock(ptep, ptl);
err = 0;
@@ -846,7 +846,18 @@ static int try_to_merge_one_page(struct
* ptes are necessarily already write-protected. But in either
* case, we need to lock and check page_count is not raised.
*/
- if (write_protect_page(vma, page, &orig_pte) == 0) {
+ err = write_protect_page(vma, page, &orig_pte);
+
+ /*
+ * After this mapping is wrprotected we don't need further
+ * checks for PageSwapCache vs page_count unlock_page(page)
+ * and we rely only on the pte_same() check run under PT lock
+ * to ensure the pte didn't change since when we wrprotected
+ * it under PG_lock.
+ */
+ unlock_page(page);
+
+ if (!err) {
if (!kpage) {
/*
* While we hold page lock, upgrade page from
@@ -855,22 +866,22 @@ static int try_to_merge_one_page(struct
*/
set_page_stable_node(page, NULL);
mark_page_accessed(page);
- err = 0;
} else if (pages_identical(page, kpage))
err = replace_page(vma, page, kpage, orig_pte);
- }
+ } else
+ err = -EFAULT;

if ((vma->vm_flags & VM_LOCKED) && kpage && !err) {
+ lock_page(page); /* for LRU manipulation */
munlock_vma_page(page);
+ unlock_page(page);
if (!PageMlocked(kpage)) {
- unlock_page(page);
lock_page(kpage);
mlock_vma_page(kpage);
- page = kpage; /* for final unlock */
+ unlock_page(kpage);
}
}

- unlock_page(page);
out:
return err;
}

\
 
 \ /
  Last update: 2010-11-03 16:35    [W:0.586 / U:2.732 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site