All of lore.kernel.org
 help / color / mirror / Atom feed
From: Izik Eidus <ieidus@redhat.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org,
	kvm@vger.kernel.org, aarcange@redhat.com, chrisw@redhat.com,
	avi@redhat.com, izike@qumranet.com
Subject: Re: [PATCH 2/4] Add replace_page(), change the mapping of pte from one page into another
Date: Tue, 11 Nov 2008 22:57:36 +0200	[thread overview]
Message-ID: <4919F1C0.2050009@redhat.com> (raw)
In-Reply-To: <20081111114555.eb808843.akpm@linux-foundation.org>

Andrew Morton wrote:
> On Tue, 11 Nov 2008 15:21:39 +0200
> Izik Eidus <ieidus@redhat.com> wrote:
>
>   
>> From: Izik Eidus <izike@qumranet.com>
>>
>> this function is needed in cases you want to change the userspace
>> virtual mapping into diffrent physical page,
>>     
>
> Not sure that I understand that description.  We want to replace a live
> page in an anonymous VMA with a different one?
>
> It looks that way.
>   
yes but it replace it with kernel allocated page.
> page migration already kinda does that.  Is there common ground?
>
>   
page migration as far as i saw cant migrate anonymous page into kernel page.
if you want we can change page_migration to do that, but i thought you 
will rather have ksm changes separate.

>> KSM need this for merging the identical pages.
>>
>> this function is working by removing the oldpage from the rmap and
>> calling put_page on it, and by setting the virtual address pte
>> to point into the new page.
>> (note that the new page (the page that we change the pte to map to)
>> cannot be anonymous page)
>>
>>     
>
> I don't understand the restrictions on anonymous pages.  Please expand
> the changelog so that reviewers can understand the reasons for this
> restriction.
>   
the page that we are going to map into the pte going to be nonlinear 
from the point of view of anon-vma
therefore it cannot be anonymous.

>
>   
>> ---
>>  include/linux/mm.h |    3 ++
>>  mm/memory.c        |   68 ++++++++++++++++++++++++++++++++++++++++++++++++++++
>>  2 files changed, 71 insertions(+), 0 deletions(-)
>>
>> diff --git a/include/linux/mm.h b/include/linux/mm.h
>> index ffee2f7..4da7fa8 100644
>> --- a/include/linux/mm.h
>> +++ b/include/linux/mm.h
>> @@ -1207,6 +1207,9 @@ int vm_insert_pfn(struct vm_area_struct *vma, unsigned long addr,
>>  int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
>>  			unsigned long pfn);
>>  
>> +int replace_page(struct vm_area_struct *vma, struct page *oldpage,
>> +		 struct page *newpage, pte_t orig_pte, pgprot_t prot);
>> +
>>  struct page *follow_page(struct vm_area_struct *, unsigned long address,
>>  			unsigned int foll_flags);
>>  #define FOLL_WRITE	0x01	/* check pte is writable */
>> diff --git a/mm/memory.c b/mm/memory.c
>> index 164951c..b2c542c 100644
>> --- a/mm/memory.c
>> +++ b/mm/memory.c
>> @@ -1472,6 +1472,74 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
>>  }
>>  EXPORT_SYMBOL(vm_insert_mixed);
>>  
>> +/**
>> + * replace _page - replace the pte mapping related to vm area between two pages
>>     
>
> s/replace _page/replace_page/
>
>   
>> + * (from oldpage to newpage)
>> + * NOTE: you should take into consideration the impact on the VM when replacing
>> + * anonymous pages with kernel non swappable pages.
>> + */
>>     
>
> This _is_ a kerneldoc comment, but kernedoc comments conventionally
> document the arguments and the return value also.
>
>   
>> +int replace_page(struct vm_area_struct *vma, struct page *oldpage,
>> +		 struct page *newpage, pte_t orig_pte, pgprot_t prot)
>> +{
>> +	struct mm_struct *mm = vma->vm_mm;
>> +	pgd_t *pgd;
>> +	pud_t *pud;
>> +	pmd_t *pmd;
>> +	pte_t *ptep;
>> +	spinlock_t *ptl;
>> +	unsigned long addr;
>> +	int ret;
>> +
>> +	BUG_ON(PageAnon(newpage));
>> +
>> +	ret = -EFAULT;
>> +	addr = page_address_in_vma(oldpage, vma);
>> +	if (addr == -EFAULT)
>> +		goto out;
>> +
>> +	pgd = pgd_offset(mm, addr);
>> +	if (!pgd_present(*pgd))
>> +		goto out;
>> +
>> +	pud = pud_offset(pgd, addr);
>> +	if (!pud_present(*pud))
>> +		goto out;
>> +
>> +	pmd = pmd_offset(pud, addr);
>> +	if (!pmd_present(*pmd))
>> +		goto out;
>> +
>> +	ptep = pte_offset_map_lock(mm, pmd, addr, &ptl);
>> +	if (!ptep)
>> +		goto out;
>> +
>> +	if (!pte_same(*ptep, orig_pte)) {
>> +		pte_unmap_unlock(ptep, ptl);
>> +		goto out;
>> +	}
>> +
>> +	ret = 0;
>> +	get_page(newpage);
>> +	page_add_file_rmap(newpage);
>> +
>> +	flush_cache_page(vma, addr, pte_pfn(*ptep));
>> +	ptep_clear_flush(vma, addr, ptep);
>> +	set_pte_at(mm, addr, ptep, mk_pte(newpage, prot));
>> +
>> +	page_remove_rmap(oldpage, vma);
>> +	if (PageAnon(oldpage)) {
>> +		dec_mm_counter(mm, anon_rss);
>> +		inc_mm_counter(mm, file_rss);
>> +	}
>> +	put_page(oldpage);
>> +
>> +	pte_unmap_unlock(ptep, ptl);
>> +
>> +out:
>> +	return ret;
>> +}
>> +EXPORT_SYMBOL(replace_page);
>>     
>
> Again, we could make the presence of this code selectable by subsystems
> which want it.
>
> ]

