From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.3 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,NICE_REPLY_A, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C6C94C4338F for ; Tue, 24 Aug 2021 16:26:49 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 4B80461212 for ; Tue, 24 Aug 2021 16:26:49 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 4B80461212 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id C47056B006C; Tue, 24 Aug 2021 12:26:48 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BF7456B0071; Tue, 24 Aug 2021 12:26:48 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A97A96B0072; Tue, 24 Aug 2021 12:26:48 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0148.hostedemail.com [216.40.44.148]) by kanga.kvack.org (Postfix) with ESMTP id 8C1DB6B006C for ; Tue, 24 Aug 2021 12:26:48 -0400 (EDT) Received: from smtpin13.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 2C596250BD for ; Tue, 24 Aug 2021 16:26:48 +0000 (UTC) X-FDA: 78510502896.13.6A0D85E Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by imf05.hostedemail.com (Postfix) with ESMTP id B94B35027114 for ; Tue, 24 Aug 2021 16:26:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1629822407; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=TYtQtl/3C2Gj/kt8xj0pTccd7H5GHAf8Dw42NMrmVXU=; b=TDpaDZ6Udwpu0ea601OExdaZovM+kITkfMqhecbycp4Mv4FkS6szKHzdY+0IbwUqEmO+mV SjXG6R+VlLCNChg0iAzFmznfPdbBemYkdXfoSA/blewuF9CJWun/xTBbS8lDZ3mBqNCq2g EeBohuuE1YHjwGlX3hDLqiA2+Mv/mKU= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-593-LaduQmpqOT25y7RFChvIiA-1; Tue, 24 Aug 2021 12:26:45 -0400 X-MC-Unique: LaduQmpqOT25y7RFChvIiA-1 Received: by mail-wm1-f69.google.com with SMTP id y188-20020a1c7dc5000000b002e80e0b2f87so1472601wmc.1 for ; Tue, 24 Aug 2021 09:26:45 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:organization :message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=TYtQtl/3C2Gj/kt8xj0pTccd7H5GHAf8Dw42NMrmVXU=; b=ZMj4WVfz5VgaGMCo2i1roqwAzXFUobNc/my00yhvMXEGSxtVqISXLFBKawYDqDlSqh lSnp/320rG0+5O3c1Pw5bAkQVmAkUGkk8Glg8IjL7mvELGjC+yd8SS9TaueZ/Ef2LYu8 htaDjxkvjzHTiG/9Nx53R7GbYYr79R7pLhaphxxfbvqlNnr+cPZc2h9rx7NsYOyN06fs ht0gT7El/KA7EHP2Qym4ziGqsihkjpCn89h7BPEWnVKaQaKy3yJduAg3F1woRhmlLiTi 0BM8Se9s42S1ldrbX78bvDeloo4NUhiHNg46P0v1O7vjnAt0B2qnZMsYUDs5IOWVcz2u TYrQ== X-Gm-Message-State: AOAM532jDt8PApTa3qXgbfVqp3gtjrx59B5qoSdkEJNL0RBs+76BAbeW xz+LuZsa6m5gx3Kq6HAYje3l+6TALoptM+IklwRihGSKdj6CZMbxQ9T9KxANbs9Ozp9VGm3BOqt dKdGYvHVo8/A= X-Received: by 2002:adf:f101:: with SMTP id r1mr17135285wro.355.1629822404364; Tue, 24 Aug 2021 09:26:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx97fjaFa36+aZbM+EMQ9R++YVwrZeW3RMKAV9fGubIm+gCe79sLjVmW3/mIgQ7bDDbaucWcg== X-Received: by 2002:adf:f101:: with SMTP id r1mr17135258wro.355.1629822404086; Tue, 24 Aug 2021 09:26:44 -0700 (PDT) Received: from [192.168.3.132] (p4ff23c4d.dip0.t-ipconnect.de. [79.242.60.77]) by smtp.gmail.com with ESMTPSA id e2sm19925957wrq.56.2021.08.24.09.26.42 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 24 Aug 2021 09:26:43 -0700 (PDT) Subject: Re: [PATCH v2 1/9] mm: introduce pmd_install() helper To: Qi Zheng , 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 References: <20210819031858.98043-1-zhengqi.arch@bytedance.com> <20210819031858.98043-2-zhengqi.arch@bytedance.com> From: David Hildenbrand Organization: Red Hat Message-ID: Date: Tue, 24 Aug 2021 18:26:42 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: <20210819031858.98043-2-zhengqi.arch@bytedance.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=TDpaDZ6U; spf=none (imf05.hostedemail.com: domain of david@redhat.com has no SPF policy when checking 216.205.24.124) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: B94B35027114 X-Stat-Signature: 1fndf9cuhciq1ywco4eu17hhh3dqqb5g X-HE-Tag: 1629822407-617039 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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 > --- > 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 That's mostly unrelated to the remaining part of the series and can be picked up early. -- Thanks, David / dhildenb