linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Tim Chen <tim.c.chen@linux.intel.com>
To: linux-mm@kvack.org, akpm@linux-foundation.org
Cc: Tim Chen <tim.c.chen@linux.intel.com>,
	Wei Xu <weixugc@google.com>, Huang Ying <ying.huang@intel.com>,
	Greg Thelen <gthelen@google.com>, Yang Shi <shy828301@gmail.com>,
	Davidlohr Bueso <dave@stgolabs.net>,
	Brice Goglin <brice.goglin@gmail.com>,
	Michal Hocko <mhocko@kernel.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Hesham Almatary <hesham.almatary@huawei.com>,
	Dave Hansen <dave.hansen@intel.com>,
	Jonathan Cameron <Jonathan.Cameron@huawei.com>,
	Alistair Popple <apopple@nvidia.com>,
	Dan Williams <dan.j.williams@intel.com>,
	Feng Tang <feng.tang@intel.com>,
	Jagdish Gediya <jvgediya@linux.ibm.com>,
	Baolin Wang <baolin.wang@linux.alibaba.com>,
	David Rientjes <rientjes@google.com>,
	"Aneesh Kumar K . V" <aneesh.kumar@linux.ibm.com>,
	Shakeel Butt <shakeelb@google.com>
Subject: [RFC PATCH 1/3] mm/memory-tiers Add functions for tier memory usage in a cgroup
Date: Tue, 14 Jun 2022 15:25:33 -0700	[thread overview]
Message-ID: <94a10c772c50d378b81dad654476551bfc50e3d7.1655242024.git.tim.c.chen@linux.intel.com> (raw)
In-Reply-To: <cover.1655242024.git.tim.c.chen@linux.intel.com>

Add functions to provide tier based memory usage.  This is in preparation
for query via sysfs and for controlling a cgroup's top tier memory usage.

This patch introduces the tiered memory usage query interface and a
simple implementation.  A more efficient implementation to get toptier
memory usage will be introduced in the next patch.
---
 include/linux/memory-tiers.h |  2 ++
 mm/memcontrol.c              | 35 +++++++++++++++++++++++++++++++++++
 mm/memory-tiers.c            |  3 ++-
 3 files changed, 39 insertions(+), 1 deletion(-)

diff --git a/include/linux/memory-tiers.h b/include/linux/memory-tiers.h
index de4098f6d5d5..1177dcbbdeda 100644
--- a/include/linux/memory-tiers.h
+++ b/include/linux/memory-tiers.h
@@ -31,6 +31,8 @@ struct memory_tier {
 };
 
 extern bool numa_demotion_enabled;
+extern struct list_head memory_tiers;
+
 int node_create_and_set_memory_tier(int node, int tier);
 int next_demotion_node(int node);
 int node_set_memory_tier(int node, int tier);
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index abec50f31fe6..2f6e95e6d200 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -63,6 +63,7 @@
 #include <linux/resume_user_mode.h>
 #include <linux/psi.h>
 #include <linux/seq_buf.h>
+#include <linux/memory-tiers.h>
 #include "internal.h"
 #include <net/sock.h>
 #include <net/ip.h>
@@ -3921,6 +3922,40 @@ static int memcg_numa_stat_show(struct seq_file *m, void *v)
 
 	return 0;
 }
+
+unsigned long mem_cgroup_memtier_usage(struct mem_cgroup *memcg,
+					struct memory_tier *memtier)
+{
+	int node;
+	struct memory_tier *node_tier;
+	unsigned long usage = 0;
+
+	if (!memcg)
+		return 0;
+
+	rcu_read_lock();
+	for_each_online_node(node) {
+		node_tier = node_get_memory_tier(node);
+		if (node_tier == memtier)
+			usage += mem_cgroup_node_nr_lru_pages(memcg, node,
+					LRU_ALL, true);
+		node_put_memory_tier(node_tier);
+	}
+	rcu_read_unlock();
+	return usage;
+}
+
+unsigned long mem_cgroup_toptier_usage(struct mem_cgroup *memcg)
+{
+	struct memory_tier *top_tier;
+
+	top_tier = list_first_entry(&memory_tiers, struct memory_tier, list);
+	if (top_tier)
+		return mem_cgroup_memtier_usage(memcg, top_tier);
+	else
+		return 0;
+}
+
 #endif /* CONFIG_NUMA */
 
 static const unsigned int memcg1_stats[] = {
diff --git a/mm/memory-tiers.c b/mm/memory-tiers.c
index 0dae3114e22c..d552ac1e9d57 100644
--- a/mm/memory-tiers.c
+++ b/mm/memory-tiers.c
@@ -16,7 +16,8 @@ struct demotion_nodes {
 #define to_memory_tier(device) container_of(device, struct memory_tier, dev)
 static void establish_migration_targets(void);
 static DEFINE_MUTEX(memory_tier_lock);
-static LIST_HEAD(memory_tiers);
+LIST_HEAD(memory_tiers);
+EXPORT_SYMBOL(memory_tiers);
 static int top_tier_rank;
 /*
  * node_demotion[] examples:
-- 
2.35.1



  reply	other threads:[~2022-06-14 22:26 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-14 22:25 [RFC PATCH 0/3] Cgroup accounting of memory tier usage Tim Chen
2022-06-14 22:25 ` Tim Chen [this message]
2022-06-21  4:18   ` [RFC PATCH 1/3] mm/memory-tiers Add functions for tier memory usage in a cgroup Aneesh Kumar K.V
2022-06-23 23:07     ` Tim Chen
2022-06-14 22:25 ` [RFC PATCH 2/3] mm/memory-tiers: Use page counter to track toptier memory usage Tim Chen
2022-06-15  0:27   ` Wei Xu
2022-06-15  0:30   ` Wei Xu
2022-06-16  4:12     ` Tim Chen
2022-06-14 22:25 ` [RFC PATCH 3/3] mm/memory-tiers: Show toptier memory usage for cgroup Tim Chen
2022-06-15  4:58 ` [RFC PATCH 0/3] Cgroup accounting of memory tier usage Ying Huang
2022-06-15 17:47   ` Tim Chen
2022-06-15 11:11 ` Michal Hocko
2022-06-15 15:23   ` Tim Chen
2022-06-15 15:59     ` Michal Hocko

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=94a10c772c50d378b81dad654476551bfc50e3d7.1655242024.git.tim.c.chen@linux.intel.com \
    --to=tim.c.chen@linux.intel.com \
    --cc=Jonathan.Cameron@huawei.com \
    --cc=akpm@linux-foundation.org \
    --cc=aneesh.kumar@linux.ibm.com \
    --cc=apopple@nvidia.com \
    --cc=baolin.wang@linux.alibaba.com \
    --cc=brice.goglin@gmail.com \
    --cc=dan.j.williams@intel.com \
    --cc=dave.hansen@intel.com \
    --cc=dave@stgolabs.net \
    --cc=feng.tang@intel.com \
    --cc=gthelen@google.com \
    --cc=hesham.almatary@huawei.com \
    --cc=jvgediya@linux.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mhocko@kernel.org \
    --cc=rientjes@google.com \
    --cc=shakeelb@google.com \
    --cc=shy828301@gmail.com \
    --cc=weixugc@google.com \
    --cc=ying.huang@intel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).