Skip to content

Commit bb9dd3d

Browse files
stevecapperarmtorvalds
authored andcommitted
arm64: hugetlb: refactor find_num_contig()
Patch series "Support for contiguous pte hugepages", v4. This patchset updates the hugetlb code to fix issues arising from contiguous pte hugepages (such as on arm64). Compared to v3, This version addresses a build failure on arm64 by including two cleanup patches. Other than the arm64 cleanups, the rest are generic code changes. The remaining arm64 support based on these patches will be posted separately. The patches are based on v4.12-rc2. Previous related postings can be found at [0], [1], [2], and [3]. The patches fall into three categories - * Patch 1-2 - arm64 cleanups required to greatly simplify changing huge_pte_offset() prototype in Patch 5. Catalin, Will - are you happy for these patches to go via mm? * Patches 3-4 address issues with gup * Patches 5-8 relate to passing a size argument to hugepage helpers to disambiguate the size of the referred page. These changes are required to enable arch code to properly handle swap entries for contiguous pte hugepages. The changes to huge_pte_offset() (patch 5) touch multiple architectures but I've managed to minimise these changes for the other affected functions - huge_pte_clear() and set_huge_pte_at(). These patches gate the enabling of contiguous hugepages support on arm64 which has been requested for systems using !4k page granule. The ARM64 architecture supports two flavours of hugepages - * Block mappings at the pud/pmd level These are regular hugepages where a pmd or a pud page table entry points to a block of memory. Depending on the PAGE_SIZE in use the following size of block mappings are supported - PMD PUD --- --- 4K: 2M 1G 16K: 32M 64K: 512M For certain applications/usecases such as HPC and large enterprise workloads, folks are using 64k page size but the minimum hugepage size of 512MB isn't very practical. To overcome this ... * Using the Contiguous bit The architecture provides a contiguous bit in the translation table entry which acts as a hint to the mmu to indicate that it is one of a contiguous set of entries that can be cached in a single TLB entry. We use the contiguous bit in Linux to increase the mapping size at the pmd and pte (last) level. The number of supported contiguous entries varies by page size and level of the page table. Using the contiguous bit allows additional hugepage sizes - CONT PTE PMD CONT PMD PUD -------- --- -------- --- 4K: 64K 2M 32M 1G 16K: 2M 32M 1G 64K: 2M 512M 16G Of these, 64K with 4K and 2M with 64K pages have been explicitly requested by a few different users. Entries with the contiguous bit set are required to be modified all together - which makes things like memory poisoning and migration impossible to do correctly without knowing the size of hugepage being dealt with - the reason for adding size parameter to a few of the hugepage helpers in this series. This patch (of 8): As we regularly check for contiguous pte's in the huge accessors, remove this extra check from find_num_contig. [[email protected]: resolve rebase conflicts due to patch re-ordering] Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Steve Capper <[email protected]> Signed-off-by: Punit Agrawal <[email protected]> Cc: David Woods <[email protected]> Cc: Kirill A. Shutemov <[email protected]> Cc: Aneesh Kumar K.V <[email protected]> Cc: Catalin Marinas <[email protected]> Cc: Naoya Horiguchi <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Hillf Danton <[email protected]> Cc: Michal Hocko <[email protected]> Cc: Mike Kravetz <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 8bc3c3f commit bb9dd3d

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

arch/arm64/mm/hugetlbpage.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,13 @@ int pud_huge(pud_t pud)
4242
}
4343

4444
static int find_num_contig(struct mm_struct *mm, unsigned long addr,
45-
pte_t *ptep, pte_t pte, size_t *pgsize)
45+
pte_t *ptep, size_t *pgsize)
4646
{
4747
pgd_t *pgd = pgd_offset(mm, addr);
4848
pud_t *pud;
4949
pmd_t *pmd;
5050

5151
*pgsize = PAGE_SIZE;
52-
if (!pte_cont(pte))
53-
return 1;
5452
pud = pud_offset(pgd, addr);
5553
pmd = pmd_offset(pud, addr);
5654
if ((pte_t *)pmd == ptep) {
@@ -65,15 +63,16 @@ void set_huge_pte_at(struct mm_struct *mm, unsigned long addr,
6563
{
6664
size_t pgsize;
6765
int i;
68-
int ncontig = find_num_contig(mm, addr, ptep, pte, &pgsize);
66+
int ncontig;
6967
unsigned long pfn;
7068
pgprot_t hugeprot;
7169

72-
if (ncontig == 1) {
70+
if (!pte_cont(pte)) {
7371
set_pte_at(mm, addr, ptep, pte);
7472
return;
7573
}
7674

75+
ncontig = find_num_contig(mm, addr, ptep, &pgsize);
7776
pfn = pte_pfn(pte);
7877
hugeprot = __pgprot(pte_val(pfn_pte(pfn, __pgprot(0))) ^ pte_val(pte));
7978
for (i = 0; i < ncontig; i++) {
@@ -188,7 +187,7 @@ pte_t huge_ptep_get_and_clear(struct mm_struct *mm,
188187
bool is_dirty = false;
189188

190189
cpte = huge_pte_offset(mm, addr);
191-
ncontig = find_num_contig(mm, addr, cpte, *cpte, &pgsize);
190+
ncontig = find_num_contig(mm, addr, cpte, &pgsize);
192191
/* save the 1st pte to return */
193192
pte = ptep_get_and_clear(mm, addr, cpte);
194193
for (i = 1, addr += pgsize; i < ncontig; ++i, addr += pgsize) {
@@ -228,7 +227,7 @@ int huge_ptep_set_access_flags(struct vm_area_struct *vma,
228227
cpte = huge_pte_offset(vma->vm_mm, addr);
229228
pfn = pte_pfn(*cpte);
230229
ncontig = find_num_contig(vma->vm_mm, addr, cpte,
231-
*cpte, &pgsize);
230+
&pgsize);
232231
for (i = 0; i < ncontig; ++i, ++cpte, addr += pgsize) {
233232
changed |= ptep_set_access_flags(vma, addr, cpte,
234233
pfn_pte(pfn,
@@ -251,7 +250,7 @@ void huge_ptep_set_wrprotect(struct mm_struct *mm,
251250
size_t pgsize = 0;
252251

253252
cpte = huge_pte_offset(mm, addr);
254-
ncontig = find_num_contig(mm, addr, cpte, *cpte, &pgsize);
253+
ncontig = find_num_contig(mm, addr, cpte, &pgsize);
255254
for (i = 0; i < ncontig; ++i, ++cpte, addr += pgsize)
256255
ptep_set_wrprotect(mm, addr, cpte);
257256
} else {
@@ -269,7 +268,7 @@ void huge_ptep_clear_flush(struct vm_area_struct *vma,
269268

270269
cpte = huge_pte_offset(vma->vm_mm, addr);
271270
ncontig = find_num_contig(vma->vm_mm, addr, cpte,
272-
*cpte, &pgsize);
271+
&pgsize);
273272
for (i = 0; i < ncontig; ++i, ++cpte, addr += pgsize)
274273
ptep_clear_flush(vma, addr, cpte);
275274
} else {

0 commit comments

Comments
 (0)