From: bibo mao <maobibo@loongson.cn>
To: Huacai Chen <chenhuacai@kernel.org>
Cc: Dennis Zhou <dennis@kernel.org>, Tejun Heo <tj@kernel.org>,
Christoph Lameter <cl@linux.com>,
Andrew Morton <akpm@linux-foundation.org>,
loongarch@lists.linux.dev, linux-kernel@vger.kernel.org,
linux-mm@kvack.org, WANG Xuerui <kernel@xen0n.name>
Subject: Re: [PATCH 2/3] LoongArch: Code cleanup in function pcpu_populate_pte
Date: Tue, 1 Aug 2023 09:18:22 +0800 [thread overview]
Message-ID: <bae284ee-aa1d-a31e-20bf-73db79824717@loongson.cn> (raw)
In-Reply-To: <CAAhV-H4nG=vRqaU+q7j3Kp9v24u-NNEjdisF34QP-kM+_J2+tg@mail.gmail.com>
在 2023/7/31 22:15, Huacai Chen 写道:
> On Wed, Jul 12, 2023 at 11:16 AM Bibo Mao <maobibo@loongson.cn> wrote:
>>
>> There are some code cleanups in function pcpu_populate_pte:
>> 1. Replace memblock_alloc with memblock_alloc_raw for pud and pmd since
>> they will be reinitialized with pud_init and pmd_init.
>>
>> 2. Add memory allocation failure handling
>>
>> 3. Replace pgd_populate with p4d_populate, it will be useful if there
>> four-level page tables.
>>
>> Signed-off-by: Bibo Mao <maobibo@loongson.cn>
>> ---
>> arch/loongarch/kernel/numa.c | 33 ++++++++++++++++++++-------------
>> 1 file changed, 20 insertions(+), 13 deletions(-)
>>
>> diff --git a/arch/loongarch/kernel/numa.c b/arch/loongarch/kernel/numa.c
>> index 708665895b47..778e1c20bfb0 100644
>> --- a/arch/loongarch/kernel/numa.c
>> +++ b/arch/loongarch/kernel/numa.c
>> @@ -73,33 +73,40 @@ void __init pcpu_populate_pte(unsigned long addr)
>> pmd_t *pmd;
>>
>> if (p4d_none(*p4d)) {
>> - pud_t *new;
>> -
>> - new = memblock_alloc(PAGE_SIZE, PAGE_SIZE);
>> - pgd_populate(&init_mm, pgd, new);
>> + pud = memblock_alloc_raw(PAGE_SIZE, PAGE_SIZE);
> Don't use memblock_alloc_raw() here, it is better to keep consistency
> with mm/percpu.c.
memblock_alloc will clear the page, and there will be page table initialization
with the following pud_init(pud). memblock_alloc_raw will not clear the page.
I prefer memblock_alloc_raw for better performance however ok with both, it is
up to you to decide.
Regards
Bibo Mao
>
>
> Huacai
>> + if (!pud)
>> + goto err_alloc;
>> + p4d_populate(&init_mm, p4d, pud);
>> #ifndef __PAGETABLE_PUD_FOLDED
>> - pud_init(new);
>> + pud_init(pud);
>> #endif
>> }
>>
>> pud = pud_offset(p4d, addr);
>> if (pud_none(*pud)) {
>> - pmd_t *new;
>> -
>> - new = memblock_alloc(PAGE_SIZE, PAGE_SIZE);
>> - pud_populate(&init_mm, pud, new);
>> + pmd = memblock_alloc_raw(PAGE_SIZE, PAGE_SIZE);
>> + if (!pmd)
>> + goto err_alloc;
>> + pud_populate(&init_mm, pud, pmd);
>> #ifndef __PAGETABLE_PMD_FOLDED
>> - pmd_init(new);
>> + pmd_init(pmd);
>> #endif
>> }
>>
>> pmd = pmd_offset(pud, addr);
>> if (!pmd_present(*pmd)) {
>> - pte_t *new;
>> + pte_t *pte;
>>
>> - new = memblock_alloc(PAGE_SIZE, PAGE_SIZE);
>> - pmd_populate_kernel(&init_mm, pmd, new);
>> + pte = memblock_alloc(PAGE_SIZE, PAGE_SIZE);
>> + if (!pte)
>> + goto err_alloc;
>> + pmd_populate_kernel(&init_mm, pmd, pte);
>> }
>> +
>> + return;
>> +
>> +err_alloc:
>> + panic("%s: Failed to allocate memory\n", __func__);
>> }
>>
>> void __init setup_per_cpu_areas(void)
>> --
>> 2.27.0
>>
next prev parent reply other threads:[~2023-08-01 1:18 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-12 3:16 [PATCH 0/3] LoongArch: mm: Code cleanup with populate pte Bibo Mao
2023-07-12 3:16 ` [PATCH 1/3] mm/percpu: Remove some local variables in pcpu_populate_pte Bibo Mao
2023-07-27 23:08 ` Dennis Zhou
2023-07-28 1:13 ` bibo mao
2023-07-12 3:16 ` [PATCH 2/3] LoongArch: Code cleanup in function pcpu_populate_pte Bibo Mao
2023-07-31 14:15 ` Huacai Chen
2023-08-01 1:18 ` bibo mao [this message]
2023-07-12 3:16 ` [PATCH 3/3] LoongArch: mm: Add unified function populate_kernel_pte Bibo Mao
2023-07-31 14:15 ` Huacai Chen
2023-08-01 1:22 ` bibo mao
2023-08-02 7:25 ` Huacai Chen
2023-08-10 4:08 ` bibo mao
2023-08-10 4:27 ` Huacai Chen
2023-08-10 4:42 ` bibo mao
2023-07-25 0:36 ` [PATCH 0/3] LoongArch: mm: Code cleanup with populate pte bibo mao
2023-07-25 2:33 ` Dennis Zhou
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=bae284ee-aa1d-a31e-20bf-73db79824717@loongson.cn \
--to=maobibo@loongson.cn \
--cc=akpm@linux-foundation.org \
--cc=chenhuacai@kernel.org \
--cc=cl@linux.com \
--cc=dennis@kernel.org \
--cc=kernel@xen0n.name \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=loongarch@lists.linux.dev \
--cc=tj@kernel.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