linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Andrea Arcangeli <aarcange@redhat.com>
To: Hugh Dickins <hugh.dickins@tiscali.co.uk>
Cc: Rik van Riel <riel@redhat.com>,
	linux-mm@kvack.org, Andrew Morton <akpm@linux-foundation.org>,
	Marcelo Tosatti <mtosatti@redhat.com>,
	Adam Litke <agl@us.ibm.com>, Avi Kivity <avi@redhat.com>,
	Izik Eidus <ieidus@redhat.com>, Nick Piggin <npiggin@suse.de>,
	Mel Gorman <mel@csn.ul.ie>, Dave Hansen <dave@linux.vnet.ibm.com>,
	Benjamin Herrenschmidt <benh@kernel.crashing.org>,
	Ingo Molnar <mingo@elte.hu>, Mike Travis <travis@sgi.com>,
	KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>,
	Christoph Lameter <cl@linux-foundation.org>,
	Chris Wright <chrisw@sous-sol.org>,
	bpicco@redhat.com,
	KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>,
	Balbir Singh <balbir@linux.vnet.ibm.com>,
	Arnd Bergmann <arnd@arndb.de>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Johannes Weiner <hannes@cmpxchg.org>
Subject: Re: [PATCH 35 of 41] don't leave orhpaned swap cache after ksm merging
Date: Mon, 29 Mar 2010 16:01:25 +0200	[thread overview]
Message-ID: <20100329140125.GT5825@random.random> (raw)
In-Reply-To: <20100327010818.GI5825@random.random>

On Sat, Mar 27, 2010 at 02:08:18AM +0100, Andrea Arcangeli wrote:
> more familiar with, only takes the PG_lock during page_wrprotect! Why
> do you keep the PG_lock during replace_page too? do_wp_page can't run
> as we re-verify the pte didn't change. Maybe is just to be safer?

I re-read it and I can't see any valid reason to hold the PG_lock
after write_protect_page returns. The only reason we added the PG_lock
is needed is to abort the page merging if there's any GUP pin on the
page. And so we must prevent the swapcache to alter the page_count
while we read PageSwapCache and we include it in the page_count
comparison. We also must read the pte value inside that critical
section to re-check it later inside replace_page with pte_same with
the PT lock hold to serialize against the VM.

So I think returning to the previous locking should be the preferred
way. What do you think? I don't think the fact kpage can be swapped
can affect it, "page" should always be a regular anon page and never a
ksm page. Otherwise it would be futile to try to wrprotect it in the
first place for example.

Let me know if you think something like this could be ok, and I'll
send it to Andrew separately (not more mixed with the rest).

Thanks again for spotting it ;).
Andrea

Subject: don't leave orhpaned swap cache after ksm merging

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>
---

diff --git a/mm/ksm.c b/mm/ksm.c
--- a/mm/ksm.c
+++ b/mm/ksm.c
@@ -817,7 +817,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;
@@ -863,7 +863,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
@@ -872,22 +883,20 @@ 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) {
 		munlock_vma_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;
 }

--
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>

  reply	other threads:[~2010-03-29 14:02 UTC|newest]

