diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index a08fa3f1648c2b6df0f908c4fb8e3add16a5f9c4..83344333670e2c26774bd7246309e8797f895ee8 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -1389,6 +1389,17 @@ config ASCEND_IOPF_HIPRI CPU which processes IOPF work is the same as that which processes IOPF event interrupts. +config ASCEND_CHARGE_MIGRATE_HUGEPAGES + bool "Enable support for migrate hugepages" + default y + help + When reseved hugepages are used up, we attempts to apply for migrate + hugepages. We expect that the migrated hugepages that are applied for + can be charged in memcg to limit the memory usage. + + This option enable the feature to charge migrate hugepages to memory + cgroup. + endif endmenu diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 0eb0c943397fdeb868bd145ad2675db53fd49a82..3460ab634941a2ec1f7ecedccfbc2d82d5d9d69d 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -54,6 +54,7 @@ static struct hstate * __initdata parsed_hstate; static unsigned long __initdata default_hstate_max_huge_pages; static unsigned long __initdata default_hstate_size; static bool __initdata parsed_valid_hugepagesz = true; +static int enable_charge_mighp __read_mostly; /* * Protects updates to hugepage_freelists, hugepage_activelist, nr_huge_pages, @@ -1710,8 +1711,12 @@ struct page *alloc_huge_page_node(struct hstate *h, int nid) page = dequeue_huge_page_nodemask(h, gfp_mask, nid, NULL, NULL); spin_unlock(&hugetlb_lock); - if (!page) + if (!page) { + if (enable_charge_mighp) + gfp_mask |= __GFP_ACCOUNT; + page = alloc_migrate_huge_page(h, gfp_mask, nid, NULL); + } return page; } @@ -5227,4 +5232,18 @@ int hugetlb_insert_hugepage_pte_by_pa(struct mm_struct *mm, return 0; } EXPORT_SYMBOL_GPL(hugetlb_insert_hugepage_pte_by_pa); + +#ifdef CONFIG_ASCEND_CHARGE_MIGRATE_HUGEPAGES + +static int __init ascend_enable_charge_migrate_hugepages(char *s) +{ + enable_charge_mighp = 1; + + pr_info("Ascend enable charge migrate hugepage\n"); + + return 1; +} +__setup("enable_charge_mighp", ascend_enable_charge_migrate_hugepages); + +#endif #endif