sure.


WARNING: multiple messages have this Message-ID (diff)
From: Izik Eidus <ieidus@redhat.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org,
	kvm@vger.kernel.org, aarcange@redhat.com, chrisw@redhat.com,
	avi@redhat.com, izike@qumranet.com
Subject: Re: [PATCH 2/4] Add replace_page(), change the mapping of pte from one page into another
Date: Tue, 11 Nov 2008 22:57:36 +0200	[thread overview]
Message-ID: <4919F1C0.2050009@redhat.com> (raw)
In-Reply-To: <20081111114555.eb808843.akpm@linux-foundation.org>

Andrew Morton wrote:
> On Tue, 11 Nov 2008 15:21:39 +0200
> Izik Eidus <ieidus@redhat.com> wrote:
>
>   
>> From: Izik Eidus <izike@qumranet.com>
>>
>> this function is needed in cases you want to change the userspace
>> virtual mapping into diffrent physical page,
>>     
>
> Not sure that I understand that description.  We want to replace a live
> page in an anonymous VMA with a different one?
>
> It looks that way.
>   
yes but it replace it with kernel allocated page.
> page migration already kinda does that.  Is there common ground?
>
>   
page migration as far as i saw cant migrate anonymous page into kernel page.
if you want we can change page_migration to do that, but i thought you 
will rather have ksm changes separate.

>> KSM need this for merging the identical pages.
>>
>> this function is working by removing the oldpage from the rmap and
>> calling put_page on it, and by setting the virtual address pte
>> to point into the new page.
>> (note that the new page (the page that we change the pte to map to)
>> cannot be anonymous page)
>>
>>     
>
> I don't understand the restrictions on anonymous pages.  Please expand
> the changelog so that reviewers can understand the reasons for this
> restriction.
>   
the page that we are going to map into the pte going to be nonlinear 
from the point of view of anon-vma
therefore it cannot be anonymous.

