提交 03aaeca8 编写于 作者: Z Zhou Guanghui 提交者: Zhong Jinghua

mm: sharepool: Charge Buddy hugepage to memcg

ascend inclusion
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/I6A3YT

-------------------------------------------------

Charge buddy hugepage to memcg when kmemcg is disabled. If kmemcg
is enabled, we can also use kmemcg to charge buddy hugepages.
Signed-off-by: NZhou Guanghui <zhouguanghui1@huawei.com>
上级 5199766d
无相关合并请求
......@@ -46,6 +46,7 @@
#include <linux/dynamic_hugetlb.h>
#include "internal.h"
#include "hugetlb_vmemmap.h"
#include "share_pool_internal.h"
int hugetlb_max_hstate __read_mostly;
unsigned int default_hstate_idx;
......@@ -1625,6 +1626,7 @@ void free_huge_page(struct page *page)
h->resv_huge_pages++;
if (HPageTemporary(page)) {
sp_memcg_uncharge_hpage(page);
remove_hugetlb_page(h, page, false);
spin_unlock_irqrestore(&hugetlb_lock, flags);
update_and_free_page(h, page, true);
......
......@@ -4031,6 +4031,7 @@ vm_fault_t sharepool_no_page(struct mm_struct *mm,
int err;
int node_id;
struct sp_area *spa;
bool charge_hpage;
spa = vma->vm_private_data;
if (!spa) {
......@@ -4046,12 +4047,15 @@ vm_fault_t sharepool_no_page(struct mm_struct *mm,
if (idx >= size)
goto out;
charge_hpage = false;
page = alloc_huge_page(vma, haddr, 0);
if (IS_ERR(page)) {
page = hugetlb_alloc_hugepage(node_id,
HUGETLB_ALLOC_BUDDY | HUGETLB_ALLOC_NORECLAIM);
if (!page)
page = ERR_PTR(-ENOMEM);
else if (!PageMemcgKmem(page))
charge_hpage = true;
}
if (IS_ERR(page)) {
ptl = huge_pte_lock(h, mm, ptep);
......@@ -4064,6 +4068,13 @@ vm_fault_t sharepool_no_page(struct mm_struct *mm,
ret = vmf_error(PTR_ERR(page));
goto out;
}
if (charge_hpage && mem_cgroup_charge(page, vma->vm_mm, GFP_KERNEL)) {
put_page(page);
ret = vmf_error(-ENOMEM);
goto out;
}
__SetPageUptodate(page);
new_page = true;
......@@ -4096,9 +4107,8 @@ vm_fault_t sharepool_no_page(struct mm_struct *mm,
spin_unlock(ptl);
if (new_page) {
if (new_page)
SetPagePrivate(&page[1]);
}
unlock_page(page);
out:
......
/* SPDX-License-Identifier: GPL-2.0 */
#ifndef SHARE_POOL_INTERNAL_H
#define SHARE_POOL_INTERNAL_H
#include <linux/hugetlb.h>
#include <linux/memcontrol.h>
#ifdef CONFIG_ASCEND_SHARE_POOL
static inline void sp_memcg_uncharge_hpage(struct page *page)
{
if (!sp_is_enabled())
return;
mem_cgroup_uncharge(page);
}
#else
static inline void sp_memcg_uncharge_hpage(struct page *page)
{
}
#endif
#endif
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册
反馈
建议
客服 返回
顶部