lkml.org 
[lkml]   [2020]   [Sep]   [15]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[RFC PATCH 15/24] mm/hugetlb: Use PG_slab to indicate split pmd
Date
When we allocate hugetlb page from buddy, we may need split huge pmd
to pte. When we free the hugetlb page, we can merge pte to pmd. So
we need to distinguish whether the previous pmd has been split. The
page table is not allocated from slab. So we can reuse the PG_slab
to indicate that the pmd has been split.

Signed-off-by: Muchun Song <songmuchun@bytedance.com>
---
mm/hugetlb.c | 23 ++++++++++++++++++++++-
1 file changed, 22 insertions(+), 1 deletion(-)

diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index 5cc796dc3a0a..c42c27a12df2 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -1629,6 +1629,25 @@ static void split_vmemmap_huge_page(struct page *head, pmd_t *pmd)
flush_tlb_kernel_range(start, addr);
}

+static inline bool pmd_split(pmd_t *pmd)
+{
+ return PageSlab(pmd_page(*pmd));
+}
+
+static inline void set_pmd_split(pmd_t *pmd)
+{
+ /*
+ * We should not use slab for page table allocation. So we can set
+ * PG_slab to indicate that the pmd has been split.
+ */
+ __SetPageSlab(pmd_page(*pmd));
+}
+
+static inline void clear_pmd_split(pmd_t *pmd)
+{
+ __ClearPageSlab(pmd_page(*pmd));
+}
+
static void free_huge_page_vmemmap(struct hstate *h, struct page *head)
{
pmd_t *pmd;
@@ -1645,6 +1664,7 @@ static void free_huge_page_vmemmap(struct hstate *h, struct page *head)
if (vmemmap_pmd_huge(pmd)) {
VM_BUG_ON(!nr_pgtable(h));
split_vmemmap_huge_page(head, pmd);
+ set_pmd_split(pmd);
}

remap_huge_page_pmd_vmemmap(h, pmd, (unsigned long)head, &free_pages,
@@ -1718,11 +1738,12 @@ static void alloc_huge_page_vmemmap(struct hstate *h, struct page *head)
spin_lock(ptl);
remap_huge_page_pmd_vmemmap(h, pmd, (unsigned long)head, &remap_pages,
__remap_huge_page_pte_vmemmap);
- if (!freed_vmemmap_hpage_dec(pmd_page(*pmd))) {
+ if (!freed_vmemmap_hpage_dec(pmd_page(*pmd)) && pmd_split(pmd)) {
/*
* Todo:
* Merge pte to huge pmd if it has ever been split.
*/
+ clear_pmd_split(pmd);
}
spin_unlock(ptl);
}
--
2.20.1
\
 
 \ /
  Last update: 2020-09-16 02:43    [W:0.167 / U:5.240 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site