diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index 9a5c7aba1d599ce61e3a139897910336ea6e44fc..a50d82dc33e74af3378d7d58126a250f11faf749 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -1359,6 +1359,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 157bffb45099accff4b719716896d5f7d90f977e..41a1be919f84f23b05ccc4d1b5f22ed8ebe13e6b 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; } @@ -5225,4 +5230,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