linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: kaiyang2@cs.cmu.edu
To: linux-mm@kvack.org, linux-kernel@vger.kernel.org
Cc: Kaiyang Zhao <kaiyang2@cs.cmu.edu>,
	hannes@cmpxchg.org, ziy@nvidia.com, dskarlat@cs.cmu.edu
Subject: [RFC PATCH 1/7] sysfs interface for the boundary of movable zone
Date: Wed, 20 Mar 2024 02:42:12 +0000	[thread overview]
Message-ID: <20240320024218.203491-2-kaiyang2@cs.cmu.edu> (raw)
In-Reply-To: <20240320024218.203491-1-kaiyang2@cs.cmu.edu>

From: Kaiyang Zhao <kaiyang2@cs.cmu.edu>

Exports the pfn and memory block id for boundary

Signed-off-by: Kaiyang Zhao <zh_kaiyang@hotmail.com>
---
 drivers/base/memory.c  |  2 +-
 drivers/base/node.c    | 32 ++++++++++++++++++++++++++++++++
 include/linux/memory.h |  1 +
 3 files changed, 34 insertions(+), 1 deletion(-)

diff --git a/drivers/base/memory.c b/drivers/base/memory.c
index b456ac213610..281b229d7019 100644
--- a/drivers/base/memory.c
+++ b/drivers/base/memory.c
@@ -55,7 +55,7 @@ static inline unsigned long memory_block_id(unsigned long section_nr)
 	return section_nr / sections_per_block;
 }
 
-static inline unsigned long pfn_to_block_id(unsigned long pfn)
+unsigned long pfn_to_block_id(unsigned long pfn)
 {
 	return memory_block_id(pfn_to_section_nr(pfn));
 }
diff --git a/drivers/base/node.c b/drivers/base/node.c
index b46db17124f3..f29ce07565ba 100644
--- a/drivers/base/node.c
+++ b/drivers/base/node.c
@@ -486,6 +486,37 @@ static ssize_t node_read_meminfo(struct device *dev,
 #undef K
 static DEVICE_ATTR(meminfo, 0444, node_read_meminfo, NULL);
 
+static ssize_t node_read_movable_zone(struct device *dev,
+			struct device_attribute *attr, char *buf)
+{
+	int len = 0;
+	struct zone *unmovable_zone;
+	unsigned long movable_start_pfn, unmovable_end_pfn;
+	unsigned long movable_start_block_id, unmovable_end_block_id;
+
+	movable_start_pfn = NODE_DATA(dev->id)->node_zones[ZONE_MOVABLE].zone_start_pfn;
+	movable_start_block_id = pfn_to_block_id(movable_start_pfn);
+
+	if (populated_zone(&(NODE_DATA(dev->id)->node_zones[ZONE_NORMAL])))
+		unmovable_zone = &(NODE_DATA(dev->id)->node_zones[ZONE_NORMAL]);
+	else
+		unmovable_zone = &(NODE_DATA(dev->id)->node_zones[ZONE_DMA32]);
+
+	unmovable_end_pfn = zone_end_pfn(unmovable_zone);
+	unmovable_end_block_id = pfn_to_block_id(unmovable_end_pfn);
+
+	len = sysfs_emit_at(buf, len,
+			    "movable_zone_start_pfn %lu\n"
+				"movable_zone_start_block_id %lu\n"
+				"unmovable_zone_end_pfn %lu\n"
+				"unmovable_zone_end_block_id %lu\n",
+			    movable_start_pfn, movable_start_block_id,
+				unmovable_end_pfn, unmovable_end_block_id);
+
+	return len;
+}
+static DEVICE_ATTR(movable_zone, 0444, node_read_movable_zone, NULL);
+
 static ssize_t node_read_numastat(struct device *dev,
 				  struct device_attribute *attr, char *buf)
 {
@@ -565,6 +596,7 @@ static DEVICE_ATTR(distance, 0444, node_read_distance, NULL);
 
 static struct attribute *node_dev_attrs[] = {
 	&dev_attr_meminfo.attr,
+	&dev_attr_movable_zone.attr,
 	&dev_attr_numastat.attr,
 	&dev_attr_distance.attr,
 	&dev_attr_vmstat.attr,
diff --git a/include/linux/memory.h b/include/linux/memory.h
index 31343566c221..17a92a5c1ae5 100644
--- a/include/linux/memory.h
+++ b/include/linux/memory.h
@@ -92,6 +92,7 @@ struct memory_block {
 int arch_get_memory_phys_device(unsigned long start_pfn);
 unsigned long memory_block_size_bytes(void);
 int set_memory_block_size_order(unsigned int order);
+unsigned long pfn_to_block_id(unsigned long pfn);
 
 /* These states are exposed to userspace as text strings in sysfs */
 #define	MEM_ONLINE		(1<<0) /* exposed to userspace */
-- 
2.40.1



  reply	other threads:[~2024-03-20  2:42 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-20  2:42 [RFC PATCH 0/7] mm: providing ample physical memory contiguity by confining unmovable allocations kaiyang2
2024-03-20  2:42 ` kaiyang2 [this message]
2024-03-20  2:42 ` [RFC PATCH 2/7] Disallows high-order movable allocations in other zones if ZONE_MOVABLE is populated kaiyang2
2024-03-20  2:42 ` [RFC PATCH 3/7] compaction accepts a destination zone kaiyang2
2024-03-20  2:42 ` [RFC PATCH 4/7] vmstat counter for pages migrated across zones kaiyang2
2024-03-20  2:42 ` [RFC PATCH 5/7] proactively move pages out of unmovable zones in kcompactd kaiyang2
2024-03-20  2:42 ` [RFC PATCH 6/7] pass gfp mask of the allocation that waked kswapd to track number of pages scanned on behalf of each alloc type kaiyang2
2024-03-20  2:42 ` [RFC PATCH 7/7] exports the number of pages scanned on behalf of movable/unmovable allocations kaiyang2
2024-03-20  2:47 ` [RFC PATCH 0/7] mm: providing ample physical memory contiguity by confining unmovable allocations Zi Yan
2024-03-20  2:57 ` kaiyang2

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=20240320024218.203491-2-kaiyang2@cs.cmu.edu \
    --to=kaiyang2@cs.cmu.edu \
    --cc=dskarlat@cs.cmu.edu \
    --cc=hannes@cmpxchg.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=ziy@nvidia.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