Unverified Commit cc16eb45 authored by openeuler-ci-bot's avatar openeuler-ci-bot Committed by Gitee
Browse files

!3976 Introduce dynamic pool feature

Merge Pull Request from: @ci-robot 
 
PR sync from: Liu Shixin <liushixin2@huawei.com>
https://mailweb.openeuler.org/hyperkitty/list/kernel@openeuler.org/message/7FMVCZPLH3ZICEQCGFXDT6I23BKQ3GBN/ 
Rename from dynamic hugetlb(OLK_5.10) to dynamic pool.

A per-memcg pagepool. The task in the memcg will prefer to alloc
pages from corresponding pool.

Liu Shixin (26):
  mm/memcg: introduce mem_cgroup_scan_cgroups to scan all memcgs
  mm/memcg: introduce memcg_has_children to check memcg
  mm/dynamic_pool: introduce per-memcg memory pool
  mm/dynamic_pool: introduce PG_dpool to mark free pages in dpool
  mm/dynamic_pool: introduce PG_pool to mark pages allocated from dpool
  mm/dynamic_pool: create dpool by dhugetlb.nr_pages interface
  mm/dynamic_pool: fill dpool with HugeTLB 1G pages
  mm/dynamic_pool: add interface to configure the count of hugepages
  mm/dynamic_pool: add restore_pool ops to reclaim memory and restore
    hugepages
  mm/dynamic_pool: support to flow pages between 1G and 2M pages pool
  mm/dynamic_pool: support to flow pages between 2M and 4K pages pool
  mm/dynamic_pool: migrate used pages before promote to huge page
  mm/dynamic_pool: call mem_cgroup_force_empty before restore pool
  mm/dynamic_pool: prevent task attach to another dpool
  mm/dynamic_pool: support page allocation from dpool
  mm/dynamic_pool: speed up allocation by percpu pages pool
  mm/dynamic_pool: check resv for HugeTLB allocation from dpool
  mm/dynamic_pool: support HugeTLB page allocation from dpool
  mm/dynamic_pool: add tracepoints for dpool
  mm/dynamic_pool: fill dpool with pagelist
  mm/dynamic_pool: disable THP for task attached with dpool
  mm/dynamic_pool: compatible with HugeTLB dissolve
  mm/dynamic_pool: compatible with HugeTLB Vmemmap
  mm/dynamic_pool: compatible with memory hwpoison
  mm/dynamic_pool: add Document for dynamic hugetlb feature
  mm/dynamic_pool: enable CONFIG_DYNAMIC_POOL on x86_64 and arm64 by
    default


-- 
2.25.1
 
https://gitee.com/openeuler/kernel/issues/I8S9BY 
 
Link:https://gitee.com/openeuler/kernel/pulls/3976

 

Reviewed-by: default avatarKefeng Wang <wangkefeng.wang@huawei.com>
Reviewed-by: default avatarLu Jialin <lujialin4@huawei.com>
Reviewed-by: default avatarzhangyi (F) <yi.zhang@huawei.com>
Reviewed-by: default avatarXu Kuohai <xukuohai@huawei.com>
Reviewed-by: default avatarZucheng Zheng <zhengzucheng@huawei.com>
Reviewed-by: default avatarLiu Chao <liuchao173@huawei.com>
Signed-off-by: default avatarZheng Zengkai <zhengzengkai@huawei.com>
parents 2212880a 90368855
Loading
Loading
Loading
Loading
+100 −0
Original line number Diff line number Diff line
.. SPDX-License-Identifier: GPL-2.0

===============
Dynamic Hugetlb
===============

Overview
========

Dynamic hugetlb is a self-developed feature based on the hugetlb and memcontrol.
It supports to split huge page dynamically in a memory cgroup. There is a new structure
dhugetlb_pool in every mem_cgroup to manage the pages configured to the mem_cgroup.
For the mem_cgroup configured with dhugetlb_pool, processes in the mem_cgroup will
preferentially use the pages in dhugetlb_pool.

Dynamic hugetlb supports three types of pages, including 1G/2M huge pages and 4K pages.
For the mem_cgroup configured with dhugetlb_pool, processes will be limited to alloc
1G/2M huge pages only from dhugetlb_pool. But there is no such constraint for 4K pages.
If there are insufficient 4K pages in the dhugetlb_pool, pages can also be allocated from
buddy system. So before using dynamic hugetlb, user must know how many huge pages they
need.

Conflict
========

1. Conflict with THP
--------------------

When THP is enabled, the allocation of a page(order=0) may be converted to
an allocation of pages(order>0). In this case, the allocation will skip the
dhugetlb_pool. When we want to use dynamic hugetlb feature, we have to
disable THP for now.

2. Conflict with hugetlb_vmemmap
--------------------------------

