From: Zhou Guanghui zhouguanghui1@huawei.com
ascend inclusion category: feature Bugzilla: N/A CVE: N/A
-------------------------------------------------------------
When the driver gets huge pages by alloc_huge_page_node, it attempts to apply for migrate hugepages after the reserved memory hugepages are used up. We expect that the migrated hugepages that are applied for can be charged in memcg to limit the memory usage.
__GFP_ACOUNT flag is added to gfp mask before we allocate migrage hugepages. Then, if memcg is set by memalloc_use_memcg(), the allocated migrate hugepages will be charged to this memcg.
Signed-off-by: Zhou Guanghui zhouguanghui1@huawei.com Reviewed-by: Ding Tianhong dingtianhong@huawei.com Reviewed-by: Kefeng Wang wangkefeng.wang@huawei.com Signed-off-by: Yang Yingliang yangyingliang@huawei.com --- arch/arm64/Kconfig | 11 +++++++++++ mm/hugetlb.c | 21 ++++++++++++++++++++- 2 files changed, 31 insertions(+), 1 deletion(-)
diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index a08fa3f1648c2..83344333670e2 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 0eb0c943397fd..3460ab634941a 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