Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1686929 > unrolled thread
| Started by | Jérôme Glisse <jglisse@redhat.com> |
|---|---|
| First post | 2017-07-13 23:20 +0200 |
| Last post | 2017-07-18 05:30 +0200 |
| Articles | 3 — 2 participants |
Back to article view | Back to linux.kernel
[PATCH 0/6] Cache coherent device memory (CDM) with HMM v5 Jérôme Glisse <jglisse@redhat.com> - 2017-07-13 23:20 +0200
[PATCH 3/6] mm/hmm: add new helper to hotplug CDM memory region v3 Jérôme Glisse <jglisse@redhat.com> - 2017-07-13 23:20 +0200
Re: [PATCH 0/6] Cache coherent device memory (CDM) with HMM v5 Bob Liu <liubo95@huawei.com> - 2017-07-18 05:30 +0200
| From | Jérôme Glisse <jglisse@redhat.com> |
|---|---|
| Date | 2017-07-13 23:20 +0200 |
| Subject | [PATCH 0/6] Cache coherent device memory (CDM) with HMM v5 |
| Message-ID | <u2TGF-2pl-5@gated-at.bofh.it> |
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/
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(-)
--
2.13.0
[toc] | [next] | [standalone]
| From | Jérôme Glisse <jglisse@redhat.com> |
|---|---|
| Date | 2017-07-13 23:20 +0200 |
| Subject | [PATCH 3/6] mm/hmm: add new helper to hotplug CDM memory region v3 |
| Message-ID | <u2TGG-2pl-33@gated-at.bofh.it> |
| In reply to | #1686929 |
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
Signed-off-by: Jérôme Glisse <jglisse@redhat.com>
Reviewed-by: Balbir Singh <bsingharora@gmail.com>
---
include/linux/hmm.h | 3 ++
mm/hmm.c | 85 +++++++++++++++++++++++++++++++++++++++++++++++++----
2 files changed, 83 insertions(+), 5 deletions(-)
diff --git a/include/linux/hmm.h b/include/linux/hmm.h
index a40288309fd2..e44cb8edb137 100644
--- a/include/linux/hmm.h
+++ b/include/linux/hmm.h
@@ -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);
/*
diff --git a/mm/hmm.c b/mm/hmm.c
index eadf70829c34..28e54e3b4e1d 100644
--- a/mm/hmm.c
+++ b/mm/hmm.c
@@ -849,7 +849,11 @@ static void hmm_devmem_release(struct device *dev, void *data)
zone = page_zone(page);
mem_hotplug_begin();
- __remove_pages(zone, start_pfn, npages);
+ if (resource->desc == IORES_DESC_DEVICE_PRIVATE_MEMORY)
+ __remove_pages(zone, start_pfn, npages);
+ else
+ arch_remove_memory(start_pfn << PAGE_SHIFT,
+ npages << PAGE_SHIFT);
mem_hotplug_done();
hmm_devmem_radix_release(resource);
@@ -885,7 +889,11 @@ static int hmm_devmem_pages_create(struct hmm_devmem *devmem)
if (is_ram == REGION_INTERSECTS)
return -ENXIO;
- devmem->pagemap.type = MEMORY_DEVICE_PRIVATE;
+ if (devmem->resource->desc == IORES_DESC_DEVICE_PUBLIC_MEMORY)
+ devmem->pagemap.type = MEMORY_DEVICE_PUBLIC;
+ else
+ devmem->pagemap.type = MEMORY_DEVICE_PRIVATE;
+
devmem->pagemap.res = devmem->resource;
devmem->pagemap.page_fault = hmm_devmem_fault;
devmem->pagemap.page_free = hmm_devmem_free;
@@ -924,8 +932,11 @@ static int hmm_devmem_pages_create(struct hmm_devmem *devmem)
nid = numa_mem_id();
mem_hotplug_begin();
- ret = add_pages(nid, align_start >> PAGE_SHIFT,
- align_size >> PAGE_SHIFT, false);
+ if (devmem->pagemap.type == MEMORY_DEVICE_PUBLIC)
+ ret = arch_add_memory(nid, align_start, align_size, false);
+ else
+ ret = add_pages(nid, align_start >> PAGE_SHIFT,
+ align_size >> PAGE_SHIFT, false);
if (ret) {
mem_hotplug_done();
goto error_add_memory;
@@ -1075,6 +1086,67 @@ struct hmm_devmem *hmm_devmem_add(const struct hmm_devmem_ops *ops,
}
EXPORT_SYMBOL(hmm_devmem_add);
+struct hmm_devmem *hmm_devmem_add_resource(const struct hmm_devmem_ops *ops,
+ struct device *device,
+ struct resource *res)
+{
+ struct hmm_devmem *devmem;
+ int ret;
+
+ if (res->desc != IORES_DESC_DEVICE_PUBLIC_MEMORY)
+ return ERR_PTR(-EINVAL);
+
+ static_branch_enable(&device_private_key);
+
+ devmem = devres_alloc_node(&hmm_devmem_release, sizeof(*devmem),
+ GFP_KERNEL, dev_to_node(device));
+ if (!devmem)
+ return ERR_PTR(-ENOMEM);
+
+ init_completion(&devmem->completion);
+ devmem->pfn_first = -1UL;
+ devmem->pfn_last = -1UL;
+ devmem->resource = res;
+ devmem->device = device;
+ devmem->ops = ops;
+
+ ret = percpu_ref_init(&devmem->ref, &hmm_devmem_ref_release,
+ 0, GFP_KERNEL);
+ if (ret)
+ goto error_percpu_ref;
+
+ ret = devm_add_action(device, hmm_devmem_ref_exit, &devmem->ref);
+ if (ret)
+ goto error_devm_add_action;
+
+
+ devmem->pfn_first = devmem->resource->start >> PAGE_SHIFT;
+ devmem->pfn_last = devmem->pfn_first +
+ (resource_size(devmem->resource) >> PAGE_SHIFT);
+
+ ret = hmm_devmem_pages_create(devmem);
+ if (ret)
+ goto error_devm_add_action;
+
+ devres_add(device, devmem);
+
+ ret = devm_add_action(device, hmm_devmem_ref_kill, &devmem->ref);
+ if (ret) {
+ hmm_devmem_remove(devmem);
+ return ERR_PTR(ret);
+ }
+
+ return devmem;
+
+error_devm_add_action:
+ hmm_devmem_ref_kill(&devmem->ref);
+ hmm_devmem_ref_exit(&devmem->ref);
+error_percpu_ref:
+ devres_free(devmem);
+ return ERR_PTR(ret);
+}
+EXPORT_SYMBOL(hmm_devmem_add_resource);
+
/*
* hmm_devmem_remove() - remove device memory (kill and free ZONE_DEVICE)
*
@@ -1088,6 +1160,7 @@ void hmm_devmem_remove(struct hmm_devmem *devmem)
{
resource_size_t start, size;
struct device *device;
+ bool cdm = false;
if (!devmem)
return;
@@ -1096,11 +1169,13 @@ void hmm_devmem_remove(struct hmm_devmem *devmem)
start = devmem->resource->start;
size = resource_size(devmem->resource);
+ cdm = devmem->resource->desc == IORES_DESC_DEVICE_PUBLIC_MEMORY;
hmm_devmem_ref_kill(&devmem->ref);
hmm_devmem_ref_exit(&devmem->ref);
hmm_devmem_pages_remove(devmem);
- devm_release_mem_region(device, start, size);
+ if (!cdm)
+ devm_release_mem_region(device, start, size);
}
EXPORT_SYMBOL(hmm_devmem_remove);
--
2.13.0
[toc] | [prev] | [next] | [standalone]
| From | Bob Liu <liubo95@huawei.com> |
|---|---|
| Date | 2017-07-18 05:30 +0200 |
| Message-ID | <u4rmV-5vl-13@gated-at.bofh.it> |
| In reply to | #1686929 |
On 2017/7/14 5:15, Jérôme Glisse wrote: > 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. > 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 > 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(-) >
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web