From: Qi Zheng <zhengqi.arch@bytedance.com>
To: David Hildenbrand <david@redhat.com>,
akpm@linux-foundation.org, tglx@linutronix.de,
hannes@cmpxchg.org, mhocko@kernel.org, vdavydov.dev@gmail.com,
kirill.shutemov@linux.intel.com, mika.penttila@nextfour.com
Cc: linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-mm@kvack.org, songmuchun@bytedance.com
Subject: Re: [PATCH v2 1/9] mm: introduce pmd_install() helper
Date: Thu, 26 Aug 2021 00:20:31 +0800 [thread overview]
Message-ID: <c650ef29-0f9e-02a0-9426-b406a4608c8f@bytedance.com> (raw)
In-Reply-To: <edd82170-7149-1abf-6204-f1d665a5fca2@redhat.com>
On 2021/8/25 AM12:26, David Hildenbrand wrote:
> On 19.08.21 05:18, Qi Zheng wrote:
>> Currently we have three times the same few lines repeated in the
>> code. Deduplicate them by newly introduced pmd_install() helper.
>>
>> Signed-off-by: Qi Zheng <zhengqi.arch@bytedance.com>
>> ---
>> include/linux/mm.h | 1 +
>> mm/filemap.c | 11 ++---------
>> mm/memory.c | 34 ++++++++++++++++------------------
>> 3 files changed, 19 insertions(+), 27 deletions(-)
>>
>> diff --git a/include/linux/mm.h b/include/linux/mm.h
>> index ce8fc0fd6d6e..57e48217bd71 100644
>> --- a/include/linux/mm.h
>> +++ b/include/linux/mm.h
>> @@ -2471,6 +2471,7 @@ static inline spinlock_t *pud_lock(struct
>> mm_struct *mm, pud_t *pud)
>> return ptl;
>> }
>> +extern void pmd_install(struct mm_struct *mm, pmd_t *pmd, pgtable_t
>> *pte);
>> extern void __init pagecache_init(void);
>> extern void __init free_area_init_memoryless_node(int nid);
>> extern void free_initmem(void);
>> diff --git a/mm/filemap.c b/mm/filemap.c
>> index 53913fced7ae..9f773059c6dc 100644
>> --- a/mm/filemap.c
>> +++ b/mm/filemap.c
>> @@ -3210,15 +3210,8 @@ static bool filemap_map_pmd(struct vm_fault
>> *vmf, struct page *page)
>> }
>> }
>> - if (pmd_none(*vmf->pmd)) {
>> - vmf->ptl = pmd_lock(mm, vmf->pmd);
>> - if (likely(pmd_none(*vmf->pmd))) {
>> - mm_inc_nr_ptes(mm);
>> - pmd_populate(mm, vmf->pmd, vmf->prealloc_pte);
>> - vmf->prealloc_pte = NULL;
>> - }
>> - spin_unlock(vmf->ptl);
>> - }
>> + if (pmd_none(*vmf->pmd))
>> + pmd_install(mm, vmf->pmd, &vmf->prealloc_pte);
>> /* See comment in handle_pte_fault() */
>> if (pmd_devmap_trans_unstable(vmf->pmd)) {
>> diff --git a/mm/memory.c b/mm/memory.c
>> index 39e7a1495c3c..ef7b1762e996 100644
>> --- a/mm/memory.c
>> +++ b/mm/memory.c
>> @@ -433,9 +433,20 @@ void free_pgtables(struct mmu_gather *tlb, struct
>> vm_area_struct *vma,
>> }
>> }
>> +void pmd_install(struct mm_struct *mm, pmd_t *pmd, pgtable_t *pte)
>> +{
>> + spinlock_t *ptl = pmd_lock(mm, pmd);
>> +
>> + if (likely(pmd_none(*pmd))) { /* Has another populated it ? */
>> + mm_inc_nr_ptes(mm);
>> + pmd_populate(mm, pmd, *pte);
>> + *pte = NULL;
>> + }
>> + spin_unlock(ptl);
>> +}
>> +
>> int __pte_alloc(struct mm_struct *mm, pmd_t *pmd)
>> {
>> - spinlock_t *ptl;
>> pgtable_t new = pte_alloc_one(mm);
>> if (!new)
>> return -ENOMEM;
>> @@ -455,13 +466,7 @@ int __pte_alloc(struct mm_struct *mm, pmd_t *pmd)
>> */
>> smp_wmb(); /* Could be smp_wmb__xxx(before|after)_spin_lock */
>> - ptl = pmd_lock(mm, pmd);
>> - if (likely(pmd_none(*pmd))) { /* Has another populated it ? */
>> - mm_inc_nr_ptes(mm);
>> - pmd_populate(mm, pmd, new);
>> - new = NULL;
>> - }
>> - spin_unlock(ptl);
>> + pmd_install(mm, pmd, &new);
>> if (new)
>> pte_free(mm, new);
>> return 0;
>> @@ -4027,17 +4032,10 @@ vm_fault_t finish_fault(struct vm_fault *vmf)
>> return ret;
>> }
>> - if (vmf->prealloc_pte) {
>> - vmf->ptl = pmd_lock(vma->vm_mm, vmf->pmd);
>> - if (likely(pmd_none(*vmf->pmd))) {
>> - mm_inc_nr_ptes(vma->vm_mm);
>> - pmd_populate(vma->vm_mm, vmf->pmd, vmf->prealloc_pte);
>> - vmf->prealloc_pte = NULL;
>> - }
>> - spin_unlock(vmf->ptl);
>> - } else if (unlikely(pte_alloc(vma->vm_mm, vmf->pmd))) {
>> + if (vmf->prealloc_pte)
>> + pmd_install(vma->vm_mm, vmf->pmd, &vmf->prealloc_pte);
>> + else if (unlikely(pte_alloc(vma->vm_mm, vmf->pmd)))
>> return VM_FAULT_OOM;
>> - }
>> }
>> /* See comment in handle_pte_fault() */
>>
>
> Reviewed-by: David Hildenbrand <david@redhat.com>
Thanks for your review, I will add this to the patch v3.
>
> That's mostly unrelated to the remaining part of the series and can be
> picked up early.
The implementation of subsequent patches depends on pmd_install().
So I am worried that if this patch is submitted as a separate patch,
subsequent patches will not be updated until this patch is merged.
What do you think?
>
next prev parent reply other threads:[~2021-08-25 16:21 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-19 3:18 [PATCH v2 0/9] Free user PTE page table pages Qi Zheng
2021-08-19 3:18 ` [PATCH v2 1/9] mm: introduce pmd_install() helper Qi Zheng
2021-08-24 16:26 ` David Hildenbrand
2021-08-25 16:20 ` Qi Zheng [this message]
2021-08-25 16:32 ` David Hildenbrand
2021-08-26 3:04 ` Qi Zheng
2021-08-19 3:18 ` [PATCH v2 2/9] mm: remove redundant smp_wmb() Qi Zheng
2021-08-19 3:18 ` [PATCH v2 3/9] mm: rework the parameter of lock_page_or_retry() Qi Zheng
2021-08-19 3:18 ` [PATCH v2 4/9] mm: move pte_alloc{,_map,_map_lock}() to a separate file Qi Zheng
2021-08-19 3:18 ` [PATCH v2 5/9] mm: pte_refcount infrastructure Qi Zheng
2021-08-19 3:18 ` [PATCH v2 6/9] mm: free user PTE page table pages Qi Zheng
2021-08-19 7:01 ` David Hildenbrand
2021-08-19 10:18 ` [External] " Qi Zheng
2021-09-01 13:53 ` Jason Gunthorpe
2021-09-01 13:57 ` David Hildenbrand
2021-09-01 15:32 ` Jason Gunthorpe
2021-09-01 16:13 ` David Hildenbrand
2021-09-01 16:16 ` Jason Gunthorpe
2021-09-01 16:19 ` David Hildenbrand
2021-09-01 17:10 ` Jason Gunthorpe
2021-09-01 17:49 ` David Hildenbrand
2021-09-01 17:55 ` Jason Gunthorpe
2021-09-01 17:58 ` David Hildenbrand
2021-09-01 18:09 ` Jason Gunthorpe
2021-09-01 18:10 ` David Hildenbrand
2021-09-02 7:04 ` Qi Zheng
2021-09-02 6:53 ` Qi Zheng
2021-08-19 3:18 ` [PATCH v2 7/9] mm: add THP support for pte_ref Qi Zheng
2021-08-19 3:18 ` [PATCH v2 8/9] mm: free PTE page table by using rcu mechanism Qi Zheng
2021-08-19 3:18 ` [PATCH v2 9/9] mm: use mmu_gather to free PTE page table Qi Zheng
2021-09-01 12:32 ` [PATCH v2 0/9] Free user PTE page table pages David Hildenbrand
2021-09-01 16:07 ` Jason Gunthorpe
2021-09-01 16:10 ` David Hildenbrand
2021-09-02 3:37 ` Qi Zheng
2021-09-15 14:52 ` Qi Zheng
2021-09-15 14:59 ` Jason Gunthorpe
2021-09-16 5:32 ` Qi Zheng
2021-09-16 8:30 ` David Hildenbrand
2021-09-16 8:41 ` Qi Zheng
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=c650ef29-0f9e-02a0-9426-b406a4608c8f@bytedance.com \
--to=zhengqi.arch@bytedance.com \
--cc=akpm@linux-foundation.org \
--cc=david@redhat.com \
--cc=hannes@cmpxchg.org \
--cc=kirill.shutemov@linux.intel.com \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mhocko@kernel.org \
--cc=mika.penttila@nextfour.com \
--cc=songmuchun@bytedance.com \
--cc=tglx@linutronix.de \
--cc=vdavydov.dev@gmail.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).