lkml.org 
[lkml]   [2022]   [Jun]   [28]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
Date
SubjectRe: [RFC PATCH 08/26] hugetlb: add hugetlb_free_range to free PT structures
On Fri, Jun 24, 2022 at 10:37 AM James Houghton <jthoughton@google.com> wrote:
>
> This is a helper function for freeing the bits of the page table that
> map a particular HugeTLB PTE.
>
> Signed-off-by: James Houghton <jthoughton@google.com>
> ---
> include/linux/hugetlb.h | 2 ++
> mm/hugetlb.c | 17 +++++++++++++++++
> 2 files changed, 19 insertions(+)
>
> diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h
> index 1d4ec9dfdebf..33ba48fac551 100644
> --- a/include/linux/hugetlb.h
> +++ b/include/linux/hugetlb.h
> @@ -107,6 +107,8 @@ bool hugetlb_pte_none_mostly(const struct hugetlb_pte *hpte);
> pte_t hugetlb_ptep_get(const struct hugetlb_pte *hpte);
> void hugetlb_pte_clear(struct mm_struct *mm, const struct hugetlb_pte *hpte,
> unsigned long address);
> +void hugetlb_free_range(struct mmu_gather *tlb, const struct hugetlb_pte *hpte,
> + unsigned long start, unsigned long end);
>
> struct hugepage_subpool {
> spinlock_t lock;
> diff --git a/mm/hugetlb.c b/mm/hugetlb.c
> index 1a1434e29740..a2d2ffa76173 100644
> --- a/mm/hugetlb.c
> +++ b/mm/hugetlb.c
> @@ -1120,6 +1120,23 @@ static bool vma_has_reserves(struct vm_area_struct *vma, long chg)
> return false;
> }
>
> +void hugetlb_free_range(struct mmu_gather *tlb, const struct hugetlb_pte *hpte,
> + unsigned long start, unsigned long end)
> +{
> + unsigned long floor = start & hugetlb_pte_mask(hpte);
> + unsigned long ceiling = floor + hugetlb_pte_size(hpte);
> +
> + if (hugetlb_pte_size(hpte) >= PGDIR_SIZE) {
> + free_p4d_range(tlb, (pgd_t *)hpte->ptep, start, end, floor, ceiling);
> + } else if (hugetlb_pte_size(hpte) >= P4D_SIZE) {
> + free_pud_range(tlb, (p4d_t *)hpte->ptep, start, end, floor, ceiling);
> + } else if (hugetlb_pte_size(hpte) >= PUD_SIZE) {
> + free_pmd_range(tlb, (pud_t *)hpte->ptep, start, end, floor, ceiling);
> + } else if (hugetlb_pte_size(hpte) >= PMD_SIZE) {
> + free_pte_range(tlb, (pmd_t *)hpte->ptep, start);
> + }

Same as the previous patch: I wonder about >=, and if possible
calculate hugetlb_pte_size() once, or use *_SHIFT comparison.

> +}
> +
> bool hugetlb_pte_present_leaf(const struct hugetlb_pte *hpte)
> {
> pgd_t pgd;
> --
> 2.37.0.rc0.161.g10f37bed90-goog
>

\
 
 \ /
  Last update: 2022-06-28 22:30    [W:0.653 / U:2.372 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site