From: Anshuman Khandual <khandual@linux.vnet.ibm.com>
To: linux-kernel@vger.kernel.org, linux-mm@kvack.org
Cc: mhocko@suse.com, vbabka@suse.cz, mgorman@suse.de,
minchan@kernel.org, aneesh.kumar@linux.vnet.ibm.com,
bsingharora@gmail.com, srikar@linux.vnet.ibm.com,
haren@linux.vnet.ibm.com, jglisse@redhat.com,
dave.hansen@intel.com
Subject: [DEBUG 10/12] mm: Add a new migration function migrate_virtual_range()
Date: Tue, 22 Nov 2016 19:49:46 +0530 [thread overview]
Message-ID: <1479824388-30446-11-git-send-email-khandual@linux.vnet.ibm.com> (raw)
In-Reply-To: <1479824388-30446-1-git-send-email-khandual@linux.vnet.ibm.com>
This adds a new virtual address range based migration interface which
can migrate all the mapped pages from a virtual range of a process to
a destination node. This also exports this new function symbol.
Signed-off-by: Anshuman Khandual <khandual@linux.vnet.ibm.com>
---
include/linux/mempolicy.h | 7 +++++
include/linux/migrate.h | 3 ++
mm/mempolicy.c | 7 ++---
mm/migrate.c | 71 +++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 83 insertions(+), 5 deletions(-)
diff --git a/include/linux/mempolicy.h b/include/linux/mempolicy.h
index 5e5b296..c2b4a18 100644
--- a/include/linux/mempolicy.h
+++ b/include/linux/mempolicy.h
@@ -152,6 +152,9 @@ extern struct zonelist *huge_zonelist(struct vm_area_struct *vma,
extern bool mempolicy_nodemask_intersects(struct task_struct *tsk,
const nodemask_t *mask);
extern unsigned int mempolicy_slab_node(void);
+extern int queue_pages_range(struct mm_struct *mm, unsigned long start,
+ unsigned long end, nodemask_t *nodes,
+ unsigned long flags, struct list_head *pagelist);
extern enum zone_type policy_zone;
@@ -302,4 +305,8 @@ static inline void mpol_put_task_policy(struct task_struct *task)
{
}
#endif /* CONFIG_NUMA */
+
+#define MPOL_MF_DISCONTIG_OK (MPOL_MF_INTERNAL << 0) /* Skip checks for continuous vmas */
+#define MPOL_MF_INVERT (MPOL_MF_INTERNAL << 1) /* Invert check for nodemask */
+
#endif
diff --git a/include/linux/migrate.h b/include/linux/migrate.h
index ae8d475..e2a1af5 100644
--- a/include/linux/migrate.h
+++ b/include/linux/migrate.h
@@ -49,6 +49,9 @@ extern int migrate_page_move_mapping(struct address_space *mapping,
struct page *newpage, struct page *page,
struct buffer_head *head, enum migrate_mode mode,
int extra_count);
+
+extern int migrate_virtual_range(int pid, unsigned long vaddr,
+ unsigned long size, int nid);
#else
static inline void putback_movable_pages(struct list_head *l) {}
diff --git a/mm/mempolicy.c b/mm/mempolicy.c
index 0b859af..728347a 100644
--- a/mm/mempolicy.c
+++ b/mm/mempolicy.c
@@ -100,10 +100,6 @@
#include "internal.h"
-/* Internal flags */
-#define MPOL_MF_DISCONTIG_OK (MPOL_MF_INTERNAL << 0) /* Skip checks for continuous vmas */
-#define MPOL_MF_INVERT (MPOL_MF_INTERNAL << 1) /* Invert check for nodemask */
-
static struct kmem_cache *policy_cache;
static struct kmem_cache *sn_cache;
@@ -662,7 +658,7 @@ static int queue_pages_test_walk(unsigned long start, unsigned long end,
* @nodes and @flags,) it's isolated and queued to the pagelist which is
* passed via @private.)
*/
-static int
+int
queue_pages_range(struct mm_struct *mm, unsigned long start, unsigned long end,
nodemask_t *nodes, unsigned long flags,
struct list_head *pagelist)
@@ -683,6 +679,7 @@ static int queue_pages_test_walk(unsigned long start, unsigned long end,
return walk_page_range(start, end, &queue_pages_walk);
}
+EXPORT_SYMBOL(queue_pages_range);
/*
* Apply policy to a single VMA
diff --git a/mm/migrate.c b/mm/migrate.c
index 99250ae..4f20415 100644
--- a/mm/migrate.c
+++ b/mm/migrate.c
@@ -1367,6 +1367,77 @@ int migrate_pages(struct list_head *from, new_page_t get_new_page,
return rc;
}
+static struct page *new_node_page(struct page *page,
+ unsigned long node, int **x)
+{
+ return __alloc_pages_node(node, GFP_HIGHUSER_MOVABLE
+ | __GFP_THISNODE, 0);
+}
+
+/*
+ * migrate_virtual_range - migrate all the pages faulted within a virtual
+ * address range to a specified node.
+ *
+ * @pid: PID of the task
+ * @start: Virtual address range beginning
+ * @end: Virtual address range end
+ * @nid: Target migration node
+ *
+ * The function first scans the process VMA list to find out the VMA which
+ * contains the given virtual range. Then validates that the virtual range
+ * is within the given VMA's limits.
+ *
+ * Returns the number of pages that were not migrated or an error code.
+ */
+int migrate_virtual_range(int pid, unsigned long start,
+ unsigned long end, int nid)
+{
+ struct mm_struct *mm;
+ struct vm_area_struct *vma;
+ nodemask_t nmask;
+ int ret = -EINVAL;
+
+ LIST_HEAD(mlist);
+
+ nodes_clear(nmask);
+ nodes_setall(nmask);
+
+ if ((!start) || (!end))
+ return -EINVAL;
+
+ rcu_read_lock();
+ mm = find_task_by_vpid(pid)->mm;
+ rcu_read_unlock();
+
+ start &= PAGE_MASK;
+ end &= PAGE_MASK;
+ down_write(&mm->mmap_sem);
+ for (vma = mm->mmap; vma; vma = vma->vm_next) {
+ if ((start < vma->vm_start) || (end > vma->vm_end))
+ continue;
+
+ ret = queue_pages_range(mm, start, end, &nmask, MPOL_MF_MOVE_ALL
+ | MPOL_MF_DISCONTIG_OK, &mlist);
+ if (ret) {
+ putback_movable_pages(&mlist);
+ break;
+ }
+
+ if (list_empty(&mlist)) {
+ ret = -ENOMEM;
+ break;
+ }
+
+ ret = migrate_pages(&mlist, new_node_page, NULL, nid,
+ MIGRATE_SYNC, MR_COMPACTION);
+ if (ret)
+ putback_movable_pages(&mlist);
+ }
+ up_write(&mm->mmap_sem);
+ return ret;
+}
+EXPORT_SYMBOL(migrate_virtual_range);
+
#ifdef CONFIG_NUMA
/*
* Move a list of individual pages
--
1.8.3.1
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next prev parent reply other threads:[~2016-11-22 14:20 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-11-22 14:19 [RFC 0/4] Define coherent device memory node Anshuman Khandual
2016-11-22 14:19 ` [RFC 1/4] mm: " Anshuman Khandual
2016-11-29 17:57 ` Dave Hansen
2016-11-30 11:46 ` Anshuman Khandual
2016-11-22 14:19 ` [RFC 2/4] mm/cpuset: Exclude coherent device memory nodes from mems_allowed Anshuman Khandual
2016-11-22 14:19 ` [RFC 3/4] mm/hugetlb: Restrict HugeTLB page allocations only to system ram nodemask Anshuman Khandual
2016-11-22 14:19 ` [RFC 4/4] mm: Ignore cpuset enforcement when allocation flag has __GFP_THISNODE Anshuman Khandual
2016-11-28 21:12 ` Dave Hansen
2016-11-29 6:51 ` Anshuman Khandual
2016-11-29 16:52 ` Dave Hansen
2016-11-30 11:17 ` Anshuman Khandual
2016-11-30 19:43 ` Dave Hansen
2016-11-22 14:19 ` [DEBUG 05/12] powerpc/mm: Identify coherent device memory nodes during platform init Anshuman Khandual
2016-11-22 14:19 ` [DEBUG 06/12] powerpc/mm: Create numa nodes for hotplug memory Anshuman Khandual
2016-11-22 14:19 ` [DEBUG 07/12] powerpc/mm: Allow memory hotplug into a memory less node Anshuman Khandual
2016-11-22 14:19 ` [DEBUG 08/12] mm: Enable CONFIG_MOVABLE_NODE on powerpc Anshuman Khandual
2016-11-22 14:19 ` [DEBUG 09/12] powerpc: Enable CONFIG_MOVABLE_NODE for PPC64 platform Anshuman Khandual
2016-11-22 14:19 ` Anshuman Khandual [this message]
2016-11-22 14:19 ` [DEBUG 11/12] drivers: Add two drivers for coherent device memory tests Anshuman Khandual
2016-11-22 14:19 ` [DEBUG 12/12] test: Add a script to perform random VMA migrations across nodes Anshuman Khandual
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=1479824388-30446-11-git-send-email-khandual@linux.vnet.ibm.com \
--to=khandual@linux.vnet.ibm.com \
--cc=aneesh.kumar@linux.vnet.ibm.com \
--cc=bsingharora@gmail.com \
--cc=dave.hansen@intel.com \
--cc=haren@linux.vnet.ibm.com \
--cc=jglisse@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mgorman@suse.de \
--cc=mhocko@suse.com \
--cc=minchan@kernel.org \
--cc=srikar@linux.vnet.ibm.com \
--cc=vbabka@suse.cz \
/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;
as well as URLs for NNTP newsgroup(s).