All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ning Zhang <ningzhang@linux.alibaba.com>
To: linux-mm@kvack.org
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Johannes Weiner <hannes@cmpxchg.org>,
	Michal Hocko <mhocko@kernel.org>,
	Vladimir Davydov <vdavydov.dev@gmail.com>,
	Yu Zhao <yuzhao@google.com>
Subject: [RFC 2/6] mm, thp: add a global interface for zero subapges reclaim
Date: Thu, 28 Oct 2021 19:56:51 +0800	[thread overview]
Message-ID: <1635422215-99394-3-git-send-email-ningzhang@linux.alibaba.com> (raw)
In-Reply-To: <1635422215-99394-1-git-send-email-ningzhang@linux.alibaba.com>

Add a global interface to configure zero subpages reclaim global:

  /sys/kernel/mm/transparent_hugepage/reclaim

It has three modes:

  memcg, means every memory cgroup will use their own configure.
  enable, means every mem cgroup will enable reclaim.
  disable, means every mem cgroup will disable reclaim.

The default mode is memcg.

Signed-off-by: Ning Zhang <ningzhang@linux.alibaba.com>
---
 include/linux/huge_mm.h    |  1 +
 include/linux/memcontrol.h |  8 ++++++++
 mm/huge_memory.c           | 44 ++++++++++++++++++++++++++++++++++++++++++++
 mm/memcontrol.c            |  2 +-
 mm/vmscan.c                |  2 +-
 5 files changed, 55 insertions(+), 2 deletions(-)

diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h
index e1b3bf9..04607b1 100644
--- a/include/linux/huge_mm.h
+++ b/include/linux/huge_mm.h
@@ -186,6 +186,7 @@ unsigned long thp_get_unmapped_area(struct file *filp, unsigned long addr,
 bool is_transparent_hugepage(struct page *page);
 
 #ifdef CONFIG_MEMCG
+extern int global_thp_reclaim;
 int zsr_get_hpage(struct hpage_reclaim *hr_queue, struct page **reclaim_page);
 unsigned long zsr_reclaim_hpage(struct lruvec *lruvec, struct page *page);
 static inline struct list_head *hpage_reclaim_list(struct page *page)
diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h
index 502a6ab..f99f13f 100644
--- a/include/linux/memcontrol.h
+++ b/include/linux/memcontrol.h
@@ -1123,6 +1123,14 @@ unsigned long mem_cgroup_soft_limit_reclaim(pg_data_t *pgdat, int order,
 
 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
 void del_hpage_from_queue(struct page *page);
+
+static inline int get_thp_reclaim_mode(struct mem_cgroup *memcg)
+{
+	int reclaim = READ_ONCE(global_thp_reclaim);
+
+	return (reclaim != THP_RECLAIM_MEMCG) ? reclaim :
+			READ_ONCE(memcg->thp_reclaim);
+}
 #endif
 
 #else /* CONFIG_MEMCG */
diff --git a/mm/huge_memory.c b/mm/huge_memory.c
index 21e3c01..84fd738 100644
--- a/mm/huge_memory.c
+++ b/mm/huge_memory.c
@@ -60,6 +60,10 @@
 
 static struct shrinker deferred_split_shrinker;
 
+#ifdef CONFIG_MEMCG
+int global_thp_reclaim = THP_RECLAIM_MEMCG;
+#endif
+
 static atomic_t huge_zero_refcount;
 struct page *huge_zero_page __read_mostly;
 unsigned long huge_zero_pfn __read_mostly = ~0UL;
@@ -330,6 +334,43 @@ static ssize_t hpage_pmd_size_show(struct kobject *kobj,
 static struct kobj_attribute hpage_pmd_size_attr =
 	__ATTR_RO(hpage_pmd_size);
 
+#ifdef CONFIG_MEMCG
+static ssize_t reclaim_show(struct kobject *kobj,
+			    struct kobj_attribute *attr, char *buf)
+{
+	int thp_reclaim = READ_ONCE(global_thp_reclaim);
+
+	if (thp_reclaim == THP_RECLAIM_MEMCG)
+		return sprintf(buf, "[memcg] enable disable\n");
+	else if (thp_reclaim == THP_RECLAIM_ENABLE)
+		return sprintf(buf, "memcg [enable] disable\n");
+	else
+		return sprintf(buf, "memcg enable [disable]\n");
+}
+
+static ssize_t reclaim_store(struct kobject *kobj,
+			     struct kobj_attribute *attr,
+			     const char *buf, size_t count)
+{
+	if (!memcmp("memcg", buf,
+		    min(sizeof("memcg")-1, count)))
+		WRITE_ONCE(global_thp_reclaim, THP_RECLAIM_MEMCG);
+	else if (!memcmp("enable", buf,
+		    min(sizeof("enable")-1, count)))
+		WRITE_ONCE(global_thp_reclaim, THP_RECLAIM_ENABLE);
+	else if (!memcmp("disable", buf,
+		    min(sizeof("disable")-1, count)))
+		WRITE_ONCE(global_thp_reclaim, THP_RECLAIM_DISABLE);
+	else
+		return -EINVAL;
+
+	return count;
+}
+
+static struct kobj_attribute reclaim_attr =
+	__ATTR(reclaim, 0644, reclaim_show, reclaim_store);
+#endif
+
 static struct attribute *hugepage_attr[] = {
 	&enabled_attr.attr,
 	&defrag_attr.attr,
@@ -338,6 +379,9 @@ static ssize_t hpage_pmd_size_show(struct kobject *kobj,
 #ifdef CONFIG_SHMEM
 	&shmem_enabled_attr.attr,
 #endif
+#ifdef CONFIG_MEMCG
+	&reclaim_attr.attr,
+#endif
 	NULL,
 };
 
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 5df1cdd..ae96781 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -2746,7 +2746,7 @@ static void add_hpage_to_queue(struct page *page, struct mem_cgroup *memcg)
 	struct hpage_reclaim *hr_queue;
 	unsigned long flags;
 
-	if (READ_ONCE(memcg->thp_reclaim) == THP_RECLAIM_DISABLE)
+	if (get_thp_reclaim_mode(memcg) == THP_RECLAIM_DISABLE)
 		return;
 
 	page = compound_head(page);
diff --git a/mm/vmscan.c b/mm/vmscan.c
index 9be136f..f4ff14d 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -2801,7 +2801,7 @@ static unsigned long reclaim_hpage_zero_subpages(struct lruvec *lruvec,
 		goto out;
 
 	hr_queue = &memcg->nodeinfo[nid]->hpage_reclaim_queue;
-	if (!READ_ONCE(memcg->thp_reclaim))
+	if (get_thp_reclaim_mode(memcg) == THP_RECLAIM_DISABLE)
 		goto out;
 
 	/* The last scan loop will scan all the huge pages.*/
-- 
1.8.3.1



  parent reply	other threads:[~2021-10-28 11:57 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-28 11:56 [RFC 0/6] Reclaim zero subpages of thp to avoid memory bloat Ning Zhang
2021-10-28 11:56 ` [RFC 1/6] mm, thp: introduce thp zero subpages reclaim Ning Zhang
2021-10-28 12:53   ` Matthew Wilcox
2021-10-29 12:16     ` ning zhang
2021-10-28 20:50   ` kernel test robot
2021-10-28 20:50     ` kernel test robot
2021-10-28 11:56 ` Ning Zhang [this message]
2021-10-29  0:44   ` [RFC 2/6] mm, thp: add a global interface for zero subapges reclaim kernel test robot
2021-10-29  0:44     ` kernel test robot
2021-10-28 11:56 ` [RFC 3/6] mm, thp: introduce zero subpages reclaim threshold Ning Zhang
2021-10-28 11:56 ` [RFC 4/6] mm, thp: introduce a controller to trigger zero subpages reclaim Ning Zhang
2021-10-28 11:56 ` [RFC 5/6] mm, thp: add some statistics for " Ning Zhang
2021-10-28 11:56 ` [RFC 6/6] mm, thp: add document " Ning Zhang
2021-10-28 14:13 ` [RFC 0/6] Reclaim zero subpages of thp to avoid memory bloat Kirill A. Shutemov
2021-10-29 12:07   ` ning zhang
2021-10-29 16:56     ` Yang Shi
2021-11-01  2:50       ` ning zhang
2021-10-29 13:38 ` Michal Hocko
2021-10-29 16:12   ` ning zhang
2021-11-01  9:20     ` Michal Hocko
2021-11-08  3:24       ` ning zhang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1635422215-99394-3-git-send-email-ningzhang@linux.alibaba.com \
    --to=ningzhang@linux.alibaba.com \
    --cc=akpm@linux-foundation.org \
    --cc=hannes@cmpxchg.org \
    --cc=linux-mm@kvack.org \
    --cc=mhocko@kernel.org \
    --cc=vdavydov.dev@gmail.com \
    --cc=yuzhao@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.