The dynamic_hugetlb feature need to split and merge pages frequently.
hugetlb_vmemmap will affects the perforemance of page split and merge.
If want to use dynamic hugetlb, please disable hugetlb_vmemmap.

Usage
=====

1) Add 'dynamic_hugetlb=on' in cmdline to enable dynamic hugetlb feature.

2) Prealloc some 1G hugepages through hugetlb.

3) Create a mem_cgroup and configure dhugetlb_pool to mem_cgroup.

4) Configure the count of 1G/2M hugepages, and the remaining pages in dhugetlb_pool will
   be used as basic pages.

5) Bound the process to mem_cgroup. then the memory for it will be allocated from dhugetlb_pool.

User control
============

1. dynamic_hugetlb=
-------------------

Add ``dynamic_hugtlb=on`` in cmdline to enable dynamic hugetlb feature.
By default, the feature si disabled.

2. dhugetlb.nr_pages
--------------------

In each memory cgroup, there is a ``dhugetlb.nr_pages`` interface used to create and configure dynamic
hugetlb. If this interface is not configured, the original functions are not affected. If configured,
then the memory used by processes in this memory cgroup will be allocated from corresponding hpool.

Usage:
	``echo <nid> <nr_pages> > /sys/fs/cgroup/memory/<memory cgroup>/dhugetlb.nr_pages``:

	Create a dynamic hugetlb pool and add <nr_pages> 1G hugepages from numa node <nid> to the pool.

	``cat /sys/fs/cgroup/memory/<memory cgroup>/dhugetlb.nr_pages``:

	Reads the memory information in the hpool, include the free amount and used amount of huge pages and
	normal pages.

3. dhugetlb.1G.reserved_pages
-----------------------------

In each memory cgroup, there is a ``dhugetlb.nr_pages`` interface used to reserved 1G huge pages.
By default, all memory configured to a dynamic hugetlb pool can be used only as normal pages, if want to use
it as 1G huge pages, need to configure the number of 1G huge pages by this interface firstly.

Usage:
	``echo <nr_pages> > /sys/fs/cgroup/memory/<memory cgroup>/dhugetlb.1G.reserved_pages``

4. dhugetlb.2M.reserved_pages
-----------------------------

Similar to the previous interface, this is used to configure the number of 2M huge pages.

Usage:
	``echo <nr_pages> > /sys/fs/cgroup/memory/<memory cgroup>/dhugetlb.2M.reserved_pages``

---
Liu Shixin, Jan 2022
+1 −0
Original line number Diff line number Diff line
@@ -1151,6 +1151,7 @@ CONFIG_ARCH_SUPPORTS_PER_VMA_LOCK=y
CONFIG_PER_VMA_LOCK=y
CONFIG_LOCK_MM_AND_FIND_VMA=y
CONFIG_MEMORY_RELIABLE=y
CONFIG_DYNAMIC_POOL=y

#
# Data Access Monitoring
+1 −0
Original line number Diff line number Diff line
@@ -1166,6 +1166,7 @@ CONFIG_LRU_GEN=y
CONFIG_ARCH_SUPPORTS_PER_VMA_LOCK=y
CONFIG_PER_VMA_LOCK=y
CONFIG_LOCK_MM_AND_FIND_VMA=y
CONFIG_DYNAMIC_POOL=y

#
# Data Access Monitoring
+5 −0
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@
#include <linux/magic.h>
#include <linux/migrate.h>
#include <linux/uio.h>
#include <linux/dynamic_pool.h>

#include <linux/uaccess.h>
#include <linux/sched/mm.h>
@@ -1294,6 +1295,9 @@ static struct inode *hugetlbfs_alloc_inode(struct super_block *sb)
	 */
	mpol_shared_policy_init(&p->policy, NULL);

	/* Initialize hpool here in case of a quick call to destroy */
	dynamic_pool_bind_file(p, sbinfo->hstate);

	return &p->vfs_inode;
}

@@ -1306,6 +1310,7 @@ static void hugetlbfs_destroy_inode(struct inode *inode)
{
	hugetlbfs_inc_free_inodes(HUGETLBFS_SB(inode->i_sb));
	mpol_free_shared_policy(&HUGETLBFS_I(inode)->policy);
	dynamic_pool_unbind_file(HUGETLBFS_I(inode));
}

static const struct address_space_operations hugetlbfs_aops = {
+3 −0
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@
#include <linux/cma.h>
#endif
#include <linux/zswap.h>
#include <linux/dynamic_pool.h>
#include <asm/page.h>
#include "internal.h"

@@ -170,6 +171,8 @@ static int meminfo_proc_show(struct seq_file *m, void *v)

	reliable_report_meminfo(m);

	dynamic_pool_show_meminfo(m);

	return 0;
}

Loading