From: Hugh Dickins <hugh.dickins@tiscali.co.uk>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Izik Eidus <ieidus@redhat.com>,
Andrea Arcangeli <aarcange@redhat.com>,
linux-kernel@vger.kernel.org, linux-mm@kvack.org
Subject: [PATCH 2/6] ksm: remove redundancies when merging page
Date: Thu, 12 Nov 2009 23:15:01 +0000 (GMT) [thread overview]
Message-ID: <Pine.LNX.4.64.0911122314040.4050@sister.anvils> (raw)
In-Reply-To: <Pine.LNX.4.64.0911122303450.3378@sister.anvils>
There is no need for replace_page() to calculate a write-protected prot
vm_page_prot must already be write-protected for an anonymous page (see
mm/memory.c do_anonymous_page() for similar reliance on vm_page_prot).
There is no need for try_to_merge_one_page() to get_page and put_page
on newpage and oldpage: in every case we already hold a reference to
each of them.
But some instinct makes me move try_to_merge_one_page()'s unlock_page
of oldpage down after replace_page(): that doesn't increase contention
on the ksm page, and makes thinking about the transition easier.
Signed-off-by: Hugh Dickins <hugh.dickins@tiscali.co.uk>
---
mm/ksm.c | 26 ++++++--------------------
1 file changed, 6 insertions(+), 20 deletions(-)
--- ksm1/mm/ksm.c 2009-11-12 15:28:36.000000000 +0000
+++ ksm2/mm/ksm.c 2009-11-12 15:28:42.000000000 +0000
@@ -647,7 +647,7 @@ static int write_protect_page(struct vm_
* Check that no O_DIRECT or similar I/O is in progress on the
* page
*/
- if ((page_mapcount(page) + 2 + swapped) != page_count(page)) {
+ if (page_mapcount(page) + 1 + swapped != page_count(page)) {
set_pte_at_notify(mm, addr, ptep, entry);
goto out_unlock;
}
@@ -682,11 +682,8 @@ static int replace_page(struct vm_area_s
pte_t *ptep;
spinlock_t *ptl;
unsigned long addr;
- pgprot_t prot;
int err = -EFAULT;
- prot = vm_get_page_prot(vma->vm_flags & ~VM_WRITE);
-
addr = page_address_in_vma(oldpage, vma);
if (addr == -EFAULT)
goto out;
@@ -714,7 +711,7 @@ static int replace_page(struct vm_area_s
flush_cache_page(vma, addr, pte_pfn(*ptep));
ptep_clear_flush(vma, addr, ptep);
- set_pte_at_notify(mm, addr, ptep, mk_pte(newpage, prot));
+ set_pte_at_notify(mm, addr, ptep, mk_pte(newpage, vma->vm_page_prot));
page_remove_rmap(oldpage);
put_page(oldpage);
@@ -746,13 +743,9 @@ static int try_to_merge_one_page(struct
if (!(vma->vm_flags & VM_MERGEABLE))
goto out;
-
if (!PageAnon(oldpage))
goto out;
- get_page(newpage);
- get_page(oldpage);
-
/*
* We need the page lock to read a stable PageSwapCache in
* write_protect_page(). We use trylock_page() instead of
@@ -761,25 +754,18 @@ static int try_to_merge_one_page(struct
* then come back to this page when it is unlocked.
*/
if (!trylock_page(oldpage))
- goto out_putpage;
+ goto out;
/*
* If this anonymous page is mapped only here, its pte may need
* to be write-protected. If it's mapped elsewhere, all of its
* 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, oldpage, &orig_pte)) {
- unlock_page(oldpage);
- goto out_putpage;
- }
- unlock_page(oldpage);
-
- if (pages_identical(oldpage, newpage))
+ if (write_protect_page(vma, oldpage, &orig_pte) == 0 &&
+ pages_identical(oldpage, newpage))
err = replace_page(vma, oldpage, newpage, orig_pte);
-out_putpage:
- put_page(oldpage);
- put_page(newpage);
+ unlock_page(oldpage);
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>
next prev parent reply other threads:[~2009-11-12 23:15 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-11-12 23:12 [PATCH 0/6] ksm: not quite swapping yet Hugh Dickins
2009-11-12 23:13 ` [PATCH 1/6] ksm: three remove_rmap_item_from_tree cleanups Hugh Dickins
2009-11-12 23:15 ` Hugh Dickins [this message]
2009-11-12 23:17 ` [PATCH 3/6] ksm: cleanup some function arguments Hugh Dickins
2009-11-12 23:17 ` [PATCH 4/6] ksm: singly-linked rmap_list Hugh Dickins
2009-11-12 23:19 ` [PATCH 5/6] ksm: separate stable_node Hugh Dickins
2009-11-12 23:20 ` [PATCH 6/6] ksm: stable_node point to page and back Hugh Dickins
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.0911122314040.4050@sister.anvils \
--to=hugh.dickins@tiscali.co.uk \
--cc=aarcange@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=ieidus@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
/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