Skip to contentSkip to conversation

AutoNUMA19

PATCH In review Andrea Arcangeli 16 participants 178 messages Jun 28, 2012 – Oct 24, 2012 Page 2 of 2

Subsystems (15)
Memory management x86 VFS PowerPC +11 more subsystems
lore
Share & tools
lore
#172 lore raw

PATCH 39/40 autonuma: bugcheck page_autonuma fields on newly allocated pages

In reply to Andrea Arcangeli

Debug tweak.

---
 include/linux/autonuma.h |   11 +++++++++++
 mm/page_alloc.c          |    1 +
 2 files changed, 12 insertions(+), 0 deletions(-)
include/linux/autonuma.h +11 -0
index 67af86a..05bd8c1 100644
@@ -29,6 +29,16 @@ static inline void autonuma_free_page(struct page *page)
 	}
 }
 
+static inline void autonuma_check_new_page(struct page *page)
+{
+	struct page_autonuma *page_autonuma;
+	if (!autonuma_impossible()) {
+		page_autonuma = lookup_page_autonuma(page);
+		BUG_ON(page_autonuma->autonuma_migrate_nid != -1);
+		BUG_ON(page_autonuma->autonuma_last_nid != -1);
+	}
+}
+
 #define autonuma_printk(format, args...) \
 	if (autonuma_debug()) printk(format, ##args)
 
@@ -41,6 +51,7 @@ static inline void autonuma_migrate_split_huge_page(struct page *page,
 						    struct page *page_tail) {}
 static inline void autonuma_setup_new_exec(struct task_struct *p) {}
 static inline void autonuma_free_page(struct page *page) {}
+static inline void autonuma_check_new_page(struct page *page) {}
 
 #endif /* CONFIG_AUTONUMA */
 
mm/page_alloc.c +1 -0
index 2d53a1f..5943ed2 100644
@@ -833,6 +833,7 @@ static inline int check_new_page(struct page *page)
 		bad_page(page);
 		return 1;
 	}
+	autonuma_check_new_page(page);
 	return 0;
 }
 

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#173 lore raw

Re: [PATCH 39/40] autonuma: bugcheck page_autonuma fields on newly allocated pages

include/linux/autonuma.h static inline void autonuma_free_page(struct page *page) · line 38

Quoted 9 lines · Andrea Arcangeli

Debug tweak.

include/linux/autonuma.h +7 -0
+static inline void autonuma_check_new_page(struct page *page)
+{
+	struct page_autonuma *page_autonuma;
+	if (!autonuma_impossible()) {
+		page_autonuma = lookup_page_autonuma(page);
+		BUG_ON(page_autonuma->autonuma_migrate_nid != -1);
+		BUG_ON(page_autonuma->autonuma_last_nid != -1);

At this point, BUG_ON is not likely to give us a useful backtrace at all.

mm/page_alloc.c static inline int check_new_page(struct page *page) · line 838

Quoted 11 lines
mm/page_alloc.c +1 -0
index 2d53a1f..5943ed2 100644
@@ -833,6 +833,7 @@ static inline int check_new_page(struct page *page)
  		bad_page(page);
  		return 1;
  	}
+	autonuma_check_new_page(page);
  	return 0;
  }

Why don't you hook into the return codes that
check_new_page uses?

They appear to be there for a reason.

Signature · 7 lines
All rights reversed

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#174 lore raw

PATCH 40/40 autonuma: shrink the per-page page_autonuma struct size

In reply to Andrea Arcangeli
Quoted 1 line

From 32 to 12 bytes, so the AutoNUMA memory footprint is reduced to

0.29% of RAM.

