Cache coherent device memory (CDM) with HMM v4
Subsystems (12)
cover Cache coherent device memory (CDM) with HMM v4
Changes since v3:
- change name to device host (s/DEVICE_PUBLIC/DEVICE_HOST/)
- added comments about how such memory is accounted (rss and memcg)
- added a documentation patch (to explain rss and memcg choice)
- add proper include to migrate.c and drop #if/#endif
- fix missing #if/#endif so this works even if DEVICE_PRIVATE is not enabled
Git tree:
https://cgit.freedesktop.org/~glisse/linux/log/?h=hmm-cdm-v4
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 - add DEVICE_HOST type to ZONE_DEVICE (all core mm changes) patch 02 - add an helper to HMM for hotplug of CDM memory patch 03 - preparatory patch for memory controller changes (memch) patch 04 - update memory controller to properly handle
ZONE_DEVICE pages when uncharging
patch 05 - 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/
JA(C)rA'me Glisse (5):
mm/device-host-memory: device memory cache coherent with CPU v3 mm/hmm: add new helper to hotplug CDM memory region v2 mm/memcontrol: allow to uncharge page without using page->lru field mm/memcontrol: support MEMORY_DEVICE_PRIVATE and MEMORY_DEVICE_HOST v2 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 | 21 +++++ include/linux/mm.h | 20 ++-- kernel/memremap.c | 17 +++- 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, 431 insertions(+), 131 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>
PATCH 1/5 mm/device-host-memory: device memory cache coherent with CPU v3
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 v2:
- s/public/host
- add proper include in migrate.c and drop useless #if/#endif
Changed since v1:
- Kconfig and #if/#else cleanup
--- 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
@@ -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
@@ -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_HOST )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_HOST */ /* Below are for HMM internal use only! Not to be used by device driver! */
include/linux/ioport.h +1 -0
@@ -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_HOST_MEMORY = 7, };/* helpers to define resources */
include/linux/memremap.h +21 -0
@@ -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_HOST: +* 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_PUBLIC =0 ,MEMORY_DEVICE_PRIVATE , +MEMORY_DEVICE_HOST , };/*
@@ -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_HOST 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_host_page (const struct page *page) +{ +return is_zone_device_page (page) && + page->pgmap->type ==MEMORY_DEVICE_HOST ; +}#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_host_page (const struct page *page) +{ +return false; +}#endif /**
include/linux/mm.h +12 -8
@@ -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_HOST ) +void put_zone_device_private_or_host_page (struct page *page);#else -static inline void put_zone_device_private_page (struct page *page) +static inline void put_zone_device_private_or_host_page (struct page *page) { } -#endif +#endif /* CONFIG_DEVICE_PRIVATE || CONFIG_DEVICE_HOST */ static inline bool is_device_private_page (const struct page *page); +static inline bool is_device_host_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_host_page (page))) { +put_zone_device_private_or_host_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_host_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
@@ -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_HOST ) +void put_zone_device_private_or_host_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_host_page); +#endif /* CONFIG_DEVICE_PRIVATE || CONFIG_DEVICE_HOST */
mm/Kconfig +11 -0
@@ -712,12 +712,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_HOST + 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
@@ -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 host page in the gate +* area). +*/ +if (is_device_host_page (*page)) + goto unmap; }get_page (*page); out:
mm/hmm.c +2 -2
@@ -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_HOST )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_HOST */
mm/madvise.c +1 -1
@@ -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
@@ -760,6 +760,17 @@ void release_pages(struct page **pages, int nr, bool cold)if (is_huge_zero_page (page))continue ; +/* Device host page can not be huge page */ +if (is_device_host_page (page)) { +if (locked_pgdat) { +spin_unlock_irqrestore (&locked_pgdat->lru_lock, + flags); + locked_pgdat =NULL ; + } +put_zone_device_private_or_host_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>
PATCH 2/5 mm/hmm: add new helper to hotplug CDM memory region v2
In reply to Jérôme GlisseUnlike 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 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
@@ -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>
PATCH 3/5 mm/memcontrol: allow to uncharge page without using page->lru field
In reply to Jérôme GlisseHMM pages (private or host 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.
--- mm/memcontrol.c | 168 +++++++++++++++++++++++++++++++------------------------- 1 file changed, 92 insertions(+), 76 deletions(-)
mm/memcontrol.c +92 -76
@@ -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
PATCH 4/5 mm/memcontrol: support MEMORY_DEVICE_PRIVATE and MEMORY_DEVICE_HOST v2
In reply to Jérôme GlisseHMM pages (private or host 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 v1:
- s/public/host
- add comments explaining how device memory behave and why
--- kernel/memremap.c | 2 ++ mm/memcontrol.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 60 insertions(+), 5 deletions(-)
kernel/memremap.c +2 -0
@@ -479,6 +479,8 @@ void put_zone_device_private_or_host_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>
PATCH 5/5 mm/hmm: documents how device memory is accounted in rss and memcg
In reply to Jérôme GlisseFor 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
@@ -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>
Quoted 2 lines · On Wed, 12 Jul 2017 14:06:02 -0400 Jérôme Glisse <[email protected]> wrote:
Changes since v3:
- change name to device host (s/DEVICE_PUBLIC/DEVICE_HOST/)
I think you've mis-interpreted what Dan said
The message @
http://www.mail-archive.com/[email protected]/msg1441839.html
states
"I was suggesting MEMORY_DEVICE_HOST for persistent memory and MEMORY_DEVICE_PUBLIC as you want for CDM."
I guess we get to keep DEVICE_PUBLIC and move persistent memory to MEMORY_DEVICE_HOST
Balbir Singh
--
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>
Quoted 6 lines · Balbir Singh
Quoted 2 lines · On Wed, 12 Jul 2017 14:06:02 -0400 Jerome Glisse <[email protected]> wrote:
Changes since v3:
- change name to device host (s/DEVICE_PUBLIC/DEVICE_HOST/)
Quoted 8 lines
I think you've mis-interpreted what Dan said
The message @
http://www.mail-archive.com/[email protected]/msg1441839.html
states"I was suggesting
MEMORY_DEVICE_HOSTfor persistent memory andMEMORY_DEVICE_PUBLICas you want for CDM."
Oh i missed that email :( is was lost in long spam thread in my inbox. Well i will likely repost a new version of HMM-CDM and with updated name then.
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>