[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20201108141113.65450-14-songmuchun@bytedance.com>
Date: Sun, 8 Nov 2020 22:11:05 +0800
From: Muchun Song <songmuchun@...edance.com>
To: 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,
osalvador@...e.de, mhocko@...e.com
Cc: duanxiongchun@...edance.com, linux-doc@...r.kernel.org,
linux-kernel@...r.kernel.org, linux-mm@...ck.org,
linux-fsdevel@...r.kernel.org,
Muchun Song <songmuchun@...edance.com>
Subject: [PATCH v3 13/21] mm/hugetlb: Use PG_slab to indicate split pmd
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@...edance.com>
---
mm/hugetlb.c | 23 ++++++++++++++++++++++-
1 file changed, 22 insertions(+), 1 deletion(-)
diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index 5d3806476212..9b1ac52d9fdd 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -1565,6 +1565,25 @@ static void split_vmemmap_huge_page(struct hstate *h, struct page *head,
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;
@@ -1579,6 +1598,7 @@ static void free_huge_page_vmemmap(struct hstate *h, struct page *head)
if (vmemmap_pmd_huge(pmd)) {
VM_BUG_ON(!pgtable_pages_to_prealloc_per_hpage(h));
split_vmemmap_huge_page(h, head, pmd);
+ set_pmd_split(pmd);
}
remap_huge_page_pmd_vmemmap(h, pmd, (unsigned long)head, &free_pages,
@@ -1651,11 +1671,12 @@ static void alloc_huge_page_vmemmap(struct hstate *h, struct page *head)
ptl = vmemmap_pmd_lock(pmd);
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.11.0
Powered by blists - more mailing lists