This however will fail to migrate pages above a 16 Terabyte offset from the start of each node (migration failure isn't fatal, simply those pages will not follow the CPU, a warning will be printed in the log just once in that case).

AutoNUMA will also fail to build if there are more than (2**15)-1 nodes supported by the MAX_NUMNODES at build time (it would be easy to relax it to (2**16)-1 nodes without increasing the memory footprint, but it's not even worth it, so let's keep the negative space reserved for now).

This means the max RAM configuration fully supported by AutoNUMA becomes AUTONUMA_LIST_MAX_PFN_OFFSET multiplied by 32767 nodes multiplied by the PAGE_SIZE (assume 4096 here, but for some archs it's bigger).

4096*32767*(0xffffffff-3)>>(10*5) = 511 PetaBytes.

---
 include/linux/autonuma_list.h  |   94 ++++++++++++++++++++++
 include/linux/autonuma_types.h |   45 ++++++-----
 include/linux/mmzone.h         |    3 +-
 include/linux/page_autonuma.h  |    2 +-
 mm/Makefile                    |    2 +-
 mm/autonuma.c                  |   86 +++++++++++++++------
 mm/autonuma_list.c             |  167 ++++++++++++++++++++++++++++++++++++++++
 mm/page_autonuma.c             |   15 ++--
 8 files changed, 362 insertions(+), 52 deletions(-)
 create mode 100644 include/linux/autonuma_list.h
 create mode 100644 mm/autonuma_list.c
include/linux/autonuma_list.h new file +94 -0
new file mode 100644
index 0000000..0f338e9
@@ -0,0 +1,94 @@
+#ifndef __AUTONUMA_LIST_H
+#define __AUTONUMA_LIST_H
+
+#include <linux/types.h>
+#include <linux/kernel.h>
+
+typedef uint32_t autonuma_list_entry;
+#define AUTONUMA_LIST_MAX_PFN_OFFSET	(AUTONUMA_LIST_HEAD-3)
+#define AUTONUMA_LIST_POISON1		(AUTONUMA_LIST_HEAD-2)
+#define AUTONUMA_LIST_POISON2		(AUTONUMA_LIST_HEAD-1)
+#define AUTONUMA_LIST_HEAD		((uint32_t)UINT_MAX)
+
+struct autonuma_list_head {
+	autonuma_list_entry anl_next_pfn;
+	autonuma_list_entry anl_prev_pfn;
+};
+
+static inline void AUTONUMA_INIT_LIST_HEAD(struct autonuma_list_head *anl)
+{
+	anl->anl_next_pfn = AUTONUMA_LIST_HEAD;
+	anl->anl_prev_pfn = AUTONUMA_LIST_HEAD;
+}
+
+/* abstraction conversion methods */
+extern struct page *autonuma_list_entry_to_page(int nid,
+					autonuma_list_entry pfn_offset);
+extern autonuma_list_entry autonuma_page_to_list_entry(int page_nid,
+						       struct page *page);
+extern struct autonuma_list_head *__autonuma_list_head(int page_nid,
+					struct autonuma_list_head *head,
+					autonuma_list_entry pfn_offset);
+
+extern bool __autonuma_list_add(int page_nid,
+				struct page *page,
+				struct autonuma_list_head *head,
+				autonuma_list_entry prev,
+				autonuma_list_entry next);
+
+/*
+ * autonuma_list_add - add a new entry
+ *
+ * Insert a new entry after the specified head.
+ */
+static inline bool autonuma_list_add(int page_nid,
+				     struct page *page,
+				     autonuma_list_entry entry,
+				     struct autonuma_list_head *head)
+{
+	struct autonuma_list_head *entry_head;
+	entry_head = __autonuma_list_head(page_nid, head, entry);
+	return __autonuma_list_add(page_nid, page, head,
+				   entry, entry_head->anl_next_pfn);
+}
+
+/*
+ * autonuma_list_add_tail - add a new entry
+ *
+ * Insert a new entry before the specified head.
+ * This is useful for implementing queues.
+ */
+static inline bool autonuma_list_add_tail(int page_nid,
+					  struct page *page,
+					  autonuma_list_entry entry,
+					  struct autonuma_list_head *head)
+{
+	struct autonuma_list_head *entry_head;
+	entry_head = __autonuma_list_head(page_nid, head, entry);
+	return __autonuma_list_add(page_nid, page, head,
+				   entry_head->anl_prev_pfn, entry);
+}
+
+/*
+ * autonuma_list_del - deletes entry from list.
+ * @entry: the element to delete from the list.
+ */
+extern void autonuma_list_del(int page_nid,
+			      struct autonuma_list_head *entry,
+			      struct autonuma_list_head *head);
+
+extern bool autonuma_list_empty(const struct autonuma_list_head *head);
+
+#if 0 /* not needed so far */
+/*
+ * autonuma_list_is_singular - tests whether a list has just one entry.
+ * @head: the list to test.
+ */
+static inline int autonuma_list_is_singular(const struct autonuma_list_head *head)
+{
+	return !autonuma_list_empty(head) &&
+		(head->anl_next_pfn == head->anl_prev_pfn);
+}
+#endif
+
+#endif /* __AUTONUMA_LIST_H */
include/linux/autonuma_types.h +26 -19

80 lines not on this page · raw message

include/linux/mmzone.h +2 -1
index ed5b0c0..acefdfa 100644
@@ -17,6 +17,7 @@
 #include <linux/pageblock-flags.h>
 #include <generated/bounds.h>
 #include <linux/atomic.h>
+#include <linux/autonuma_list.h>
 #include <asm/page.h>
 
 /* Free memory management - zoned buddy allocator.  */
@@ -710,7 +711,7 @@ typedef struct pglist_data {
 	 * <linux/page_autonuma.h> and the below field must remain the
 	 * last one of this structure.
 	 */
-	struct list_head autonuma_migrate_head[0];
+	struct autonuma_list_head autonuma_migrate_head[0];
 #endif
 } pg_data_t;
 
include/linux/page_autonuma.h +1 -1
index bc7a629..e78beda 100644
@@ -53,7 +53,7 @@ extern void __init sparse_early_page_autonuma_alloc_node(struct page_autonuma **
 /* inline won't work here */
 #define autonuma_pglist_data_size() (sizeof(struct pglist_data) +	\
 				     (autonuma_impossible() ? 0 :	\
-				      sizeof(struct list_head) * \
+				      sizeof(struct autonuma_list_head) * \
 				      num_possible_nodes()))
 
 #endif /* _LINUX_PAGE_AUTONUMA_H */
mm/Makefile +1 -1
index a4d8354..4aa90d4 100644
@@ -33,7 +33,7 @@ obj-$(CONFIG_FRONTSWAP)	+= frontswap.o
 obj-$(CONFIG_HAS_DMA)	+= dmapool.o
 obj-$(CONFIG_HUGETLBFS)	+= hugetlb.o
 obj-$(CONFIG_NUMA) 	+= mempolicy.o
-obj-$(CONFIG_AUTONUMA) 	+= autonuma.o page_autonuma.o
+obj-$(CONFIG_AUTONUMA) 	+= autonuma.o page_autonuma.o autonuma_list.o
 obj-$(CONFIG_SPARSEMEM)	+= sparse.o
 obj-$(CONFIG_SPARSEMEM_VMEMMAP) += sparse-vmemmap.o
 obj-$(CONFIG_SLOB) += slob.o
mm/autonuma.c +63 -23

156 lines not on this page · raw message

mm/autonuma_list.c new file +167 -0

167 lines not on this page · raw message

mm/page_autonuma.c +8 -7
index d7c5e4a..b629074 100644
@@ -12,7 +12,6 @@ void __meminit page_autonuma_map_init(struct page *page,
 	for (end = page + nr_pages; page < end; page++, page_autonuma++) {
 		page_autonuma->autonuma_last_nid = -1;
 		page_autonuma->autonuma_migrate_nid = -1;
-		page_autonuma->page = page;
 	}
 }
 
@@ -20,12 +19,18 @@ static void __meminit __pgdat_autonuma_init(struct pglist_data *pgdat)
 {
 	int node_iter;
 
+	/* verify the per-page page_autonuma 12 byte fixed cost */
+	BUILD_BUG_ON((unsigned long) &((struct page_autonuma *)0)[1] != 12);
+
 	spin_lock_init(&pgdat->autonuma_lock);
 	init_waitqueue_head(&pgdat->autonuma_knuma_migrated_wait);
 	pgdat->autonuma_nr_migrate_pages = 0;
 	if (!autonuma_impossible())
-		for_each_node(node_iter)
-			INIT_LIST_HEAD(&pgdat->autonuma_migrate_head[node_iter]);
+		for_each_node(node_iter) {
+			struct autonuma_list_head *head;
+			head = &pgdat->autonuma_migrate_head[node_iter];
+			AUTONUMA_INIT_LIST_HEAD(head);
+		}
 }
 
 #if !defined(CONFIG_SPARSEMEM)
@@ -112,10 +117,6 @@ struct page_autonuma *lookup_page_autonuma(struct page *page)
 	unsigned long pfn = page_to_pfn(page);
 	struct mem_section *section = __pfn_to_section(pfn);
 
-	/* if it's not a power of two we may be wasting memory */
-	BUILD_BUG_ON(SECTION_PAGE_AUTONUMA_SIZE &
-		     (SECTION_PAGE_AUTONUMA_SIZE-1));
-
 #ifdef CONFIG_DEBUG_VM
 	/*
 	 * The sanity checks the page allocator does upon freeing a

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#175 lore raw

Re: [PATCH 40/40] autonuma: shrink the per-page page_autonuma struct size

Quoted 2 lines · Andrea Arcangeli

From 32 to 12 bytes, so the AutoNUMA memory footprint is reduced to
0.29% of RAM.

Still not ideal, however once we get native THP migration working it could be practical to switch to a "have a bucket with N page_autonuma structures for every N*M pages" approach.

For example, we could have 4 struct page_autonuma pages, for 32 memory pages. That would necessitate reintroducing the page pointer into struct page_autonuma, but it would reduce memory use by roughly a factor 8.

To get from a struct page to a struct page_autonuma, we would have to look at the bucket and check whether one of the page_autonuma structs points at us. If none do, we have to claim an available one. On migration, we would have to free our page_autonuma struct, which would make it available for other pages to use.

This would complicate the code somewhat, and potentially slow down the migration of 4kB pages, but with 2MB pages things could continue exactly the way they work today.

Does this seem reasonably in any way?

Quoted 8 lines

+++ b/include/linux/autonuma_list.h

include/linux/autonuma_list.h new file +5 -0
@@ -0,0 +1,94 @@
+#ifndef __AUTONUMA_LIST_H
+#define __AUTONUMA_LIST_H
+
+#include<linux/types.h>
+#include<linux/kernel.h>
 

include/linux/autonuma_list.h line 16

Quoted 10 lines
include/linux/autonuma_list.h new file +10 -0
+typedef uint32_t autonuma_list_entry;
+#define AUTONUMA_LIST_MAX_PFN_OFFSET	(AUTONUMA_LIST_HEAD-3)
+#define AUTONUMA_LIST_POISON1		(AUTONUMA_LIST_HEAD-2)
+#define AUTONUMA_LIST_POISON2		(AUTONUMA_LIST_HEAD-1)
+#define AUTONUMA_LIST_HEAD		((uint32_t)UINT_MAX)
+
+struct autonuma_list_head {
+	autonuma_list_entry anl_next_pfn;
+	autonuma_list_entry anl_prev_pfn;
+};

This stuff needs to be documented with a large comment, explaining what is done, what the limitations are, etc...

Having that documentation in the commit message is not going to help somebody who is browsing the source code.

I also wonder if it would make sense to have this available as a generic list type, not autonuma specific but an "item number list" include file with corresponding macros.

It might be useful to have lists with item numbers, instead of prev & next pointers, in other places in the kernel.

Besides, introducing this list type separately could make things easier to review.

Signature · 7 lines
All rights reversed

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#176 lore raw

Re: [PATCH 40/40] autonuma: shrink the per-page page_autonuma struct size

Quoted 19 lines · Rik van Riel
Quoted 2 lines · Andrea Arcangeli

From 32 to 12 bytes, so the AutoNUMA memory footprint is reduced to
0.29% of RAM.

Still not ideal, however once we get native THP migration working it could be practical to switch to a "have a bucket with N page_autonuma structures for every N*M pages" approach.

For example, we could have 4 struct page_autonuma pages, for 32 memory pages. That would necessitate reintroducing the page pointer into struct page_autonuma, but it would reduce memory use by roughly a factor 8.

To get from a struct page to a struct page_autonuma, we would have to look at the bucket and check whether one of the page_autonuma structs points at us. If none do, we have to claim an available one. On migration, we would have to free our page_autonuma struct, which would make it available for other pages to use.

Quoted 5 lines

This would complicate the code somewhat, and potentially slow down the migration of 4kB pages, but with 2MB pages things could continue exactly the way they work today.

Does this seem reasonably in any way?

Reducing the max lru size loses info too. The thing I dislike is that knuma_migrated may not migrate the page until a few knuma_scand passed on large systems (giving a chance to last_nid_set to notice if there's false sharing and cancel the migration). I conceptually like the unlimited sized LRU migration list.

The other cons is that it'll increase the complexity even more by having to deal with dynamic objects instead of an extension of the struct page.

And the 2bytes for the last_nid information would need to be retained for every page, unless we drop the last_nid logic which I doubt would be good.

And the alternative without an hash is not feasible: one could reduce it to 8bytes per-page (for the pointer to the page_autonuma structure) plus 2 bytes for last_nid, so 10 bytes per page plus the actual array, instead of the current 12 bytes per page.

Quoted 9 lines

I also wonder if it would make sense to have this available as a generic list type, not autonuma specific but an "item number list" include file with corresponding macros.

It might be useful to have lists with item numbers, instead of prev & next pointers, in other places in the kernel.

Besides, introducing this list type separately could make things easier to review.

Macros bypassing type checking usually aren't recommended and certainly it's more readable as it is now. But this can always be done later if needed.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#177 lore raw
In reply to Andrea Arcangeli
Quoted 1 line · Andrea Arcangeli

o reduced the page_autonuma memory overhead to from 32 to 12 bytes per page

This bit still worries me a little.

Between the compact list management code, the migrate daemon, the list locking and page queuing and unqueuing code, we are looking at 1000-2000 lines of code.

I know your reasoning why asynchronous migration done by a kernel thread should be better than migrate-on-fault, but there is no actual evidence that it is in fact true.

Would it be an idea to simplify the code for now, and add the asynchronous migration later on, if there are compelling benchmark results that show it to be useful?

The amount of source code involved is large enough that a justification like that would be useful, IMHO...

Signature · 7 lines
All rights reversed

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>