linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: "Hillf Danton" <dhillf@sina.com>
To: Mel Gorman <mgorman@suse.de>
Cc: Rik van Riel <riel@redhat.com>,
	Andrea Arcangeli <aarcange@redhat.com>,
	linux-kernel <linux-kernel@vger.kernel.org>,
	linux-mm <linux-mm@kvack.org>, Hillf Danton <dhillf@gmail.com>
Subject: [RFC PATCH] mm: numa: adjust hinting fault record if page is migrated
Date: Sat, 14 Sep 2013 19:53:35 +0800	[thread overview]
Message-ID: <20130914115335.3AA33428001@webmail.sinamail.sina.com.cn> (raw)

After page A on source node is migrated to page B on target node, hinting
fault is recorded on the target node for B. On the source node there is
another record for A, since a two-stage filter is used when migrating pages.

Page A is no longer used after migration, so we have to erase its record.

Signed-off-by: Hillf Danton <dhillf@gmail.com>
---

--- a/include/linux/sched.h	Sat Sep 14 16:57:32 2013
+++ b/include/linux/sched.h	Sat Sep 14 17:22:20 2013
@@ -1440,12 +1440,13 @@ struct task_struct {
 #define TNF_NO_GROUP	0x02
 
 #ifdef CONFIG_NUMA_BALANCING
-extern void task_numa_fault(int last_node, int node, int pages, int flags);
+extern void task_numa_fault(int last_cpupid, int src_node,
+					int dst_node, int pages, int flags);
 extern pid_t task_numa_group_id(struct task_struct *p);
 extern void set_numabalancing_state(bool enabled);
 #else
-static inline void task_numa_fault(int last_node, int node, int pages,
-				   int flags)
+static inline void task_numa_fault(int last_cpupid, int src_node,
+					int dst_node, int pages, int flags)
 {
 }
 static inline pid_t task_numa_group_id(struct task_struct *p)
--- a/kernel/sched/fair.c	Wed Sep 11 18:33:00 2013
+++ b/kernel/sched/fair.c	Sat Sep 14 17:57:16 2013
@@ -1493,7 +1493,8 @@ void task_numa_free(struct task_struct *
 /*
  * Got a PROT_NONE fault for a page on @node.
  */
-void task_numa_fault(int last_cpupid, int node, int pages, int flags)
+void task_numa_fault(int last_cpupid, int src_node, int dst_node,
+						int pages, int flags)
 {
 	struct task_struct *p = current;
 	bool migrated = flags & TNF_MIGRATED;
@@ -1559,7 +1560,15 @@ void task_numa_fault(int last_cpupid, in
 	if (migrated)
 		p->numa_pages_migrated += pages;
 
-	p->numa_faults_buffer[task_faults_idx(node, priv)] += pages;
+	p->numa_faults_buffer[task_faults_idx(dst_node, priv)] += pages;
+
+	if (migrated) {
+		/* extract numa-hint faults from src node */
+		int idx = task_faults_idx(src_node, priv);
+
+		if (p->numa_faults[idx] >= pages)
+			p->numa_faults[idx] -= pages;
+	}
 }
 
 static void reset_ptenuma_scan(struct task_struct *p)
--- a/mm/huge_memory.c	Sat Sep 14 16:54:28 2013
+++ b/mm/huge_memory.c	Sat Sep 14 17:46:54 2013
@@ -1295,6 +1295,7 @@ int do_huge_pmd_numa_page(struct mm_stru
 	unsigned long haddr = addr & HPAGE_PMD_MASK;
 	int page_nid = -1, this_nid = numa_node_id();
 	int target_nid, last_cpupid = -1;
+	int src_nid;
 	bool page_locked;
 	bool migrated = false;
 	int flags = 0;
@@ -1306,6 +1307,7 @@ int do_huge_pmd_numa_page(struct mm_stru
 	page = pmd_page(pmd);
 	BUG_ON(is_huge_zero_page(page));
 	page_nid = page_to_nid(page);
+	src_nid = page_nid;
 	last_cpupid = page_cpupid_last(page);
 	count_vm_numa_event(NUMA_HINT_FAULTS);
 	if (page_nid == this_nid)
@@ -1388,7 +1390,7 @@ out:
 		page_unlock_anon_vma_read(anon_vma);
 
 	if (page_nid != -1)
-		task_numa_fault(last_cpupid, page_nid, HPAGE_PMD_NR, flags);
+		task_numa_fault(last_cpupid, src_nid, page_nid, HPAGE_PMD_NR, flags);
 
 	return 0;
 }
--- a/mm/memory.c	Sat Sep 14 16:54:52 2013
+++ b/mm/memory.c	Sat Sep 14 17:52:02 2013
@@ -3555,6 +3555,7 @@ int do_numa_page(struct mm_struct *mm, s
 	struct page *page = NULL;
 	spinlock_t *ptl;
 	int page_nid = -1;
+	int src_nid;
 	int last_cpupid;
 	int target_nid;
 	bool migrated = false;
@@ -3597,6 +3598,7 @@ int do_numa_page(struct mm_struct *mm, s
 
 	last_cpupid = page_cpupid_last(page);
 	page_nid = page_to_nid(page);
+	src_nid = page_nid;
 	target_nid = numa_migrate_prep(page, vma, addr, page_nid);
 	pte_unmap_unlock(ptep, ptl);
 	if (target_nid == -1) {
@@ -3613,7 +3615,7 @@ int do_numa_page(struct mm_struct *mm, s
 
 out:
 	if (page_nid != -1)
-		task_numa_fault(last_cpupid, page_nid, 1, flags);
+		task_numa_fault(last_cpupid, src_nid, page_nid, 1, flags);
 	return 0;
 }
 
@@ -3652,6 +3654,7 @@ static int do_pmd_numa_page(struct mm_st
 		pte_t pteval = *pte;
 		struct page *page;
 		int page_nid = -1;
+		int src_nid;
 		int target_nid;
 		bool migrated = false;
 		int flags = 0;
@@ -3684,6 +3687,7 @@ static int do_pmd_numa_page(struct mm_st
 
 		last_cpupid = page_cpupid_last(page);
 		page_nid = page_to_nid(page);
+		src_nid = page_nid;
 		target_nid = numa_migrate_prep(page, vma, addr, page_nid);
 		pte_unmap_unlock(pte, ptl);
 		if (target_nid != -1) {
@@ -3697,7 +3701,7 @@ static int do_pmd_numa_page(struct mm_st
 		}
 
 		if (page_nid != -1)
-			task_numa_fault(last_cpupid, page_nid, 1, flags);
+			task_numa_fault(last_cpupid, src_nid, page_nid, 1, flags);
 
 		pte = pte_offset_map_lock(mm, pmdp, addr, &ptl);
 	}
--

             reply	other threads:[~2013-09-14 11:53 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-09-14 11:53 Hillf Danton [this message]
2013-09-14 15:55 ` Rik van Riel
2013-09-15  1:11   ` Hillf Danton

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20130914115335.3AA33428001@webmail.sinamail.sina.com.cn \
    --to=dhillf@sina.com \
    --cc=aarcange@redhat.com \
    --cc=dhillf@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mgorman@suse.de \
    --cc=riel@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox