Skip to contentSkip to conversation

numa/core patches

PATCH NAK Peter Zijlstra 18 participants 135 messages Oct 25, 2012 – Dec 21, 2012 Page 2 of 2

Subsystems (19)
lore
Share & tools
lore
reviewer
#88 lore raw

Re: [PATCH 24/31] sched, numa, mm: Introduce last_nid in the pageframe

In reply to Peter Zijlstra
Quoted 3 lines · Peter Zijlstra

Introduce a per-page last_nid field, fold this into the struct page::flags field whenever possible.

This is used later in the series.

Quoted 2 lines

The unlikely/rare 32bit NUMA configs will likely grow the page-frame.

If someone files a bug report that lowmem pressure is higher on their 32-bit NUMA machine I would be a bit surprised. Maybe abusers of NUMA care but screw it.

Quoted 34 lines

Completely dropping 32bit support for CONFIG_SCHED_NUMA would simplify things, but it would also remove the warning if we grow enough 64bit only page-flags to push the last-nid out.

Cc Linus Torvalds <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Rik van Riel <[email protected]>
Cc Andrea Arcangeli <[email protected]>
---
 include/linux/mm.h                |   90 ++++++++++++++++++++------------------
 include/linux/mm_types.h          |    5 ++
 include/linux/mmzone.h            |   14 -----
 include/linux/page-flags-layout.h |   83 +++++++++++++++++++++++++++++++++++
 mm/huge_memory.c                  |    1 
 mm/memory.c                       |    4 +
 6 files changed, 143 insertions(+), 54 deletions(-)
 create mode 100644 include/linux/page-flags-layout.h

Index: tip/include/linux/mm.h
===================================================================

