Commit 8822f347 authored by Liu Shixin's avatar Liu Shixin
Browse files

mm/dynamic_pool: introduce per-memcg memory pool

hulk inclusion
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/I8S9BY


CVE: NA

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

This patch introduce a per-memcg memory pool named dynamic pool(dpool).
The dpool is created by call dpool_create(). The child memcg will inherit
the dpool. The dpool will be destroyed when remove the memcg.

Signed-off-by: default avatarLiu Shixin <liushixin2@huawei.com>
parent 3e8bcb36
Loading
Loading
Loading
Loading
+54 −0
Original line number Diff line number Diff line
/* SPDX-License-Identifier: GPL-2.0-or-later */
#ifndef __LINUX_DYNAMIC_POOL_H
#define __LINUX_DYNAMIC_POOL_H

#include <linux/memcontrol.h>
#include <linux/hugetlb.h>
#include <linux/kabi.h>

#ifdef CONFIG_DYNAMIC_POOL

DECLARE_STATIC_KEY_FALSE(dynamic_pool_key);
#define dpool_enabled (static_branch_unlikely(&dynamic_pool_key))

enum pages_pool_type {
	PAGES_POOL_1G,
	PAGES_POOL_2M,
	PAGES_POOL_4K,
	PAGES_POOL_MAX,
};

struct pages_pool {
	unsigned long free_pages;
	unsigned long used_pages;
	struct list_head freelist;
};

struct dynamic_pool {
	refcount_t refcnt;
	bool online;
	struct mem_cgroup *memcg;

	spinlock_t lock;
	struct pages_pool pool[PAGES_POOL_MAX];

	KABI_RESERVE(1)
};

void dynamic_pool_inherit(struct mem_cgroup *memcg);
int dynamic_pool_destroy(struct cgroup *cgrp, bool *clear_css_online);

#else
struct dynamic_pool {};

static inline void dynamic_pool_inherit(struct mem_cgroup *memcg)
{
}

static inline int dynamic_pool_destroy(struct cgroup *cgrp,
				       bool *clear_css_online)
{
	return 0;
}
#endif /* CONFIG_DYNAMIC_POOL */
#endif /* __LINUX_DYNAMIC_POOL_H */
+5 −0
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ struct page;
struct mm_struct;
struct kmem_cache;
struct oom_control;
struct dynamic_pool;

/* Cgroup-specific page state, on top of universal node page state */
enum memcg_stat_item {
@@ -364,6 +365,10 @@ struct mem_cgroup {
	struct swap_device *swap_dev;
#endif

#ifdef CONFIG_DYNAMIC_POOL
	struct dynamic_pool *dpool;
#endif

	struct mem_cgroup_per_node *nodeinfo[];
};

+10 −0
Original line number Diff line number Diff line
@@ -59,6 +59,7 @@
#include <linux/sched/cputime.h>
#include <linux/sched/deadline.h>
#include <linux/psi.h>
#include <linux/dynamic_pool.h>
#include <net/sock.h>
#include <linux/backing-dev.h>

@@ -5965,6 +5966,7 @@ static int cgroup_destroy_locked(struct cgroup *cgrp)
	struct cgroup_subsys_state *css;
	struct cgrp_cset_link *link;
	int ssid;
	bool clear_css_online = false;

	lockdep_assert_held(&cgroup_mutex);

@@ -5983,6 +5985,14 @@ static int cgroup_destroy_locked(struct cgroup *cgrp)
	if (css_has_online_children(&cgrp->self))
		return -EBUSY;

	/*
	 * If dynamic pool is enabled, make sure dpool is destroyed before
	 * removing the corresponding memory cgroup. If CSS_ONLINE is set,
	 * this function will clear it and set clear_css_online to true.
	 */
	if (dynamic_pool_destroy(cgrp, &clear_css_online))
		return -EBUSY;

	/*
	 * Mark @cgrp and the associated csets dead.  The former prevents
	 * further task migration and child creation by disabling
+9 −0
Original line number Diff line number Diff line
@@ -1365,6 +1365,15 @@ config MEMORY_RELIABLE
	  To enable this function, mirrored memory is needed and
	  "kernelcore=reliable" need to be added in kernel parameters.

config DYNAMIC_POOL
	bool "Dynamic Pool support"
	depends on X86_64 || (ARM64 && ARM64_4K_PAGES)
	depends on MEMCG && HUGETLB_PAGE
	default n
	help
	  A per-memcg pagepool. The task in the memcg will prefer to alloc
	  pages from corresponding pool.

source "mm/damon/Kconfig"

endmenu
+1 −0
Original line number Diff line number Diff line
@@ -145,3 +145,4 @@ obj-$(CONFIG_MEMCG_MEMFS_INFO) += memcg_memfs_info.o
obj-$(CONFIG_PAGE_CACHE_LIMIT) += page_cache_limit.o
obj-$(CONFIG_CLEAR_FREELIST_PAGE) += clear_freelist_page.o
obj-$(CONFIG_MEMORY_RELIABLE) += mem_reliable.o
obj-$(CONFIG_DYNAMIC_POOL)	+= dynamic_pool.o
Loading