[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20201109172144.GB17356@linux>
Date: Mon, 9 Nov 2020 18:21:44 +0100
From: Oscar Salvador <osalvador@...e.de>
To: Muchun Song <songmuchun@...edance.com>
Cc: corbet@....net, mike.kravetz@...cle.com, tglx@...utronix.de,
mingo@...hat.com, bp@...en8.de, x86@...nel.org, hpa@...or.com,
dave.hansen@...ux.intel.com, luto@...nel.org, peterz@...radead.org,
viro@...iv.linux.org.uk, akpm@...ux-foundation.org,
paulmck@...nel.org, mchehab+huawei@...nel.org,
pawan.kumar.gupta@...ux.intel.com, rdunlap@...radead.org,
oneukum@...e.com, anshuman.khandual@....com, jroedel@...e.de,
almasrymina@...gle.com, rientjes@...gle.com, willy@...radead.org,
mhocko@...e.com, duanxiongchun@...edance.com,
linux-doc@...r.kernel.org, linux-kernel@...r.kernel.org,
linux-mm@...ck.org, linux-fsdevel@...r.kernel.org
Subject: Re: [PATCH v3 05/21] mm/hugetlb: Introduce pgtable
allocation/freeing helpers
On Sun, Nov 08, 2020 at 10:10:57PM +0800, Muchun Song wrote:
> +static inline unsigned int pgtable_pages_to_prealloc_per_hpage(struct hstate *h)
> +{
> + unsigned long vmemmap_size = vmemmap_pages_size_per_hpage(h);
> +
> + /*
> + * No need pre-allocate page tabels when there is no vmemmap pages
> + * to free.
s /tabels/tables/
> +static int vmemmap_pgtable_prealloc(struct hstate *h, struct page *page)
> +{
> + int i;
> + pgtable_t pgtable;
> + unsigned int nr = pgtable_pages_to_prealloc_per_hpage(h);
> +
> + if (!nr)
> + return 0;
> +
> + vmemmap_pgtable_init(page);
> +
> + for (i = 0; i < nr; i++) {
> + pte_t *pte_p;
> +
> + pte_p = pte_alloc_one_kernel(&init_mm);
> + if (!pte_p)
> + goto out;
> + vmemmap_pgtable_deposit(page, virt_to_page(pte_p));
> + }
> +
> + return 0;
> +out:
> + while (i-- && (pgtable = vmemmap_pgtable_withdraw(page)))
> + pte_free_kernel(&init_mm, page_to_virt(pgtable));
would not be enough to:
while (pgtable = vmemmap_pgtable_withdrag(page))
pte_free_kernel(&init_mm, page_to_virt(pgtable));
> + return -ENOMEM;
> +}
> +
> +static void vmemmap_pgtable_free(struct hstate *h, struct page *page)
> +{
> + pgtable_t pgtable;
> + unsigned int nr = pgtable_pages_to_prealloc_per_hpage(h);
> +
> + if (!nr)
> + return;
We can get rid of "nr" and its check and keep only the check below, right?
AFAICS, they go together, e.g: if page_huge_pte does not return null,
it means that we preallocated a pagetable, and viceversa.
> +
> + pgtable = page_huge_pte(page);
> + if (!pgtable)
> + return;
> +
> + while (nr-- && (pgtable = vmemmap_pgtable_withdraw(page)))
> + pte_free_kernel(&init_mm, page_to_virt(pgtable));
Same as above, that "nr" can go?
--
Oscar Salvador
SUSE L3
Powered by blists - more mailing lists