include/linux/mm.h +0 -5
@@ -594,50 +594,11 @@ static inline pte_t maybe_mkwrite(pte_t
  * sets it, so none of the operations on it need to be atomic.
  */
 
-
-/*
- * page->flags layout:
- *
- * There are three possibilities for how page->flags get

include/linux/mm.h static inline pte_t maybe_mkwrite(pte_t · line 611

Quoted 10 lines
include/linux/mm.h +0 -10
- * laid out.  The first is for the normal case, without
- * sparsemem.  The second is for sparsemem when there is
- * plenty of space for node and section.  The last is when
- * we have run out of space and have to fall back to an
- * alternate (slower) way of determining the node.
- *
- * No sparsemem or sparsemem vmemmap: |       NODE     | ZONE | ... | FLAGS |
- * classic sparse with space for node:| SECTION | NODE | ZONE | ... | FLAGS |
- * classic sparse no space for node:  | SECTION |     ZONE    | ... | FLAGS |
- */

The move to page-flags-layout.h should have been a separate patch! Figuring out what you actually added to the layout is going to be a complete headache (headache was not the first word I was going to use).

In other words I did not try very hard and I'll just be scanning for something obvious.

Quoted 35 lines
include/linux/mm.h +2 -26
-#if defined(CONFIG_SPARSEMEM) && !defined(CONFIG_SPARSEMEM_VMEMMAP)
-#define SECTIONS_WIDTH		SECTIONS_SHIFT
-#else
-#define SECTIONS_WIDTH		0
-#endif
-
-#define ZONES_WIDTH		ZONES_SHIFT
-
-#if SECTIONS_WIDTH+ZONES_WIDTH+NODES_SHIFT <= BITS_PER_LONG - NR_PAGEFLAGS
-#define NODES_WIDTH		NODES_SHIFT
-#else
-#ifdef CONFIG_SPARSEMEM_VMEMMAP
-#error "Vmemmap: No space for nodes field in page flags"
-#endif
-#define NODES_WIDTH		0
-#endif
-
-/* Page flags: | [SECTION] | [NODE] | ZONE | ... | FLAGS | */
+/* Page flags: | [SECTION] | [NODE] | ZONE | [LAST_NID] | ... | FLAGS | */
 #define SECTIONS_PGOFF		((sizeof(unsigned long)*8) - SECTIONS_WIDTH)
 #define NODES_PGOFF		(SECTIONS_PGOFF - NODES_WIDTH)
 #define ZONES_PGOFF		(NODES_PGOFF - ZONES_WIDTH)
-
-/*
- * We are going to use the flags for the page to node mapping if its in
- * there.  This includes the case where there is no node, so it is implicit.
- */
-#if !(NODES_WIDTH > 0 || NODES_SHIFT == 0)
-#define NODE_NOT_IN_PAGE_FLAGS
-#endif
+#define LAST_NID_PGOFF		(ZONES_PGOFF - LAST_NID_WIDTH)
 
 /*
  * Define the bit shifts to access each section.  For non-existent

include/linux/mm.h static inline pte_t maybe_mkwrite(pte_t · line 612

Quoted 5 lines
include/linux/mm.h +1 -0
@@ -647,6 +608,7 @@ static inline pte_t maybe_mkwrite(pte_t
 #define SECTIONS_PGSHIFT	(SECTIONS_PGOFF * (SECTIONS_WIDTH != 0))
 #define NODES_PGSHIFT		(NODES_PGOFF * (NODES_WIDTH != 0))
 #define ZONES_PGSHIFT		(ZONES_PGOFF * (ZONES_WIDTH != 0))
+#define LAST_NID_PGSHIFT	(LAST_NID_PGOFF * (LAST_NID_WIDTH != 0))
 

Why is LAST_NID_PGSHIFT != NODES_PGSHIFT?

Oh, it more or less is but it's hidden. Screw that, get rid of LAST_NIFT_SHIFT WIDTH and express this entirely in terms of NODES_PFSHIFT and friends.

Quoted 29 lines
include/linux/mm.h +16 -0
 /* NODE:ZONE or SECTION:ZONE is used to ID a zone for the buddy allocator */
 #ifdef NODE_NOT_IN_PAGE_FLAGS
@@ -668,6 +630,7 @@ static inline pte_t maybe_mkwrite(pte_t
 #define ZONES_MASK		((1UL << ZONES_WIDTH) - 1)
 #define NODES_MASK		((1UL << NODES_WIDTH) - 1)
 #define SECTIONS_MASK		((1UL << SECTIONS_WIDTH) - 1)
+#define LAST_NID_MASK		((1UL << LAST_NID_WIDTH) - 1)
 #define ZONEID_MASK		((1UL << ZONEID_SHIFT) - 1)
 
 static inline enum zone_type page_zonenum(const struct page *page)
@@ -706,6 +669,51 @@ static inline int page_to_nid(const stru
 }
 #endif
 
+#ifdef CONFIG_SCHED_NUMA
+#ifdef LAST_NID_NOT_IN_PAGE_FLAGS
+static inline int page_xchg_last_nid(struct page *page, int nid)
+{
+	return xchg(&page->_last_nid, nid);
+}
+
+static inline int page_last_nid(struct page *page)
+{
+	return page->_last_nid;
+}
+#else
+static inline int page_xchg_last_nid(struct page *page, int nid)
+{
+	unsigned long old_flags, flags;

include/linux/mm.h static inline int page_to_nid(const stru · line 696

Quoted 10 lines
include/linux/mm.h +10 -0
+	int last_nid;
+
+	do {
+		old_flags = flags = page->flags;
+		last_nid = (flags >> LAST_NID_PGSHIFT) & LAST_NID_MASK;
+
+		flags &= ~(LAST_NID_MASK << LAST_NID_PGSHIFT);
+		flags |= (nid & LAST_NID_MASK) << LAST_NID_PGSHIFT;
+	} while (unlikely(cmpxchg(&page->flags, old_flags, flags) != old_flags));
+

This opens a very small window where this function messed up the flags and fixes them up very shortly afterwards. For most page flags it will not matter but potentially causes weirdness with the extended page flags or are we protected by something else?

Quoted 202 lines
include/linux/mm.h +20 -0
+	return last_nid;
+}
+
+static inline int page_last_nid(struct page *page)
+{
+	return (page->flags >> LAST_NID_PGSHIFT) & LAST_NID_MASK;
+}
+#endif /* LAST_NID_NOT_IN_PAGE_FLAGS */
+#else /* CONFIG_SCHED_NUMA */
+static inline int page_xchg_last_nid(struct page *page, int nid)
+{
+	return page_to_nid(page);
+}
+
+static inline int page_last_nid(struct page *page)
+{
+	return page_to_nid(page);
+}
+#endif /* CONFIG_SCHED_NUMA */
+
 static inline struct zone *page_zone(const struct page *page)
 {
 	return &NODE_DATA(page_to_nid(page))->node_zones[page_zonenum(page)];

Index: tip/include/linux/mm_types.h
===================================================================

include/linux/mm_types.h +5 -0
@@ -12,6 +12,7 @@
 #include <linux/cpumask.h>
 #include <linux/page-debug-flags.h>
 #include <linux/uprobes.h>
+#include <linux/page-flags-layout.h>
 #include <asm/page.h>
 #include <asm/mmu.h>
 
@@ -175,6 +176,10 @@ struct page {
 	 */
 	void *shadow;
 #endif
+
+#ifdef LAST_NID_NOT_IN_PAGE_FLAGS
+	int _last_nid;
+#endif
 }
 /*
  * The struct page can be forced to be double word aligned so that atomic ops

Index: tip/include/linux/mmzone.h
===================================================================

include/linux/mmzone.h +1 -13
@@ -15,7 +15,7 @@
 #include <linux/seqlock.h>
 #include <linux/nodemask.h>
 #include <linux/pageblock-flags.h>
-#include <generated/bounds.h>
+#include <linux/page-flags-layout.h>
 #include <linux/atomic.h>
 #include <asm/page.h>
 
@@ -317,16 +317,6 @@ enum zone_type {
  * match the requested limits. See gfp_zone() in include/linux/gfp.h
  */
 
-#if MAX_NR_ZONES < 2
-#define ZONES_SHIFT 0
-#elif MAX_NR_ZONES <= 2
-#define ZONES_SHIFT 1
-#elif MAX_NR_ZONES <= 4
-#define ZONES_SHIFT 2
-#else
-#error ZONES_SHIFT -- too many zones configured adjust calculation
-#endif
-
 struct zone {
 	/* Fields commonly accessed by the page allocator */
 
@@ -1029,8 +1019,6 @@ static inline unsigned long early_pfn_to
  * PA_SECTION_SHIFT		physical address to/from section number
  * PFN_SECTION_SHIFT		pfn to/from section number
  */
-#define SECTIONS_SHIFT		(MAX_PHYSMEM_BITS - SECTION_SIZE_BITS)
-
 #define PA_SECTION_SHIFT	(SECTION_SIZE_BITS)
 #define PFN_SECTION_SHIFT	(SECTION_SIZE_BITS - PAGE_SHIFT)
 

Index: tip/include/linux/page-flags-layout.h
===================================================================

include/linux/page-flags-layout.h new file +83 -0
@@ -0,0 +1,83 @@
+#ifndef _LINUX_PAGE_FLAGS_LAYOUT
+#define _LINUX_PAGE_FLAGS_LAYOUT
+
+#include <linux/numa.h>
+#include <generated/bounds.h>
+
+#if MAX_NR_ZONES < 2
+#define ZONES_SHIFT 0
+#elif MAX_NR_ZONES <= 2
+#define ZONES_SHIFT 1
+#elif MAX_NR_ZONES <= 4
+#define ZONES_SHIFT 2
+#else
+#error ZONES_SHIFT -- too many zones configured adjust calculation
+#endif
+
+#ifdef CONFIG_SPARSEMEM
+#include <asm/sparsemem.h>
+
+/* 
+ * SECTION_SHIFT    		#bits space required to store a section #
+ */
+#define SECTIONS_SHIFT         (MAX_PHYSMEM_BITS - SECTION_SIZE_BITS)
+#endif
+
+/*
+ * page->flags layout:
+ *
+ * There are five possibilities for how page->flags get laid out.  The first
+ * (and second) is for the normal case, without sparsemem. The third is for
+ * sparsemem when there is plenty of space for node and section. The last is
+ * when we have run out of space and have to fall back to an alternate (slower)
+ * way of determining the node.
+ *
+ * No sparsemem or sparsemem vmemmap: |       NODE     | ZONE |            ... | FLAGS |
+ *     "      plus space for last_nid:|       NODE     | ZONE | LAST_NID | ... | FLAGS |
+ * classic sparse with space for node:| SECTION | NODE | ZONE |            ... | FLAGS |
+ *     "      plus space for last_nid:| SECTION | NODE | ZONE | LAST_NID | ... | FLAGS |
+ * classic sparse no space for node:  | SECTION |     ZONE    |            ... | FLAGS |
+ */
+#if defined(CONFIG_SPARSEMEM) && !defined(CONFIG_SPARSEMEM_VMEMMAP)
+
+#define SECTIONS_WIDTH		SECTIONS_SHIFT
+#else
+#define SECTIONS_WIDTH		0
+#endif
+
+#define ZONES_WIDTH		ZONES_SHIFT
+
+#if SECTIONS_WIDTH+ZONES_WIDTH+NODES_SHIFT <= BITS_PER_LONG - NR_PAGEFLAGS
+#define NODES_WIDTH		NODES_SHIFT
+#else
+#ifdef CONFIG_SPARSEMEM_VMEMMAP
+#error "Vmemmap: No space for nodes field in page flags"
+#endif
+#define NODES_WIDTH		0
+#endif
+
+#ifdef CONFIG_SCHED_NUMA
+#define LAST_NID_SHIFT	NODES_SHIFT
+#else
+#define LAST_NID_SHIFT	0
+#endif
+
+#if SECTIONS_WIDTH+ZONES_WIDTH+NODES_SHIFT+LAST_NID_SHIFT <= BITS_PER_LONG - NR_PAGEFLAGS
+#define LAST_NID_WIDTH	LAST_NID_SHIFT
+#else
+#define LAST_NID_WIDTH	0
+#endif
+
+/*
+ * We are going to use the flags for the page to node mapping if its in
+ * there.  This includes the case where there is no node, so it is implicit.
+ */
+#if !(NODES_WIDTH > 0 || NODES_SHIFT == 0)
+#define NODE_NOT_IN_PAGE_FLAGS
+#endif
+
+#if defined(CONFIG_SCHED_NUMA) && LAST_NID_WIDTH == 0
+#define LAST_NID_NOT_IN_PAGE_FLAGS
+#endif
+
+#endif /* _LINUX_PAGE_FLAGS_LAYOUT */

Index: tip/mm/huge_memory.c
===================================================================

mm/huge_memory.c +1 -0
@@ -1440,6 +1440,7 @@ static void __split_huge_page_refcount(s
 		page_tail->mapping = page->mapping;
 
 		page_tail->index = page->index + i;
+		page_xchg_last_nid(page, page_last_nid(page_tail));
 
 		BUG_ON(!PageAnon(page_tail));
 		BUG_ON(!PageUptodate(page_tail));

Index: tip/mm/memory.c
===================================================================

mm/memory.c +4 -0
@@ -68,6 +68,10 @@
 
 #include "internal.h"
 
+#ifdef LAST_NID_NOT_IN_PAGE_FLAGS
+#warning Unfortunate NUMA config, growing page-frame for last_nid.
+#endif
+
 #ifndef CONFIG_NEED_MULTIPLE_NODES
 /* use the per-pgdat data instead for discontigmem - mbligh */
 unsigned long max_mapnr;
Signature · 8 lines
Mel Gorman
SUSE Labs

--
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>
reviewer
#98 lore raw

Re: [PATCH 26/31] sched, numa, mm: Add fault driven placement and migration policy

In reply to Peter Zijlstra
Quoted 15 lines · Peter Zijlstra

As per the problem/design document Documentation/scheduler/numa-problem.txt implement 3ac & 4.

( A pure 3a was found too unstable, I did briefly try 3bc
but found no significant improvement. )

Implement a per-task memory placement scheme relying on a regular PROT_NONE 'migration' fault to scan the memory space of the procress and uses a two stage migration scheme to reduce the invluence of unlikely usage relations.

It relies on the assumption that the compute part is tied to a paticular task and builds a task<->page relation set to model the compute<->data relation.

Quoted 8 lines

In the previous patch we made memory migrate towards where the task is running, here we select the node on which most memory is located as the preferred node to run on.

This creates a feed-back control loop between trying to schedule a task on a node and migrating memory towards the node the task is scheduled on.

Ok.

Quoted 23 lines
---
 include/linux/mm_types.h |    4 +
 include/linux/sched.h    |   35 +++++++--
 kernel/sched/core.c      |   16 ++++
 kernel/sched/fair.c      |  175 +++++++++++++++++++++++++++++++++++++++++++++++
 kernel/sched/features.h  |    1 
 kernel/sched/sched.h     |   31 +++++---
 kernel/sysctl.c          |   31 +++++++-
 mm/huge_memory.c         |    7 +
 mm/memory.c              |    4 -
 9 files changed, 282 insertions(+), 22 deletions(-)

Index: tip/include/linux/mm_types.h
===================================================================

include/linux/mm_types.h struct mm_struct { · line 407

Quoted 5 lines
include/linux/mm_types.h +2 -0
@@ -403,6 +403,10 @@ struct mm_struct {
 #ifdef CONFIG_CPUMASK_OFFSTACK
 	struct cpumask cpumask_allocation;
 #endif
+#ifdef CONFIG_SCHED_NUMA
+	unsigned long numa_next_scan;

comment.

include/linux/mm_types.h struct mm_struct { · line 408

Quoted 1 line
include/linux/mm_types.h +1 -0
+	int numa_scan_seq;

comment! at least the other one is easy to guess. This thing looks like it's preventing multiple threads in a process space scanning and updating PTEs at the same time. Effectively it's a type of barrier but without a comment I'm not sure if what it's doing is what you expect it to be doing or something else entirely.

Quoted 183 lines
include/linux/mm_types.h +1 -0
+#endif
 	struct uprobes_state uprobes_state;
 };
 

Index: tip/include/linux/sched.h
===================================================================

include/linux/sched.h +27 -8
@@ -1481,9 +1481,16 @@ struct task_struct {
 	short pref_node_fork;
 #endif
 #ifdef CONFIG_SCHED_NUMA
-	int node;
+	int node;			/* task home node   */
+	int numa_scan_seq;
+	int numa_migrate_seq;
+	unsigned int numa_scan_period;
+	u64 node_stamp;			/* migration stamp  */
 	unsigned long numa_contrib;
-#endif
+	unsigned long *numa_faults;
+	struct callback_head numa_work;
+#endif /* CONFIG_SCHED_NUMA */
+
 	struct rcu_head rcu;
 
 	/*
@@ -1558,15 +1565,24 @@ struct task_struct {
 /* Future-safe accessor for struct task_struct's cpus_allowed. */
 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
 
+#ifdef CONFIG_SCHED_NUMA
 static inline int tsk_home_node(struct task_struct *p)
 {
-#ifdef CONFIG_SCHED_NUMA
 	return p->node;
+}
+
+extern void task_numa_fault(int node, int pages);
 #else
+static inline int tsk_home_node(struct task_struct *p)
+{
 	return -1;
-#endif
 }
 
+static inline void task_numa_fault(int node, int pages)
+{
+}
+#endif /* CONFIG_SCHED_NUMA */
+
 /*
  * Priority of a process goes from 0..MAX_PRIO-1, valid RT
  * priority is 0..MAX_RT_PRIO-1, and SCHED_NORMAL/SCHED_BATCH
@@ -2004,6 +2020,10 @@ enum sched_tunable_scaling {
 };
 extern enum sched_tunable_scaling sysctl_sched_tunable_scaling;
 
+extern unsigned int sysctl_sched_numa_scan_period_min;
+extern unsigned int sysctl_sched_numa_scan_period_max;
+extern unsigned int sysctl_sched_numa_settle_count;
+
 #ifdef CONFIG_SCHED_DEBUG
 extern unsigned int sysctl_sched_migration_cost;
 extern unsigned int sysctl_sched_nr_migrate;
@@ -2014,18 +2034,17 @@ extern unsigned int sysctl_sched_shares_
 int sched_proc_update_handler(struct ctl_table *table, int write,
 		void __user *buffer, size_t *length,
 		loff_t *ppos);
-#endif
-#ifdef CONFIG_SCHED_DEBUG
+
 static inline unsigned int get_sysctl_timer_migration(void)
 {
 	return sysctl_timer_migration;
 }
-#else
+#else /* CONFIG_SCHED_DEBUG */
 static inline unsigned int get_sysctl_timer_migration(void)
 {
 	return 1;
 }
-#endif
+#endif /* CONFIG_SCHED_DEBUG */
 extern unsigned int sysctl_sched_rt_period;
 extern int sysctl_sched_rt_runtime;
 

Index: tip/kernel/sched/core.c
===================================================================

kernel/sched/core.c +16 -0
@@ -1533,6 +1533,21 @@ static void __sched_fork(struct task_str
 #ifdef CONFIG_PREEMPT_NOTIFIERS
 	INIT_HLIST_HEAD(&p->preempt_notifiers);
 #endif
+
+#ifdef CONFIG_SCHED_NUMA
+	if (p->mm && atomic_read(&p->mm->mm_users) == 1) {
+		p->mm->numa_next_scan = jiffies;
+		p->mm->numa_scan_seq = 0;
+	}
+
+	p->node = -1;
+	p->node_stamp = 0ULL;
+	p->numa_scan_seq = p->mm ? p->mm->numa_scan_seq : 0;
+	p->numa_migrate_seq = p->mm ? p->mm->numa_scan_seq - 1 : 0;
+	p->numa_faults = NULL;
+	p->numa_scan_period = sysctl_sched_numa_scan_period_min;
+	p->numa_work.next = &p->numa_work;
+#endif /* CONFIG_SCHED_NUMA */
 }
 
 /*
@@ -1774,6 +1789,7 @@ static void finish_task_switch(struct rq
 	if (mm)
 		mmdrop(mm);
 	if (unlikely(prev_state == TASK_DEAD)) {
+		task_numa_free(prev);
 		/*
 		 * Remove function-return probe instances associated with this
 		 * task and put them back on the free list.

Index: tip/kernel/sched/fair.c
===================================================================

kernel/sched/fair.c +40 -0
@@ -27,6 +27,8 @@
 #include <linux/profile.h>
 #include <linux/interrupt.h>
 #include <linux/random.h>
+#include <linux/mempolicy.h>
+#include <linux/task_work.h>
 
 #include <trace/events/sched.h>
 
@@ -775,6 +777,21 @@ update_stats_curr_start(struct cfs_rq *c
 
 /**************************************************
  * Scheduling class numa methods.
+ *
+ * The purpose of the NUMA bits are to maintain compute (task) and data
+ * (memory) locality. We try and achieve this by making tasks stick to
+ * a particular node (their home node) but if fairness mandates they run
+ * elsewhere for long enough, we let the memory follow them.
+ *
+ * Tasks start out with their home-node unset (-1) this effectively means
+ * they act !NUMA until we've established the task is busy enough to bother
+ * with placement.
+ *
+ * We keep a home-node per task and use periodic fault scans to try and
+ * estalish a task<->page relation. This assumes the task<->page relation is a
+ * compute<->data relation, this is false for things like virt. and n:m
+ * threading solutions but its the best we can do given the information we
+ * have.
  */
 
 #ifdef CONFIG_SMP
@@ -805,6 +822,157 @@ static void account_numa_dequeue(struct
 	} else
 		rq->onnode_running--;
 }
+
+/*
+ * numa task sample period in ms: 5s
+ */
+unsigned int sysctl_sched_numa_scan_period_min = 5000;
+unsigned int sysctl_sched_numa_scan_period_max = 5000*16;
+
+/*
+ * Wait for the 2-sample stuff to settle before migrating again
+ */
+unsigned int sysctl_sched_numa_settle_count = 2;
+
+static void task_numa_placement(struct task_struct *p)
+{
+	unsigned long faults, max_faults = 0;
+	int node, max_node = -1;
+	int seq = ACCESS_ONCE(p->mm->numa_scan_seq);
+
+	if (p->numa_scan_seq == seq)
+		return;
+
+	p->numa_scan_seq = seq;
+

kernel/sched/fair.c static void account_numa_dequeue(struct · line 857

Quoted 10 lines
kernel/sched/fair.c +10 -0
+	for (node = 0; node < nr_node_ids; node++) {
+		faults = p->numa_faults[node];
+
+		if (faults > max_faults) {
+			max_faults = faults;
+			max_node = node;
+		}
+
+		p->numa_faults[node] /= 2;
+	}

No comments explaining the logic behind the decaying average. It can be inferred if someone reads Documentation/scheduler/numa-problem.txt and point 3c carefully enough. At the very least point them at it.

kernel/sched/fair.c static void account_numa_dequeue(struct · line 868

Quoted 11 lines
kernel/sched/fair.c +11 -0
+
+	if (max_node == -1)
+		return;
+
+	if (p->node != max_node) {
+		p->numa_scan_period = sysctl_sched_numa_scan_period_min;
+		if (sched_feat(NUMA_SETTLE) &&
+		    (seq - p->numa_migrate_seq) <= (int)sysctl_sched_numa_settle_count)
+			return;
+		p->numa_migrate_seq = seq;
+		sched_setnode(p, max_node);

Ok, so at a guess even if we do ping-pong it will only take effect every 10 seconds which could be far worse.

Quoted 11 lines
kernel/sched/fair.c +11 -0
+	} else {
+		p->numa_scan_period = min(sysctl_sched_numa_scan_period_max,
+				p->numa_scan_period * 2);
+	}
+}
+
+/*
+ * Got a PROT_NONE fault for a page on @node.
+ */
+void task_numa_fault(int node, int pages)
+{

kernel/sched/fair.c static void account_numa_dequeue(struct · line 889

Quoted 10 lines
kernel/sched/fair.c +10 -0
+	struct task_struct *p = current;
+
+	if (unlikely(!p->numa_faults)) {
+		int size = sizeof(unsigned long) * nr_node_ids;
+
+		p->numa_faults = kzalloc(size, GFP_KERNEL);
+		if (!p->numa_faults)
+			return;
+	}
+

On a maximally configured machine this will be an order-4 allocation and you need at least 512 nodes before it's an order-1 allocation. As unlikely as it is, should this be GFP_NOWARN?

Quoted 43 lines
kernel/sched/fair.c +43 -0
+	task_numa_placement(p);
+
+	p->numa_faults[node] += pages;
+}
+
+/*
+ * The expensive part of numa migration is done from task_work context.
+ * Triggered from task_tick_numa().
+ */
+void task_numa_work(struct callback_head *work)
+{
+	unsigned long migrate, next_scan, now = jiffies;
+	struct task_struct *p = current;
+	struct mm_struct *mm = p->mm;
+
+	WARN_ON_ONCE(p != container_of(work, struct task_struct, numa_work));
+
+	work->next = work; /* protect against double add */
+	/*
+	 * Who cares about NUMA placement when they're dying.
+	 *
+	 * NOTE: make sure not to dereference p->mm before this check,
+	 * exit_task_work() happens _after_ exit_mm() so we could be called
+	 * without p->mm even though we still had it when we enqueued this
+	 * work.
+	 */
+	if (p->flags & PF_EXITING)
+		return;
+
+	/*
+	 * Enforce maximal scan/migration frequency..
+	 */
+	migrate = mm->numa_next_scan;
+	if (time_before(now, migrate))
+		return;
+
+	next_scan = now + 2*msecs_to_jiffies(sysctl_sched_numa_scan_period_min);
+	if (cmpxchg(&mm->numa_next_scan, migrate, next_scan) != migrate)
+		return;
+
+	ACCESS_ONCE(mm->numa_scan_seq)++;
+	{
+		struct vm_area_struct *vma;

kernel/sched/fair.c static void account_numa_dequeue(struct · line 942

Quoted 10 lines
kernel/sched/fair.c +10 -0
+
+		down_write(&mm->mmap_sem);
+		for (vma = mm->mmap; vma; vma = vma->vm_next) {
+			if (!vma_migratable(vma))
+				continue;
+			change_protection(vma, vma->vm_start, vma->vm_end, vma_prot_none(vma), 0);
+		}
+		up_write(&mm->mmap_sem);
+	}
+}

Ok, I like the idea of the scanning cost being incurred by the process. I was going to complain though that for very large processes that the length time it takes to complete this scan could be considerable. However, a quick glance forward indicates that you cope with this problem later by limiting how much is scanned each time.

Quoted 11 lines
kernel/sched/fair.c +11 -0
+
+/*
+ * Drive the periodic memory faults..
+ */
+void task_tick_numa(struct rq *rq, struct task_struct *curr)
+{
+	struct callback_head *work = &curr->numa_work;
+	u64 period, now;
+
+	/*
+	 * We don't care about NUMA placement if we don't have memory.

kernel/sched/fair.c static void account_numa_dequeue(struct · line 963

Quoted 10 lines
kernel/sched/fair.c +10 -0
+	 */
+	if (!curr->mm || (curr->flags & PF_EXITING) || work->next != work)
+		return;
+
+	/*
+	 * Using runtime rather than walltime has the dual advantage that
+	 * we (mostly) drive the selection from busy threads and that the
+	 * task needs to have done some actual work before we bother with
+	 * NUMA placement.
+	 */

Makes sense.

Quoted 205 lines
kernel/sched/fair.c +19 -0
+	now = curr->se.sum_exec_runtime;
+	period = (u64)curr->numa_scan_period * NSEC_PER_MSEC;
+
+	if (now - curr->node_stamp > period) {
+		curr->node_stamp = now;
+
+		if (!time_before(jiffies, curr->mm->numa_next_scan)) {
+			init_task_work(work, task_numa_work); /* TODO: move this into sched_fork() */
+			task_work_add(curr, work, true);
+		}
+	}
+}
 #else
 #ifdef CONFIG_SMP
 static struct list_head *account_numa_enqueue(struct rq *rq, struct task_struct *p)
@@ -816,6 +984,10 @@ static struct list_head *account_numa_en
 static void account_numa_dequeue(struct rq *rq, struct task_struct *p)
 {
 }
+
+static void task_tick_numa(struct rq *rq, struct task_struct *curr)
+{
+}
 #endif /* CONFIG_SCHED_NUMA */
 
 /**************************************************
@@ -5265,6 +5437,9 @@ static void task_tick_fair(struct rq *rq
 		cfs_rq = cfs_rq_of(se);
 		entity_tick(cfs_rq, se, queued);
 	}
+
+	if (sched_feat_numa(NUMA))
+		task_tick_numa(rq, curr);
 }
 
 /*

Index: tip/kernel/sched/features.h
===================================================================

kernel/sched/features.h +1 -0
@@ -69,5 +69,6 @@ SCHED_FEAT(NUMA_TTWU_BIAS, false)
 SCHED_FEAT(NUMA_TTWU_TO,   false)
 SCHED_FEAT(NUMA_PULL,      true)
 SCHED_FEAT(NUMA_PULL_BIAS, true)
+SCHED_FEAT(NUMA_SETTLE,    true)
 #endif
 

Index: tip/kernel/sched/sched.h
===================================================================

kernel/sched/sched.h +22 -9
@@ -3,6 +3,7 @@
 #include <linux/mutex.h>
 #include <linux/spinlock.h>
 #include <linux/stop_machine.h>
+#include <linux/slab.h>
 
 #include "cpupri.h"
 
@@ -476,15 +477,6 @@ struct rq {
 #endif
 };
 
-static inline struct list_head *offnode_tasks(struct rq *rq)
-{
-#ifdef CONFIG_SCHED_NUMA
-	return &rq->offnode_tasks;
-#else
-	return NULL;
-#endif
-}
-
 static inline int cpu_of(struct rq *rq)
 {
 #ifdef CONFIG_SMP
@@ -502,6 +494,27 @@ DECLARE_PER_CPU(struct rq, runqueues);
 #define cpu_curr(cpu)		(cpu_rq(cpu)->curr)
 #define raw_rq()		(&__raw_get_cpu_var(runqueues))
 
+#ifdef CONFIG_SCHED_NUMA
+static inline struct list_head *offnode_tasks(struct rq *rq)
+{
+	return &rq->offnode_tasks;
+}
+
+static inline void task_numa_free(struct task_struct *p)
+{
+	kfree(p->numa_faults);
+}
+#else /* CONFIG_SCHED_NUMA */
+static inline struct list_head *offnode_tasks(struct rq *rq)
+{
+	return NULL;
+}
+
+static inline void task_numa_free(struct task_struct *p)
+{
+}
+#endif /* CONFIG_SCHED_NUMA */
+
 #ifdef CONFIG_SMP
 
 #define rcu_dereference_check_sched_domain(p) \

Index: tip/kernel/sysctl.c
===================================================================

kernel/sysctl.c +29 -2
@@ -256,9 +256,11 @@ static int min_sched_granularity_ns = 10
 static int max_sched_granularity_ns = NSEC_PER_SEC;	/* 1 second */
 static int min_wakeup_granularity_ns;			/* 0 usecs */
 static int max_wakeup_granularity_ns = NSEC_PER_SEC;	/* 1 second */
+#ifdef CONFIG_SMP
 static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
 static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
-#endif
+#endif /* CONFIG_SMP */
+#endif /* CONFIG_SCHED_DEBUG */
 
 #ifdef CONFIG_COMPACTION
 static int min_extfrag_threshold;
@@ -301,6 +303,7 @@ static struct ctl_table kern_table[] = {
 		.extra1		= &min_wakeup_granularity_ns,
 		.extra2		= &max_wakeup_granularity_ns,
 	},
+#ifdef CONFIG_SMP
 	{
 		.procname	= "sched_tunable_scaling",
 		.data		= &sysctl_sched_tunable_scaling,
@@ -347,7 +350,31 @@ static struct ctl_table kern_table[] = {
 		.extra1		= &zero,
 		.extra2		= &one,
 	},
-#endif
+#endif /* CONFIG_SMP */
+#ifdef CONFIG_SCHED_NUMA
+	{
+		.procname	= "sched_numa_scan_period_min_ms",
+		.data		= &sysctl_sched_numa_scan_period_min,
+		.maxlen		= sizeof(unsigned int),
+		.mode		= 0644,
+		.proc_handler	= proc_dointvec,
+	},
+	{
+		.procname	= "sched_numa_scan_period_max_ms",
+		.data		= &sysctl_sched_numa_scan_period_max,
+		.maxlen		= sizeof(unsigned int),
+		.mode		= 0644,
+		.proc_handler	= proc_dointvec,
+	},
+	{
+		.procname	= "sched_numa_settle_count",
+		.data		= &sysctl_sched_numa_settle_count,
+		.maxlen		= sizeof(unsigned int),
+		.mode		= 0644,
+		.proc_handler	= proc_dointvec,
+	},
+#endif /* CONFIG_SCHED_NUMA */
+#endif /* CONFIG_SCHED_DEBUG */
 	{
 		.procname	= "sched_rt_period_us",
 		.data		= &sysctl_sched_rt_period,

Index: tip/mm/huge_memory.c
===================================================================

mm/huge_memory.c +5 -2
@@ -774,9 +774,10 @@ fixup:
 
 unlock:
 	spin_unlock(&mm->page_table_lock);
-	if (page)
+	if (page) {
+		task_numa_fault(page_to_nid(page), HPAGE_PMD_NR);
 		put_page(page);
-
+	}
 	return;
 
 migrate:
@@ -845,6 +846,8 @@ migrate:
 
 	put_page(page);			/* Drop the rmap reference */
 
+	task_numa_fault(node, HPAGE_PMD_NR);
+
 	if (lru)
 		put_page(page);		/* drop the LRU isolation reference */
 

Index: tip/mm/memory.c
===================================================================

mm/memory.c +3 -1
@@ -3512,8 +3512,10 @@ out_pte_upgrade_unlock:
 out_unlock:
 	pte_unmap_unlock(ptep, ptl);
 out:
-	if (page)
+	if (page) {
+		task_numa_fault(page_nid, 1);
 		put_page(page);
+	}
 
 	return 0;
 
Signature · 8 lines
Mel Gorman
SUSE Labs

--
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>
reviewer
#101 lore raw

Re: [PATCH 28/31] sched, numa, mm: Implement constant, per task Working Set Sampling (WSS) rate

In reply to Peter Zijlstra
Quoted 132 lines · Peter Zijlstra

Previously, to probe the working set of a task, we'd use a very simple and crude method: mark all of its address space PROT_NONE.

That method has various (obvious) disadvantages:

- it samples the working set at dissimilar rates, giving some tasks a sampling quality advantage over others.

- creates performance problems for tasks with very large working sets

- over-samples processes with large address spaces but which only very rarely execute

Improve that method by keeping a rotating offset into the address space that marks the current position of the scan, and advance it by a constant rate (in a CPU cycles execution proportional manner). If the offset reaches the last mapped address of the mm then it then it starts over at the first address.

The per-task nature of the working set sampling functionality in this tree allows such constant rate, per task, execution-weight proportional sampling of the working set, with an adaptive sampling interval/frequency that goes from once per 100 msecs up to just once per 1.6 seconds. The current sampling volume is 256 MB per interval.

As tasks mature and converge their working set, so does the sampling rate slow down to just a trickle, 256 MB per 1.6 seconds of CPU time executed.

This, beyond being adaptive, also rate-limits rarely executing systems and does not over-sample on overloaded systems.

[ In AutoNUMA speak, this patch deals with the effective sampling
rate of the 'hinting page fault'. AutoNUMA's scanning is currently rate-limited, but it is also fundamentally single-threaded, executing in the knuma_scand kernel thread, so the limit in AutoNUMA is global and does not scale up with the number of CPUs, nor does it scan tasks in an execution proportional manner.

So the idea of rate-limiting the scanning was first implemented in the AutoNUMA tree via a global rate limit. This patch goes beyond that by implementing an execution rate proportional working set sampling rate that is not implemented via a single global scanning daemon. ]

[ Dan Carpenter pointed out a possible NULL pointer dereference in the
first version of this patch. ]

Cc Linus Torvalds <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Andrea Arcangeli <[email protected]>
Cc Rik van Riel <[email protected]>
[ Wrote changelog and fixed bug. ]
---
 include/linux/mm_types.h |    1 +
 include/linux/sched.h    |    1 +
 kernel/sched/fair.c      |   43 ++++++++++++++++++++++++++++++-------------
 kernel/sysctl.c          |    7 +++++++
 4 files changed, 39 insertions(+), 13 deletions(-)

Index: tip/include/linux/mm_types.h
===================================================================

include/linux/mm_types.h +1 -0
@@ -405,6 +405,7 @@ struct mm_struct {
 #endif
 #ifdef CONFIG_SCHED_NUMA
 	unsigned long numa_next_scan;
+	unsigned long numa_scan_offset;
 	int numa_scan_seq;
 #endif
 	struct uprobes_state uprobes_state;

Index: tip/include/linux/sched.h
===================================================================

include/linux/sched.h +1 -0
@@ -2022,6 +2022,7 @@ extern enum sched_tunable_scaling sysctl
 
 extern unsigned int sysctl_sched_numa_scan_period_min;
 extern unsigned int sysctl_sched_numa_scan_period_max;
+extern unsigned int sysctl_sched_numa_scan_size;
 extern unsigned int sysctl_sched_numa_settle_count;
 
 #ifdef CONFIG_SCHED_DEBUG

Index: tip/kernel/sched/fair.c
===================================================================

kernel/sched/fair.c +6 -8
@@ -829,8 +829,9 @@ static void account_numa_dequeue(struct
 /*
  * numa task sample period in ms: 5s
  */
-unsigned int sysctl_sched_numa_scan_period_min = 5000;
-unsigned int sysctl_sched_numa_scan_period_max = 5000*16;
+unsigned int sysctl_sched_numa_scan_period_min = 100;
+unsigned int sysctl_sched_numa_scan_period_max = 100*16;
+unsigned int sysctl_sched_numa_scan_size = 256;   /* MB */
 
 /*
  * Wait for the 2-sample stuff to settle before migrating again
@@ -904,6 +905,9 @@ void task_numa_work(struct callback_head
 	unsigned long migrate, next_scan, now = jiffies;
 	struct task_struct *p = current;
 	struct mm_struct *mm = p->mm;
+	struct vm_area_struct *vma;
+	unsigned long offset, end;
+	long length;
 
 	WARN_ON_ONCE(p != container_of(work, struct task_struct, numa_work));
 
@@ -930,18 +934,31 @@ void task_numa_work(struct callback_head
 	if (cmpxchg(&mm->numa_next_scan, migrate, next_scan) != migrate)
 		return;
 
-	ACCESS_ONCE(mm->numa_scan_seq)++;
-	{
-		struct vm_area_struct *vma;
-
-		down_write(&mm->mmap_sem);
-		for (vma = mm->mmap; vma; vma = vma->vm_next) {

kernel/sched/fair.c void task_numa_work(struct callback_head · line 941

Quoted 10 lines
kernel/sched/fair.c +5 -5
-			if (!vma_migratable(vma))
-				continue;
-			change_protection(vma, vma->vm_start, vma->vm_end, vma_prot_none(vma), 0);
-		}
-		up_write(&mm->mmap_sem);
+	offset = mm->numa_scan_offset;
+	length = sysctl_sched_numa_scan_size;
+	length <<= 20;
+
+	down_write(&mm->mmap_sem);

I should have spotted this during the last patch but we have to take mmap_sem for write?!? Why? Parallel mmap and fault performance is potentially mutilated by this depending on how often this task_numa_work thing is running.

kernel/sched/fair.c void task_numa_work(struct callback_head · line 942

Quoted 1 line
kernel/sched/fair.c +1 -0
+	vma = find_vma(mm, offset);

and a find_vma every scan restart. That sucks too.

Cache the vma as well as the offset. Compare vma->mm under mmap_sem held for read and that the offset still matches. Will that avoid the expense of the lookup?

Quoted 27 lines
kernel/sched/fair.c +18 -0
+	if (!vma) {
+		ACCESS_ONCE(mm->numa_scan_seq)++;
+		offset = 0;
+		vma = mm->mmap;
+	}
+	for (; vma && length > 0; vma = vma->vm_next) {
+		if (!vma_migratable(vma))
+			continue;
+
+		offset = max(offset, vma->vm_start);
+		end = min(ALIGN(offset + length, HPAGE_SIZE), vma->vm_end);
+		length -= end - offset;
+
+		change_prot_none(vma, offset, end);
+
+		offset = end;
 	}
+	mm->numa_scan_offset = offset;
+	up_write(&mm->mmap_sem);
 }
 
 /*

Index: tip/kernel/sysctl.c
===================================================================

kernel/sysctl.c static struct ctl_table kern_table[] = { · line 376

Quoted 10 lines
kernel/sysctl.c +7 -0
@@ -367,6 +367,13 @@ static struct ctl_table kern_table[] = {
 		.proc_handler	= proc_dointvec,
 	},
 	{
+		.procname	= "sched_numa_scan_size_mb",
+		.data		= &sysctl_sched_numa_scan_size,
+		.maxlen		= sizeof(unsigned int),
+		.mode		= 0644,
+		.proc_handler	= proc_dointvec,
+	},
+	{

If some muppet writes 0 into this, it effectively disables scanning. I guess who cares, but maybe a minimum value of a a hugepage size would make some sort of sense.

Quoted 5 lines
kernel/sysctl.c +0 -0
 		.procname	= "sched_numa_settle_count",
 		.data		= &sysctl_sched_numa_settle_count,
 		.maxlen		= sizeof(unsigned int),
Signature · 8 lines
Mel Gorman
SUSE Labs

--
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>
reviewer
#104 lore raw

Re: [PATCH 30/31] sched, numa, mm: Implement slow start for working set sampling

In reply to Peter Zijlstra
Quoted 7 lines · Peter Zijlstra

Add a 1 second delay before starting to scan the working set of a task and starting to balance it amongst nodes.

[ note that before the constant per task WSS sampling rate patch
the initial scan would happen much later still, in effect that patch caused this regression. ]

Quoted 6 lines

The theory is that short-run tasks benefit very little from NUMA
placement: they come and go, and they better stick to the node they were started on. As tasks mature and rebalance to other CPUs and nodes, so does their NUMA placement have to change and so does it start to matter more and more.

Yeah, ok. It's done by wall time, right? Should it be CPU time in case it spent the first second asleep?

Signature · 8 lines
Mel Gorman
SUSE Labs

--
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>
#124 lore raw
In reply to Hugh Dickins
Quoted 50 lines · Hugh Dickins
Quoted 9 lines · Hugh Dickins
Quoted 8 lines · Zhouping Liu
Quoted 7 lines · Hugh Dickins

There's quite a few put_page()s in do_huge_pmd_numa_page(), and it would help if we could focus on the one which is giving the trouble, but I don't know which that is. Zhouping, if you can, please would you do an "objdump -ld vmlinux >bigfile" of your kernel, then extract from bigfile just the lines from "<do_huge_pmd_numa_page>:" to whatever is the next function, and post or mail privately just that disassembly. That should be good to identify which of the put_page()s is involved.

Quoted 8 lines
Quoted 3 lines

Hugh, I didn't find the next function, as I can't find any words that matched "do_huge_pmd_numa_page".
is there any other methods?

Hmm, do_huge_pmd_numa_page does appear in your stacktrace, unless I've made a typo but am blind to it.

Were you applying objdump to the vmlinux which gave you the BUG at mm/memcontrol.c:1134! ?

Thanks for the further info you then sent privately: I have not made any more effort to reproduce the issue, but your objdump did tell me that the put_page hitting the problem is the one on line 872 of mm/huge_memory.c, "Drop the local reference", just before successful return after migration.

I didn't really get the inspiration I'd hoped for out of knowing that, but it did make wonder whether you're suffering from one of the issues I already mentioned, and I can now see a way in which it might cause the mm/memcontrol.c:1134 BUG:-

migrate_page_copy() does TestClearPageActive on the source page:
so given the unsafe way in which do_huge_pmd_numa_page() was proceeding with a !PageLRU page, it's quite possible that the page was sitting in a pagevec, and added to the active lru (so added to the lru_size of the active lru), but our final put_page removes it from lru, active flag has been cleared, so we subtract it from the lru_size of the inactive lru - that could indeed make it go negative and trigger the BUG.

Here's a patch fixing and tidying up that and a few other things there. But I'm not signing it off yet, partly because I've barely tested it (quite probably I didn't even have any numa pmd migration happening at all), and partly because just a moment ago I ran across this instructive comment in __collapse_huge_page_isolate():

	/* cannot use mapcount: can't collapse if there's a gup pin */
	if (page_count(page) != 1) {

Hmm, yes, below I've added the page_mapcount() check I proposed to do_huge_pmd_numa_page(), but is even that safe enough? Do we actually need a page_count() check (for 2?) to guard against get_user_pages()? I suspect we do, but then do we have enough locking to stabilize such a check? Probably, but...

Quoted 3 lines

This will take more time, and I doubt get_user_pages() is an issue in your testing, so please would you try the patch below, to see if it does fix the BUGs you are seeing? Thanks a lot.

Hugh, I have tested the patch for 5 more hours, the issue can't be reproduced again, so I think it has fixed the issue, thank you :)

Zhouping

Quoted 83 lines
Not-Yet-Signed-off-by Hugh Dickins <[email protected]>

---

  mm/huge_memory.c |   24 +++++++++---------------
  1 file changed, 9 insertions(+), 15 deletions(-)
mm/huge_memory.c +9 -16
@@ -745,7 +745,7 @@ void do_huge_pmd_numa_page(struct mm_str
  	struct mem_cgroup *memcg = NULL;
  	struct page *new_page = NULL;
  	struct page *page = NULL;
-	int node, lru;
+	int node = -1;
 
  	spin_lock(&mm->page_table_lock);
  	if (unlikely(!pmd_same(*pmd, entry)))
@@ -762,7 +762,8 @@ void do_huge_pmd_numa_page(struct mm_str
  		VM_BUG_ON(!PageCompound(page) || !PageHead(page));
 
  		get_page(page);
-		node = mpol_misplaced(page, vma, haddr);
+		if (page_mapcount(page) == 1)	/* Only do exclusively mapped */
+			node = mpol_misplaced(page, vma, haddr);
  		if (node != -1)
  			goto migrate;
  	}
@@ -801,13 +802,11 @@ migrate:
  	if (!new_page)
  		goto alloc_fail;
 
-	lru = PageLRU(page);
-
-	if (lru && isolate_lru_page(page)) /* does an implicit get_page() */
+	if (isolate_lru_page(page))	/* Does an implicit get_page() */
  		goto alloc_fail;
 
-	if (!trylock_page(new_page))
-		BUG();
+	__set_page_locked(new_page);
+	SetPageSwapBacked(new_page);
 
  	/* anon mapping, we can simply copy page->mapping to the new page: */
  	new_page->mapping = page->mapping;
@@ -820,8 +819,6 @@ migrate:
  	spin_lock(&mm->page_table_lock);
  	if (unlikely(!pmd_same(*pmd, entry))) {
  		spin_unlock(&mm->page_table_lock);
-		if (lru)
-			putback_lru_page(page);
 
  		unlock_page(new_page);
  		ClearPageActive(new_page);	/* Set by migrate_page_copy() */
@@ -829,6 +826,7 @@ migrate:
  		put_page(new_page);		/* Free it */
 
  		unlock_page(page);
+		putback_lru_page(page);
  		put_page(page);			/* Drop the local reference */
 
  		return;
@@ -859,16 +857,12 @@ migrate:
  	mem_cgroup_end_migration(memcg, page, new_page, true);
  	spin_unlock(&mm->page_table_lock);
 
-	put_page(page);			/* Drop the rmap reference */
-
  	task_numa_fault(node, HPAGE_PMD_NR);
 
-	if (lru)
-		put_page(page);		/* drop the LRU isolation reference */
-
  	unlock_page(new_page);
-
  	unlock_page(page);
+	put_page(page);			/* Drop the rmap reference */
+	put_page(page);			/* Drop the LRU isolation reference */
  	put_page(page);			/* Drop the local reference */
 
  	return;
 
--
Quoted 4 lines

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>

--
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>

#125 lore raw
Quoted 16 lines · Zhouping Liu
Quoted 15 lines · Hugh Dickins

Here's a patch fixing and tidying up that and a few other things there. But I'm not signing it off yet, partly because I've barely tested it (quite probably I didn't even have any numa pmd migration happening at all), and partly because just a moment ago I ran across this instructive comment in __collapse_huge_page_isolate():

	/* cannot use mapcount: can't collapse if there's a gup pin */
	if (page_count(page) != 1) {

Hmm, yes, below I've added the page_mapcount() check I proposed to do_huge_pmd_numa_page(), but is even that safe enough? Do we actually need a page_count() check (for 2?) to guard against get_user_pages()? I suspect we do, but then do we have enough locking to stabilize such a check? Probably, but...

Quoted 7 lines
Quoted 3 lines

This will take more time, and I doubt get_user_pages() is an issue in your testing, so please would you try the patch below, to see if it does fix the BUGs you are seeing? Thanks a lot.

Hugh, I have tested the patch for 5 more hours,
the issue can't be reproduced again,
so I think it has fixed the issue, thank you :)

Thanks a lot for testing and reporting back, that's good news.

However, I've meanwhile become convinced that more fixes are needed here, to be safe against get_user_pages() (including get_user_pages_fast()); to get the Mlocked count right; and to recover correctly when !pmd_same with an Unevictable page.

Won't now have time to update the patch today, but these additional fixes shouldn't hold up your testing.

Hugh

--
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>

#129 lore raw
In reply to Mel Gorman
Quoted 5 lines

In reality, this report is larger but I chopped it down a bit for brevity. autonuma beats schednuma *heavily* on this benchmark both in terms of average operations per numa node and overall throughput.

Quoted 7 lines

SPECJBB PEAKS
3.7.0 3.7.0 3.7.0
rc2-stats-v2r1 rc2-autonuma-v27r8 rc2-schednuma-v1r3

 Expctd Warehouse                   12.00 (  0.00%)                   12.00 (  0.00%)                   12.00 (  0.00%)
 Expctd Peak Bops               442225.00 (  0.00%)               596039.00 ( 34.78%)               555342.00 ( 25.58%)
 Actual Warehouse                    7.00 (  0.00%)                    9.00 ( 28.57%)                    8.00 ( 14.29%)
 Actual Peak Bops               550747.00 (  0.00%)               646124.00 ( 17.32%)               560635.00 (  1.80%)

It is impressive report!

Could you like to share the what JVM and options are you using in the testing, and based on which kinds of platform?

Signature · 8 lines
Thanks
    Alex

--
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>
reviewer
#130 lore raw
Quoted 13 lines · Alex Shi
Quoted 5 lines

In reality, this report is larger but I chopped it down a bit for brevity. autonuma beats schednuma *heavily* on this benchmark both in terms of average operations per numa node and overall throughput.

Quoted 7 lines

SPECJBB PEAKS
3.7.0 3.7.0 3.7.0
rc2-stats-v2r1 rc2-autonuma-v27r8 rc2-schednuma-v1r3

 Expctd Warehouse                   12.00 (  0.00%)                   12.00 (  0.00%)                   12.00 (  0.00%)
 Expctd Peak Bops               442225.00 (  0.00%)               596039.00 ( 34.78%)               555342.00 ( 25.58%)
 Actual Warehouse                    7.00 (  0.00%)                    9.00 ( 28.57%)                    8.00 ( 14.29%)
 Actual Peak Bops               550747.00 (  0.00%)               646124.00 ( 17.32%)               560635.00 (  1.80%)
Quoted 5 lines

It is impressive report!

Could you like to share the what JVM and options are you using in the testing, and based on which kinds of platform?

Oracle JVM version "1.7.0_07"
Java(TM) SE Runtime Environment (build 1.7.0_07-b10) Java HotSpot(TM) 64-Bit Server VM (build 23.3-b01, mixed mode)

4 JVMs were run, one for each node.

JVM switch specified was -Xmx12901m so it would consume roughly 80% of memory overall.

Machine is x86-64 4-node, 64G of RAM, CPUs are E7-4807, 48 cores in total with HT enabled.

Signature · 8 lines
Mel Gorman
SUSE Labs

--
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>
#134 lore raw
In reply to Peter Zijlstra

Hey Peter,

Here are results on 2node and 8node machine while running the autonuma benchmark.
----------------------------------------------------------------------------
On 2 node, 12 core 24GB
----------------------------------------------------------------------------
KernelVersion: 3.7.0-rc3

                        Testcase:      Min      Max      Avg
                          numa01:   121.23   122.43   121.53
                numa01_HARD_BIND:    80.90    81.07    80.96
             numa01_INVERSE_BIND:   145.91   146.06   145.97
             numa01_THREAD_ALLOC:   395.81   398.30   397.47
   numa01_THREAD_ALLOC_HARD_BIND:   264.09   264.27   264.18
numa01_THREAD_ALLOC_INVERSE_BIND:   476.36   476.65   476.53
                          numa02:    53.11    53.19    53.15
                numa02_HARD_BIND:    35.20    35.29    35.25
             numa02_INVERSE_BIND:    63.52    63.55    63.54
                      numa02_SMT:    60.28    62.00    61.33
            numa02_SMT_HARD_BIND:    42.63    43.61    43.22
         numa02_SMT_INVERSE_BIND:    76.27    78.06    77.31

KernelVersion: numasched (i.e 3.7.0-rc3 + your patches)

                        Testcase:      Min      Max      Avg  %Change
                          numa01:   121.28   121.71   121.47    0.05%
                numa01_HARD_BIND:    80.89    81.01    80.96    0.00%
             numa01_INVERSE_BIND:   145.87   146.04   145.96    0.01%
             numa01_THREAD_ALLOC:   398.07   400.27   398.90   -0.36%
   numa01_THREAD_ALLOC_HARD_BIND:   264.02   264.21   264.14    0.02%
numa01_THREAD_ALLOC_INVERSE_BIND:   476.13   476.62   476.41    0.03%
                          numa02:    52.97    53.25    53.13    0.04%
                numa02_HARD_BIND:    35.21    35.28    35.24    0.03%
             numa02_INVERSE_BIND:    63.51    63.54    63.53    0.02%
                      numa02_SMT:    61.35    62.46    61.97   -1.03%
            numa02_SMT_HARD_BIND:    42.89    43.85    43.22    0.00%
         numa02_SMT_INVERSE_BIND:    76.53    77.68    77.08    0.30%

----------------------------------------------------------------------------

KernelVersion: 3.7.0-rc3(with HT enabled )

                        Testcase:      Min      Max      Avg
                          numa01:   242.58   244.39   243.68
                numa01_HARD_BIND:   169.36   169.40   169.38
             numa01_INVERSE_BIND:   299.69   299.73   299.71
             numa01_THREAD_ALLOC:   399.86   404.10   401.50
   numa01_THREAD_ALLOC_HARD_BIND:   278.72   278.77   278.75
numa01_THREAD_ALLOC_INVERSE_BIND:   493.46   493.59   493.54
                          numa02:    53.00    53.33    53.19
                numa02_HARD_BIND:    36.77    36.88    36.82
             numa02_INVERSE_BIND:    66.07    66.10    66.09
                      numa02_SMT:    53.23    53.51    53.35
            numa02_SMT_HARD_BIND:    35.19    35.27    35.24
         numa02_SMT_INVERSE_BIND:    63.50    63.54    63.52

KernelVersion: numasched (i.e 3.7.0-rc3 + your patches) (with HT enabled)

                        Testcase:      Min      Max      Avg  %Change
                          numa01:   242.68   244.59   243.53    0.06%
                numa01_HARD_BIND:   169.37   169.42   169.40   -0.01%
             numa01_INVERSE_BIND:   299.83   299.96   299.91   -0.07%
             numa01_THREAD_ALLOC:   399.53   403.13   401.62   -0.03%
   numa01_THREAD_ALLOC_HARD_BIND:   278.78   278.80   278.79   -0.01%
numa01_THREAD_ALLOC_INVERSE_BIND:   493.63   493.90   493.78   -0.05%
                          numa02:    53.06    53.42    53.22   -0.06%
                numa02_HARD_BIND:    36.78    36.87    36.82    0.00%
             numa02_INVERSE_BIND:    66.09    66.10    66.10   -0.02%
                      numa02_SMT:    53.34    53.55    53.42   -0.13%
            numa02_SMT_HARD_BIND:    35.22    35.29    35.25   -0.03%
         numa02_SMT_INVERSE_BIND:    63.50    63.58    63.53   -0.02%

----------------------------------------------------------------------------

On 8 node, 64 core, 320 GB
----------------------------------------------------------------------------

KernelVersion: 3.7.0-rc3()

                        Testcase:      Min      Max      Avg
                          numa01:  1550.56  1596.03  1574.24
                numa01_HARD_BIND:   915.25  2540.64  1392.42
             numa01_INVERSE_BIND:  2964.66  3716.33  3149.10
             numa01_THREAD_ALLOC:   922.99  1003.31   972.99
   numa01_THREAD_ALLOC_HARD_BIND:   579.54  1266.65   896.75
numa01_THREAD_ALLOC_INVERSE_BIND:  1794.51  2057.16  1922.86
                          numa02:   126.22   133.01   130.91
                numa02_HARD_BIND:    25.85    26.25    26.06
             numa02_INVERSE_BIND:   341.38   350.35   345.82
                      numa02_SMT:   153.06   175.41   163.47
            numa02_SMT_HARD_BIND:    27.10   212.39   114.37
         numa02_SMT_INVERSE_BIND:   285.70  1542.83   540.62

KernelVersion: numasched()

                        Testcase:      Min      Max      Avg  %Change
                          numa01:  1542.69  1601.81  1569.68    0.29%
                numa01_HARD_BIND:   867.35  1094.00   966.05   44.14%
             numa01_INVERSE_BIND:  2835.71  3030.36  2966.99    6.14%
             numa01_THREAD_ALLOC:   326.35   379.43   347.01  180.39%
   numa01_THREAD_ALLOC_HARD_BIND:   611.55   720.09   657.06   36.48%
numa01_THREAD_ALLOC_INVERSE_BIND:  1839.60  1999.58  1919.36    0.18%
                          numa02:    35.35    55.09    40.81  220.78%
                numa02_HARD_BIND:    26.58    26.81    26.68   -2.32%
             numa02_INVERSE_BIND:   341.86   355.36   347.68   -0.53%
                      numa02_SMT:    37.65    48.65    43.08  279.46%
            numa02_SMT_HARD_BIND:    28.29   157.66    84.29   35.69%
         numa02_SMT_INVERSE_BIND:   313.07   346.72   333.69   62.01%

----------------------------------------------------------------------------

Signature · 2 lines
Thanks and Regards
Srikar
#133 lore raw
In reply to Mel Gorman
Quoted 9 lines · Mel Gorman
Quoted 7 lines · Peter Zijlstra

Hi all,

Here's a re-post of the NUMA scheduling and migration improvement patches that we are working on. These include techniques from AutoNUMA and the sched/numa tree and form a unified basis - it has got all the bits that look good and mergeable.

Quoted 6 lines

Thanks for the repost. I have not even started a review yet as I was travelling and just online today. It will be another day or two before I can start but I was at least able to do a comparison test between autonuma and schednuma today to see which actually performs the best. Even without the review I was able to stick on similar vmstats as was applied to autonuma to give a rough estimate of the relative overhead of both implementations.

Peter, Ingo,

do you have any comments on the performance measurements by Mel?

Any ideas on how to fix sched/numa or numa/core?

At this point, I suspect the easiest way forward might be to merge the basic infrastructure from Mel's combined tree (in -mm? in -tip?), so we can experiment with different NUMA placement policies on top.

That way we can do apples to apples comparison of the policies, and figure out what works best, and why.

--
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>

#131 lore raw
In reply to Mel Gorman
Quoted 24 lines · Mel Gorman
Quoted 13 lines · Alex Shi
Quoted 5 lines

In reality, this report is larger but I chopped it down a bit for brevity. autonuma beats schednuma *heavily* on this benchmark both in terms of average operations per numa node and overall throughput.

Quoted 7 lines

SPECJBB PEAKS
3.7.0 3.7.0 3.7.0
rc2-stats-v2r1 rc2-autonuma-v27r8 rc2-schednuma-v1r3

 Expctd Warehouse                   12.00 (  0.00%)                   12.00 (  0.00%)                   12.00 (  0.00%)
 Expctd Peak Bops               442225.00 (  0.00%)               596039.00 ( 34.78%)               555342.00 ( 25.58%)
 Actual Warehouse                    7.00 (  0.00%)                    9.00 ( 28.57%)                    8.00 ( 14.29%)
 Actual Peak Bops               550747.00 (  0.00%)               646124.00 ( 17.32%)               560635.00 (  1.80%)
Quoted 5 lines

It is impressive report!

Could you like to share the what JVM and options are you using in the testing, and based on which kinds of platform?

Oracle JVM version "1.7.0_07"
Java(TM) SE Runtime Environment (build 1.7.0_07-b10) Java HotSpot(TM) 64-Bit Server VM (build 23.3-b01, mixed mode)

Quoted 8 lines

4 JVMs were run, one for each node.

JVM switch specified was -Xmx12901m so it would consume roughly 80% of memory overall.

Machine is x86-64 4-node, 64G of RAM, CPUs are E7-4807, 48 cores in total with HT enabled.

Thanks for configuration sharing!

I used Jrockit and openjdk with Hugepage plus pin JVM to cpu socket. In previous sched numa version, I had found 20% dropping with Jrockit with our configuration. but for this version. No clear regression found. also has no benefit found.

Seems we need to expend the testing configurations. :)

Signature · 8 lines
Thanks
    Alex

--
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>
reviewer
#132 lore raw
Quoted 30 lines · Alex Shi
Quoted 29 lines · Mel Gorman
Quoted 13 lines · Alex Shi
Quoted 5 lines

In reality, this report is larger but I chopped it down a bit for brevity. autonuma beats schednuma *heavily* on this benchmark both in terms of average operations per numa node and overall throughput.

Quoted 7 lines

SPECJBB PEAKS
3.7.0 3.7.0 3.7.0
rc2-stats-v2r1 rc2-autonuma-v27r8 rc2-schednuma-v1r3

 Expctd Warehouse                   12.00 (  0.00%)                   12.00 (  0.00%)                   12.00 (  0.00%)
 Expctd Peak Bops               442225.00 (  0.00%)               596039.00 ( 34.78%)               555342.00 ( 25.58%)
 Actual Warehouse                    7.00 (  0.00%)                    9.00 ( 28.57%)                    8.00 ( 14.29%)
 Actual Peak Bops               550747.00 (  0.00%)               646124.00 ( 17.32%)               560635.00 (  1.80%)
Quoted 5 lines

It is impressive report!

Could you like to share the what JVM and options are you using in the testing, and based on which kinds of platform?

Oracle JVM version "1.7.0_07"
Java(TM) SE Runtime Environment (build 1.7.0_07-b10) Java HotSpot(TM) 64-Bit Server VM (build 23.3-b01, mixed mode)

4 JVMs were run, one for each node.

JVM switch specified was -Xmx12901m so it would consume roughly 80% of memory overall.

Quoted 7 lines
Quoted 3 lines

Machine is x86-64 4-node, 64G of RAM, CPUs are E7-4807, 48 cores in total with HT enabled.

Thanks for configuration sharing!

I used Jrockit and openjdk with Hugepage plus pin JVM to cpu socket.

If you are using hugepages then automatic numa is not migrating those pages. If you are pinning the JVMs to the socket then automatic numa balancing is unnecessary as they are already on the correct node.

Quoted 4 lines

In previous sched numa version, I had found 20% dropping with Jrockit with our configuration. but for this version. No clear regression found. also has no benefit found.

You are only checking for regressions with your configuration which is important because it showed that schednuma introduced only overhead in an optimisation NUMA configuration.

In your case, you will see little or not benefit with any automatic NUMA balancing implementation as the most important pages neiter can migrate nor need to.

Signature · 8 lines
Mel Gorman
SUSE Labs

--
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>
maintainer
#37 lore raw

Re: [PATCH 2/3] x86,mm: drop TLB flush from ptep_set_access_flags

In reply to Linus Torvalds
Quoted 6 lines · Linus Torvalds
Quoted 2 lines · Borislav Petkov

On current AMD64 processors,

Can you verify that this is true for older cpu's too (ie the old pre-64-bit ones, say K6 and original Athlon)?

Albeit with a slight delay, the answer is yes: all AMD cpus automatically invalidate cached TLB entries (and intermediate walk results, for that matter) on a #PF.

I don't know, however, whether it would be prudent to have some sort of a cheap assertion in the code (cheaper than INVLPG %ADDR, although on older cpus we do MOV CR3) just in case. This should be enabled only with DEBUG_VM on, of course...

HTH.

Signature · 8 lines
Regards/Gruss,
Boris.

--
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>
#38 lore raw

Re: [PATCH 2/3] x86,mm: drop TLB flush from ptep_set_access_flags

Quoted 4 lines · Borislav Petkov

Albeit with a slight delay, the answer is yes: all AMD cpus automatically invalidate cached TLB entries (and intermediate walk results, for that matter) on a #PF.

Thanks. I suspect it ends up being basically architectural, and that Windows (and quite possibly Linux versions too) have depended on the behavior.

Quoted 4 lines

I don't know, however, whether it would be prudent to have some sort of a cheap assertion in the code (cheaper than INVLPG %ADDR, although on older cpus we do MOV CR3) just in case. This should be enabled only with DEBUG_VM on, of course...

I wonder how we could actually test for it. We'd have to have some per-cpu page-fault address check (along with a generation count on the mm or similar). I doubt we'd figure out anything that works reliably and efficiently and would actually show any problems (plus we would have no way to ever know we even got the code right, since presumably we'd never find hardware that actually shows the behavior we'd be looking for..)

Linus

--
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>

maintainer
#39 lore raw

Re: [PATCH 2/3] x86,mm: drop TLB flush from ptep_set_access_flags

Quoted 7 lines · Linus Torvalds

I wonder how we could actually test for it. We'd have to have some per-cpu page-fault address check (along with a generation count on the mm or similar). I doubt we'd figure out anything that works reliably and efficiently and would actually show any problems (plus we would have no way to ever know we even got the code right, since presumably we'd never find hardware that actually shows the behavior we'd be looking for..)

Hmm, touching some wrong page through the stale TLB entry could be a pretty nasty issue to debug. But you're probably right: how does one test cheaply whether a PTE just got kicked out of the TLB? Maybe mark it not-present but this would force a rewalk in the case when it is shared, which is penalty we don't want to pay.

Oh well...

Signature · 8 lines
Regards/Gruss,
Boris.

--
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>
#40 lore raw

Re: [PATCH 2/3] x86,mm: drop TLB flush from ptep_set_access_flags

In reply to Linus Torvalds
Quoted 10 lines · Linus Torvalds
Quoted 4 lines · Borislav Petkov

I don't know, however, whether it would be prudent to have some sort of a cheap assertion in the code (cheaper than INVLPG %ADDR, although on older cpus we do MOV CR3) just in case. This should be enabled only with DEBUG_VM on, of course...

I wonder how we could actually test for it. We'd have to have some per-cpu page-fault address check (along with a generation count on the mm or similar). I doubt we'd figure out anything that works reliably and efficiently and would actually show any problems

Would it be enough to simply print out a warning if we fault on the same address twice (or three times) in a row, and then flush the local TLB?

I realize this would not just trigger on CPUs that fail to invalidate TLB entries that cause faults, but also on kernel paths that cause a page fault to be re-taken...

... but then again, don't we want to find those paths and fix them, anyway? :)

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>
#41 lore raw

Re: [PATCH 2/3] x86,mm: drop TLB flush from ptep_set_access_flags

Quoted 15 lines · Rik van Riel
Quoted 9 lines · Linus Torvalds
Quoted 5 lines · Borislav Petkov

I don't know, however, whether it would be prudent to have some sort of a cheap assertion in the code (cheaper than INVLPG %ADDR, although on older cpus we do MOV CR3) just in case. This should be enabled only with DEBUG_VM on, of course...

Quoted 4 lines

I wonder how we could actually test for it. We'd have to have some per-cpu page-fault address check (along with a generation count on the mm or similar). I doubt we'd figure out anything that works reliably and efficiently and would actually show any problems

Quoted 7 lines

Would it be enough to simply print out a warning if we fault on the same address twice (or three times) in a row, and then flush the local TLB?

I realize this would not just trigger on CPUs that fail to invalidate TLB entries that cause faults, but also on kernel paths that cause a page fault to be re-taken...

I'm actually curious if the architecture docs/software developer manuals for IA-32 mandate any TLB invalidations on a #PF

Is there any official vendor documentation on the subject?

And perhaps equally valid, should we trust it if it exists?

Quoted 7 lines

... but then again, don't we want to find those paths and fix them, anyway? :)

--
All rights reversed

Quoted 5 lines

--
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>

--
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>

#42 lore raw

Re: [PATCH 2/3] x86,mm: drop TLB flush from ptep_set_access_flags

Quoted 4 lines · Shentino

I'm actually curious if the architecture docs/software developer manuals for IA-32 mandate any TLB invalidations on a #PF

Is there any official vendor documentation on the subject?

Yes. Quoting a prior email:

Actually, it is architected on x86. This was first described in the intel appnote 317080 "TLBs, Paging-Structure Caches, and Their Invalidation", last paragraph of section 5.1. Nowadays, the same contents are buried somewhere in Volume 3 of the architecture manual (in my copy: 4.10.4.1 Operations that Invalidate TLBs and Paging-Structure Caches)

Quoted 1 line

And perhaps equally valid, should we trust it if it exists?

I know that Intel has been very careful in documenting the architected TLB behaviors and did it with the understanding that people should be able to depend on what's being written up there.

Signature · 8 lines
Michel "Walken" Lespinasse
A program is never fully debugged until the last user dies.

--
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>
#29 lore raw

trailing flush_tlb_fix_spurious_fault in handle_pte_fault (was Re: [PATCH 1/3] x86/mm: only do a local TLB flush in ptep_set_access_flags())

In reply to Rik van Riel
Quoted 15 lines · Rik van Riel
Quoted 6 lines · Linus Torvalds
Quoted 5 lines · Rik van Riel

I can change the text of the changelog, however it looks like do_wp_page does actually use ptep_set_access_flags to set the write bit in the pte...

Quoted 7 lines
Quoted 2 lines

I guess both need to be reflected in the changelog text somehow?

Yeah, and by now, after all this discussion, I suspect it should be committed with a comment too. Commit messages are good and all, but unless chasing a particular bug they introduced, we shouldn't expect people to read them for background information.

Quoted 8 lines

Now that we have the TLB things taken care of, and comments to patches 10/31 and 26/31 have been addressed, is there anything else that needs to be done before these NUMA patches can be merged?

Anyone, this is a good time to speak up. We have some time to address whatever concern you may have.

Hi,

I know I'm very late in speaking up - but still I'll hazard a try. This is not exactly the same topic but closely related.

There is a a different call to flush_tlb_fix_spurious( ), towards the end of handle_pte_fault( ) which commit 61c77326d "x86, mm: Avoid unnecessary TLB flush" made no-op for X86. However is this really needed for any arch at all - even if we don't know all the arch specific quirks.

Given the code flow below

handle_pte_fault( )
....
....
if ptep_set_access_flags()-> if PTE chg remote TLB shot (pgtable-generic.c ver)
update_mmu_cache -> if PTE chg local TLB possibly shot too
else
flush_tlb_fix_spurious_fault -> PTE didn't change - still remote TLB shotdown

So for PTE unchanged case, we default to doing remote TLB IPIs (barring X86) - unless arch makes this macro NULL.

Thing is, in case of SMP races - due to PTE being different - any fixups to local/remote will be handled within ptep_set_access_flags( ) - arch-specific or generic versions. What I fail to understand is need to do anything - specially a remote shootdown, for PTE not changed case.

I could shut up and just make it NO-OP for ARC, but ....

Please note that for the record, the addition of this special case was done via following change. It might help answer what I feel to comprehend.

2005-10-29 1a44e14 [PATCH] .text page fault SMP scalability optimization

I might be totally off track so please feel free to bash me - but atleast I would end up knowing more !

Thx,
-Vineet

--
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>