From: "Yin, Fengwei" <fengwei.yin@intel.com>
To: David Hildenbrand <david@redhat.com>, <willy@infradead.org>,
<linux-mm@kvack.org>
Cc: <dave.hansen@intel.com>, <tim.c.chen@intel.com>, <ying.huang@intel.com>
Subject: Re: [RFC PATCH v2 4/5] mm: add do_set_pte_range()
Date: Wed, 1 Feb 2023 18:04:36 +0800 [thread overview]
Message-ID: <62c0f97d-5cbf-4d7c-cfa0-85e2c3e2f1f7@intel.com> (raw)
In-Reply-To: <9e304ddf-29f7-1260-f585-bbcaf9575f6a@redhat.com>
On 2/1/2023 5:09 PM, David Hildenbrand wrote:
> On 01.02.23 09:17, Yin Fengwei wrote:
>> do_set_pte_range() allows to setup page table entries for a
>> specific range. It calls page_add_file_rmap_range() to take
>> advantage of batched rmap update for large folio.
>>
>> Signed-off-by: Yin Fengwei <fengwei.yin@intel.com>
>> ---
>> include/linux/mm.h | 2 ++
>> mm/filemap.c | 1 -
>> mm/memory.c | 60 ++++++++++++++++++++++++++++++++++++----------
>> 3 files changed, 49 insertions(+), 14 deletions(-)
>>
>> diff --git a/include/linux/mm.h b/include/linux/mm.h
>> index d6f8f41514cc..96e08fcdce24 100644
>> --- a/include/linux/mm.h
>> +++ b/include/linux/mm.h
>> @@ -1162,6 +1162,8 @@ static inline pte_t maybe_mkwrite(pte_t pte, struct vm_area_struct *vma)
>> vm_fault_t do_set_pmd(struct vm_fault *vmf, struct page *page);
>> void do_set_pte(struct vm_fault *vmf, struct page *page, unsigned long addr);
>> +void do_set_pte_range(struct vm_fault *vmf, struct folio *folio,
>> + unsigned long start, unsigned long addr, unsigned int nr);
>> vm_fault_t finish_fault(struct vm_fault *vmf);
>> vm_fault_t finish_mkwrite_fault(struct vm_fault *vmf);
>> diff --git a/mm/filemap.c b/mm/filemap.c
>> index 9cc5edd8f998..95f634d11581 100644
>> --- a/mm/filemap.c
>> +++ b/mm/filemap.c
>> @@ -3386,7 +3386,6 @@ static vm_fault_t filemap_map_folio_range(struct vm_fault *vmf,
>> ref_count++;
>> do_set_pte(vmf, page, addr);
>> - update_mmu_cache(vma, addr, vmf->pte);
>> } while (vmf->pte++, page++, addr += PAGE_SIZE, ++count < nr_pages);
>> /*
>> diff --git a/mm/memory.c b/mm/memory.c
>> index 51c04bb60724..7e41142e1e4f 100644
>> --- a/mm/memory.c
>> +++ b/mm/memory.c
>> @@ -4257,7 +4257,8 @@ vm_fault_t do_set_pmd(struct vm_fault *vmf, struct page *page)
>> }
>> #endif
>> -void do_set_pte(struct vm_fault *vmf, struct page *page, unsigned long addr)
>> +static void do_set_pte_entry(struct vm_fault *vmf, struct page *page,
>> + unsigned long addr)
>> {
>> struct vm_area_struct *vma = vmf->vma;
>> bool uffd_wp = pte_marker_uffd_wp(vmf->orig_pte);
>> @@ -4277,16 +4278,52 @@ void do_set_pte(struct vm_fault *vmf, struct page *page, unsigned long addr)
>> entry = maybe_mkwrite(pte_mkdirty(entry), vma);
>> if (unlikely(uffd_wp))
>> entry = pte_mkuffd_wp(entry);
>> - /* copy-on-write page */
>> - if (write && !(vma->vm_flags & VM_SHARED)) {
>> - inc_mm_counter(vma->vm_mm, MM_ANONPAGES);
>> - page_add_new_anon_rmap(page, vma, addr);
>> - lru_cache_add_inactive_or_unevictable(page, vma);
>> - } else {
>> - inc_mm_counter(vma->vm_mm, mm_counter_file(page));
>> - page_add_file_rmap(page, vma, false);
>> - }
>> set_pte_at(vma->vm_mm, addr, vmf->pte, entry);
>> +
>> + /* no need to invalidate: a not-present page won't be cached */
>> + update_mmu_cache(vma, addr, vmf->pte);
>> +}
>> +
>> +void do_set_pte_range(struct vm_fault *vmf, struct folio *folio,
>> + unsigned long start, unsigned long addr, unsigned int nr)
>> +{
>> + unsigned int i = 0;
>> + struct page *page = folio_page(folio, start);
>> + struct vm_area_struct *vma = vmf->vma;
>> + bool cow = (vmf->flags & FAULT_FLAG_WRITE) &&
>> + !(vma->vm_flags & VM_SHARED);
>> +
>> + /*
>> + * file page: batched update rmap, mm counter.
>> + * copy-on-write page: batched update mm counter.
>> + */
>> + if (!cow) {
>> + page_add_file_rmap_range(folio, start, nr, vma, false);
>> + add_mm_counter(vma->vm_mm, mm_counter_file(page), nr);
>> + } else
>> + add_mm_counter(vma->vm_mm, MM_ANONPAGES, nr);
>> +
>> + do {
>> + if (cow) {
>> + page_add_new_anon_rmap(page, vma, addr);
>
> This doesn't work with anon pages the way you intended in this patch.
>
> Please leave anon pages out of the picture for now and make do_set_pte_range() only deal with !cow.
OK. I will move the check to do_set_pte() and only call to
do_set_pte_range() when it's !cow. Thanks.
Regards
Yin, Fengwei
>
next prev parent reply other threads:[~2023-02-01 10:05 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-01 8:17 [RFC PATCH v2 0/5] folio based filemap_map_pages() Yin Fengwei
2023-02-01 8:17 ` [RFC PATCH v2 1/5] mm: Enable fault around for shared file page fault Yin Fengwei
2023-02-01 14:34 ` Kirill A. Shutemov
2023-02-02 1:54 ` Yin, Fengwei
2023-02-01 8:17 ` [RFC PATCH v2 2/5] filemap: add function filemap_map_folio_range() Yin Fengwei
2023-02-01 8:17 ` [RFC PATCH v2 3/5] rmap: add page_add_file_rmap_range() Yin Fengwei
2023-02-01 17:32 ` Matthew Wilcox
2023-02-02 2:00 ` Yin, Fengwei
2023-02-01 8:17 ` [RFC PATCH v2 4/5] mm: add do_set_pte_range() Yin Fengwei
2023-02-01 9:09 ` David Hildenbrand
2023-02-01 10:04 ` Yin, Fengwei [this message]
2023-02-01 17:38 ` Matthew Wilcox
2023-02-01 21:59 ` Matthew Wilcox
2023-02-02 3:18 ` Yin, Fengwei
2023-02-03 8:54 ` Yin Fengwei
2023-02-01 8:17 ` [RFC PATCH v2 5/5] filemap: batched update mm counter,rmap when map file folio Yin Fengwei
2023-02-01 15:50 ` Matthew Wilcox
2023-02-02 3:31 ` Yin, Fengwei
2023-02-03 13:15 ` Yin, Fengwei
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=62c0f97d-5cbf-4d7c-cfa0-85e2c3e2f1f7@intel.com \
--to=fengwei.yin@intel.com \
--cc=dave.hansen@intel.com \
--cc=david@redhat.com \
--cc=linux-mm@kvack.org \
--cc=tim.c.chen@intel.com \
--cc=willy@infradead.org \
--cc=ying.huang@intel.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