>
>   
>> ---
>>  include/linux/mm.h |    3 ++
>>  mm/memory.c        |   68 ++++++++++++++++++++++++++++++++++++++++++++++++++++
>>  2 files changed, 71 insertions(+), 0 deletions(-)
>>
>> diff --git a/include/linux/mm.h b/include/linux/mm.h
>> index ffee2f7..4da7fa8 100644
>> --- a/include/linux/mm.h
>> +++ b/include/linux/mm.h
>> @@ -1207,6 +1207,9 @@ int vm_insert_pfn(struct vm_area_struct *vma, unsigned long addr,
>>  int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
>>  			unsigned long pfn);
>>  
>> +int replace_page(struct vm_area_struct *vma, struct page *oldpage,
>> +		 struct page *newpage, pte_t orig_pte, pgprot_t prot);
>> +
>>  struct page *follow_page(struct vm_area_struct *, unsigned long address,
>>  			unsigned int foll_flags);
>>  #define FOLL_WRITE	0x01	/* check pte is writable */
>> diff --git a/mm/memory.c b/mm/memory.c
>> index 164951c..b2c542c 100644
>> --- a/mm/memory.c
>> +++ b/mm/memory.c
>> @@ -1472,6 +1472,74 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
>>  }
>>  EXPORT_SYMBOL(vm_insert_mixed);
>>  
>> +/**
>> + * replace _page - replace the pte mapping related to vm area between two pages
>>     
>
> s/replace _page/replace_page/
>
>   
>> + * (from oldpage to newpage)
>> + * NOTE: you should take into consideration the impact on the VM when replacing
>> + * anonymous pages with kernel non swappable pages.
>> + */
>>     
>
> This _is_ a kerneldoc comment, but kernedoc comments conventionally
> document the arguments and the return value also.
>
>   
>> +int replace_page(struct vm_area_struct *vma, struct page *oldpage,
>> +		 struct page *newpage, pte_t orig_pte, pgprot_t prot)
>> +{
>> +	struct mm_struct *mm = vma->vm_mm;
>> +	pgd_t *pgd;
>> +	pud_t *pud;
>> +	pmd_t *pmd;
>> +	pte_t *ptep;
>> +	spinlock_t *ptl;
>> +	unsigned long addr;
>> +	int ret;
>> +
>> +	BUG_ON(PageAnon(newpage));
>> +
>> +	ret = -EFAULT;
>> +	addr = page_address_in_vma(oldpage, vma);
>> +	if (addr == -EFAULT)
>> +		goto out;
>> +
>> +	pgd = pgd_offset(mm, addr);
>> +	if (!pgd_present(*pgd))
>> +		goto out;
>> +
>> +	pud = pud_offset(pgd, addr);
>> +	if (!pud_present(*pud))
>> +		goto out;
>> +
>> +	pmd = pmd_offset(pud, addr);
>> +	if (!pmd_present(*pmd))
>> +		goto out;
>> +
>> +	ptep = pte_offset_map_lock(mm, pmd, addr, &ptl);
>> +	if (!ptep)
>> +		goto out;
>> +
>> +	if (!pte_same(*ptep, orig_pte)) {
>> +		pte_unmap_unlock(ptep, ptl);
>> +		goto out;
>> +	}
>> +
>> +	ret = 0;
>> +	get_page(newpage);
>> +	page_add_file_rmap(newpage);
>> +
>> +	flush_cache_page(vma, addr, pte_pfn(*ptep));
>> +	ptep_clear_flush(vma, addr, ptep);
>> +	set_pte_at(mm, addr, ptep, mk_pte(newpage, prot));
>> +
>> +	page_remove_rmap(oldpage, vma);
>> +	if (PageAnon(oldpage)) {
>> +		dec_mm_counter(mm, anon_rss);
>> +		inc_mm_counter(mm, file_rss);
>> +	}
>> +	put_page(oldpage);
>> +
>> +	pte_unmap_unlock(ptep, ptl);
>> +
>> +out:
>> +	return ret;
>> +}
>> +EXPORT_SYMBOL(replace_page);
>>     
>
> Again, we could make the presence of this code selectable by subsystems
> which want it.
>
> ]

sure.

--
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:[~2008-11-11 20:59 UTC|newest]