Thread overview: 70+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-03-26 17:00 [PATCH 00 of 41] Transparent Hugepage Support #15 Andrea Arcangeli
2010-03-26 17:00 ` [PATCH 01 of 41] define MADV_HUGEPAGE Andrea Arcangeli
2010-03-26 17:00 ` [PATCH 02 of 41] compound_lock Andrea Arcangeli
2010-03-26 17:00 ` [PATCH 03 of 41] alter compound get_page/put_page Andrea Arcangeli
2010-03-26 17:00 ` [PATCH 04 of 41] update futex compound knowledge Andrea Arcangeli
2010-03-26 17:00 ` [PATCH 05 of 41] fix bad_page to show the real reason the page is bad Andrea Arcangeli
2010-03-26 17:00 ` [PATCH 06 of 41] clear compound mapping Andrea Arcangeli
2010-03-26 17:00 ` [PATCH 07 of 41] add native_set_pmd_at Andrea Arcangeli
2010-03-26 17:00 ` [PATCH 08 of 41] add pmd paravirt ops Andrea Arcangeli
2010-03-26 17:00 ` [PATCH 09 of 41] no paravirt version of pmd ops Andrea Arcangeli
2010-03-26 17:00 ` [PATCH 10 of 41] export maybe_mkwrite Andrea Arcangeli
2010-03-26 17:00 ` [PATCH 11 of 41] comment reminder in destroy_compound_page Andrea Arcangeli
2010-03-26 17:00 ` [PATCH 12 of 41] config_transparent_hugepage Andrea Arcangeli
2010-03-26 17:00 ` [PATCH 13 of 41] special pmd_trans_* functions Andrea Arcangeli
2010-03-26 17:00 ` [PATCH 14 of 41] add pmd mangling generic functions Andrea Arcangeli
2010-03-26 17:00 ` [PATCH 15 of 41] add pmd mangling functions to x86 Andrea Arcangeli
2010-03-26 17:00 ` [PATCH 16 of 41] bail out gup_fast on splitting pmd Andrea Arcangeli
2010-03-26 17:00 ` [PATCH 17 of 41] pte alloc trans splitting Andrea Arcangeli
2010-03-26 17:00 ` [PATCH 18 of 41] add pmd mmu_notifier helpers Andrea Arcangeli
2010-03-26 17:00 ` [PATCH 19 of 41] clear page compound Andrea Arcangeli
2010-03-26 17:00 ` [PATCH 20 of 41] add pmd_huge_pte to mm_struct Andrea Arcangeli
2010-03-26 17:00 ` [PATCH 21 of 41] split_huge_page_mm/vma Andrea Arcangeli
2010-03-26 17:00 ` [PATCH 22 of 41] split_huge_page paging Andrea Arcangeli
2010-03-26 17:00 ` [PATCH 23 of 41] clear_copy_huge_page Andrea Arcangeli
2010-03-26 17:00 ` [PATCH 24 of 41] kvm mmu transparent hugepage support Andrea Arcangeli
2010-03-26 17:00 ` [PATCH 25 of 41] _GFP_NO_KSWAPD Andrea Arcangeli
2010-03-26 17:00 ` [PATCH 26 of 41] don't alloc harder for gfp nomemalloc even if nowait Andrea Arcangeli
2010-03-26 17:00 ` [PATCH 27 of 41] transparent hugepage core Andrea Arcangeli
2010-03-26 17:00 ` [PATCH 28 of 41] verify pmd_trans_huge isn't leaking Andrea Arcangeli
2010-03-26 17:00 ` [PATCH 29 of 41] madvise(MADV_HUGEPAGE) Andrea Arcangeli
2010-03-26 17:00 ` [PATCH 30 of 41] pmd_trans_huge migrate bugcheck Andrea Arcangeli
2010-03-26 17:00 ` [PATCH 31 of 41] memcg compound Andrea Arcangeli
2010-03-29  1:57   ` Daisuke Nishimura
2010-03-29 18:23     ` Andrea Arcangeli
2010-03-26 17:00 ` [PATCH 32 of 41] memcg huge memory Andrea Arcangeli
2010-03-26 17:00 ` [PATCH 33 of 41] transparent hugepage vmstat Andrea Arcangeli
2010-03-29  2:13   ` Daisuke Nishimura
2010-03-29 18:21     ` Andrea Arcangeli
2010-03-30  0:40       ` Daisuke Nishimura
2010-03-26 17:00 ` [PATCH 34 of 41] khugepaged Andrea Arcangeli
2010-03-26 17:00 ` [PATCH 35 of 41] don't leave orhpaned swap cache after ksm merging Andrea Arcangeli
2010-03-26 17:16   ` Rik van Riel
2010-03-26 17:23     ` Andrea Arcangeli
2010-03-26 21:32       ` Hugh Dickins
2010-03-27  1:08         ` Andrea Arcangeli
2010-03-29 14:01           ` Andrea Arcangeli [this message]
2010-03-30  6:56             ` Hugh Dickins
2010-04-01 16:47               ` Andrea Arcangeli
2010-03-26 17:00 ` [PATCH 36 of 41] skip transhuge pages in ksm for now Andrea Arcangeli
2010-03-26 17:20   ` Rik van Riel
2010-03-26 17:00 ` [PATCH 37 of 41] add x86 32bit support Andrea Arcangeli
2010-03-26 17:45   ` Rik van Riel
2010-03-26 17:54   ` Johannes Weiner
2010-03-26 19:54     ` Andrea Arcangeli
2010-03-26 17:00 ` [PATCH 38 of 41] mincore transparent hugepage support Andrea Arcangeli
2010-03-26 18:13   ` Rik van Riel
2010-03-26 17:00 ` [PATCH 39 of 41] add pmd_modify Andrea Arcangeli
2010-03-26 18:24   ` Rik van Riel
2010-03-26 17:00 ` [PATCH 40 of 41] mprotect: pass vma down to page table walkers Andrea Arcangeli
2010-03-26 18:26   ` Rik van Riel
2010-03-26 17:00 ` [PATCH 41 of 41] mprotect: transparent huge page support Andrea Arcangeli
2010-03-26 18:27   ` Rik van Riel
2010-03-26 17:36 ` [PATCH 00 of 41] Transparent Hugepage Support #15 Mel Gorman
2010-03-26 18:07   ` Andrea Arcangeli
2010-03-26 21:09     ` Mel Gorman
2010-03-26 18:00 ` Christoph Lameter
2010-03-26 18:23   ` Andrea Arcangeli
2010-03-26 18:44     ` Christoph Lameter
2010-03-26 19:34       ` Andrea Arcangeli
2010-03-26 19:55         ` 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=20100329140125.GT5825@random.random \
    --to=aarcange@redhat.com \
    --cc=agl@us.ibm.com \
    --cc=akpm@linux-foundation.org \
    --cc=arnd@arndb.de \
    --cc=avi@redhat.com \
    --cc=balbir@linux.vnet.ibm.com \
    --cc=benh@kernel.crashing.org \
    --cc=bpicco@redhat.com \
    --cc=chrisw@sous-sol.org \
    --cc=cl@linux-foundation.org \
    --cc=dave@linux.vnet.ibm.com \
    --cc=hannes@cmpxchg.org \
    --cc=hugh.dickins@tiscali.co.uk \
    --cc=ieidus@redhat.com \
    --cc=kamezawa.hiroyu@jp.fujitsu.com \
    --cc=kosaki.motohiro@jp.fujitsu.com \
    --cc=linux-mm@kvack.org \
    --cc=mel@csn.ul.ie \
    --cc=mingo@elte.hu \
    --cc=mst@redhat.com \
    --cc=mtosatti@redhat.com \
    --cc=npiggin@suse.de \
    --cc=peterz@infradead.org \
    --cc=riel@redhat.com \
    --cc=travis@sgi.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;
as well as URLs for NNTP newsgroup(s).