[RFC PATCH v2 07/16] mm: Define function to create a dir for each migrate type

Juan Yescas <[email protected]>
Newsgroups gmane.linux.kernel,gmane.linux.kernel.mm,gmane.linux.kernel.mm
Message-ID <[email protected]>
This change creates a directory for each migrate type inside
the order directory.

This function won't create a directory for MIGRATE_ISOLATE due
they can't be allocated using the Buddy Allocator.

Note: The MIGRATE_CMA directory won't be created yet. It will
be supported in the future.

Signed-off-by: Juan Yescas <[email protected]>
---

Changes in v2:
	- Update comments.
	- Remove unused parameters.

 mm/page_alloc_hogger.c | 36 +++++++++++++++++++++++++++++++++++-
 1 file changed, 35 insertions(+), 1 deletion(-)

diff --git a/mm/page_alloc_hogger.c b/mm/page_alloc_hogger.c
index 24856f7ea5d7..ab39ea300704 100644
--- a/mm/page_alloc_hogger.c
+++ b/mm/page_alloc_hogger.c
@@ -127,20 +127,54 @@ struct page_alloc {
 static struct kmem_cache *req_alloc_cache;
 static struct kmem_cache *page_alloc_cache;
 
+/**
+ * create_migrate_type_subdirs() - Creates a directory for each migrate type
+ * inside the order directory.
+ */
+static inline int create_migrate_type_subdirs(struct dentry *orderdir)
+{
+	struct dentry *migratedir;
+	char dirname[24];
+
+	for (int mtype = 0; mtype < MIGRATE_TYPES; mtype++) {
+#ifdef CONFIG_CMA
+		if (mtype == MIGRATE_CMA) /* CMA allocs are not supported yet*/
+			continue;
+#endif
+#ifdef CONFIG_MEMORY_ISOLATION
+		if (mtype == MIGRATE_ISOLATE) /* can't allocate from here */
+			continue;
+#endif
+		snprintf(dirname, sizeof(dirname), "migrate-%s",
+			 migratetype_names[mtype]);
+		migratedir = debugfs_create_dir(dirname, orderdir);
+		if (IS_ERR(migratedir))
+			return PTR_ERR(migratedir);
+	}
+
+	return 0;
+}
+
 /**
  * create_page_orders_subdirs() - Creates a directory for each page order inside
- * the zone directory.
+ * the zone directory. Once that the page order directory is created, it creates
+ * a directory for each migrate type.
  */
 static inline int create_page_orders_subdirs(struct dentry *zonedir)
 {
 	struct dentry *orderdir;
 	char dirname[12];
+	int ret;
 
 	for (int order = 0; order < NR_PAGE_ORDERS; order++) {
 		snprintf(dirname, sizeof(dirname), "order-%d", order);
 		orderdir = debugfs_create_dir(dirname, zonedir);
 		if (IS_ERR(orderdir))
 			return PTR_ERR(orderdir);
+
+		ret = create_migrate_type_subdirs(orderdir);
+		if (ret)
+			return ret;
 	}
 
 	return 0;
-- 
2.55.0.629.g250fe7f194-goog
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.