Thread overview: 139+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-11-11 13:21 [PATCH 0/4] ksm - dynamic page sharing driver for linux Izik Eidus
2008-11-11 13:21 ` Izik Eidus
2008-11-11 13:21 ` [PATCH 1/4] rmap: add page_wrprotect() function, Izik Eidus
2008-11-11 13:21   ` Izik Eidus, Izik Eidus
2008-11-11 13:21   ` [PATCH 2/4] Add replace_page(), change the mapping of pte from one page into another Izik Eidus
2008-11-11 13:21     ` Izik Eidus, Izik Eidus
2008-11-11 13:21     ` [PATCH 3/4] add ksm kernel shared memory driver Izik Eidus
2008-11-11 13:21       ` Izik Eidus, Izik Eidus
2008-11-11 13:21       ` [PATCH 4/4] MMU_NOTIFIRES: add set_pte_at_notify() Izik Eidus
2008-11-11 13:21         ` Izik Eidus, Izik Eidus
2008-11-11 20:38       ` [PATCH 3/4] add ksm kernel shared memory driver Andrew Morton
2008-11-11 20:38         ` Andrew Morton
2008-11-11 22:03         ` Andrea Arcangeli
2008-11-11 22:03           ` Andrea Arcangeli
2008-11-11 22:03       ` Jonathan Corbet
2008-11-11 22:03         ` Jonathan Corbet
2008-11-11 22:17         ` Izik Eidus
2008-11-11 22:17           ` Izik Eidus
2008-11-11 22:25           ` Jonathan Corbet
2008-11-11 22:25             ` Jonathan Corbet
2008-11-11 22:31             ` Izik Eidus
2008-11-11 22:31               ` Izik Eidus
2008-11-11 22:30           ` Jonathan Corbet
2008-11-11 22:30             ` Jonathan Corbet
2008-11-11 22:38             ` Izik Eidus
2008-11-11 22:38               ` Izik Eidus
2008-11-11 23:02             ` Izik Eidus
2008-11-11 23:02               ` Izik Eidus
2008-11-11 23:03             ` Andrea Arcangeli
2008-11-11 23:03               ` Andrea Arcangeli
2008-11-11 22:49           ` Avi Kivity
2008-11-11 22:49             ` Avi Kivity
2008-11-11 22:40         ` Valdis.Kletnieks
2008-11-13  6:13           ` Eric Rannaud
2008-11-13  6:13             ` Eric Rannaud
2008-11-11 22:43         ` Avi Kivity
2008-11-11 22:43           ` Avi Kivity
2008-11-11 19:45     ` [PATCH 2/4] Add replace_page(), change the mapping of pte from one page into another Andrew Morton
2008-11-11 19:45       ` Andrew Morton
2008-11-11 20:57       ` Izik Eidus [this message]
2008-11-11 20:57         ` Izik Eidus
2008-11-11 21:21         ` Christoph Lameter
2008-11-11 21:21           ` Christoph Lameter
2008-11-11 21:23           ` Izik Eidus
2008-11-11 21:23             ` Izik Eidus
2008-11-11 21:31             ` Christoph Lameter
2008-11-11 21:31               ` Christoph Lameter
2008-11-11 21:37               ` Izik Eidus
2008-11-11 21:37                 ` Izik Eidus
2008-11-11 22:24               ` Andrea Arcangeli
2008-11-11 22:24                 ` Andrea Arcangeli
2008-11-12  2:19                 ` KAMEZAWA Hiroyuki
2008-11-12  2:19                   ` KAMEZAWA Hiroyuki
2008-11-12 10:05                   ` Avi Kivity
2008-11-12 10:05                     ` Avi Kivity
2008-11-12 11:11                     ` Izik Eidus
2008-11-12 11:11                       ` Izik Eidus
2008-11-13  6:11                       ` KAMEZAWA Hiroyuki
2008-11-13  6:11                         ` KAMEZAWA Hiroyuki
2008-11-13 10:38                         ` Izik Eidus
2008-11-13 10:38                           ` Izik Eidus
2008-11-13 11:32                           ` KAMEZAWA Hiroyuki
2008-11-13 11:32                             ` KAMEZAWA Hiroyuki
2008-11-11 21:35           ` Andrea Arcangeli
2008-11-11 21:35             ` Andrea Arcangeli
2008-11-11 21:06       ` Andrea Arcangeli
2008-11-11 21:06         ` Andrea Arcangeli
2008-11-11 21:26         ` Christoph Lameter
2008-11-11 21:26           ` Christoph Lameter
2008-11-11 21:39           ` Avi Kivity
2008-11-11 21:39             ` Avi Kivity
2008-11-11 21:47             ` Christoph Lameter
2008-11-11 21:47               ` Christoph Lameter
2008-11-11 21:55               ` Izik Eidus
2008-11-11 21:55                 ` Izik Eidus
2008-11-11 22:36               ` Avi Kivity
2008-11-11 22:36                 ` Avi Kivity
2008-11-11 22:17           ` Andrea Arcangeli
2008-11-11 22:17             ` Andrea Arcangeli
2008-11-11 22:30             ` Christoph Lameter
2008-11-11 22:30               ` Christoph Lameter
2008-11-11 23:17               ` Andrea Arcangeli
2008-11-11 23:17                 ` Andrea Arcangeli
2008-11-11 23:25                 ` Andrea Arcangeli
2008-11-11 23:25                   ` Andrea Arcangeli
2008-11-12  0:27                 ` Christoph Lameter
2008-11-12  0:27                   ` Christoph Lameter
2008-11-12  2:27                   ` Andrea Arcangeli
2008-11-12  2:27                     ` Andrea Arcangeli
2008-11-12  3:10                     ` Christoph Lameter
2008-11-12  3:10                       ` Christoph Lameter
2008-11-12 17:32                       ` Andrea Arcangeli
2008-11-12 17:32                         ` Andrea Arcangeli
2008-11-12 20:08                         ` Lee Schermerhorn
2008-11-12 20:08                           ` Lee Schermerhorn
2008-11-12 20:31                           ` Christoph Lameter
2008-11-12 20:31                             ` Christoph Lameter
2008-11-12 20:27                         ` Christoph Lameter
2008-11-12 20:27                           ` Christoph Lameter
2008-11-12 22:09                           ` Lee Schermerhorn
2008-11-12 22:09                             ` Lee Schermerhorn
2008-11-13  2:00                             ` Andrea Arcangeli
2008-11-13  2:00                               ` Andrea Arcangeli
2008-11-13  2:31                               ` Andrea Arcangeli
2008-11-13  2:31                                 ` Andrea Arcangeli
2008-11-13  4:02                                 ` Nick Piggin
2008-11-13  4:02                                   ` Nick Piggin
2008-11-11 19:39   ` [PATCH 1/4] rmap: add page_wrprotect() function, Andrew Morton
2008-11-11 19:39     ` Andrew Morton
2008-11-11 20:38     ` Andrea Arcangeli
2008-11-11 20:38       ` Andrea Arcangeli
2008-11-11 21:01       ` Andrew Morton
2008-11-11 21:01         ` Andrew Morton
2008-11-11 21:17         ` Andrea Arcangeli
2008-11-11 21:17           ` Andrea Arcangeli
2008-11-11 18:30 ` [PATCH 0/4] ksm - dynamic page sharing driver for linux Andrew Morton
2008-11-11 18:30   ` Andrew Morton
2008-11-11 18:48   ` Avi Kivity
2008-11-11 18:48     ` Avi Kivity
2008-11-11 19:08     ` Izik Eidus
2008-11-11 19:08       ` Izik Eidus
2008-11-11 19:11     ` Andrew Morton
2008-11-11 19:11       ` Andrew Morton
2008-11-11 19:18       ` Izik Eidus
2008-11-11 19:18         ` Izik Eidus
2008-11-11 19:32         ` Andrew Morton
2008-11-11 19:32           ` Andrew Morton
2008-11-11 19:52           ` Izik Eidus
2008-11-11 19:52             ` Izik Eidus
2008-11-11 20:08             ` Izik Eidus
2008-11-11 20:08               ` Izik Eidus
2008-11-11 19:29       ` Avi Kivity
2008-11-11 19:29         ` Avi Kivity
2008-11-11 19:55       ` Andrea Arcangeli
2008-11-11 19:55         ` Andrea Arcangeli
2008-11-11 19:07   ` Izik Eidus
2008-11-11 19:07     ` Izik Eidus
2008-11-11 19:20     ` Andrew Morton
2008-11-11 19:20       ` Andrew Morton

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=4919F1C0.2050009@redhat.com \
    --to=ieidus@redhat.com \
    --cc=aarcange@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=avi@redhat.com \
    --cc=chrisw@redhat.com \
    --cc=izike@qumranet.com \
    --cc=kvm@vger.kernel.org \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.