Skip to contentSkip to conversation

Cache coherent device memory (CDM) with HMM v5

PATCH In review Jérôme Glisse 7 participants 43 messages Jul 13, 2017 – Nov 16, 2017

Subsystems (12)
lore
Share & tools
lore
#6 lore raw

PATCH 4/6 mm/memcontrol: allow to uncharge page without using page->lru field

In reply to Jérôme Glisse

HMM pages (private or public device pages) are ZONE_DEVICE page and thus you can not use page->lru fields of those pages. This patch re-arrange the uncharge to allow single page to be uncharge without modifying the lru field of the struct page.

There is no change to memcontrol logic, it is the same as it was before this patch.

Cc Johannes Weiner <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Vladimir Davydov <[email protected]>
---
 mm/memcontrol.c | 168 +++++++++++++++++++++++++++++++-------------------------
 1 file changed, 92 insertions(+), 76 deletions(-)
mm/memcontrol.c +92 -76
index 3df3c04d73ab..c709fdceac13 100644
@@ -5509,48 +5509,102 @@ void mem_cgroup_cancel_charge(struct page *page, struct mem_cgroup *memcg,
 	cancel_charge(memcg, nr_pages);
 }
 
-static void uncharge_batch(struct mem_cgroup *memcg, unsigned long pgpgout,
-			   unsigned long nr_anon, unsigned long nr_file,
-			   unsigned long nr_kmem, unsigned long nr_huge,
-			   unsigned long nr_shmem, struct page *dummy_page)
+struct uncharge_gather {
+	struct mem_cgroup *memcg;
+	unsigned long pgpgout;
+	unsigned long nr_anon;
+	unsigned long nr_file;
+	unsigned long nr_kmem;
+	unsigned long nr_huge;
+	unsigned long nr_shmem;
+	struct page *dummy_page;
+};
+
+static inline void uncharge_gather_clear(struct uncharge_gather *ug)
 {
-	unsigned long nr_pages = nr_anon + nr_file + nr_kmem;
+	memset(ug, 0, sizeof(*ug));
+}
+
+static void uncharge_batch(const struct uncharge_gather *ug)
+{
+	unsigned long nr_pages = ug->nr_anon + ug->nr_file + ug->nr_kmem;
 	unsigned long flags;
 
-	if (!mem_cgroup_is_root(memcg)) {
-		page_counter_uncharge(&memcg->memory, nr_pages);
+	if (!mem_cgroup_is_root(ug->memcg)) {
+		page_counter_uncharge(&ug->memcg->memory, nr_pages);
 		if (do_memsw_account())
-			page_counter_uncharge(&memcg->memsw, nr_pages);
-		if (!cgroup_subsys_on_dfl(memory_cgrp_subsys) && nr_kmem)
-			page_counter_uncharge(&memcg->kmem, nr_kmem);
-		memcg_oom_recover(memcg);
+			page_counter_uncharge(&ug->memcg->memsw, nr_pages);
+		if (!cgroup_subsys_on_dfl(memory_cgrp_subsys) && ug->nr_kmem)
+			page_counter_uncharge(&ug->memcg->kmem, ug->nr_kmem);
+		memcg_oom_recover(ug->memcg);
 	}
 
 	local_irq_save(flags);
-	__this_cpu_sub(memcg->stat->count[MEMCG_RSS], nr_anon);
-	__this_cpu_sub(memcg->stat->count[MEMCG_CACHE], nr_file);
-	__this_cpu_sub(memcg->stat->count[MEMCG_RSS_HUGE], nr_huge);
-	__this_cpu_sub(memcg->stat->count[NR_SHMEM], nr_shmem);
-	__this_cpu_add(memcg->stat->events[PGPGOUT], pgpgout);
-	__this_cpu_add(memcg->stat->nr_page_events, nr_pages);
-	memcg_check_events(memcg, dummy_page);
+	__this_cpu_sub(ug->memcg->stat->count[MEMCG_RSS], ug->nr_anon);
+	__this_cpu_sub(ug->memcg->stat->count[MEMCG_CACHE], ug->nr_file);
+	__this_cpu_sub(ug->memcg->stat->count[MEMCG_RSS_HUGE], ug->nr_huge);
+	__this_cpu_sub(ug->memcg->stat->count[NR_SHMEM], ug->nr_shmem);
+	__this_cpu_add(ug->memcg->stat->events[PGPGOUT], ug->pgpgout);
+	__this_cpu_add(ug->memcg->stat->nr_page_events, nr_pages);
+	memcg_check_events(ug->memcg, ug->dummy_page);
 	local_irq_restore(flags);
 
-	if (!mem_cgroup_is_root(memcg))
-		css_put_many(&memcg->css, nr_pages);
+	if (!mem_cgroup_is_root(ug->memcg))
+		css_put_many(&ug->memcg->css, nr_pages);
+}
+
+static void uncharge_page(struct page *page, struct uncharge_gather *ug)
+{
+	VM_BUG_ON_PAGE(PageLRU(page), page);
+	VM_BUG_ON_PAGE(!PageHWPoison(page) && page_count(page), page);
+
+	if (!page->mem_cgroup)
+		return;
+
+	/*
+	 * Nobody should be changing or seriously looking at
+	 * page->mem_cgroup at this point, we have fully
+	 * exclusive access to the page.
+	 */
+
+	if (ug->memcg != page->mem_cgroup) {
+		if (ug->memcg) {
+			uncharge_batch(ug);
+			uncharge_gather_clear(ug);
+		}
+		ug->memcg = page->mem_cgroup;
+	}
+
+	if (!PageKmemcg(page)) {
+		unsigned int nr_pages = 1;
+
+		if (PageTransHuge(page)) {
+			nr_pages <<= compound_order(page);
+			ug->nr_huge += nr_pages;
+		}
+		if (PageAnon(page))
+			ug->nr_anon += nr_pages;
+		else {
+			ug->nr_file += nr_pages;
+			if (PageSwapBacked(page))
+				ug->nr_shmem += nr_pages;
+		}
+		ug->pgpgout++;
+	} else {
+		ug->nr_kmem += 1 << compound_order(page);
+		__ClearPageKmemcg(page);
+	}
+
+	ug->dummy_page = page;
+	page->mem_cgroup = NULL;
 }
 
 static void uncharge_list(struct list_head *page_list)
 {
-	struct mem_cgroup *memcg = NULL;
-	unsigned long nr_shmem = 0;
-	unsigned long nr_anon = 0;
-	unsigned long nr_file = 0;
-	unsigned long nr_huge = 0;
-	unsigned long nr_kmem = 0;
-	unsigned long pgpgout = 0;
+	struct uncharge_gather ug;
 	struct list_head *next;
-	struct page *page;
+
+	uncharge_gather_clear(&ug);
 
 	/*
 	 * Note that the list can be a single page->lru; hence the
@@ -5558,57 +5612,16 @@ static void uncharge_list(struct list_head *page_list)
 	 */
 	next = page_list->next;
 	do {
+		struct page *page;
+
 		page = list_entry(next, struct page, lru);
 		next = page->lru.next;
 
-		VM_BUG_ON_PAGE(PageLRU(page), page);
-		VM_BUG_ON_PAGE(!PageHWPoison(page) && page_count(page), page);
-
-		if (!page->mem_cgroup)
-			continue;
-
-		/*
-		 * Nobody should be changing or seriously looking at
-		 * page->mem_cgroup at this point, we have fully
-		 * exclusive access to the page.
-		 */
-
-		if (memcg != page->mem_cgroup) {
-			if (memcg) {
-				uncharge_batch(memcg, pgpgout, nr_anon, nr_file,
-					       nr_kmem, nr_huge, nr_shmem, page);
-				pgpgout = nr_anon = nr_file = nr_kmem = 0;
-				nr_huge = nr_shmem = 0;
-			}
-			memcg = page->mem_cgroup;
-		}
-
-		if (!PageKmemcg(page)) {
-			unsigned int nr_pages = 1;
-
-			if (PageTransHuge(page)) {
-				nr_pages <<= compound_order(page);
-				nr_huge += nr_pages;
-			}
-			if (PageAnon(page))
-				nr_anon += nr_pages;
-			else {
-				nr_file += nr_pages;
-				if (PageSwapBacked(page))
-					nr_shmem += nr_pages;
-			}
-			pgpgout++;
-		} else {
-			nr_kmem += 1 << compound_order(page);
-			__ClearPageKmemcg(page);
-		}
-
-		page->mem_cgroup = NULL;
+		uncharge_page(page, &ug);
 	} while (next != page_list);
 
-	if (memcg)
-		uncharge_batch(memcg, pgpgout, nr_anon, nr_file,
-			       nr_kmem, nr_huge, nr_shmem, page);
+	if (ug.memcg)
+		uncharge_batch(&ug);
 }
 
 /**
@@ -5620,6 +5633,8 @@ static void uncharge_list(struct list_head *page_list)
  */
 void mem_cgroup_uncharge(struct page *page)
 {
+	struct uncharge_gather ug;
+
 	if (mem_cgroup_disabled())
 		return;
 
@@ -5627,8 +5642,9 @@ void mem_cgroup_uncharge(struct page *page)
 	if (!page->mem_cgroup)
 		return;
 
-	INIT_LIST_HEAD(&page->lru);
-	uncharge_list(&page->lru);
+	uncharge_gather_clear(&ug);
+	uncharge_page(page, &ug);
+	uncharge_batch(&ug);
 }
 
 /**
Signature · 1 line
2.13.0
#8 lore raw

PATCH 5/6 mm/memcontrol: support MEMORY_DEVICE_PRIVATE and MEMORY_DEVICE_PUBLIC v3

In reply to Jérôme Glisse

HMM pages (private or public device pages) are ZONE_DEVICE page and thus need special handling when it comes to lru or refcount. This patch make sure that memcontrol properly handle those when it face them. Those pages are use like regular pages in a process address space either as anonymous page or as file back page. So from memcg point of view we want to handle them like regular page for now at least.

Changed since v2:
- s/host/public
Changed since v1:
- s/public/host
- add comments explaining how device memory behave and why

Cc Johannes Weiner <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Vladimir Davydov <[email protected]>
---
 kernel/memremap.c |  2 ++
 mm/memcontrol.c   | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++-----
 2 files changed, 60 insertions(+), 5 deletions(-)
kernel/memremap.c +2 -0
index 25c098151ed2..4d74b4a4f8f5 100644
@@ -479,6 +479,8 @@ void put_zone_device_private_or_public_page(struct page *page)
 		__ClearPageActive(page);
 		__ClearPageWaiters(page);
 
+		mem_cgroup_uncharge(page);
+
 		page->pgmap->page_free(page, page->pgmap->data);
 	}
 	else if (!count)
mm/memcontrol.c +58 -5

139 lines not on this page · raw message

Signature · 7 lines
2.13.0

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

cover Cache coherent device memory (CDM) with HMM v5

Sorry i made horrible mistake on names in v4, i completly miss- understood the suggestion. So here i repost with proper naming. This is the only change since v3. Again sorry about the noise with v4.

Changes since v4:
- s/DEVICE_HOST/DEVICE_PUBLIC

Git tree:
https://cgit.freedesktop.org/~glisse/linux/log/?h=hmm-cdm-v5

Cache coherent device memory apply to architecture with system bus like CAPI or CCIX. Device connected to such system bus can expose their memory to the system and allow cache coherent access to it from the CPU.

Even if for all intent and purposes device memory behave like regular memory, we still want to manage it in isolation from regular memory. Several reasons for that, first and foremost this memory is less reliable than regular memory if the device hangs because of invalid commands we can loose access to device memory. Second CPU access to this memory is expected to be slower than to regular memory. Third having random memory into device means that some of the bus bandwith wouldn't be available to the device but would be use by CPU access.

This is why we want to manage such memory in isolation from regular memory. Kernel should not try to use this memory even as last resort when running out of memory, at least for now.

This patchset add a new type of ZONE_DEVICE memory (DEVICE_HOST) that is use to represent CDM memory. This patchset build on top of the HMM patchset that already introduce a new type of ZONE_DEVICE memory for private device memory (see HMM patchset).

The end result is that with this patchset if a device is in use in a process you might have private anonymous memory or file back page memory using ZONE_DEVICE (DEVICE_HOST). Thus care must be taken to not overwritte lru fields of such pages.

Hence all core mm changes are done to address assumption that any process memory is back by a regular struct page that is part of the lru. ZONE_DEVICE page are not on the lru and the lru pointer of struct page are use to store device specific informations.

Thus this patchset update all code path that would make assumptions about lruness of a process page.

patch 01 - rename DEVICE_PUBLIC to DEVICE_HOST to free DEVICE_PUBLIC name patch 02 - add DEVICE_PUBLIC type to ZONE_DEVICE (all core mm changes) patch 03 - add an helper to HMM for hotplug of CDM memory patch 04 - preparatory patch for memory controller changes (memch) patch 05 - update memory controller to properly handle
ZONE_DEVICE pages when uncharging
patch 06 - documentation patch

Previous posting:
v1 https://lkml.org/lkml/2017/4/7/638
v2 https://lwn.net/Articles/725412/
v3 https://lwn.net/Articles/727114/
v4 https://lwn.net/Articles/727692/

JA(C)rA'me Glisse (6):
mm/zone-device: rename DEVICE_PUBLIC to DEVICE_HOST mm/device-public-memory: device memory cache coherent with CPU v4 mm/hmm: add new helper to hotplug CDM memory region v3 mm/memcontrol: allow to uncharge page without using page->lru field mm/memcontrol: support MEMORY_DEVICE_PRIVATE and MEMORY_DEVICE_PUBLIC

    v3

mm/hmm: documents how device memory is accounted in rss and memcg

 Documentation/vm/hmm.txt |  40 ++++++++
 fs/proc/task_mmu.c       |   2 +-
 include/linux/hmm.h      |   7 +-
 include/linux/ioport.h   |   1 +
 include/linux/memremap.h |  25 ++++-
 include/linux/mm.h       |  20 ++--
 kernel/memremap.c        |  19 ++--
 mm/Kconfig               |  11 +++
 mm/gup.c                 |   7 ++
 mm/hmm.c                 |  89 ++++++++++++++++--
 mm/madvise.c             |   2 +-
 mm/memcontrol.c          | 231 ++++++++++++++++++++++++++++++-----------------
 mm/memory.c              |  46 +++++++++-
 mm/migrate.c             |  57 +++++++-----
 mm/swap.c                |  11 +++
 15 files changed, 434 insertions(+), 134 deletions(-)
Signature · 7 lines
2.13.0

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

PATCH 1/6 mm/zone-device: rename DEVICE_PUBLIC to DEVICE_HOST

Existing user of ZONE_DEVICE in its DEVICE_PUBLIC variant are not tie to specific device and behave more like host memory. This patch rename DEVICE_PUBLIC to DEVICE_HOST and free the name DEVICE_PUBLIC to be use for cache coherent device memory that has strong tie with the device on which the memory is (for instance on board GPU memory).

There is no functional change here.

Cc Dan Williams <[email protected]>
Cc Ross Zwisler <[email protected]>
---
 include/linux/memremap.h | 4 ++--
 kernel/memremap.c        | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)
include/linux/memremap.h +2 -2
index 57546a07a558..ae5ff92f72b4 100644
@@ -41,7 +41,7 @@ static inline struct vmem_altmap *to_vmem_altmap(unsigned long memmap_start)
  * Specialize ZONE_DEVICE memory into multiple types each having differents
  * usage.
  *
- * MEMORY_DEVICE_PUBLIC:
+ * MEMORY_DEVICE_HOST:
  * Persistent device memory (pmem): struct page might be allocated in different
  * memory and architecture might want to perform special actions. It is similar
  * to regular memory, in that the CPU can access it transparently. However,
@@ -59,7 +59,7 @@ static inline struct vmem_altmap *to_vmem_altmap(unsigned long memmap_start)
  * include/linux/hmm.h and Documentation/vm/hmm.txt.
  */
 enum memory_type {
-	MEMORY_DEVICE_PUBLIC = 0,
+	MEMORY_DEVICE_HOST = 0,
 	MEMORY_DEVICE_PRIVATE,
 };
 
kernel/memremap.c +1 -1
index b9baa6c07918..4e07525aa273 100644
@@ -350,7 +350,7 @@ void *devm_memremap_pages(struct device *dev, struct resource *res,
 	}
 	pgmap->ref = ref;
 	pgmap->res = &page_map->res;
-	pgmap->type = MEMORY_DEVICE_PUBLIC;
+	pgmap->type = MEMORY_DEVICE_HOST;
 	pgmap->page_fault = NULL;
 	pgmap->page_free = NULL;
 	pgmap->data = NULL;
Signature · 7 lines
2.13.0

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

PATCH 2/6 mm/device-public-memory: device memory cache coherent with CPU v4

In reply to Jérôme Glisse

Platform with advance system bus (like CAPI or CCIX) allow device memory to be accessible from CPU in a cache coherent fashion. Add a new type of ZONE_DEVICE to represent such memory. The use case are the same as for the un-addressable device memory but without all the corners cases.

Changed since v3:
- s/public/public (going back)
Changed since v2:
- s/public/public
- add proper include in migrate.c and drop useless #if/#endif
Changed since v1:
- Kconfig and #if/#else cleanup

Cc Balbir Singh <[email protected]>
Cc Aneesh Kumar <[email protected]>
Cc Paul E. McKenney <[email protected]>
Cc Benjamin Herrenschmidt <[email protected]>
Cc Dan Williams <[email protected]>
Cc Ross Zwisler <[email protected]>
---
 fs/proc/task_mmu.c       |  2 +-
 include/linux/hmm.h      |  4 ++--
 include/linux/ioport.h   |  1 +
 include/linux/memremap.h | 21 ++++++++++++++++++
 include/linux/mm.h       | 20 ++++++++++-------
 kernel/memremap.c        | 15 ++++++++-----
 mm/Kconfig               | 11 ++++++++++
 mm/gup.c                 |  7 ++++++
 mm/hmm.c                 |  4 ++--
 mm/madvise.c             |  2 +-
 mm/memory.c              | 46 +++++++++++++++++++++++++++++++++-----
 mm/migrate.c             | 57 ++++++++++++++++++++++++++++++------------------
 mm/swap.c                | 11 ++++++++++
 13 files changed, 156 insertions(+), 45 deletions(-)
fs/proc/task_mmu.c +1 -1
index 957b6ea80d5f..1f38f2c7cc34 100644
@@ -1182,7 +1182,7 @@ static pagemap_entry_t pte_to_pagemap_entry(struct pagemapread *pm,
 		if (pm->show_pfn)
 			frame = pte_pfn(pte);
 		flags |= PM_PRESENT;
-		page = vm_normal_page(vma, addr, pte);
+		page = _vm_normal_page(vma, addr, pte, true);
 		if (pte_soft_dirty(pte))
 			flags |= PM_SOFT_DIRTY;
 	} else if (is_swap_pte(pte)) {
include/linux/hmm.h +2 -2
index 458d0d6d82f3..a40288309fd2 100644
@@ -327,7 +327,7 @@ int hmm_vma_fault(struct vm_area_struct *vma,
 #endif /* IS_ENABLED(CONFIG_HMM_MIRROR) */
 
 
-#if IS_ENABLED(CONFIG_DEVICE_PRIVATE)
+#if IS_ENABLED(CONFIG_DEVICE_PRIVATE) ||  IS_ENABLED(CONFIG_DEVICE_PUBLIC)
 struct hmm_devmem;
 
 struct page *hmm_vma_alloc_locked_page(struct vm_area_struct *vma,
@@ -443,7 +443,7 @@ struct hmm_device {
  */
 struct hmm_device *hmm_device_new(void *drvdata);
 void hmm_device_put(struct hmm_device *hmm_device);
-#endif /* IS_ENABLED(CONFIG_DEVICE_PRIVATE) */
+#endif /* CONFIG_DEVICE_PRIVATE || CONFIG_DEVICE_PUBLIC */
 
 
 /* Below are for HMM internal use only! Not to be used by device driver! */
include/linux/ioport.h +1 -0
index 3a4f69137bc2..f5cf32e80041 100644
@@ -131,6 +131,7 @@ enum {
 	IORES_DESC_PERSISTENT_MEMORY		= 4,
 	IORES_DESC_PERSISTENT_MEMORY_LEGACY	= 5,
 	IORES_DESC_DEVICE_PRIVATE_MEMORY	= 6,
+	IORES_DESC_DEVICE_PUBLIC_MEMORY		= 7,
 };
 
 /* helpers to define resources */
include/linux/memremap.h +21 -0
index ae5ff92f72b4..c7b4c75ae3f8 100644
@@ -57,10 +57,18 @@ static inline struct vmem_altmap *to_vmem_altmap(unsigned long memmap_start)
  *
  * A more complete discussion of unaddressable memory may be found in
  * include/linux/hmm.h and Documentation/vm/hmm.txt.
+ *
+ * MEMORY_DEVICE_PUBLIC:
+ * Device memory that is cache coherent from device and CPU point of view. This
+ * is use on platform that have an advance system bus (like CAPI or CCIX). A
+ * driver can hotplug the device memory using ZONE_DEVICE and with that memory
+ * type. Any page of a process can be migrated to such memory. However no one
+ * should be allow to pin such memory so that it can always be evicted.
  */
 enum memory_type {
 	MEMORY_DEVICE_HOST = 0,
 	MEMORY_DEVICE_PRIVATE,
+	MEMORY_DEVICE_PUBLIC,
 };
 
 /*
@@ -92,6 +100,8 @@ enum memory_type {
  * The page_free() callback is called once the page refcount reaches 1
  * (ZONE_DEVICE pages never reach 0 refcount unless there is a refcount bug.
  * This allows the device driver to implement its own memory management.)
+ *
+ * For MEMORY_DEVICE_PUBLIC only the page_free() callback matter.
  */
 typedef int (*dev_page_fault_t)(struct vm_area_struct *vma,
 				unsigned long addr,
@@ -134,6 +144,12 @@ static inline bool is_device_private_page(const struct page *page)
 	return is_zone_device_page(page) &&
 		page->pgmap->type == MEMORY_DEVICE_PRIVATE;
 }
+
+static inline bool is_device_public_page(const struct page *page)
+{
+	return is_zone_device_page(page) &&
+		page->pgmap->type == MEMORY_DEVICE_PUBLIC;
+}
 #else
 static inline void *devm_memremap_pages(struct device *dev,
 		struct resource *res, struct percpu_ref *ref,
@@ -157,6 +173,11 @@ static inline bool is_device_private_page(const struct page *page)
 {
 	return false;
 }
+
+static inline bool is_device_public_page(const struct page *page)
+{
+	return false;
+}
 #endif
 
 /**
include/linux/mm.h +12 -8
index 330a216ac315..980354828177 100644
@@ -796,15 +796,16 @@ static inline bool is_zone_device_page(const struct page *page)
 }
 #endif
 
-#ifdef CONFIG_DEVICE_PRIVATE
-void put_zone_device_private_page(struct page *page);
+#if IS_ENABLED(CONFIG_DEVICE_PRIVATE) ||  IS_ENABLED(CONFIG_DEVICE_PUBLIC)
+void put_zone_device_private_or_public_page(struct page *page);
 #else
-static inline void put_zone_device_private_page(struct page *page)
+static inline void put_zone_device_private_or_public_page(struct page *page)
 {
 }
-#endif
+#endif /* CONFIG_DEVICE_PRIVATE || CONFIG_DEVICE_PUBLIC */
 
 static inline bool is_device_private_page(const struct page *page);
+static inline bool is_device_public_page(const struct page *page);
 
 DECLARE_STATIC_KEY_FALSE(device_private_key);
 
@@ -830,8 +831,9 @@ static inline void put_page(struct page *page)
 	 * include/linux/memremap.h and HMM for details.
 	 */
 	if (static_branch_unlikely(&device_private_key) &&
-	    unlikely(is_device_private_page(page))) {
-		put_zone_device_private_page(page);
+	    unlikely(is_device_private_page(page) ||
+		     is_device_public_page(page))) {
+		put_zone_device_private_or_public_page(page);
 		return;
 	}
 
@@ -1220,8 +1222,10 @@ struct zap_details {
 	pgoff_t last_index;			/* Highest page->index to unmap */
 };
 
-struct page *vm_normal_page(struct vm_area_struct *vma, unsigned long addr,
-		pte_t pte);
+struct page *_vm_normal_page(struct vm_area_struct *vma, unsigned long addr,
+			     pte_t pte, bool with_public_device);
+#define vm_normal_page(vma, addr, pte) _vm_normal_page(vma, addr, pte, false)
+
 struct page *vm_normal_page_pmd(struct vm_area_struct *vma, unsigned long addr,
 				pmd_t pmd);
 
kernel/memremap.c +10 -5
index 4e07525aa273..25c098151ed2 100644
@@ -465,8 +465,8 @@ struct vmem_altmap *to_vmem_altmap(unsigned long memmap_start)
 #endif /* CONFIG_ZONE_DEVICE */
 
 
-#ifdef CONFIG_DEVICE_PRIVATE
-void put_zone_device_private_page(struct page *page)
+#if IS_ENABLED(CONFIG_DEVICE_PRIVATE) ||  IS_ENABLED(CONFIG_DEVICE_PUBLIC)
+void put_zone_device_private_or_public_page(struct page *page)
 {
 	int count = page_ref_dec_return(page);
 
@@ -474,10 +474,15 @@ void put_zone_device_private_page(struct page *page)
 	 * If refcount is 1 then page is freed and refcount is stable as nobody
 	 * holds a reference on the page.
 	 */
-	if (count == 1)
+	if (count == 1) {
+		/* Clear Active bit in case of parallel mark_page_accessed */
+		__ClearPageActive(page);
+		__ClearPageWaiters(page);
+
 		page->pgmap->page_free(page, page->pgmap->data);
+	}
 	else if (!count)
 		__put_page(page);
 }
-EXPORT_SYMBOL(put_zone_device_private_page);
-#endif /* CONFIG_DEVICE_PRIVATE */
+EXPORT_SYMBOL(put_zone_device_private_or_public_page);
+#endif /* CONFIG_DEVICE_PRIVATE || CONFIG_DEVICE_PUBLIC */
mm/Kconfig +11 -0
index 5960617ef781..424ef60547f8 100644
@@ -716,12 +716,23 @@ config ZONE_DEVICE
 config DEVICE_PRIVATE
 	bool "Unaddressable device memory (GPU memory, ...)"
 	depends on ARCH_HAS_HMM
+	select HMM
 
 	help
 	  Allows creation of struct pages to represent unaddressable device
 	  memory; i.e., memory that is only accessible from the device (or
 	  group of devices).
 
+config DEVICE_PUBLIC
+	bool "Addressable device memory (like GPU memory)"
+	depends on ARCH_HAS_HMM
+	select HMM
+
+	help
+	  Allows creation of struct pages to represent addressable device
+	  memory; i.e., memory that is accessible from both the device and
+	  the CPU
+
 config FRAME_VECTOR
 	bool
 
mm/gup.c +7 -0
index 23f01c40c88f..2f8e8604ff80 100644
@@ -438,6 +438,13 @@ static int get_gate_page(struct mm_struct *mm, unsigned long address,
 		if ((gup_flags & FOLL_DUMP) || !is_zero_pfn(pte_pfn(*pte)))
 			goto unmap;
 		*page = pte_page(*pte);
+
+		/*
+		 * This should never happen (a device public page in the gate
+		 * area).
+		 */
+		if (is_device_public_page(*page))
+			goto unmap;
 	}
 	get_page(*page);
 out:
mm/hmm.c +2 -2
index 4e01c9ba9cc1..eadf70829c34 100644
@@ -747,7 +747,7 @@ EXPORT_SYMBOL(hmm_vma_fault);
 #endif /* IS_ENABLED(CONFIG_HMM_MIRROR) */
 
 
-#if IS_ENABLED(CONFIG_DEVICE_PRIVATE)
+#if IS_ENABLED(CONFIG_DEVICE_PRIVATE) ||  IS_ENABLED(CONFIG_DEVICE_PUBLIC)
 struct page *hmm_vma_alloc_locked_page(struct vm_area_struct *vma,
 				       unsigned long addr)
 {
@@ -1190,4 +1190,4 @@ static int __init hmm_init(void)
 }
 
 device_initcall(hmm_init);
-#endif /* IS_ENABLED(CONFIG_DEVICE_PRIVATE) */
+#endif /* CONFIG_DEVICE_PRIVATE || CONFIG_DEVICE_PUBLIC */
mm/madvise.c +1 -1
index 9976852f1e1c..197277156ce3 100644
@@ -343,7 +343,7 @@ static int madvise_free_pte_range(pmd_t *pmd, unsigned long addr,
 			continue;
 		}
 
-		page = vm_normal_page(vma, addr, ptent);
+		page = _vm_normal_page(vma, addr, ptent, true);
 		if (!page)
 			continue;
 
mm/memory.c +41 -5

70 lines not on this page · raw message

mm/migrate.c +36 -21

111 lines not on this page · raw message

mm/swap.c +11 -0
index 60b1d2a75852..eac0e35f854f 100644
@@ -765,6 +765,17 @@ void release_pages(struct page **pages, int nr, bool cold)
 		if (is_huge_zero_page(page))
 			continue;
 
+		/* Device public page can not be huge page */
+		if (is_device_public_page(page)) {
+			if (locked_pgdat) {
+				spin_unlock_irqrestore(&locked_pgdat->lru_lock,
+						       flags);
+				locked_pgdat = NULL;
+			}
+			put_zone_device_private_or_public_page(page);
+			continue;
+		}
+
 		page = compound_head(page);
 		if (!put_page_testzero(page))
 			continue;
Signature · 7 lines
2.13.0

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

PATCH 3/6 mm/hmm: add new helper to hotplug CDM memory region v3

In reply to Jérôme Glisse

Unlike unaddressable memory, coherent device memory has a real resource associated with it on the system (as CPU can address it). Add a new helper to hotplug such memory within the HMM framework.

Changed since v2:
- s/host/public
Changed since v1:
- s/public/host

---
 include/linux/hmm.h |  3 ++
 mm/hmm.c            | 85 +++++++++++++++++++++++++++++++++++++++++++++++++----
 2 files changed, 83 insertions(+), 5 deletions(-)
include/linux/hmm.h +3 -0
index a40288309fd2..e44cb8edb137 100644
@@ -392,6 +392,9 @@ struct hmm_devmem {
 struct hmm_devmem *hmm_devmem_add(const struct hmm_devmem_ops *ops,
 				  struct device *device,
 				  unsigned long size);
+struct hmm_devmem *hmm_devmem_add_resource(const struct hmm_devmem_ops *ops,
+					   struct device *device,
+					   struct resource *res);
 void hmm_devmem_remove(struct hmm_devmem *devmem);
 
 /*
mm/hmm.c +80 -5

125 lines not on this page · raw message

Signature · 7 lines
2.13.0

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

PATCH 6/6 mm/hmm: documents how device memory is accounted in rss and memcg

In reply to Jérôme Glisse

For now we account device memory exactly like a regular page in respect to rss counters and memory cgroup. We do this so that any existing application that starts using device memory without knowing about it will keep running unimpacted. This also simplify migration code.

We will likely revisit this choice once we gain more experience with how device memory is use and how it impacts overall memory resource management. For now we believe this is a good enough choice.

Note that device memory can not be pin. Nor by device driver, nor by GUP thus device memory can always be free and unaccounted when a process exit.

---
 Documentation/vm/hmm.txt | 40 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)
Documentation/vm/hmm.txt +40 -0
index 192dcdb38bd1..4d3aac9f4a5d 100644
@@ -15,6 +15,15 @@ section present the new migration helper that allow to leverage the device DMA
 engine.
 
 
+1) Problems of using device specific memory allocator:
+2) System bus, device memory characteristics
+3) Share address space and migration
+4) Address space mirroring implementation and API
+5) Represent and manage device memory from core kernel point of view
+6) Migrate to and from device memory
+7) Memory cgroup (memcg) and rss accounting
+
+
 -------------------------------------------------------------------------------
 
 1) Problems of using device specific memory allocator:
@@ -342,3 +351,34 @@ that happens then the finalize_and_map() can catch any pages that was not
 migrated. Note those page were still copied to new page and thus we wasted
 bandwidth but this is considered as a rare event and a price that we are
 willing to pay to keep all the code simpler.
+
+
+-------------------------------------------------------------------------------
+
+7) Memory cgroup (memcg) and rss accounting
+
+For now device memory is accounted as any regular page in rss counters (either
+anonymous if device page is use for anonymous, file if device page is use for
+file back page or shmem if device page is use for share memory). This is a
+deliberate choice to keep existing application that might start using device
+memory without knowing about it to keep runing unimpacted.
+
+Drawbacks is that OOM killer might kill an application using a lot of device
+memory and not a lot of regular system memory and thus not freeing much system
+memory. We want to gather more real world experience on how application and
+system react under memory pressure in the presence of device memory before
+deciding to account device memory differently.
+
+
+Same decision was made for memory cgroup. Device memory page are accounted
+against same memory cgroup a regular page would be accounted to. This does
+simplify migration to and from device memory. This also means that migration
+back from device memory to regular memory can not fail because it would
+go above memory cgroup limit. We might revisit this choice latter on once we
+get more experience in how device memory is use and its impact on memory
+resource control.
+
+
+Note that device memory can never be pin nor by device driver nor through GUP
+and thus such memory is always free upon process exit. Or when last reference
+is drop in case of share memory or file back memory.
Signature · 7 lines
2.13.0

--
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>
Acked-by on v1 2/6
#4 lore raw

Re: [PATCH 2/6] mm/device-public-memory: device memory cache coherent with CPU v4

In reply to Jérôme Glisse
Quoted 14 lines · JA(C)rA'me Glisse

Platform with advance system bus (like CAPI or CCIX) allow device memory to be accessible from CPU in a cache coherent fashion. Add a new type of ZONE_DEVICE to represent such memory. The use case are the same as for the un-addressable device memory but without all the corners cases.

Changed since v3:
- s/public/public (going back)
Changed since v2:
- s/public/public
- add proper include in migrate.c and drop useless #if/#endif
Changed since v1:
- Kconfig and #if/#else cleanup

Quoted 8 lines
Cc Balbir Singh <[email protected]>
Cc Aneesh Kumar <[email protected]>
Cc Paul E. McKenney <[email protected]>
Cc Benjamin Herrenschmidt <[email protected]>
Cc Dan Williams <[email protected]>
Cc Ross Zwisler <[email protected]>

---

--
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 Acked-by on v1 6/6
#11 lore raw

Re: [PATCH 6/6] mm/hmm: documents how device memory is accounted in rss and memcg

In reply to Jérôme Glisse
Quoted 6 lines · Jerome Glisse

For now we account device memory exactly like a regular page in respect to rss counters and memory cgroup. We do this so that any existing application that starts using device memory without knowing about it will keep running unimpacted. This also simplify migration code.

Quoted 7 lines

We will likely revisit this choice once we gain more experience with how device memory is use and how it impacts overall memory resource management. For now we believe this is a good enough choice.

Note that device memory can not be pin. Nor by device driver, nor by GUP thus device memory can always be free and unaccounted when a process exit.

I have to look at the implementation but this gives a good idea of what is going on and why.

Quoted 2 lines
Quoted 61 lines
---
 Documentation/vm/hmm.txt | 40 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)
Documentation/vm/hmm.txt +40 -0
index 192dcdb38bd1..4d3aac9f4a5d 100644
@@ -15,6 +15,15 @@ section present the new migration helper that allow to leverage the device DMA
 engine.
 
 
+1) Problems of using device specific memory allocator:
+2) System bus, device memory characteristics
+3) Share address space and migration
+4) Address space mirroring implementation and API
+5) Represent and manage device memory from core kernel point of view
+6) Migrate to and from device memory
+7) Memory cgroup (memcg) and rss accounting
+
+
 -------------------------------------------------------------------------------
 
 1) Problems of using device specific memory allocator:
@@ -342,3 +351,34 @@ that happens then the finalize_and_map() can catch any pages that was not
 migrated. Note those page were still copied to new page and thus we wasted
 bandwidth but this is considered as a rare event and a price that we are
 willing to pay to keep all the code simpler.
+
+
+-------------------------------------------------------------------------------
+
+7) Memory cgroup (memcg) and rss accounting
+
+For now device memory is accounted as any regular page in rss counters (either
+anonymous if device page is use for anonymous, file if device page is use for
+file back page or shmem if device page is use for share memory). This is a
+deliberate choice to keep existing application that might start using device
+memory without knowing about it to keep runing unimpacted.
+
+Drawbacks is that OOM killer might kill an application using a lot of device
+memory and not a lot of regular system memory and thus not freeing much system
+memory. We want to gather more real world experience on how application and
+system react under memory pressure in the presence of device memory before
+deciding to account device memory differently.
+
+
+Same decision was made for memory cgroup. Device memory page are accounted
+against same memory cgroup a regular page would be accounted to. This does
+simplify migration to and from device memory. This also means that migration
+back from device memory to regular memory can not fail because it would
+go above memory cgroup limit. We might revisit this choice latter on once we
+get more experience in how device memory is use and its impact on memory
+resource control.
+
+
+Note that device memory can never be pin nor by device driver nor through GUP
+and thus such memory is always free upon process exit. Or when last reference
+is drop in case of share memory or file back memory.
Signature · 1 line
2.13.0
Signature · 8 lines
Michal Hocko
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>
Acked-by on v1 1/6
#2 lore raw

Re: [PATCH 1/6] mm/zone-device: rename DEVICE_PUBLIC to DEVICE_HOST

In reply to Jérôme Glisse
Quoted 6 lines · JA(C)rA'me Glisse

Existing user of ZONE_DEVICE in its DEVICE_PUBLIC variant are not tie to specific device and behave more like host memory. This patch rename DEVICE_PUBLIC to DEVICE_HOST and free the name DEVICE_PUBLIC to be use for cache coherent device memory that has strong tie with the device on which the memory is (for instance on board GPU memory).

Quoted 6 lines

There is no functional change here.

Cc Dan Williams <[email protected]>
Cc Ross Zwisler <[email protected]>

---

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

Acked-by on v1 4/6
#7 lore raw

Re: [PATCH 4/6] mm/memcontrol: allow to uncharge page without using page->lru field

In reply to Jérôme Glisse
Quoted 8 lines · Jérôme Glisse

HMM pages (private or public device pages) are ZONE_DEVICE page and thus you can not use page->lru fields of those pages. This patch re-arrange the uncharge to allow single page to be uncharge without modifying the lru field of the struct page.

There is no change to memcontrol logic, it is the same as it was before this patch.

Quoted 6 lines
Cc Johannes Weiner <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Vladimir Davydov <[email protected]>

---

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

Acked-by on v1 5/6
#9 lore raw

Re: [PATCH 5/6] mm/memcontrol: support MEMORY_DEVICE_PRIVATE and MEMORY_DEVICE_PUBLIC v3

In reply to Jérôme Glisse
Quoted 14 lines · Jérôme Glisse

HMM pages (private or public device pages) are ZONE_DEVICE page and thus need special handling when it comes to lru or refcount. This patch make sure that memcontrol properly handle those when it face them. Those pages are use like regular pages in a process address space either as anonymous page or as file back page. So from memcg point of view we want to handle them like regular page for now at least.

Changed since v2:
- s/host/public
Changed since v1:
- s/public/host
- add comments explaining how device memory behave and why

Quoted 6 lines
Cc Johannes Weiner <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Vladimir Davydov <[email protected]>

---

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

#12 lore raw
In reply to Jérôme Glisse
Quoted 26 lines · Jérôme Glisse

Sorry i made horrible mistake on names in v4, i completly miss- understood the suggestion. So here i repost with proper naming. This is the only change since v3. Again sorry about the noise with v4.

Changes since v4:
- s/DEVICE_HOST/DEVICE_PUBLIC

Git tree:
https://cgit.freedesktop.org/~glisse/linux/log/?h=hmm-cdm-v5

Cache coherent device memory apply to architecture with system bus like CAPI or CCIX. Device connected to such system bus can expose their memory to the system and allow cache coherent access to it from the CPU.

Even if for all intent and purposes device memory behave like regular memory, we still want to manage it in isolation from regular memory. Several reasons for that, first and foremost this memory is less reliable than regular memory if the device hangs because of invalid commands we can loose access to device memory. Second CPU access to this memory is expected to be slower than to regular memory. Third having random memory into device means that some of the bus bandwith wouldn't be available to the device but would be use by CPU access.

Quoted 4 lines

This is why we want to manage such memory in isolation from regular memory. Kernel should not try to use this memory even as last resort when running out of memory, at least for now.

I think set a very large node distance for "Cache Coherent Device Memory" may be a easier way to address these concerns.

--
Regards,
Bob Liu

Quoted 58 lines

This patchset add a new type of ZONE_DEVICE memory (DEVICE_HOST) that is use to represent CDM memory. This patchset build on top of the HMM patchset that already introduce a new type of ZONE_DEVICE memory for private device memory (see HMM patchset).

The end result is that with this patchset if a device is in use in a process you might have private anonymous memory or file back page memory using ZONE_DEVICE (DEVICE_HOST). Thus care must be taken to not overwritte lru fields of such pages.

Hence all core mm changes are done to address assumption that any process memory is back by a regular struct page that is part of the lru. ZONE_DEVICE page are not on the lru and the lru pointer of struct page are use to store device specific informations.

Thus this patchset update all code path that would make assumptions about lruness of a process page.

patch 01 - rename DEVICE_PUBLIC to DEVICE_HOST to free DEVICE_PUBLIC name patch 02 - add DEVICE_PUBLIC type to ZONE_DEVICE (all core mm changes) patch 03 - add an helper to HMM for hotplug of CDM memory patch 04 - preparatory patch for memory controller changes (memch) patch 05 - update memory controller to properly handle
ZONE_DEVICE pages when uncharging
patch 06 - documentation patch

Previous posting:
v1 https://lkml.org/lkml/2017/4/7/638
v2 https://lwn.net/Articles/725412/
v3 https://lwn.net/Articles/727114/
v4 https://lwn.net/Articles/727692/

Jérôme Glisse (6):
mm/zone-device: rename DEVICE_PUBLIC to DEVICE_HOST mm/device-public-memory: device memory cache coherent with CPU v4 mm/hmm: add new helper to hotplug CDM memory region v3 mm/memcontrol: allow to uncharge page without using page->lru field mm/memcontrol: support MEMORY_DEVICE_PRIVATE and MEMORY_DEVICE_PUBLIC

    v3

mm/hmm: documents how device memory is accounted in rss and memcg

 Documentation/vm/hmm.txt |  40 ++++++++
 fs/proc/task_mmu.c       |   2 +-
 include/linux/hmm.h      |   7 +-
 include/linux/ioport.h   |   1 +
 include/linux/memremap.h |  25 ++++-
 include/linux/mm.h       |  20 ++--
 kernel/memremap.c        |  19 ++--
 mm/Kconfig               |  11 +++
 mm/gup.c                 |   7 ++
 mm/hmm.c                 |  89 ++++++++++++++++--
 mm/madvise.c             |   2 +-
 mm/memcontrol.c          | 231 ++++++++++++++++++++++++++++++-----------------
 mm/memory.c              |  46 +++++++++-
 mm/migrate.c             |  57 +++++++-----
 mm/swap.c                |  11 +++
 15 files changed, 434 insertions(+), 134 deletions(-)
#13 lore raw
Quoted 27 lines · Bob Liu
Quoted 26 lines · Jérôme Glisse

Sorry i made horrible mistake on names in v4, i completly miss- understood the suggestion. So here i repost with proper naming. This is the only change since v3. Again sorry about the noise with v4.

Changes since v4:
- s/DEVICE_HOST/DEVICE_PUBLIC

Git tree:
https://cgit.freedesktop.org/~glisse/linux/log/?h=hmm-cdm-v5

Cache coherent device memory apply to architecture with system bus like CAPI or CCIX. Device connected to such system bus can expose their memory to the system and allow cache coherent access to it from the CPU.

Even if for all intent and purposes device memory behave like regular memory, we still want to manage it in isolation from regular memory. Several reasons for that, first and foremost this memory is less reliable than regular memory if the device hangs because of invalid commands we can loose access to device memory. Second CPU access to this memory is expected to be slower than to regular memory. Third having random memory into device means that some of the bus bandwith wouldn't be available to the device but would be use by CPU access.

Quoted 7 lines
Quoted 4 lines

This is why we want to manage such memory in isolation from regular memory. Kernel should not try to use this memory even as last resort when running out of memory, at least for now.

I think set a very large node distance for "Cache Coherent Device Memory" may be a easier way to address these concerns.

Such approach was discuss at length in the past see links below. Outcome of discussion:
- CPU less node are bad
- device memory can be unreliable (device hang) no way for application to understand that
- application and driver NUMA madvise/mbind/mempolicy ... can conflict with each other and no way the kernel can figure out which should apply
- NUMA as it is now would not work as we need further isolation that what a large node distance would provide

Probably few others argument i forget.

https://lists.gt.net/linux/kernel/2551369
https://groups.google.com/forum/#!topic/linux.kernel/Za_e8C3XnRs%5B1-25%5D
https://lwn.net/Articles/720380/

Cheers,
Jérôme

#14 lore raw
Quoted 33 lines · Jerome Glisse
Quoted 32 lines · Bob Liu
Quoted 30 lines · Jérôme Glisse

Sorry i made horrible mistake on names in v4, i completly miss- understood the suggestion. So here i repost with proper naming. This is the only change since v3. Again sorry about the noise with v4.

Changes since v4:
- s/DEVICE_HOST/DEVICE_PUBLIC

Git tree:
https://cgit.freedesktop.org/~glisse/linux/log/?h=hmm-cdm-v5

Cache coherent device memory apply to architecture with system bus like CAPI or CCIX. Device connected to such system bus can expose their memory to the system and allow cache coherent access to it from the CPU.

Even if for all intent and purposes device memory behave like regular memory, we still want to manage it in isolation from regular memory. Several reasons for that, first and foremost this memory is less reliable than regular memory if the device hangs because of invalid commands we can loose access to device memory. Second CPU access to this memory is expected to be slower than to regular memory. Third having random memory into device means that some of the bus bandwith wouldn't be available to the device but would be use by CPU access.

This is why we want to manage such memory in isolation from regular memory. Kernel should not try to use this memory even as last resort when running out of memory, at least for now.

Quoted 8 lines
Quoted 2 lines

I think set a very large node distance for "Cache Coherent Device Memory" may be a easier way to address these concerns.

Such approach was discuss at length in the past see links below. Outcome of discussion:
- CPU less node are bad
- device memory can be unreliable (device hang) no way for application to understand that

Device memory can also be more reliable if using high quality and expensive memory.

Quoted 6 lines

- application and driver NUMA madvise/mbind/mempolicy ... can conflict with each other and no way the kernel can figure out which should apply
- NUMA as it is now would not work as we need further isolation that what a large node distance would provide

Agree, that's where we need spend time on.

One drawback of HMM-CDM I'm worry about is one more extra copy.
In the cache coherent case, CPU can write data to device memory directly then start fpga/GPU/other accelerators.

Thanks,
Bob Liu

#15 lore raw
Quoted 37 lines · Bob Liu
Quoted 36 lines · Jerome Glisse
Quoted 34 lines · Bob Liu
Quoted 26 lines · Jerome Glisse

Sorry i made horrible mistake on names in v4, i completly miss- understood the suggestion. So here i repost with proper naming. This is the only change since v3. Again sorry about the noise with v4.

Changes since v4:
- s/DEVICE_HOST/DEVICE_PUBLIC

Git tree:
https://cgit.freedesktop.org/~glisse/linux/log/?h=hmm-cdm-v5

Cache coherent device memory apply to architecture with system bus like CAPI or CCIX. Device connected to such system bus can expose their memory to the system and allow cache coherent access to it from the CPU.

Even if for all intent and purposes device memory behave like regular memory, we still want to manage it in isolation from regular memory. Several reasons for that, first and foremost this memory is less reliable than regular memory if the device hangs because of invalid commands we can loose access to device memory. Second CPU access to this memory is expected to be slower than to regular memory. Third having random memory into device means that some of the bus bandwith wouldn't be available to the device but would be use by CPU access.

Quoted 4 lines

This is why we want to manage such memory in isolation from regular memory. Kernel should not try to use this memory even as last resort when running out of memory, at least for now.

I think set a very large node distance for "Cache Coherent Device Memory" may be a easier way to address these concerns.

Quoted 7 lines
Quoted 5 lines

Such approach was discuss at length in the past see links below. Outcome of discussion:
- CPU less node are bad
- device memory can be unreliable (device hang) no way for application to understand that

Device memory can also be more reliable if using high quality and expensive memory.

Even ECC memory does not compensate for device hang. When your GPU lockups you might need to re-init GPU from scratch after which the content of the device memory is unreliable. During init the device memory might not get proper clock or proper refresh cycle and thus is susceptible to corruption.

Quoted 8 lines
Quoted 7 lines

- application and driver NUMA madvise/mbind/mempolicy ... can conflict with each other and no way the kernel can figure out which should apply
- NUMA as it is now would not work as we need further isolation that what a large node distance would provide

Quoted 5 lines

Agree, that's where we need spend time on.

One drawback of HMM-CDM I'm worry about is one more extra copy. In the cache coherent case, CPU can write data to device memory directly then start fpga/GPU/other accelerators.

There is not necessarily an extra copy. Device driver can pre-allocate virtual address range of a process with device memory. Device page fault can directly allocate device memory. Once allocated CPU access will use the device memory.

There is plan to allow other allocation (CPU page fault, file cache, ...) to also use device memory directly. We just don't know what kind of userspace API will fit best for that so at first it might be hidden behind device driver specific ioctl.

Jerome

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

#16 lore raw
Quoted 59 lines · Jerome Glisse
Quoted 37 lines · Bob Liu
Quoted 36 lines · Jerome Glisse
Quoted 34 lines · Bob Liu
Quoted 26 lines · Jerome Glisse

Sorry i made horrible mistake on names in v4, i completly miss- understood the suggestion. So here i repost with proper naming. This is the only change since v3. Again sorry about the noise with v4.

Changes since v4:
- s/DEVICE_HOST/DEVICE_PUBLIC

Git tree:
https://cgit.freedesktop.org/~glisse/linux/log/?h=hmm-cdm-v5

Cache coherent device memory apply to architecture with system bus like CAPI or CCIX. Device connected to such system bus can expose their memory to the system and allow cache coherent access to it from the CPU.

Even if for all intent and purposes device memory behave like regular memory, we still want to manage it in isolation from regular memory. Several reasons for that, first and foremost this memory is less reliable than regular memory if the device hangs because of invalid commands we can loose access to device memory. Second CPU access to this memory is expected to be slower than to regular memory. Third having random memory into device means that some of the bus bandwith wouldn't be available to the device but would be use by CPU access.

Quoted 4 lines

This is why we want to manage such memory in isolation from regular memory. Kernel should not try to use this memory even as last resort when running out of memory, at least for now.

I think set a very large node distance for "Cache Coherent Device Memory" may be a easier way to address these concerns.

Quoted 7 lines
Quoted 5 lines

Such approach was discuss at length in the past see links below. Outcome of discussion:
- CPU less node are bad
- device memory can be unreliable (device hang) no way for application to understand that

Device memory can also be more reliable if using high quality and expensive memory.

Even ECC memory does not compensate for device hang. When your GPU lockups you might need to re-init GPU from scratch after which the content of the device memory is unreliable. During init the device memory might not get proper clock or proper refresh cycle and thus is susceptible to corruption.

Quoted 8 lines
Quoted 7 lines

- application and driver NUMA madvise/mbind/mempolicy ... can conflict with each other and no way the kernel can figure out which should apply
- NUMA as it is now would not work as we need further isolation that what a large node distance would provide

Quoted 8 lines
Quoted 5 lines

Agree, that's where we need spend time on.

One drawback of HMM-CDM I'm worry about is one more extra copy. In the cache coherent case, CPU can write data to device memory directly then start fpga/GPU/other accelerators.

There is not necessarily an extra copy. Device driver can pre-allocate virtual address range of a process with device memory. Device page fault

Okay, I get your point.
But the typical use case is CPU allocate a memory and prepare/write data then launch GPU "cuda kernel". How to control the allocation go to device memory e.g HBM or system DDR at the beginning without user explicit advise? If goes to DDR by default, there is an extra copy. If goes to HBM by default, the HBM may be waste.

Quoted 3 lines

can directly allocate device memory. Once allocated CPU access will use the device memory.

Then it's more like replace the numa node solution(CDM) with ZONE_DEVICE(type MEMORY_DEVICE_PUBLIC).
But the problem is the same, e.g how to make sure the device memory say HBM won't be occupied by normal CPU allocation. Things will be more complex if there are multi GPU connected by nvlink(also cache coherent) in a system, each GPU has their own HBM. How to decide allocate physical memory from local HBM/DDR or remote HBM/DDR?
If using numa(CDM) approach there are NUMA mempolicy and autonuma mechanism at least.

Thanks,
Bob

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

#17 lore raw
Quoted 66 lines · Bob Liu
Quoted 65 lines · Jerome Glisse
Quoted 37 lines · Bob Liu
Quoted 36 lines · Jerome Glisse
Quoted 34 lines · Bob Liu
Quoted 26 lines · Jerome Glisse

Sorry i made horrible mistake on names in v4, i completly miss- understood the suggestion. So here i repost with proper naming. This is the only change since v3. Again sorry about the noise with v4.

Changes since v4:
- s/DEVICE_HOST/DEVICE_PUBLIC

Git tree:
https://cgit.freedesktop.org/~glisse/linux/log/?h=hmm-cdm-v5

Cache coherent device memory apply to architecture with system bus like CAPI or CCIX. Device connected to such system bus can expose their memory to the system and allow cache coherent access to it from the CPU.

Even if for all intent and purposes device memory behave like regular memory, we still want to manage it in isolation from regular memory. Several reasons for that, first and foremost this memory is less reliable than regular memory if the device hangs because of invalid commands we can loose access to device memory. Second CPU access to this memory is expected to be slower than to regular memory. Third having random memory into device means that some of the bus bandwith wouldn't be available to the device but would be use by CPU access.

Quoted 4 lines

This is why we want to manage such memory in isolation from regular memory. Kernel should not try to use this memory even as last resort when running out of memory, at least for now.

I think set a very large node distance for "Cache Coherent Device Memory" may be a easier way to address these concerns.

Quoted 7 lines
Quoted 5 lines

Such approach was discuss at length in the past see links below. Outcome of discussion:
- CPU less node are bad
- device memory can be unreliable (device hang) no way for application to understand that

Device memory can also be more reliable if using high quality and expensive memory.

Even ECC memory does not compensate for device hang. When your GPU lockups you might need to re-init GPU from scratch after which the content of the device memory is unreliable. During init the device memory might not get proper clock or proper refresh cycle and thus is susceptible to corruption.

Quoted 13 lines
Quoted 7 lines

- application and driver NUMA madvise/mbind/mempolicy ... can conflict with each other and no way the kernel can figure out which should apply
- NUMA as it is now would not work as we need further isolation that what a large node distance would provide

Agree, that's where we need spend time on.

One drawback of HMM-CDM I'm worry about is one more extra copy. In the cache coherent case, CPU can write data to device memory directly then start fpga/GPU/other accelerators.

Quoted 5 lines
Quoted 2 lines

There is not necessarily an extra copy. Device driver can pre-allocate virtual address range of a process with device memory. Device page fault

Okay, I get your point. But the typical use case is CPU allocate a memory and prepare/write data then launch GPU "cuda kernel".

I don't think we should make to many assumption on what is typical case. GPU compute is fast evolving and they are new domains where it is apply for instance some folks use it to process network stream and the network adapter directly write into GPU memory so there is never a CPU copy of it. So i rather not make any restrictive assumption on how it will be use.

Quoted 4 lines

How to control the allocation go to device memory e.g HBM or system DDR at the beginning without user explicit advise? If goes to DDR by default, there is an extra copy. If goes to HBM by default, the HBM may be waste.

Yes it is a hard problem to solve. We are working with NVidia and IBM on this and there are several path. But as first solution we will rely on hint/directive given by userspace program through existing GPGPU API like CUDA or OpenCL. They are plan to have hardware monitor bus traffic to gather statistics and do automatic memory placement from thos.

Quoted 10 lines
Quoted 3 lines

can directly allocate device memory. Once allocated CPU access will use the device memory.

Then it's more like replace the numa node solution(CDM) with ZONE_DEVICE (type MEMORY_DEVICE_PUBLIC). But the problem is the same, e.g how to make sure the device memory say HBM won't be occupied by normal CPU allocation. Things will be more complex if there are multi GPU connected by nvlink (also cache coherent) in a system, each GPU has their own HBM.

Quoted 5 lines

How to decide allocate physical memory from local HBM/DDR or remote HBM/ DDR?

If using numa(CDM) approach there are NUMA mempolicy and autonuma mechanism at least.

NUMA is not as easy as you think. First like i said we want the device memory to be isolated from most existing mm mechanism. Because memory is unreliable and also because device might need to be able to evict memory to make contiguous physical memory allocation for graphics.

Second device driver are not integrated that closely within mm and the scheduler kernel code to allow to efficiently plug in device access notification to page (ie to update struct page so that numa worker thread can migrate memory base on accurate informations).

Third it can be hard to decide who win between CPU and device access when it comes to updating thing like last CPU id.

Fourth there is no such thing like device id ie equivalent of CPU id. If we were to add something the CPU id field in flags of struct page would not be big enough so this can have repercusion on struct page size. This is not an easy sell.

They are other issues i can't think of right now. I think for now it is easier and better to take the HMM-CDM approach and latter down the road once we have more existing user to start thinking about numa or numa like solution.

Bottom line is we spend time thinking about this and yes numa make sense from conceptual point of view but they are many things we do not know to feel confident that we can make something good with numa as it is.

Cheers,
Jerome

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

#18 lore raw
Quoted 104 lines · Jerome Glisse
Quoted 66 lines · Bob Liu
Quoted 65 lines · Jerome Glisse
Quoted 37 lines · Bob Liu
Quoted 36 lines · Jerome Glisse
Quoted 34 lines · Bob Liu
Quoted 26 lines · Jérôme Glisse

Sorry i made horrible mistake on names in v4, i completly miss- understood the suggestion. So here i repost with proper naming. This is the only change since v3. Again sorry about the noise with v4.

Changes since v4:
- s/DEVICE_HOST/DEVICE_PUBLIC

Git tree:
https://cgit.freedesktop.org/~glisse/linux/log/?h=hmm-cdm-v5

Cache coherent device memory apply to architecture with system bus like CAPI or CCIX. Device connected to such system bus can expose their memory to the system and allow cache coherent access to it from the CPU.

Even if for all intent and purposes device memory behave like regular memory, we still want to manage it in isolation from regular memory. Several reasons for that, first and foremost this memory is less reliable than regular memory if the device hangs because of invalid commands we can loose access to device memory. Second CPU access to this memory is expected to be slower than to regular memory. Third having random memory into device means that some of the bus bandwith wouldn't be available to the device but would be use by CPU access.

Quoted 4 lines

This is why we want to manage such memory in isolation from regular memory. Kernel should not try to use this memory even as last resort when running out of memory, at least for now.

I think set a very large node distance for "Cache Coherent Device Memory" may be a easier way to address these concerns.

Quoted 7 lines
Quoted 5 lines

Such approach was discuss at length in the past see links below. Outcome of discussion:
- CPU less node are bad
- device memory can be unreliable (device hang) no way for application to understand that

Device memory can also be more reliable if using high quality and expensive memory.

Even ECC memory does not compensate for device hang. When your GPU lockups you might need to re-init GPU from scratch after which the content of the device memory is unreliable. During init the device memory might not get proper clock or proper refresh cycle and thus is susceptible to corruption.

Quoted 13 lines
Quoted 7 lines

- application and driver NUMA madvise/mbind/mempolicy ... can conflict with each other and no way the kernel can figure out which should apply
- NUMA as it is now would not work as we need further isolation that what a large node distance would provide

Agree, that's where we need spend time on.

One drawback of HMM-CDM I'm worry about is one more extra copy. In the cache coherent case, CPU can write data to device memory directly then start fpga/GPU/other accelerators.

Quoted 5 lines
Quoted 2 lines

There is not necessarily an extra copy. Device driver can pre-allocate virtual address range of a process with device memory. Device page fault

Okay, I get your point. But the typical use case is CPU allocate a memory and prepare/write data then launch GPU "cuda kernel".

I don't think we should make to many assumption on what is typical case. GPU compute is fast evolving and they are new domains where it is apply for instance some folks use it to process network stream and the network adapter directly write into GPU memory so there is never a CPU copy of it. So i rather not make any restrictive assumption on how it will be use.

Quoted 4 lines

How to control the allocation go to device memory e.g HBM or system DDR at the beginning without user explicit advise? If goes to DDR by default, there is an extra copy. If goes to HBM by default, the HBM may be waste.

Yes it is a hard problem to solve. We are working with NVidia and IBM on this and there are several path. But as first solution we will rely on hint/directive given by userspace program through existing GPGPU API like CUDA or OpenCL. They are plan to have hardware monitor bus traffic to gather statistics and do automatic memory placement from thos.

Quoted 13 lines
Quoted 3 lines

can directly allocate device memory. Once allocated CPU access will use the device memory.

Then it's more like replace the numa node solution(CDM) with ZONE_DEVICE (type MEMORY_DEVICE_PUBLIC). But the problem is the same, e.g how to make sure the device memory say HBM won't be occupied by normal CPU allocation. Things will be more complex if there are multi GPU connected by nvlink (also cache coherent) in a system, each GPU has their own HBM.

How to decide allocate physical memory from local HBM/DDR or remote HBM/ DDR?

Quoted 8 lines
Quoted 2 lines

If using numa(CDM) approach there are NUMA mempolicy and autonuma mechanism at least.

NUMA is not as easy as you think. First like i said we want the device memory to be isolated from most existing mm mechanism. Because memory is unreliable and also because device might need to be able to evict memory to make contiguous physical memory allocation for graphics.

Right, but we need isolation any way.
For hmm-cdm, the isolation is not adding device memory to lru list, and many if (is_device_public_page(page)) ...

But how to evict device memory?

Quoted 8 lines

Second device driver are not integrated that closely within mm and the scheduler kernel code to allow to efficiently plug in device access notification to page (ie to update struct page so that numa worker thread can migrate memory base on accurate informations).

Third it can be hard to decide who win between CPU and device access when it comes to updating thing like last CPU id.

Quoted 6 lines

Fourth there is no such thing like device id ie equivalent of CPU id. If we were to add something the CPU id field in flags of struct page would not be big enough so this can have repercusion on struct page size. This is not an easy sell.

They are other issues i can't think of right now. I think for now it

My opinion is most of the issues are the same no matter use CDM or HMM-CDM. I just care about a more complete solution no matter CDM,HMM-CDM or other ways. HMM or HMM-CDM depends on device driver, but haven't see a public/full driver to demonstrate the whole solution works fine.

Cheers,
Bob

Quoted 8 lines

is easier and better to take the HMM-CDM approach and latter down the road once we have more existing user to start thinking about numa or numa like solution.

Bottom line is we spend time thinking about this and yes numa make sense from conceptual point of view but they are many things we do not know to feel confident that we can make something good with numa as it is.

#19 lore raw
Quoted 7 lines · Bob Liu
Quoted 6 lines · Jerome Glisse
Quoted 5 lines · Bob Liu
Quoted 4 lines · Jerome Glisse
Quoted 3 lines · Bob Liu
Quoted 2 lines · Jerome Glisse
Quoted 1 line · Bob Liu

On 2017/7/14 5:15, Jerome Glisse wrote:

[...]

Quoted 18 lines
Quoted 9 lines
Quoted 9 lines

Then it's more like replace the numa node solution(CDM) with ZONE_DEVICE (type MEMORY_DEVICE_PUBLIC). But the problem is the same, e.g how to make sure the device memory say HBM won't be occupied by normal CPU allocation. Things will be more complex if there are multi GPU connected by nvlink (also cache coherent) in a system, each GPU has their own HBM.

How to decide allocate physical memory from local HBM/DDR or remote HBM/ DDR?

Quoted 8 lines
Quoted 2 lines

If using numa(CDM) approach there are NUMA mempolicy and autonuma mechanism at least.

NUMA is not as easy as you think. First like i said we want the device memory to be isolated from most existing mm mechanism. Because memory is unreliable and also because device might need to be able to evict memory to make contiguous physical memory allocation for graphics.

Quoted 5 lines

Right, but we need isolation any way.
For hmm-cdm, the isolation is not adding device memory to lru list, and many if (is_device_public_page(page)) ...

But how to evict device memory?

What you mean by evict ? Device driver can evict whenever they see the need to do so. CPU page fault will evict too. Process exit or munmap() will free the device memory.

Are you refering to evict in the sense of memory reclaim under pressure ?

So the way it flows for memory pressure is that if device driver want to make room it can evict stuff to system memory and if there is not enough system memory than thing get reclaim as usual before device driver can make progress on device memory reclaim.

Quoted 13 lines
Quoted 13 lines

Second device driver are not integrated that closely within mm and the scheduler kernel code to allow to efficiently plug in device access notification to page (ie to update struct page so that numa worker thread can migrate memory base on accurate informations).

Third it can be hard to decide who win between CPU and device access when it comes to updating thing like last CPU id.

Fourth there is no such thing like device id ie equivalent of CPU id. If we were to add something the CPU id field in flags of struct page would not be big enough so this can have repercusion on struct page size. This is not an easy sell.

Quoted 6 lines
Quoted 1 line

They are other issues i can't think of right now. I think for now it

My opinion is most of the issues are the same no matter use CDM or HMM-CDM. I just care about a more complete solution no matter CDM,HMM-CDM or other ways. HMM or HMM-CDM depends on device driver, but haven't see a public/full driver to demonstrate the whole solution works fine.

I am working with NVidia close source driver team to make sure that it works well for them. I am also working on nouveau open source driver for same NVidia hardware thought it will be of less use as what is missing there is a solid open source userspace to leverage this. Nonetheless open source driver are in the work.

The way i see it is start with HMM-CDM which isolate most of the changes in hmm code. Once we get more experience with real workload and not with device driver test suite then we can start revisiting NUMA and deeper integration with the linux kernel. I rather grow organicaly toward that than trying to design something that would make major changes all over the kernel without knowing for sure that we are going in the right direction. I hope that this make sense to others too.

Cheers,
Jerome

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

#20 lore raw
Quoted 35 lines · Jerome Glisse
Quoted 7 lines · Bob Liu
Quoted 6 lines · Jerome Glisse
Quoted 5 lines · Bob Liu
Quoted 4 lines · Jerome Glisse
Quoted 3 lines · Bob Liu
Quoted 2 lines · Jerome Glisse
Quoted 1 line · Bob Liu

On 2017/7/14 5:15, Jérôme Glisse wrote:

[...]

Quoted 18 lines
Quoted 9 lines
Quoted 9 lines

Then it's more like replace the numa node solution(CDM) with ZONE_DEVICE (type MEMORY_DEVICE_PUBLIC). But the problem is the same, e.g how to make sure the device memory say HBM won't be occupied by normal CPU allocation. Things will be more complex if there are multi GPU connected by nvlink (also cache coherent) in a system, each GPU has their own HBM.

How to decide allocate physical memory from local HBM/DDR or remote HBM/ DDR?

Quoted 8 lines
Quoted 2 lines

If using numa(CDM) approach there are NUMA mempolicy and autonuma mechanism at least.

NUMA is not as easy as you think. First like i said we want the device memory to be isolated from most existing mm mechanism. Because memory is unreliable and also because device might need to be able to evict memory to make contiguous physical memory allocation for graphics.

Quoted 5 lines

Right, but we need isolation any way.
For hmm-cdm, the isolation is not adding device memory to lru list, and many if (is_device_public_page(page)) ...

But how to evict device memory?

Quoted 8 lines

What you mean by evict ? Device driver can evict whenever they see the need to do so. CPU page fault will evict too. Process exit or munmap() will free the device memory.

Are you refering to evict in the sense of memory reclaim under pressure ?

So the way it flows for memory pressure is that if device driver want to make room it can evict stuff to system memory and if there is not enough

Yes, I mean this.
So every driver have to maintain their own LRU-similar list instead of reuse what already in linux kernel.

Quoted 24 lines

system memory than thing get reclaim as usual before device driver can make progress on device memory reclaim.

Quoted 13 lines
Quoted 13 lines

Second device driver are not integrated that closely within mm and the scheduler kernel code to allow to efficiently plug in device access notification to page (ie to update struct page so that numa worker thread can migrate memory base on accurate informations).

Third it can be hard to decide who win between CPU and device access when it comes to updating thing like last CPU id.

Fourth there is no such thing like device id ie equivalent of CPU id. If we were to add something the CPU id field in flags of struct page would not be big enough so this can have repercusion on struct page size. This is not an easy sell.

Quoted 6 lines
Quoted 1 line

They are other issues i can't think of right now. I think for now it

My opinion is most of the issues are the same no matter use CDM or HMM-CDM. I just care about a more complete solution no matter CDM,HMM-CDM or other ways. HMM or HMM-CDM depends on device driver, but haven't see a public/full driver to demonstrate the whole solution works fine.

Quoted 6 lines

I am working with NVidia close source driver team to make sure that it works well for them. I am also working on nouveau open source driver for same NVidia hardware thought it will be of less use as what is missing there is a solid open source userspace to leverage this. Nonetheless open source driver are in the work.

Looking forward to see these drivers be public.

Quoted 8 lines

The way i see it is start with HMM-CDM which isolate most of the changes in hmm code. Once we get more experience with real workload and not with device driver test suite then we can start revisiting NUMA and deeper integration with the linux kernel. I rather grow organicaly toward that than trying to design something that would make major changes all over the kernel without knowing for sure that we are going in the right direction. I hope that this make sense to others too.

Make sense.

Thanks,
Bob Liu

#23 lore raw
In reply to Jerome Glisse
Quoted 67 lines · Jerome Glisse
Quoted 7 lines · Bob Liu
Quoted 6 lines · Jerome Glisse
Quoted 5 lines · Bob Liu
Quoted 4 lines · Jerome Glisse
Quoted 3 lines · Bob Liu
Quoted 2 lines · Jerome Glisse
Quoted 1 line · Bob Liu

On 2017/7/14 5:15, Jérôme Glisse wrote:

[...]

Quoted 18 lines
Quoted 9 lines
Quoted 9 lines

Then it's more like replace the numa node solution(CDM) with ZONE_DEVICE (type MEMORY_DEVICE_PUBLIC). But the problem is the same, e.g how to make sure the device memory say HBM won't be occupied by normal CPU allocation. Things will be more complex if there are multi GPU connected by nvlink (also cache coherent) in a system, each GPU has their own HBM.

How to decide allocate physical memory from local HBM/DDR or remote HBM/ DDR?

Quoted 8 lines
Quoted 2 lines

If using numa(CDM) approach there are NUMA mempolicy and autonuma mechanism at least.

NUMA is not as easy as you think. First like i said we want the device memory to be isolated from most existing mm mechanism. Because memory is unreliable and also because device might need to be able to evict memory to make contiguous physical memory allocation for graphics.

Quoted 5 lines

Right, but we need isolation any way.
For hmm-cdm, the isolation is not adding device memory to lru list, and many if (is_device_public_page(page)) ...

But how to evict device memory?

What you mean by evict ? Device driver can evict whenever they see the need to do so. CPU page fault will evict too. Process exit or munmap() will free the device memory.

Are you refering to evict in the sense of memory reclaim under pressure ?

So the way it flows for memory pressure is that if device driver want to make room it can evict stuff to system memory and if there is not enough system memory than thing get reclaim as usual before device driver can make progress on device memory reclaim.

Quoted 13 lines
Quoted 13 lines

Second device driver are not integrated that closely within mm and the scheduler kernel code to allow to efficiently plug in device access notification to page (ie to update struct page so that numa worker thread can migrate memory base on accurate informations).

Third it can be hard to decide who win between CPU and device access when it comes to updating thing like last CPU id.

Fourth there is no such thing like device id ie equivalent of CPU id. If we were to add something the CPU id field in flags of struct page would not be big enough so this can have repercusion on struct page size. This is not an easy sell.

Quoted 6 lines
Quoted 1 line

They are other issues i can't think of right now. I think for now it

My opinion is most of the issues are the same no matter use CDM or HMM-CDM. I just care about a more complete solution no matter CDM,HMM-CDM or other ways. HMM or HMM-CDM depends on device driver, but haven't see a public/full driver to demonstrate the whole solution works fine.

Quoted 5 lines

I am working with NVidia close source driver team to make sure that it works well for them. I am also working on nouveau open source driver for same NVidia hardware thought it will be of less use as what is missing there is a solid open source userspace to leverage this. Nonetheless open source driver are in the work.

Can you point to the nouveau patches? I still find these HMM patches un-reviewable without an upstream consumer.

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

#21 lore raw
In reply to Bob Liu
Quoted 40 lines · Bob Liu
Quoted 39 lines · Jerome Glisse
Quoted 7 lines · Bob Liu
Quoted 6 lines · Jerome Glisse
Quoted 5 lines · Bob Liu
Quoted 4 lines · Jerome Glisse
Quoted 3 lines · Bob Liu
Quoted 2 lines · Jerome Glisse
Quoted 1 line · Bob Liu

On 2017/7/14 5:15, Jérôme Glisse wrote:

[...]

Quoted 18 lines
Quoted 9 lines
Quoted 9 lines

Then it's more like replace the numa node solution(CDM) with ZONE_DEVICE (type MEMORY_DEVICE_PUBLIC). But the problem is the same, e.g how to make sure the device memory say HBM won't be occupied by normal CPU allocation. Things will be more complex if there are multi GPU connected by nvlink (also cache coherent) in a system, each GPU has their own HBM.

How to decide allocate physical memory from local HBM/DDR or remote HBM/ DDR?

Quoted 8 lines
Quoted 2 lines

If using numa(CDM) approach there are NUMA mempolicy and autonuma mechanism at least.

NUMA is not as easy as you think. First like i said we want the device memory to be isolated from most existing mm mechanism. Because memory is unreliable and also because device might need to be able to evict memory to make contiguous physical memory allocation for graphics.

Quoted 5 lines

Right, but we need isolation any way.
For hmm-cdm, the isolation is not adding device memory to lru list, and many if (is_device_public_page(page)) ...

But how to evict device memory?

What you mean by evict ? Device driver can evict whenever they see the need to do so. CPU page fault will evict too. Process exit or munmap() will free the device memory.

Quoted 8 lines
Quoted 4 lines

Are you refering to evict in the sense of memory reclaim under pressure ?

So the way it flows for memory pressure is that if device driver want to make room it can evict stuff to system memory and if there is not enough

Yes, I mean this.
So every driver have to maintain their own LRU-similar list instead of reuse what already in linux kernel.

And how HMM-CDM can handle multiple devices or device with multiple device memories(may with different properties also)?
This kind of hardware platform would be very common when CCIX is out soon.

Thanks,
Bob Liu

Quoted 53 lines
Quoted 24 lines

system memory than thing get reclaim as usual before device driver can make progress on device memory reclaim.

Quoted 13 lines
Quoted 13 lines

Second device driver are not integrated that closely within mm and the scheduler kernel code to allow to efficiently plug in device access notification to page (ie to update struct page so that numa worker thread can migrate memory base on accurate informations).

Third it can be hard to decide who win between CPU and device access when it comes to updating thing like last CPU id.

Fourth there is no such thing like device id ie equivalent of CPU id. If we were to add something the CPU id field in flags of struct page would not be big enough so this can have repercusion on struct page size. This is not an easy sell.

Quoted 6 lines
Quoted 1 line

They are other issues i can't think of right now. I think for now it

My opinion is most of the issues are the same no matter use CDM or HMM-CDM. I just care about a more complete solution no matter CDM,HMM-CDM or other ways. HMM or HMM-CDM depends on device driver, but haven't see a public/full driver to demonstrate the whole solution works fine.

Quoted 6 lines

I am working with NVidia close source driver team to make sure that it works well for them. I am also working on nouveau open source driver for same NVidia hardware thought it will be of less use as what is missing there is a solid open source userspace to leverage this. Nonetheless open source driver are in the work.

Looking forward to see these drivers be public.

Quoted 8 lines

The way i see it is start with HMM-CDM which isolate most of the changes in hmm code. Once we get more experience with real workload and not with device driver test suite then we can start revisiting NUMA and deeper integration with the linux kernel. I rather grow organicaly toward that than trying to design something that would make major changes all over the kernel without knowing for sure that we are going in the right direction. I hope that this make sense to others too.

Make sense.

Thanks,
Bob Liu

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

Signature · 2 lines
Regards,
--Bob
#22 lore raw
Quoted 41 lines · Bob Liu
Quoted 40 lines · Bob Liu
Quoted 39 lines · Jerome Glisse
Quoted 7 lines · Bob Liu
Quoted 6 lines · Jerome Glisse
Quoted 5 lines · Bob Liu
Quoted 4 lines · Jerome Glisse
Quoted 3 lines · Bob Liu
Quoted 2 lines · Jerome Glisse
Quoted 1 line · Bob Liu

On 2017/7/14 5:15, Jerome Glisse wrote:

[...]

Quoted 18 lines
Quoted 9 lines
Quoted 9 lines

Then it's more like replace the numa node solution(CDM) with ZONE_DEVICE (type MEMORY_DEVICE_PUBLIC). But the problem is the same, e.g how to make sure the device memory say HBM won't be occupied by normal CPU allocation. Things will be more complex if there are multi GPU connected by nvlink (also cache coherent) in a system, each GPU has their own HBM.

How to decide allocate physical memory from local HBM/DDR or remote HBM/ DDR?

Quoted 8 lines
Quoted 2 lines

If using numa(CDM) approach there are NUMA mempolicy and autonuma mechanism at least.

NUMA is not as easy as you think. First like i said we want the device memory to be isolated from most existing mm mechanism. Because memory is unreliable and also because device might need to be able to evict memory to make contiguous physical memory allocation for graphics.

Quoted 5 lines

Right, but we need isolation any way.
For hmm-cdm, the isolation is not adding device memory to lru list, and many if (is_device_public_page(page)) ...

But how to evict device memory?

What you mean by evict ? Device driver can evict whenever they see the need to do so. CPU page fault will evict too. Process exit or munmap() will free the device memory.

Quoted 8 lines
Quoted 8 lines
Quoted 4 lines

Are you refering to evict in the sense of memory reclaim under pressure ?

So the way it flows for memory pressure is that if device driver want to make room it can evict stuff to system memory and if there is not enough

Yes, I mean this.
So every driver have to maintain their own LRU-similar list instead of reuse what already in linux kernel.

Regarding LRU it is again not as easy. First we do necessarily have access information like CPU page table for device page table. Second the mmu_notifier callback on per page basis is costly. Finaly device are use differently than CPU, usualy you schedule a job and once that job is done you can safely evict memory it was using. Existing device driver already have quite large memory management code of their own because of that different usage model.

LRU might make sense at one point but so far i doubt it is the right solution for device memory.

Quoted 4 lines

And how HMM-CDM can handle multiple devices or device with multiple device memories(may with different properties also)?
This kind of hardware platform would be very common when CCIX is out soon.

A) Multiple device is under control of device driver. Multiple devices link to each other through dedicated link can have themself a complex topology and remote access between device is highly tie to the device (how to program the device mmu and device registers) and thus to the device driver.

If we identify common design pattern between different hardware then we might start thinking about factoring out some common code to help those cases.

B) Multiple different device is an harder problem. Each device provide their own userspace API and that is through that API that you will get memory placement advise. If several device fight for placement of same chunk of memory one can argue that the application is broken or device is broken. But for now we assume that device and application will behave.

Rate limiting migration is hard, you need to keep migration statistics and that need memory. So unless we really need to do that i would rather avoid doing that. Again this is a thing for which we will have to wait and see how thing panout.

Maybe i should stress that HMM is a set of helpers for device memory and it is not intended to be a policy maker or to manage device memory. Intention is that device driver will keep managing device memory as they already do today.

A deeper integration with process memory management is probably bound to happen but for now it is just about having toolbox for device driver.

Jerome

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

#24 lore raw
In reply to Dan Williams
Quoted 68 lines · Dan Williams
Quoted 67 lines · Jerome Glisse
Quoted 7 lines · Bob Liu
Quoted 6 lines · Jerome Glisse
Quoted 5 lines · Bob Liu
Quoted 4 lines · Jerome Glisse
Quoted 3 lines · Bob Liu
Quoted 2 lines · Jerome Glisse
Quoted 1 line · Bob Liu

On 2017/7/14 5:15, Jerome Glisse wrote:

[...]

Quoted 18 lines
Quoted 9 lines
Quoted 9 lines

Then it's more like replace the numa node solution(CDM) with ZONE_DEVICE (type MEMORY_DEVICE_PUBLIC). But the problem is the same, e.g how to make sure the device memory say HBM won't be occupied by normal CPU allocation. Things will be more complex if there are multi GPU connected by nvlink (also cache coherent) in a system, each GPU has their own HBM.

How to decide allocate physical memory from local HBM/DDR or remote HBM/ DDR?

Quoted 8 lines
Quoted 2 lines

If using numa(CDM) approach there are NUMA mempolicy and autonuma mechanism at least.

NUMA is not as easy as you think. First like i said we want the device memory to be isolated from most existing mm mechanism. Because memory is unreliable and also because device might need to be able to evict memory to make contiguous physical memory allocation for graphics.

Quoted 5 lines

Right, but we need isolation any way.
For hmm-cdm, the isolation is not adding device memory to lru list, and many if (is_device_public_page(page)) ...

But how to evict device memory?

What you mean by evict ? Device driver can evict whenever they see the need to do so. CPU page fault will evict too. Process exit or munmap() will free the device memory.

Are you refering to evict in the sense of memory reclaim under pressure ?

So the way it flows for memory pressure is that if device driver want to make room it can evict stuff to system memory and if there is not enough system memory than thing get reclaim as usual before device driver can make progress on device memory reclaim.

Quoted 19 lines
Quoted 8 lines

Second device driver are not integrated that closely within mm and the scheduler kernel code to allow to efficiently plug in device access notification to page (ie to update struct page so that numa worker thread can migrate memory base on accurate informations).

Third it can be hard to decide who win between CPU and device access when it comes to updating thing like last CPU id.

Quoted 6 lines

Fourth there is no such thing like device id ie equivalent of CPU id. If we were to add something the CPU id field in flags of struct page would not be big enough so this can have repercusion on struct page size. This is not an easy sell.

They are other issues i can't think of right now. I think for now it

My opinion is most of the issues are the same no matter use CDM or HMM-CDM. I just care about a more complete solution no matter CDM,HMM-CDM or other ways. HMM or HMM-CDM depends on device driver, but haven't see a public/full driver to demonstrate the whole solution works fine.

Quoted 8 lines
Quoted 5 lines

I am working with NVidia close source driver team to make sure that it works well for them. I am also working on nouveau open source driver for same NVidia hardware thought it will be of less use as what is missing there is a solid open source userspace to leverage this. Nonetheless open source driver are in the work.

Can you point to the nouveau patches? I still find these HMM patches un-reviewable without an upstream consumer.

I am still working on those, i hope i will be able to post them in 3 weeks or so.

Cheers,
Jerome

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

#25 lore raw
In reply to Dan Williams
Quoted 9 lines · Dan Williams
Quoted 8 lines · Jerome Glisse
Quoted 7 lines · Bob Liu
Quoted 6 lines · Jerome Glisse
Quoted 5 lines · Bob Liu
Quoted 4 lines · Jerome Glisse
Quoted 3 lines · Bob Liu
Quoted 2 lines · Jerome Glisse
Quoted 1 line · Bob Liu

On 2017/7/14 5:15, Jerome Glisse wrote:

[...]

Quoted 20 lines
Quoted 20 lines
Quoted 19 lines
Quoted 8 lines

Second device driver are not integrated that closely within mm and the scheduler kernel code to allow to efficiently plug in device access notification to page (ie to update struct page so that numa worker thread can migrate memory base on accurate informations).

Third it can be hard to decide who win between CPU and device access when it comes to updating thing like last CPU id.

Quoted 6 lines

Fourth there is no such thing like device id ie equivalent of CPU id. If we were to add something the CPU id field in flags of struct page would not be big enough so this can have repercusion on struct page size. This is not an easy sell.

They are other issues i can't think of right now. I think for now it

My opinion is most of the issues are the same no matter use CDM or HMM-CDM. I just care about a more complete solution no matter CDM,HMM-CDM or other ways. HMM or HMM-CDM depends on device driver, but haven't see a public/full driver to demonstrate the whole solution works fine.

Quoted 8 lines
Quoted 5 lines

I am working with NVidia close source driver team to make sure that it works well for them. I am also working on nouveau open source driver for same NVidia hardware thought it will be of less use as what is missing there is a solid open source userspace to leverage this. Nonetheless open source driver are in the work.

Can you point to the nouveau patches? I still find these HMM patches un-reviewable without an upstream consumer.

So i pushed a branch with WIP for nouveau to use HMM:

https://cgit.freedesktop.org/~glisse/linux/log/?h=hmm-nouveau

Top 16 patches are HMM related (implementic logic inside the driver to use HMM). The next 16 patches are hardware specific patches and some nouveau changes needed to allow page fault.

It is enough to have simple malloc test case working:

https://cgit.freedesktop.org/~glisse/compote

There is 2 program here the old one is existing way you use GPU for compute task while the new one is what HMM allow to achieve ie use malloc memory directly.

I haven't added yet the device memory support it is in work and i will push update to this branch and repo for that. Probably next week if no pressing bug preempt my time.

So there is a lot of ugliness in all this and i don't expect this to be what end up upstream. Right now there is a large rework of nouveau vm (virtual memory) code happening to rework completely how we do address space management within nouveau. This work is prerequisite for a clean implementation for HMM inside nouveau (it will also lift the 40bits address space limitation that exist today inside nouveau driver). Once that work land i will work on clean upstreamable implementation for nouveau to use HMM as well as userspace to leverage it (this is requirement for upstream GPU driver to have open source userspace that make use of features). All this is a lot of work and there is not many people working on this.

They are other initiatives under way related to this that i can not talk about publicly but if they bare fruit they might help to speedup all this.

Jerome

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

#26 lore raw
Quoted 39 lines · Jerome Glisse
Quoted 9 lines · Dan Williams
Quoted 8 lines · Jerome Glisse
Quoted 7 lines · Bob Liu
Quoted 6 lines · Jerome Glisse
Quoted 5 lines · Bob Liu
Quoted 4 lines · Jerome Glisse
Quoted 3 lines · Bob Liu
Quoted 2 lines · Jerome Glisse
Quoted 1 line · Bob Liu

On 2017/7/14 5:15, Jérôme Glisse wrote:

[...]

Quoted 26 lines
Quoted 25 lines
Quoted 13 lines
Quoted 13 lines

Second device driver are not integrated that closely within mm and the scheduler kernel code to allow to efficiently plug in device access notification to page (ie to update struct page so that numa worker thread can migrate memory base on accurate informations).

Third it can be hard to decide who win between CPU and device access when it comes to updating thing like last CPU id.

Fourth there is no such thing like device id ie equivalent of CPU id. If we were to add something the CPU id field in flags of struct page would not be big enough so this can have repercusion on struct page size. This is not an easy sell.

Quoted 6 lines
Quoted 1 line

They are other issues i can't think of right now. I think for now it

My opinion is most of the issues are the same no matter use CDM or HMM-CDM. I just care about a more complete solution no matter CDM,HMM-CDM or other ways. HMM or HMM-CDM depends on device driver, but haven't see a public/full driver to demonstrate the whole solution works fine.

I am working with NVidia close source driver team to make sure that it works well for them. I am also working on nouveau open source driver for same NVidia hardware thought it will be of less use as what is missing there is a solid open source userspace to leverage this. Nonetheless open source driver are in the work.

Quoted 7 lines
Quoted 2 lines

Can you point to the nouveau patches? I still find these HMM patches un-reviewable without an upstream consumer.

So i pushed a branch with WIP for nouveau to use HMM:

https://cgit.freedesktop.org/~glisse/linux/log/?h=hmm-nouveau

Nice to see that.
Btw, do you have any plan for a CDM-HMM driver? CPU can write to Device memory directly without extra copy.

--
Thanks,
Bob Liu

Quoted 30 lines

Top 16 patches are HMM related (implementic logic inside the driver to use HMM). The next 16 patches are hardware specific patches and some nouveau changes needed to allow page fault.

It is enough to have simple malloc test case working:

https://cgit.freedesktop.org/~glisse/compote

There is 2 program here the old one is existing way you use GPU for compute task while the new one is what HMM allow to achieve ie use malloc memory directly.

I haven't added yet the device memory support it is in work and i will push update to this branch and repo for that. Probably next week if no pressing bug preempt my time.

So there is a lot of ugliness in all this and i don't expect this to be what end up upstream. Right now there is a large rework of nouveau vm (virtual memory) code happening to rework completely how we do address space management within nouveau. This work is prerequisite for a clean implementation for HMM inside nouveau (it will also lift the 40bits address space limitation that exist today inside nouveau driver). Once that work land i will work on clean upstreamable implementation for nouveau to use HMM as well as userspace to leverage it (this is requirement for upstream GPU driver to have open source userspace that make use of features). All this is a lot of work and there is not many people working on this.

Quoted 5 lines

They are other initiatives under way related to this that i can not talk about publicly but if they bare fruit they might help to speedup all this.

Jérôme

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

#27 lore raw
Quoted 43 lines · Bob Liu
Quoted 42 lines · Jerome Glisse
Quoted 9 lines · Dan Williams
Quoted 8 lines · Jerome Glisse
Quoted 7 lines · Bob Liu
Quoted 6 lines · Jerome Glisse
Quoted 5 lines · Bob Liu
Quoted 4 lines · Jerome Glisse
Quoted 3 lines · Bob Liu
Quoted 2 lines · Jerome Glisse
Quoted 1 line · Bob Liu

On 2017/7/14 5:15, Jérôme Glisse wrote:

[...]

Quoted 28 lines
Quoted 20 lines
Quoted 13 lines
Quoted 13 lines

Second device driver are not integrated that closely within mm and the scheduler kernel code to allow to efficiently plug in device access notification to page (ie to update struct page so that numa worker thread can migrate memory base on accurate informations).

Third it can be hard to decide who win between CPU and device access when it comes to updating thing like last CPU id.

Fourth there is no such thing like device id ie equivalent of CPU id. If we were to add something the CPU id field in flags of struct page would not be big enough so this can have repercusion on struct page size. This is not an easy sell.

Quoted 6 lines
Quoted 1 line

They are other issues i can't think of right now. I think for now it

My opinion is most of the issues are the same no matter use CDM or HMM-CDM. I just care about a more complete solution no matter CDM,HMM-CDM or other ways. HMM or HMM-CDM depends on device driver, but haven't see a public/full driver to demonstrate the whole solution works fine.

Quoted 5 lines

I am working with NVidia close source driver team to make sure that it works well for them. I am also working on nouveau open source driver for same NVidia hardware thought it will be of less use as what is missing there is a solid open source userspace to leverage this. Nonetheless open source driver are in the work.

Can you point to the nouveau patches? I still find these HMM patches un-reviewable without an upstream consumer.

Quoted 8 lines
Quoted 4 lines

So i pushed a branch with WIP for nouveau to use HMM:

https://cgit.freedesktop.org/~glisse/linux/log/?h=hmm-nouveau

Nice to see that.
Btw, do you have any plan for a CDM-HMM driver? CPU can write to Device memory directly without extra copy.

Yes nouveau CDM support on PPC (which is the only CDM platform commercialy available today) is on the TODO list. Note that the driver changes for CDM are minimal (probably less than 100 lines of code). From the driver point of view this is memory and it doesn't matter if it is CDM or not.

The real burden is on the application developpers who need to update their code to leverage this.

Also as a data point you want to avoid CPU access to CDM device memory as much as possible. The overhead for single cache line access are high (this is PCIE or derivative protocol and it is a packet protocol).

Cheers,
Jérôme

#28 lore raw
Quoted 53 lines · Jerome Glisse
Quoted 43 lines · Bob Liu
Quoted 42 lines · Jerome Glisse
Quoted 9 lines · Dan Williams
Quoted 8 lines · Jerome Glisse
Quoted 7 lines · Bob Liu
Quoted 6 lines · Jerome Glisse
Quoted 5 lines · Bob Liu
Quoted 4 lines · Jerome Glisse
Quoted 3 lines · Bob Liu
Quoted 2 lines · Jerome Glisse
Quoted 1 line · Bob Liu

On 2017/7/14 5:15, Jerome Glisse wrote:

[...]

Quoted 28 lines
Quoted 20 lines
Quoted 13 lines
Quoted 13 lines

Second device driver are not integrated that closely within mm and the scheduler kernel code to allow to efficiently plug in device access notification to page (ie to update struct page so that numa worker thread can migrate memory base on accurate informations).

Third it can be hard to decide who win between CPU and device access when it comes to updating thing like last CPU id.

Fourth there is no such thing like device id ie equivalent of CPU id. If we were to add something the CPU id field in flags of struct page would not be big enough so this can have repercusion on struct page size. This is not an easy sell.

Quoted 6 lines
Quoted 1 line

They are other issues i can't think of right now. I think for now it

My opinion is most of the issues are the same no matter use CDM or HMM-CDM. I just care about a more complete solution no matter CDM,HMM-CDM or other ways. HMM or HMM-CDM depends on device driver, but haven't see a public/full driver to demonstrate the whole solution works fine.

Quoted 5 lines

I am working with NVidia close source driver team to make sure that it works well for them. I am also working on nouveau open source driver for same NVidia hardware thought it will be of less use as what is missing there is a solid open source userspace to leverage this. Nonetheless open source driver are in the work.

Can you point to the nouveau patches? I still find these HMM patches un-reviewable without an upstream consumer.

Quoted 8 lines
Quoted 4 lines

So i pushed a branch with WIP for nouveau to use HMM:

https://cgit.freedesktop.org/~glisse/linux/log/?h=hmm-nouveau

Nice to see that.
Btw, do you have any plan for a CDM-HMM driver? CPU can write to Device memory directly without extra copy.

Quoted 8 lines

Yes nouveau CDM support on PPC (which is the only CDM platform commercialy available today) is on the TODO list. Note that the driver changes for CDM are minimal (probably less than 100 lines of code). From the driver point of view this is memory and it doesn't matter if it is CDM or not.

The real burden is on the application developpers who need to update their code to leverage this.

Why it's not transparent to application?
Application just use system malloc() and don't care whether the data is copied or not.

Quoted 5 lines

Also as a data point you want to avoid CPU access to CDM device memory as much as possible. The overhead for single cache line access are high (this is PCIE or derivative protocol and it is a packet protocol).

Thank you for the hint, we are going to follow cdm-hmm since HMM already merged into upstream.

--
Thanks,
Bob

--
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
Quoted 59 lines · Bob Liu
Quoted 58 lines · Jerome Glisse
Quoted 43 lines · Bob Liu
Quoted 42 lines · Jerome Glisse
Quoted 9 lines · Dan Williams
Quoted 8 lines · Jerome Glisse
Quoted 7 lines · Bob Liu
Quoted 6 lines · Jerome Glisse
Quoted 5 lines · Bob Liu
Quoted 4 lines · Jerome Glisse
Quoted 3 lines · Bob Liu
Quoted 2 lines · Jerome Glisse
Quoted 1 line · Bob Liu

On 2017/7/14 5:15, Jérôme Glisse wrote:

[...]

Quoted 28 lines
Quoted 20 lines
Quoted 13 lines
Quoted 13 lines

Second device driver are not integrated that closely within mm and the scheduler kernel code to allow to efficiently plug in device access notification to page (ie to update struct page so that numa worker thread can migrate memory base on accurate informations).

Third it can be hard to decide who win between CPU and device access when it comes to updating thing like last CPU id.

Fourth there is no such thing like device id ie equivalent of CPU id. If we were to add something the CPU id field in flags of struct page would not be big enough so this can have repercusion on struct page size. This is not an easy sell.

Quoted 6 lines
Quoted 1 line

They are other issues i can't think of right now. I think for now it

My opinion is most of the issues are the same no matter use CDM or HMM-CDM. I just care about a more complete solution no matter CDM,HMM-CDM or other ways. HMM or HMM-CDM depends on device driver, but haven't see a public/full driver to demonstrate the whole solution works fine.

Quoted 5 lines

I am working with NVidia close source driver team to make sure that it works well for them. I am also working on nouveau open source driver for same NVidia hardware thought it will be of less use as what is missing there is a solid open source userspace to leverage this. Nonetheless open source driver are in the work.

Can you point to the nouveau patches? I still find these HMM patches un-reviewable without an upstream consumer.

Quoted 8 lines
Quoted 4 lines

So i pushed a branch with WIP for nouveau to use HMM:

https://cgit.freedesktop.org/~glisse/linux/log/?h=hmm-nouveau

Nice to see that.
Btw, do you have any plan for a CDM-HMM driver? CPU can write to Device memory directly without extra copy.

Yes nouveau CDM support on PPC (which is the only CDM platform commercialy available today) is on the TODO list. Note that the driver changes for CDM are minimal (probably less than 100 lines of code). From the driver point of view this is memory and it doesn't matter if it is CDM or not.

Quoted 6 lines
Quoted 3 lines

The real burden is on the application developpers who need to update their code to leverage this.

Why it's not transparent to application?
Application just use system malloc() and don't care whether the data is copied or not.

Porting today software to malloc/mmap is easy and apply to both non CDM and CDM hardware.

So malloc/mmap is a given what i mean is that having CPU capable of doing cache coherent access to device memory is a new thing. It never existed before and thus no one ever though of how to take advantages of that ie there is no existing program designed with that in mind.

Cheers,
Jérôme

#30 lore raw
In reply to Jerome Glisse
Quoted 49 lines · Jerome Glisse
Quoted 48 lines · Bob Liu
Quoted 46 lines · Jerome Glisse
Quoted 9 lines · Dan Williams
Quoted 8 lines · Jerome Glisse
Quoted 7 lines · Bob Liu
Quoted 6 lines · Jerome Glisse
Quoted 5 lines · Bob Liu
Quoted 4 lines · Jerome Glisse
Quoted 3 lines · Bob Liu
Quoted 2 lines · Jerome Glisse
Quoted 1 line · Bob Liu

On 2017/7/14 5:15, Jérôme Glisse wrote:

[...]

Quoted 20 lines
Quoted 20 lines
Quoted 19 lines
Quoted 8 lines

Second device driver are not integrated that closely within mm and the scheduler kernel code to allow to efficiently plug in device access notification to page (ie to update struct page so that numa worker thread can migrate memory base on accurate informations).

Third it can be hard to decide who win between CPU and device access when it comes to updating thing like last CPU id.

Quoted 6 lines

Fourth there is no such thing like device id ie equivalent of CPU id. If we were to add something the CPU id field in flags of struct page would not be big enough so this can have repercusion on struct page size. This is not an easy sell.

They are other issues i can't think of right now. I think for now it

My opinion is most of the issues are the same no matter use CDM or HMM-CDM. I just care about a more complete solution no matter CDM,HMM-CDM or other ways. HMM or HMM-CDM depends on device driver, but haven't see a public/full driver to demonstrate the whole solution works fine.

Quoted 8 lines
Quoted 5 lines

I am working with NVidia close source driver team to make sure that it works well for them. I am also working on nouveau open source driver for same NVidia hardware thought it will be of less use as what is missing there is a solid open source userspace to leverage this. Nonetheless open source driver are in the work.

Can you point to the nouveau patches? I still find these HMM patches un-reviewable without an upstream consumer.

So i pushed a branch with WIP for nouveau to use HMM:

https://cgit.freedesktop.org/~glisse/linux/log/?h=hmm-nouveau

Quoted 9 lines
Quoted 3 lines

Nice to see that.
Btw, do you have any plan for a CDM-HMM driver? CPU can write to Device memory directly without extra copy.

Yes nouveau CDM support on PPC (which is the only CDM platform commercialy available today) is on the TODO list. Note that the driver changes for CDM are minimal (probably less than 100 lines of code). From the driver point of view this is memory and it doesn't matter if it is CDM or not.

It seems have to migrate/copy memory between system-memory and device-memory even in HMM-CDM solution.
Because device-memory is not added into buddy system, the page fault for normal malloc() always allocate memory from system-memory!! If the device then access the same virtual address, the data is copied to device-memory.

Correct me if I misunderstand something.
@Balbir, how do you plan to make zero-copy work if using HMM-CDM?

--
Thanks,
Bob

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

#31 lore raw
Quoted 67 lines · Bob Liu
Quoted 49 lines · Jerome Glisse
Quoted 48 lines · Bob Liu
Quoted 46 lines · Jerome Glisse
Quoted 9 lines · Dan Williams
Quoted 8 lines · Jerome Glisse
Quoted 7 lines · Bob Liu
Quoted 6 lines · Jerome Glisse
Quoted 5 lines · Bob Liu
Quoted 4 lines · Jerome Glisse
Quoted 3 lines · Bob Liu
Quoted 2 lines · Jerome Glisse
Quoted 1 line · Bob Liu

On 2017/7/14 5:15, Jérôme Glisse wrote:

[...]

Quoted 20 lines
Quoted 20 lines
Quoted 19 lines
Quoted 8 lines

Second device driver are not integrated that closely within mm and the scheduler kernel code to allow to efficiently plug in device access notification to page (ie to update struct page so that numa worker thread can migrate memory base on accurate informations).

Third it can be hard to decide who win between CPU and device access when it comes to updating thing like last CPU id.

Quoted 6 lines

Fourth there is no such thing like device id ie equivalent of CPU id. If we were to add something the CPU id field in flags of struct page would not be big enough so this can have repercusion on struct page size. This is not an easy sell.

They are other issues i can't think of right now. I think for now it

My opinion is most of the issues are the same no matter use CDM or HMM-CDM. I just care about a more complete solution no matter CDM,HMM-CDM or other ways. HMM or HMM-CDM depends on device driver, but haven't see a public/full driver to demonstrate the whole solution works fine.

Quoted 8 lines
Quoted 5 lines

I am working with NVidia close source driver team to make sure that it works well for them. I am also working on nouveau open source driver for same NVidia hardware thought it will be of less use as what is missing there is a solid open source userspace to leverage this. Nonetheless open source driver are in the work.

Can you point to the nouveau patches? I still find these HMM patches un-reviewable without an upstream consumer.

So i pushed a branch with WIP for nouveau to use HMM:

https://cgit.freedesktop.org/~glisse/linux/log/?h=hmm-nouveau

Quoted 9 lines
Quoted 3 lines

Nice to see that.
Btw, do you have any plan for a CDM-HMM driver? CPU can write to Device memory directly without extra copy.

Yes nouveau CDM support on PPC (which is the only CDM platform commercialy available today) is on the TODO list. Note that the driver changes for CDM are minimal (probably less than 100 lines of code). From the driver point of view this is memory and it doesn't matter if it is CDM or not.

It seems have to migrate/copy memory between system-memory and device-memory even in HMM-CDM solution.
Because device-memory is not added into buddy system, the page fault for normal malloc() always allocate memory from system-memory!! If the device then access the same virtual address, the data is copied to device-memory.

Quoted 2 lines

Correct me if I misunderstand something.
@Balbir, how do you plan to make zero-copy work if using HMM-CDM?

Device can access system memory so copy to device is _not_ mandatory. Copying data to device is for performance only ie the device driver take hint from userspace and monitor device activity to decide which memory should be migrated to device memory to maximize performance.

Moreover in some previous version of the HMM patchset we had an helper that allowed to directly allocate device memory on device page fault. I intend to post this helper again. With that helper you can have zero copy when device is the first to access the memory.

Plan is to get what we have today work properly with the open source driver and make it perform well. Once we get some experience with real workload we might look into allowing CPU page fault to be directed to device memory but at this time i don't think we need this.

Cheers,
Jérôme

#32 lore raw
Quoted 6 lines · Jerome Glisse
Quoted 5 lines · Bob Liu
Quoted 4 lines · Jerome Glisse
Quoted 3 lines · Bob Liu
Quoted 2 lines · Jerome Glisse
Quoted 1 line · Dan Williams

On Thu, Jul 20, 2017 at 6:41 PM, Jerome Glisse <[email protected]> wrote:

[...]

Quoted 25 lines
Quoted 22 lines
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines

So i pushed a branch with WIP for nouveau to use HMM:

https://cgit.freedesktop.org/~glisse/linux/log/?h=hmm-nouveau

Quoted 9 lines
Quoted 3 lines

Nice to see that.
Btw, do you have any plan for a CDM-HMM driver? CPU can write to Device memory directly without extra copy.

Yes nouveau CDM support on PPC (which is the only CDM platform commercialy available today) is on the TODO list. Note that the driver changes for CDM are minimal (probably less than 100 lines of code). From the driver point of view this is memory and it doesn't matter if it is CDM or not.

It seems have to migrate/copy memory between system-memory and device-memory even in HMM-CDM solution.
Because device-memory is not added into buddy system, the page fault for normal malloc() always allocate memory from system-memory!! If the device then access the same virtual address, the data is copied to device-memory.

Quoted 2 lines

Correct me if I misunderstand something.
@Balbir, how do you plan to make zero-copy work if using HMM-CDM?

Quoted 6 lines

Device can access system memory so copy to device is _not_ mandatory. Copying data to device is for performance only ie the device driver take hint from userspace and monitor device activity to decide which memory should be migrated to device memory to maximize performance.

Moreover in some previous version of the HMM patchset we had an helper that

Could you point in which version? I'd like to have a look.

Quoted 9 lines

allowed to directly allocate device memory on device page fault. I intend to post this helper again. With that helper you can have zero copy when device is the first to access the memory.

Plan is to get what we have today work properly with the open source driver and make it perform well. Once we get some experience with real workload we might look into allowing CPU page fault to be directed to device memory but at this time i don't think we need this.

For us, we need this feature that CPU page fault can be direct to device memory. So that don't need to copy data from system memory to device memory.
Do you have any suggestion on the implementation? I'll try to make a prototype patch.

--
Thanks,
Bob

#33 lore raw
Quoted 33 lines · Bob Liu
Quoted 6 lines · Jerome Glisse
Quoted 5 lines · Bob Liu
Quoted 4 lines · Jerome Glisse
Quoted 3 lines · Bob Liu
Quoted 2 lines · Jerome Glisse
Quoted 1 line · Dan Williams

On Thu, Jul 20, 2017 at 6:41 PM, Jerome Glisse <[email protected]> wrote:

[...]

Quoted 25 lines
Quoted 24 lines
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines

So i pushed a branch with WIP for nouveau to use HMM:

https://cgit.freedesktop.org/~glisse/linux/log/?h=hmm-nouveau

Quoted 9 lines
Quoted 3 lines

Nice to see that.
Btw, do you have any plan for a CDM-HMM driver? CPU can write to Device memory directly without extra copy.

Yes nouveau CDM support on PPC (which is the only CDM platform commercialy available today) is on the TODO list. Note that the driver changes for CDM are minimal (probably less than 100 lines of code). From the driver point of view this is memory and it doesn't matter if it is CDM or not.

It seems have to migrate/copy memory between system-memory and device-memory even in HMM-CDM solution.
Because device-memory is not added into buddy system, the page fault for normal malloc() always allocate memory from system-memory!! If the device then access the same virtual address, the data is copied to device-memory.

Correct me if I misunderstand something.
@Balbir, how do you plan to make zero-copy work if using HMM-CDM?

Quoted 8 lines
Quoted 6 lines

Device can access system memory so copy to device is _not_ mandatory. Copying data to device is for performance only ie the device driver take hint from userspace and monitor device activity to decide which memory should be migrated to device memory to maximize performance.

Moreover in some previous version of the HMM patchset we had an helper that

Could you point in which version? I'd like to have a look.

I will need to dig in.

Quoted 11 lines
Quoted 10 lines

allowed to directly allocate device memory on device page fault. I intend to post this helper again. With that helper you can have zero copy when device is the first to access the memory.

Plan is to get what we have today work properly with the open source driver and make it perform well. Once we get some experience with real workload we might look into allowing CPU page fault to be directed to device memory but at this time i don't think we need this.

Quoted 3 lines

For us, we need this feature that CPU page fault can be direct to device memory. So that don't need to copy data from system memory to device memory.
Do you have any suggestion on the implementation? I'll try to make a prototype patch.

Why do you need that ? What is the device and what are the requirement ?

Jerome

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

#34 lore raw
Quoted 39 lines · Jerome Glisse
Quoted 38 lines · Bob Liu
Quoted 6 lines · Jerome Glisse
Quoted 5 lines · Bob Liu
Quoted 4 lines · Jerome Glisse
Quoted 3 lines · Bob Liu
Quoted 2 lines · Jerome Glisse
Quoted 1 line · Dan Williams

On Thu, Jul 20, 2017 at 6:41 PM, Jerome Glisse <[email protected]> wrote:

[...]

Quoted 30 lines
Quoted 22 lines
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines

So i pushed a branch with WIP for nouveau to use HMM:

https://cgit.freedesktop.org/~glisse/linux/log/?h=hmm-nouveau

Quoted 9 lines
Quoted 3 lines

Nice to see that.
Btw, do you have any plan for a CDM-HMM driver? CPU can write to Device memory directly without extra copy.

Yes nouveau CDM support on PPC (which is the only CDM platform commercialy available today) is on the TODO list. Note that the driver changes for CDM are minimal (probably less than 100 lines of code). From the driver point of view this is memory and it doesn't matter if it is CDM or not.

It seems have to migrate/copy memory between system-memory and device-memory even in HMM-CDM solution.
Because device-memory is not added into buddy system, the page fault for normal malloc() always allocate memory from system-memory!! If the device then access the same virtual address, the data is copied to device-memory.

Quoted 2 lines

Correct me if I misunderstand something.
@Balbir, how do you plan to make zero-copy work if using HMM-CDM?

Device can access system memory so copy to device is _not_ mandatory. Copying data to device is for performance only ie the device driver take hint from userspace and monitor device activity to decide which memory should be migrated to device memory to maximize performance.

Quoted 6 lines
Quoted 3 lines
Quoted 1 line

Moreover in some previous version of the HMM patchset we had an helper that

Could you point in which version? I'd like to have a look.

I will need to dig in.

Thank you.

Quoted 11 lines
Quoted 11 lines
Quoted 10 lines

allowed to directly allocate device memory on device page fault. I intend to post this helper again. With that helper you can have zero copy when device is the first to access the memory.

Plan is to get what we have today work properly with the open source driver and make it perform well. Once we get some experience with real workload we might look into allowing CPU page fault to be directed to device memory but at this time i don't think we need this.

Quoted 6 lines
Quoted 3 lines

For us, we need this feature that CPU page fault can be direct to device memory. So that don't need to copy data from system memory to device memory.
Do you have any suggestion on the implementation? I'll try to make a prototype patch.

Why do you need that ? What is the device and what are the requirement ?

You may think it as a CCIX device or CAPI device.
The requirement is eliminate any extra copy.
A typical usecase/requirement is malloc() and madvise() allocate from device memory, then CPU write data to device memory directly and trigger device to read the data/do calculation.

Signature · 8 lines
Regards,
--Bob

--
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>
#35 lore raw
Quoted 40 lines · Bob Liu
Quoted 39 lines · Jerome Glisse
Quoted 38 lines · Bob Liu
Quoted 6 lines · Jerome Glisse
Quoted 5 lines · Bob Liu
Quoted 4 lines · Jerome Glisse
Quoted 3 lines · Bob Liu
Quoted 2 lines · Jerome Glisse
Quoted 1 line · Dan Williams

On Thu, Jul 20, 2017 at 6:41 PM, Jerome Glisse <[email protected]> wrote:

[...]

Quoted 30 lines
Quoted 22 lines
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines

So i pushed a branch with WIP for nouveau to use HMM:

https://cgit.freedesktop.org/~glisse/linux/log/?h=hmm-nouveau

Quoted 9 lines
Quoted 3 lines

Nice to see that.
Btw, do you have any plan for a CDM-HMM driver? CPU can write to Device memory directly without extra copy.

Yes nouveau CDM support on PPC (which is the only CDM platform commercialy available today) is on the TODO list. Note that the driver changes for CDM are minimal (probably less than 100 lines of code). From the driver point of view this is memory and it doesn't matter if it is CDM or not.

It seems have to migrate/copy memory between system-memory and device-memory even in HMM-CDM solution.
Because device-memory is not added into buddy system, the page fault for normal malloc() always allocate memory from system-memory!! If the device then access the same virtual address, the data is copied to device-memory.

Quoted 2 lines

Correct me if I misunderstand something.
@Balbir, how do you plan to make zero-copy work if using HMM-CDM?

Device can access system memory so copy to device is _not_ mandatory. Copying data to device is for performance only ie the device driver take hint from userspace and monitor device activity to decide which memory should be migrated to device memory to maximize performance.

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
Quoted 1 line

Moreover in some previous version of the HMM patchset we had an helper that

Could you point in which version? I'd like to have a look.

I will need to dig in.

Thank you.

I forgot about this, sorry i was traveling i am still catching up. I will send you those patches once i unearth where i end up backing them.

Quoted 16 lines
Quoted 16 lines
Quoted 15 lines
Quoted 11 lines

allowed to directly allocate device memory on device page fault. I intend to post this helper again. With that helper you can have zero copy when device is the first to access the memory.

Plan is to get what we have today work properly with the open source driver and make it perform well. Once we get some experience with real workload we might look into allowing CPU page fault to be directed to device memory but at this time i don't think we need this.

For us, we need this feature that CPU page fault can be direct to device memory. So that don't need to copy data from system memory to device memory.
Do you have any suggestion on the implementation? I'll try to make a prototype patch.

Quoted 8 lines
Quoted 2 lines

Why do you need that ? What is the device and what are the requirement ?

You may think it as a CCIX device or CAPI device.
The requirement is eliminate any extra copy.
A typical usecase/requirement is malloc() and madvise() allocate from device memory, then CPU write data to device memory directly and trigger device to read the data/do calculation.

I suggest you rely on the device driver userspace API to do a migration after malloc then. Something like:
ptr = malloc(size);
my_device_migrate(ptr, size);

Which would call an ioctl of the device driver which itself would migrate memory or allocate device memory for the range if pointer return by malloc is not yet back by any pages.

There has been several discussions already about madvise/mbind/set_mempolicy/ move_pages and at this time i don't think we want to add or change any of them to understand device memory. My personal opinion is that we first need to have enough upstream user and understand of how it is actualy use before it make sense to try to formalize and define a syscall or change an existing one. User facing API are set in stone and i don't want to design them by making broad assumption on how i think device memory will be use.

So for time being i think it is better to use existing device API to manage and give hint to the kernel on where memory should be (ie should device memory be use for some range). The first user of this are GPU and they already have a lot of ioctl to manage and propagate hint from user space. So at this time i suggest that you piggy back on any existing ioctl of your device or add new ioctl.

Hope this help.
Jerome

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

#36 lore raw
Quoted 6 lines
Quoted 5 lines

You may think it as a CCIX device or CAPI device.
The requirement is eliminate any extra copy.
A typical usecase/requirement is malloc() and madvise() allocate from device memory, then CPU write data to device memory directly and trigger device to read the data/do calculation.

Quoted 9 lines

I suggest you rely on the device driver userspace API to do a migration after malloc then. Something like:
ptr = malloc(size);
my_device_migrate(ptr, size);

Which would call an ioctl of the device driver which itself would migrate memory or allocate device memory for the range if pointer return by malloc is not yet back by any pages.

So for CCIX, I don't think there is going to be an inline device driver that would allocate any memory for you. The expansion memory will become part of the system memory as part of the boot process. So, if the host DDR is 256GB and the CCIX expansion memory is 4GB, the total system mem will be 260GB.

Assume that the 'mm' is taught to mark/anoint the ZONE_DEVICE(or ZONE_XXX) range from 256 to 260 GB. Then, for kmalloc it(mm) won't use the ZONE_DEV range. But for a malloc, it will/can use that range.

Quoted 3 lines

There has been several discussions already about madvise/mbind/set_mempolicy/ move_pages and at this time i don't think we want to add or change any of them to understand device memory. My personal opinion is that we first need to have enough

We will visit these APIs when we are more closer to building exotic CCIX devices. And the plan is to present/express the CCIX proximity attributes just like a NUMA node-proximity attribute today. That way there would be minimal disruptions to the existing OS ecosystem.

Chetan

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

#37 lore raw
Quoted 22 lines · chet l
Quoted 6 lines
Quoted 5 lines

You may think it as a CCIX device or CAPI device.
The requirement is eliminate any extra copy.
A typical usecase/requirement is malloc() and madvise() allocate from device memory, then CPU write data to device memory directly and trigger device to read the data/do calculation.

Quoted 9 lines

I suggest you rely on the device driver userspace API to do a migration after malloc then. Something like:
ptr = malloc(size);
my_device_migrate(ptr, size);

Which would call an ioctl of the device driver which itself would migrate memory or allocate device memory for the range if pointer return by malloc is not yet back by any pages.

So for CCIX, I don't think there is going to be an inline device driver that would allocate any memory for you. The expansion memory will become part of the system memory as part of the boot process. So, if the host DDR is 256GB and the CCIX expansion memory is 4GB, the total system mem will be 260GB.

Quoted 3 lines

Assume that the 'mm' is taught to mark/anoint the ZONE_DEVICE(or ZONE_XXX) range from 256 to 260 GB. Then, for kmalloc it(mm) won't use the ZONE_DEV range. But for a malloc, it will/can use that range.

HMM zone device memory would work with that, you just need to teach the platform to identify this memory zone and not hotplug it. Again you should rely on specific device driver API to allocate this memory.

Quoted 8 lines
Quoted 3 lines

There has been several discussions already about madvise/mbind/set_mempolicy/ move_pages and at this time i don't think we want to add or change any of them to understand device memory. My personal opinion is that we first need to have enough

We will visit these APIs when we are more closer to building exotic CCIX devices. And the plan is to present/express the CCIX proximity attributes just like a NUMA node-proximity attribute today. That way there would be minimal disruptions to the existing OS ecosystem.

NUMA have been rejected previously see CDM/CAPI threads. So i don't see it being accepted for CCIX either. My belief is that we want to hide this inside device driver and only once we see multiple devices all doing the same kind of thing we should move toward building something generic that catter to CCIX devices.

Jerome

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

CC'ing : [email protected]

Quoted 23 lines · Jerome Glisse
Quoted 22 lines · chet l
Quoted 6 lines
Quoted 5 lines

You may think it as a CCIX device or CAPI device.
The requirement is eliminate any extra copy.
A typical usecase/requirement is malloc() and madvise() allocate from device memory, then CPU write data to device memory directly and trigger device to read the data/do calculation.

Quoted 9 lines

I suggest you rely on the device driver userspace API to do a migration after malloc then. Something like:
ptr = malloc(size);
my_device_migrate(ptr, size);

Which would call an ioctl of the device driver which itself would migrate memory or allocate device memory for the range if pointer return by malloc is not yet back by any pages.

So for CCIX, I don't think there is going to be an inline device driver that would allocate any memory for you. The expansion memory will become part of the system memory as part of the boot process. So, if the host DDR is 256GB and the CCIX expansion memory is 4GB, the total system mem will be 260GB.

Quoted 8 lines
Quoted 3 lines

Assume that the 'mm' is taught to mark/anoint the ZONE_DEVICE(or ZONE_XXX) range from 256 to 260 GB. Then, for kmalloc it(mm) won't use the ZONE_DEV range. But for a malloc, it will/can use that range.

HMM zone device memory would work with that, you just need to teach the platform to identify this memory zone and not hotplug it. Again you should rely on specific device driver API to allocate this memory.

@Jerome - a new linux-accelerator's list has just been created. I have CC'd that list since we have overlapping interests w.r.t CCIX.

I cannot comment on surprise add/remove as of now ... will cross the bridge later.

Quoted 9 lines
Quoted 8 lines
Quoted 3 lines

There has been several discussions already about madvise/mbind/set_mempolicy/ move_pages and at this time i don't think we want to add or change any of them to understand device memory. My personal opinion is that we first need to have enough

We will visit these APIs when we are more closer to building exotic CCIX devices. And the plan is to present/express the CCIX proximity attributes just like a NUMA node-proximity attribute today. That way there would be minimal disruptions to the existing OS ecosystem.

Quoted 5 lines

NUMA have been rejected previously see CDM/CAPI threads. So i don't see it being accepted for CCIX either. My belief is that we want to hide this inside device driver and only once we see multiple devices all doing the same kind of thing we should move toward building something generic that catter to CCIX devices.

Thanks for pointing out the NUMA thingy. I will visit the CDM/CAPI threads to understand what was discussed before commenting further.

Chetan

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

#39 lore raw
Quoted 2 lines · chetan L

CC'ing : [email protected]

Sorry, CC'ing the correct list this time: [email protected]

Quoted 56 lines · Jerome Glisse
Quoted 23 lines · chet l
Quoted 22 lines
Quoted 6 lines
Quoted 5 lines

You may think it as a CCIX device or CAPI device.
The requirement is eliminate any extra copy.
A typical usecase/requirement is malloc() and madvise() allocate from device memory, then CPU write data to device memory directly and trigger device to read the data/do calculation.

Quoted 9 lines

I suggest you rely on the device driver userspace API to do a migration after malloc then. Something like:
ptr = malloc(size);
my_device_migrate(ptr, size);

Which would call an ioctl of the device driver which itself would migrate memory or allocate device memory for the range if pointer return by malloc is not yet back by any pages.

So for CCIX, I don't think there is going to be an inline device driver that would allocate any memory for you. The expansion memory will become part of the system memory as part of the boot process. So, if the host DDR is 256GB and the CCIX expansion memory is 4GB, the total system mem will be 260GB.

Quoted 8 lines
Quoted 3 lines

Assume that the 'mm' is taught to mark/anoint the ZONE_DEVICE(or ZONE_XXX) range from 256 to 260 GB. Then, for kmalloc it(mm) won't use the ZONE_DEV range. But for a malloc, it will/can use that range.

HMM zone device memory would work with that, you just need to teach the platform to identify this memory zone and not hotplug it. Again you should rely on specific device driver API to allocate this memory.

@Jerome - a new linux-accelerator's list has just been created. I have CC'd that list since we have overlapping interests w.r.t CCIX.

I cannot comment on surprise add/remove as of now ... will cross the bridge later.

Quoted 9 lines
Quoted 8 lines
Quoted 3 lines

There has been several discussions already about madvise/mbind/set_mempolicy/ move_pages and at this time i don't think we want to add or change any of them to understand device memory. My personal opinion is that we first need to have enough

We will visit these APIs when we are more closer to building exotic CCIX devices. And the plan is to present/express the CCIX proximity attributes just like a NUMA node-proximity attribute today. That way there would be minimal disruptions to the existing OS ecosystem.

Quoted 5 lines

NUMA have been rejected previously see CDM/CAPI threads. So i don't see it being accepted for CCIX either. My belief is that we want to hide this inside device driver and only once we see multiple devices all doing the same kind of thing we should move toward building something generic that catter to CCIX devices.

Quoted 3 lines

Thanks for pointing out the NUMA thingy. I will visit the CDM/CAPI threads to understand what was discussed before commenting further.

--
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
Quoted 34 lines · chetan L
Quoted 33 lines · chetan L
Quoted 31 lines · Jerome Glisse
Quoted 22 lines · chet l
Quoted 6 lines
Quoted 5 lines

You may think it as a CCIX device or CAPI device.
The requirement is eliminate any extra copy.
A typical usecase/requirement is malloc() and madvise() allocate from device memory, then CPU write data to device memory directly and trigger device to read the data/do calculation.

Quoted 9 lines

I suggest you rely on the device driver userspace API to do a migration after malloc then. Something like:
ptr = malloc(size);
my_device_migrate(ptr, size);

Which would call an ioctl of the device driver which itself would migrate memory or allocate device memory for the range if pointer return by malloc is not yet back by any pages.

So for CCIX, I don't think there is going to be an inline device driver that would allocate any memory for you. The expansion memory will become part of the system memory as part of the boot process. So, if the host DDR is 256GB and the CCIX expansion memory is 4GB, the total system mem will be 260GB.

Quoted 3 lines

Assume that the 'mm' is taught to mark/anoint the ZONE_DEVICE(or ZONE_XXX) range from 256 to 260 GB. Then, for kmalloc it(mm) won't use the ZONE_DEV range. But for a malloc, it will/can use that range.

HMM zone device memory would work with that, you just need to teach the platform to identify this memory zone and not hotplug it. Again you should rely on specific device driver API to allocate this memory.

Quoted 5 lines
Quoted 5 lines

@Jerome - a new linux-accelerator's list has just been created. I have CC'd that list since we have overlapping interests w.r.t CCIX.

I cannot comment on surprise add/remove as of now ... will cross the bridge later.

Note that this is not hotplug strictly speaking. Design today is that it is the device driver that register the memory. From kernel point of view this is an hotplug but for many of the target architecture there is no real hotplug ie device and its memory was present at boot time.

Like i said i think for now we are better of having each device manage and register its memory. HMM provide a toolbox for that. If we see common trend accross multiple devices then we can think about making something more generic.

For the NUMA discussion this is related to CPU less node ie not wanting to add any more CPU less node (node with only memory) and they are other aspect too. For instance you do not necessarily have good informations from the device to know if a page is access a lot by the device (this kind of information is often only accessible by the device driver). Thus the automatic NUMA placement is useless here. Not mentioning that for it to work we would need to change how it currently work (iirc there is issue when you not have a CPU id you can use).

Cheers,
Jerome

--
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
Quoted 6 lines · Jerome Glisse

For the NUMA discussion this is related to CPU less node ie not wanting to add any more CPU less node (node with only memory) and they are other aspect too. For instance you do not necessarily have good informations from the device to know if a page is access a lot by the device (this kind of information is often only accessible by the device driver). Thus

@Jerome - one comment w.r.t 'do not necessarily have good info on device access'.

So you could be assuming a few things here :). CCIX extends the CPU complex's coherency domain(it is now a single/unified coherency domain). The CCIX-EP (lets say an accelerator/XPU or a NIC or a combo) is now a true peer w.r.t the host-numa-node(s) (aka 1st class citizen). I don't know how much info was revealed at the latest ARM techcon where CCIX was presented. So I cannot divulge any further details until I see that slide deck. However, you can safely assume that the host will have *all* the info w.r.t the device-access and vice-versa.

Chetan

--
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
Quoted 12 lines · chetan L
Quoted 6 lines · Jerome Glisse

For the NUMA discussion this is related to CPU less node ie not wanting to add any more CPU less node (node with only memory) and they are other aspect too. For instance you do not necessarily have good informations from the device to know if a page is access a lot by the device (this kind of information is often only accessible by the device driver). Thus

@Jerome - one comment w.r.t 'do not necessarily have good info on device access'.

Quoted 9 lines

So you could be assuming a few things here :). CCIX extends the CPU complex's coherency domain(it is now a single/unified coherency domain). The CCIX-EP (lets say an accelerator/XPU or a NIC or a combo) is now a true peer w.r.t the host-numa-node(s) (aka 1st class citizen). I don't know how much info was revealed at the latest ARM techcon where CCIX was presented. So I cannot divulge any further details until I see that slide deck. However, you can safely assume that the host will have *all* the info w.r.t the device-access and vice-versa.

I do have access to CCIX, last time i read the draft, few month ago, my understanding was that there is no mechanism to differentiate between device behind the root complex. So when you do autonuma you don't know which of your CCIX device is the one faulting hence you can not keep track of that inside struct page for autonuma (ignoring the issue with the lack of CPUID for each device).

This is what i mean by NUMA is not a good fit as it is. Yes everything is cache coherent and all, but that is just a small part of what is needed to make autonuma as it is today work.

Jerome

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