From: Jérôme Glisse <[email protected]>

This patch add migrate commands to hbind() ioctl, user space can use
this commands to migrate a range of virtual address to list of target
memory.

This does not change the policy for the range, it also ignores any of
the existing policy range, it does not changes the policy for the
range.

Signed-off-by: Jérôme Glisse <[email protected]>
Cc: Rafael J. Wysocki <[email protected]>
Cc: Ross Zwisler <[email protected]>
Cc: Dan Williams <[email protected]>
Cc: Dave Hansen <[email protected]>
Cc: Haggai Eran <[email protected]>
Cc: Balbir Singh <[email protected]>
Cc: Aneesh Kumar K.V <[email protected]>
Cc: Benjamin Herrenschmidt <[email protected]>
Cc: Felix Kuehling <[email protected]>
Cc: Philip Yang <[email protected]>
Cc: Christian König <[email protected]>
Cc: Paul Blinzer <[email protected]>
Cc: Logan Gunthorpe <[email protected]>
Cc: John Hubbard <[email protected]>
Cc: Ralph Campbell <[email protected]>
Cc: Michal Hocko <[email protected]>
Cc: Jonathan Cameron <[email protected]>
Cc: Mark Hairgrove <[email protected]>
Cc: Vivek Kini <[email protected]>
Cc: Mel Gorman <[email protected]>
Cc: Dave Airlie <[email protected]>
Cc: Ben Skeggs <[email protected]>
Cc: Andrea Arcangeli <[email protected]>
---
 include/uapi/linux/hbind.h |  9 ++++++++
 mm/hms.c                   | 43 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 52 insertions(+)

diff --git a/include/uapi/linux/hbind.h b/include/uapi/linux/hbind.h
index 7bb876954e3f..ededbba22121 100644
--- a/include/uapi/linux/hbind.h
+++ b/include/uapi/linux/hbind.h
@@ -57,6 +57,15 @@ struct hbind_params {
  */
 #define HBIND_CMD_BIND 1
 
+/*
+ * HBIND_CMD_MIGRATE move existing memory to use listed target memory. This is
+ * a best effort.
+ *
+ * Additional dwords:
+ *      [0] result ie number of pages that have been migrated.
+ */
+#define HBIND_CMD_MIGRATE 2
+
 
 #define HBIND_IOCTL            _IOWR('H', 0x00, struct hbind_params)
 
diff --git a/mm/hms.c b/mm/hms.c
index 6be6f4acdd49..6764908f47bf 100644
--- a/mm/hms.c
+++ b/mm/hms.c
@@ -368,6 +368,39 @@ static int hbind_bind(struct mm_struct *mm, struct 
hbind_params *params,
 }
 
 
+static int hbind_migrate(struct mm_struct *mm, struct hbind_params *params,
+                        const uint32_t *targets, uint32_t *atoms)
+{
+       unsigned long size, npages;
+       int ret = -EINVAL;
+       unsigned i;
+
+       size = PAGE_ALIGN(params->end) - (params->start & PAGE_MASK);
+       npages = size >> PAGE_SHIFT;
+
+       for (i = 0; params->ntargets; ++i) {
+               struct hms_target *target;
+
+               target = hms_target_find(targets[i]);
+               if (target == NULL)
+                       continue;
+
+               ret = target->hbind->migrate(target, mm, params->start,
+                                            params->end, params->natoms,
+                                            atoms);
+               hms_target_put(target);
+
+               if (ret)
+                       continue;
+
+               if (atoms[0] >= npages)
+                       break;
+       }
+
+       return ret;
+}
+
+
 static long hbind_ioctl(struct file *file, unsigned cmd, unsigned long arg)
 {
        uint32_t *targets, *_dtargets = NULL, _ftargets[HBIND_FIX_ARRAY];
@@ -458,6 +491,16 @@ static long hbind_ioctl(struct file *file, unsigned cmd, 
unsigned long arg)
                        if (ret)
                                goto out_mm;
                        break;
+               case HBIND_CMD_MIGRATE:
+                       if (ndwords != 2) {
+                               ret = -EINVAL;
+                               goto out_mm;
+                       }
+                       ret = hbind_migrate(current->mm, &params,
+                                           targets, atoms);
+                       if (ret)
+                               goto out_mm;
+                       break;
                default:
                        ret = -EINVAL;
                        goto out_mm;
-- 
2.17.2

Reply via email to