diff mbox series

[RFC,11/14] mm/hbind: add bind command to heterogeneous memory policy

Message ID 20181203233509.20671-12-jglisse@redhat.com (mailing list archive)
State New, archived
Headers show
Series Heterogeneous Memory System (HMS) and hbind() | expand

Commit Message

Jerome Glisse Dec. 3, 2018, 11:35 p.m. UTC
From: Jérôme Glisse <jglisse@redhat.com>

This patch add bind command to hbind() ioctl, this allow to bind a
range of virtual address to given list of target memory. New memory
allocated in the range will try to use memory from the target memory
list.

Note that this patch does not modify existing page fault path and thus
does not activate new heterogeneous policy. Updating the CPU page fault
code path or device page fault code path (HMM) will be done in separate
patches.

Here we only introduce helpers and infrastructure that will be use by
page fault code path.

Signed-off-by: Jérôme Glisse <jglisse@redhat.com>
Cc: Rafael J. Wysocki <rafael@kernel.org>
Cc: Ross Zwisler <ross.zwisler@linux.intel.com>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Dave Hansen <dave.hansen@intel.com>
Cc: Haggai Eran <haggaie@mellanox.com>
Cc: Balbir Singh <balbirs@au1.ibm.com>
Cc: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Felix Kuehling <felix.kuehling@amd.com>
Cc: Philip Yang <Philip.Yang@amd.com>
Cc: Christian König <christian.koenig@amd.com>
Cc: Paul Blinzer <Paul.Blinzer@amd.com>
Cc: Logan Gunthorpe <logang@deltatee.com>
Cc: John Hubbard <jhubbard@nvidia.com>
Cc: Ralph Campbell <rcampbell@nvidia.com>
Cc: Michal Hocko <mhocko@kernel.org>
Cc: Jonathan Cameron <jonathan.cameron@huawei.com>
Cc: Mark Hairgrove <mhairgrove@nvidia.com>
Cc: Vivek Kini <vkini@nvidia.com>
Cc: Mel Gorman <mgorman@techsingularity.net>
Cc: Dave Airlie <airlied@redhat.com>
Cc: Ben Skeggs <bskeggs@redhat.com>
Cc: Andrea Arcangeli <aarcange@redhat.com>
---
 include/uapi/linux/hbind.h | 10 ++++++++++
 mm/hms.c                   | 40 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 50 insertions(+)
diff mbox series

Patch

diff --git a/include/uapi/linux/hbind.h b/include/uapi/linux/hbind.h
index cc4687587f5a..7bb876954e3f 100644
--- a/include/uapi/linux/hbind.h
+++ b/include/uapi/linux/hbind.h
@@ -47,6 +47,16 @@  struct hbind_params {
  */
 #define HBIND_CMD_DEFAULT 0
 
+/*
+ * HBIND_CMD_BIND strict policy ie new allocations will comes from one of the
+ * listed targets until they run of memory. Other targets can be use if the
+ * none of the listed targets can be accessed by the initiator that did fault.
+ *
+ * Additional dwords:
+ *      NONE (DWORDS MUST BE 0 !)
+ */
+#define HBIND_CMD_BIND 1
+
 
 #define HBIND_IOCTL		_IOWR('H', 0x00, struct hbind_params)
 
diff --git a/mm/hms.c b/mm/hms.c
index be2c4e526f25..6be6f4acdd49 100644
--- a/mm/hms.c
+++ b/mm/hms.c
@@ -338,6 +338,36 @@  static struct hms_policy *hms_policy_get(struct mm_struct *mm)
 }
 
 
+static int hbind_bind(struct mm_struct *mm, struct hbind_params *params,
+		      const uint32_t *targets, uint32_t *atoms)
+{
+	struct hms_policy_range *prange;
+	struct hms_policy *hpolicy;
+	int ret;
+
+	hpolicy = hms_policy_get(mm);
+	if (hpolicy == NULL)
+		return -ENOMEM;
+
+	prange = hms_policy_range_new(targets, params->start, params->end,
+				      params->ntargets);
+	if (prange == NULL)
+		return -ENOMEM;
+
+	down_write(&hpolicy->sem);
+	ret = hbind_default_locked(hpolicy, params);
+	if (ret)
+		goto out;
+
+	interval_tree_insert(&prange->node, &hpolicy->ranges);
+
+out:
+	up_write(&hpolicy->sem);
+
+	return ret;
+}
+
+
 static long hbind_ioctl(struct file *file, unsigned cmd, unsigned long arg)
 {
 	uint32_t *targets, *_dtargets = NULL, _ftargets[HBIND_FIX_ARRAY];
@@ -418,6 +448,16 @@  static long hbind_ioctl(struct file *file, unsigned cmd, unsigned long arg)
 			if (ret)
 				goto out_mm;
 			break;
+		case HBIND_CMD_BIND:
+			if (ndwords != 1) {
+				ret = -EINVAL;
+				goto out_mm;
+			}
+			ret = hbind_bind(current->mm, &params,
+					 targets, atoms);
+			if (ret)
+				goto out_mm;
+			break;
 		default:
 			ret = -EINVAL;
 			goto out_mm;