Cache coherent device memory (CDM) with HMM
Subsystems (11)
cover Cache coherent device memory (CDM) with HMM
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 as last resort when running out of memory, at least for now.
This patchset add a new type of ZONE_DEVICE memory (DEVICE_PUBLIC) 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 patch if a device is in use in a process you might have private anonymous memory or file back page memory using ZONE_DEVICE (MEMORY_PUBLIC). 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 patch update all code path that would make assumptions about lruness of a process page.
patch 01 - deals with all the core mm functions patch 02 - add an helper to HMM for hotplug of CDM memory patch 03 - preparatory patch for memory controller changes patch 04 - update memory controller to properly handle
ZONE_DEVICE pages when uncharging
patch 05 - kernel configuration updates and cleanup
git tree:
https://cgit.freedesktop.org/~glisse/linux/log/?h=hmm-cdm-v2
Jérôme Glisse (5):
mm/device-public-memory: device memory cache coherent with CPU mm/hmm: add new helper to hotplug CDM memory region mm/memcontrol: allow to uncharge page without using page->lru field mm/memcontrol: support MEMORY_DEVICE_PRIVATE and MEMORY_DEVICE_PUBLIC mm/hmm: simplify kconfig and enable HMM and DEVICE_PUBLIC for ppc64
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 | 16 ++-- kernel/memremap.c | 13 ++- mm/Kconfig | 30 +++---- mm/gup.c | 7 ++ mm/hmm.c | 89 +++++++++++++++++-- mm/madvise.c | 2 +- mm/memcontrol.c | 226 ++++++++++++++++++++++++++++++----------------- mm/memory.c | 46 ++++++++-- mm/migrate.c | 60 ++++++++----- mm/swap.c | 11 +++ 14 files changed, 389 insertions(+), 142 deletions(-)
Signature · 1 line
2.9.3
PATCH 3/5 mm/memcontrol: allow to uncharge page without using page->lru field
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.
--- 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.9.3
PATCH 4/5 mm/memcontrol: support MEMORY_DEVICE_PRIVATE and MEMORY_DEVICE_PUBLIC
In reply to Jérôme GlisseHMM 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.
--- kernel/memremap.c | 2 ++ mm/memcontrol.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 55 insertions(+), 5 deletions(-)
kernel/memremap.c +2 -0
@@ -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 +53 -5
134 lines not on this page · raw message
Signature · 7 lines
2.9.3 -- 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-public-memory: device memory cache coherent with CPU
In reply to Jérôme GlissePlatform 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.
--- fs/proc/task_mmu.c | 2 +- include/linux/ioport.h | 1 + include/linux/memremap.h | 21 +++++++++++++++++ include/linux/mm.h | 16 ++++++++----- kernel/memremap.c | 11 ++++++--- mm/Kconfig | 13 +++++++++++ mm/gup.c | 7 ++++++ mm/madvise.c | 2 +- mm/memory.c | 46 +++++++++++++++++++++++++++++++++---- mm/migrate.c | 60 ++++++++++++++++++++++++++++++++---------------- mm/swap.c | 11 +++++++++ 11 files changed, 154 insertions(+), 36 deletions(-)
fs/proc/task_mmu.c +1 -1
@@ -1187,7 +1187,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/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_PUBLIC_MEMORY = 7, };/* helpers to define resources */
include/linux/memremap.h +21 -0
@@ -56,10 +56,18 @@ static inline struct vmem_altmap *to_vmem_altmap(unsigned long memmap_start)* page must be treated as an opaque object, rather than a "normal" struct page. * 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_PERSISTENT =0 ,MEMORY_DEVICE_PRIVATE , +MEMORY_DEVICE_PUBLIC , };/*
@@ -91,6 +99,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_CACHE_COHERENT only the page_free() callback matter. */ typedef int (*dev_page_fault_t)(struct vm_area_struct *vma, unsigned long addr,
@@ -133,6 +143,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,
@@ -156,6 +172,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 +10 -6
@@ -797,14 +797,15 @@ 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); +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 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 +8 -3
@@ -466,7 +466,7 @@ struct vmem_altmap *to_vmem_altmap(unsigned long memmap_start)#ifdef CONFIG_DEVICE_PRIVATE -void put_zone_device_private_page (struct page *page) +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); +EXPORT_SYMBOL (put_zone_device_private_or_public_page);#endif /* CONFIG_DEVICE_PRIVATE */
mm/Kconfig +13 -0
@@ -731,6 +731,19 @@ config DEVICE_PRIVATE memory; i.e., memory that is only accessible from the device (or group of devices). +config DEVICE_PUBLIC + bool "Unaddressable device memory (GPU memory, ...)" + depends on X86_64 + depends on ZONE_DEVICE + depends on MEMORY_HOTPLUG + depends on MEMORY_HOTREMOVE + depends on SPARSEMEM_VMEMMAP + + 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 public page in the gate +* area). +*/ +if (is_device_public_page (*page)) + goto unmap; }get_page (*page); out:
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 +40 -20
109 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 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.9.3 -- 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
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.
--- 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); int hmm_devmem_fault_range(struct hmm_devmem *devmem,
mm/hmm.c +80 -5
125 lines not on this page · raw message
Signature · 7 lines
2.9.3 -- 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: simplify kconfig and enable HMM and DEVICE_PUBLIC for ppc64
In reply to Jérôme GlisseThis just simplify kconfig and allow HMM and DEVICE_PUBLIC to be selected for ppc64 once ZONE_DEVICE is allowed on ppc64 (different patchset).
--- include/linux/hmm.h | 4 ++-- mm/Kconfig | 27 ++++++--------------------- mm/hmm.c | 4 ++-- 3 files changed, 10 insertions(+), 25 deletions(-)
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_HMM_DEVMEM ) +#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,
@@ -456,7 +456,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_HMM_DEVMEM) */ +#endif /* CONFIG_DEVICE_PRIVATE || CONFIG_DEVICE_PUBLIC */ /* Below are for HMM internal use only! Not to be used by device driver! */
mm/Kconfig +6 -21
@@ -265,7 +265,7 @@ config ARCH_ENABLE_HUGEPAGE_MIGRATION config ARCH_HAS_HMM bool default y - depends on X86_64 + depends on X86_64 || PPC64 depends on ZONE_DEVICE depends on MMU && 64BIT depends on MEMORY_HOTPLUG
@@ -277,7 +277,7 @@ config HMM config HMM_MIRROR bool "HMM mirror CPU page table into a device page table" - depends on ARCH_HAS_HMM + depends on ARCH_HAS_HMM && X86_64 select MMU_NOTIFIER select HMM help
@@ -287,15 +287,6 @@ config HMM_MIRROR page tables (at PAGE_SIZE granularity), and must be able to recover from the resulting potential page faults. -config HMM_DEVMEM - bool "HMM device memory helpers (to leverage ZONE_DEVICE)" - depends on ARCH_HAS_HMM - select HMM - help - HMM devmem is a set of helper routines to leverage the ZONE_DEVICE - feature. This is just to avoid having device drivers to replicating a lot - of boiler plate code. See Documentation/vm/hmm.txt. - config PHYS_ADDR_T_64BIT def_bool 64BIT || ARCH_PHYS_ADDR_T_64BIT
@@ -720,11 +711,8 @@ config ZONE_DEVICE config DEVICE_PRIVATE bool "Unaddressable device memory (GPU memory, ...)" - depends on X86_64 - depends on ZONE_DEVICE - depends on MEMORY_HOTPLUG - depends on MEMORY_HOTREMOVE - depends on SPARSEMEM_VMEMMAP + depends on ARCH_HAS_HMM && X86_64 + select HMM help Allows creation of struct pages to represent unaddressable device
@@ -733,11 +721,8 @@ config DEVICE_PRIVATE config DEVICE_PUBLIC bool "Unaddressable device memory (GPU memory, ...)" - depends on X86_64 - depends on ZONE_DEVICE - depends on MEMORY_HOTPLUG - depends on MEMORY_HOTREMOVE - depends on SPARSEMEM_VMEMMAP + depends on ARCH_HAS_HMM + select HMM help Allows creation of struct pages to represent addressable device
mm/hmm.c +2 -2
@@ -747,7 +747,7 @@ EXPORT_SYMBOL(hmm_vma_fault);#endif /* IS_ENABLED(CONFIG_HMM_MIRROR) */ -#if IS_ENABLED (CONFIG_HMM_DEVMEM ) +#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) {
@@ -1306,4 +1306,4 @@ static int __init hmm_init(void) }device_initcall (hmm_init); -#endif /* IS_ENABLED(CONFIG_HMM_DEVMEM) */ +#endif /* CONFIG_DEVICE_PRIVATE || CONFIG_DEVICE_PUBLIC */
Signature · 7 lines
2.9.3 -- 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 4 lines · Jérôme Glisse
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.
How does this interact with device memory that's enumerated in the new ACPI 6.2 HMAT? That stuff is also in the normal e820 and, by default, treated as normal system RAM. Would this mechanism be used for those devices as well?
http://www.uefi.org/sites/default/files/resources/ACPI_6_2.pdf
--
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 · Dave Hansen
Quoted 4 lines · Jérôme Glisse
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.
Quoted 6 lines
How does this interact with device memory that's enumerated in the new ACPI 6.2 HMAT? That stuff is also in the normal e820 and, by default, treated as normal system RAM. Would this mechanism be used for those devices as well?
http://www.uefi.org/sites/default/files/resources/ACPI_6_2.pdf
It doesn't interact with that. HMM-CDM is a set of helper that don't do anything unless instructed so. So for device memory to be presented as HMM-CDM you need to hotplug it as ZONE_DEVICE(DEVICE_PUBLIC) which can be done with the helper introduced in patch 2 of this patchset.
I don't think that the HMAT inside ACPI is restricted or even intended for device memory. The kind of memory i am refering too in HMM-CDM is for instance GPU on board memory. On PCIE system the CPU can not access such memory in the same manner as regular memory but on CAPI or CCIX system it can.
How such memory is listed is platform/architecture specific and HMM-CDM does not deal with that. So PowerPC CAPI will have its own way of discovering such device memory. So will CCIX platform (thought for CCIX i expect that UEFI/ACPI will be involve through HMAT or something new).
Also if HMAT allow represent device memory, the choice to use HMM-CDM would still be with the device driver. For persistent memory is does not make sense and it might not make sense for other devices too. I expect this to be usefull for GPU, FPGA or similar accelerator (like Xeon Phi as add on card if there is ever something like CCIX supported by Intel).
Hope this answer your question
Jérôme
Quoted 11 lines · Jerome Glisse
Quoted 10 lines · Dave Hansen
Quoted 4 lines · Jérôme Glisse
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.
How does this interact with device memory that's enumerated in the new ACPI 6.2 HMAT? That stuff is also in the normal e820 and, by default, treated as normal system RAM. Would this mechanism be used for those devices as well?
Quoted 5 lines
It doesn't interact with that. HMM-CDM is a set of helper that don't do anything unless instructed so. So for device memory to be presented as HMM-CDM you need to hotplug it as
ZONE_DEVICE(DEVICE_PUBLIC)which can be done with the helper introduced in patch 2 of this patchset.
I guess I'm asking whether we *should* instruct HMM-CDM to manage all coherent device memory. If not, where do we draw the line for what we use HMM-CDM, and for what we use the core MM?
Quoted 2 lines
I don't think that the HMAT inside ACPI is restricted or even intended for device memory.
It can definitely describe memory attached to memory controllers which are not directly attached to CPUs. That means either some kind of memory expander, or device memory.
Quoted 10 lines · Dave Hansen
Quoted 6 lines
It doesn't interact with that. HMM-CDM is a set of helper that don't do anything unless instructed so. So for device memory to be presented as HMM-CDM you need to hotplug it as
ZONE_DEVICE(DEVICE_PUBLIC)which can be done with the helper introduced in patch 2 of this patchset.I guess I'm asking whether we *should* instruct HMM-CDM to manage all coherent device memory. If not, where do we draw the line for what we use HMM-CDM, and for what we use the core MM?
Well, if you want the features of HMM ... It basically boils down to whether you have some kind of coherent processing unit close to that memory and want to manage transparent migration of pages between system and device memory, that sort of thing.
Cheers,
Ben.
--
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>
John Hubbard
reviewerRe: [HMM-CDM 5/5] mm/hmm: simplify kconfig and enable HMM and DEVICE_PUBLIC for ppc64
In reply to Jérôme GlisseQuoted 52 lines · Jérôme Glisse
This just simplify kconfig and allow HMM and
DEVICE_PUBLICto be selected for ppc64 onceZONE_DEVICEis allowed on ppc64 (different patchset).Signed-off-by Jérôme Glisse <[email protected]>Signed-off-by John Hubbard <[email protected]>Cc Balbir Singh <[email protected]>Cc Aneesh Kumar <[email protected]>Cc Paul E. McKenney <[email protected]>Cc Benjamin Herrenschmidt <[email protected]>--- include/linux/hmm.h | 4 ++-- mm/Kconfig | 27 ++++++--------------------- mm/hmm.c | 4 ++-- 3 files changed, 10 insertions(+), 25 deletions(-)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_HMM_DEVMEM ) +#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,@@ -456,7 +456,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_HMM_DEVMEM) */ +#endif /* CONFIG_DEVICE_PRIVATE || CONFIG_DEVICE_PUBLIC */ /* Below are for HMM internal use only! Not to be used by device driver! */ mm/Kconfig +1
-1@@ -265,7 +265,7 @@ config ARCH_ENABLE_HUGEPAGE_MIGRATION config ARCH_HAS_HMM bool default y - depends on X86_64 + depends on X86_64 || PPC64 depends on ZONE_DEVICE depends on MMU && 64BIT depends on MEMORY_HOTPLUG
mm/Kconfig config HMM · line 283
Quoted 8 lines
mm/Kconfig +1
-1@@ -277,7 +277,7 @@ config HMM config HMM_MIRROR bool "HMM mirror CPU page table into a device page table" - depends on ARCH_HAS_HMM + depends on ARCH_HAS_HMM && X86_64 select MMU_NOTIFIER select HMM help
Hi Jerome,
There are still some problems with using this configuration. First and foremost, it is still possible (and likely, given the complete dissimilarity in naming, and difference in location on the screen) to choose HMM_MIRROR, and *not* to choose either DEVICE_PRIVATE or DEVICE_PUBLIC. And then we end up with a swath of important page fault handling code being ifdef'd out, and one ends up having to investigate why.
As for solutions, at least for the x86 (DEVICE_PRIVATE)case, we could do this:
mm/Kconfig +1 -0
@@ -279,6 +279,7 @@ config HMM_MIRROR bool "HMM mirror CPU page table into a device page table" depends on ARCH_HAS_HMM && X86_64 select MMU_NOTIFIER + select DEVICE_PRIVATE select HMM help Select HMM_MIRROR if you want to mirror range of the CPU page table of a
...and that is better than the other direction (having HMM_MIRROR depend on DEVICE_PRIVATE), because in the latter case, HMM_MIRROR will disappear (and it's several lines above) until you select DEVICE_PRIVATE. That is hard to work with for the user.
The user will tend to select HMM_MIRROR, but it is *not* obvious that he/she should also select DEVICE_PRIVATE. So Kconfig should do it for them.
In fact, I'm not even sure if the DEVICE_PRIVATE and DEVICE_PUBLIC actually need Kconfig protection, but if they don't, then life would be easier for whoever is configuring their kernel.
mm/Kconfig config HMM_MIRROR · line 298
Quoted 13 lines
mm/Kconfig +0
-9@@ -287,15 +287,6 @@ config HMM_MIRROR page tables (at PAGE_SIZE granularity), and must be able to recover from the resulting potential page faults. -config HMM_DEVMEM - bool "HMM device memory helpers (to leverage ZONE_DEVICE)" - depends on ARCH_HAS_HMM - select HMM - help - HMM devmem is a set of helper routines to leverage the ZONE_DEVICE - feature. This is just to avoid having device drivers to replicating a lot - of boiler plate code. See Documentation/vm/hmm.txt. -
Yes, probably good to remove HMM_DEVMEM as a separate conig choice.
Quoted 18 lines
mm/Kconfig +2
-5config PHYS_ADDR_T_64BIT def_bool 64BIT || ARCH_PHYS_ADDR_T_64BIT@@ -720,11 +711,8 @@ config ZONE_DEVICE config DEVICE_PRIVATE bool "Unaddressable device memory (GPU memory, ...)" - depends on X86_64 - depends on ZONE_DEVICE - depends on MEMORY_HOTPLUG - depends on MEMORY_HOTREMOVE - depends on SPARSEMEM_VMEMMAP + depends on ARCH_HAS_HMM && X86_64 + select HMM help Allows creation of struct pages to represent unaddressable device
mm/Kconfig config DEVICE_PRIVATE · line 723
Quoted 3 lines
mm/Kconfig +0
-0@@ -733,11 +721,8 @@ config DEVICE_PRIVATE config DEVICE_PUBLIC bool "Unaddressable device memory (GPU memory, ...)"
Typo: this is a copy-and-paste from DEVICE_PRIVATE, but the "Unaddressable" part wasn't changed, so you'll end up with two identical-looking lines in make menuconfig.
Maybe "Directly addressable device memory"? And make the line less identical to DEVICE_PRIVATE?
thanks,
--
John Hubbard
NVIDIA
Quoted 32 lines
mm/Kconfig +2
-5- depends on X86_64 - depends on ZONE_DEVICE - depends on MEMORY_HOTPLUG - depends on MEMORY_HOTREMOVE - depends on SPARSEMEM_VMEMMAP + depends on ARCH_HAS_HMM + select HMM help Allows creation of struct pages to represent addressable devicemm/hmm.c +2
-2@@ -747,7 +747,7 @@ EXPORT_SYMBOL(hmm_vma_fault);#endif /* IS_ENABLED(CONFIG_HMM_MIRROR) */ -#if IS_ENABLED (CONFIG_HMM_DEVMEM ) +#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) {@@ -1306,4 +1306,4 @@ static int __init hmm_init(void) }device_initcall (hmm_init); -#endif /* IS_ENABLED(CONFIG_HMM_DEVMEM) */ +#endif /* CONFIG_DEVICE_PRIVATE || CONFIG_DEVICE_PUBLIC */ Signature · 1 line
2.9.3
--
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 12 lines · Dave Hansen
Quoted 11 lines · Jerome Glisse
Quoted 10 lines · Dave Hansen
Quoted 4 lines · Jérôme Glisse
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.
How does this interact with device memory that's enumerated in the new ACPI 6.2 HMAT? That stuff is also in the normal e820 and, by default, treated as normal system RAM. Would this mechanism be used for those devices as well?
Quoted 6 lines
Quoted 5 lines
It doesn't interact with that. HMM-CDM is a set of helper that don't do anything unless instructed so. So for device memory to be presented as HMM-CDM you need to hotplug it as
ZONE_DEVICE(DEVICE_PUBLIC)which can be done with the helper introduced in patch 2 of this patchset.
[Removing my cc'd email id and responding from a different address]
Quoted 4 lines
I guess I'm asking whether we *should* instruct HMM-CDM to manage all coherent device memory. If not, where do we draw the line for what we use HMM-CDM, and for what we use the core MM?
If you believe the memory is managed by the device (and owned by a device driver) I'd suggest using HMM-CDM. The idea behind HMM-CDM was that it enables transparent migration of pages and its preferred when locality of computation
and locality of memory access is the preferred model.
The other model was N_COHERENT_MEMORY that used the core MM, but there were objections to exposing device memory using that technology.
Balbir Singh.
Re: [HMM-CDM 4/5] mm/memcontrol: support MEMORY_DEVICE_PRIVATE and MEMORY_DEVICE_PUBLIC
In reply to Jérôme GlisseQuoted 23 lines · On Wed, 14 Jun 2017 16:11:43 -0400 Jérôme Glisse <[email protected]> wrote:
HMM pages (private or public device pages) are
ZONE_DEVICEpage 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.Signed-off-by Jérôme Glisse <[email protected]>Cc Johannes Weiner <[email protected]>Cc Michal Hocko <[email protected]>Cc Vladimir Davydov <[email protected]>--- kernel/memremap.c | 2 ++ mm/memcontrol.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 55 insertions(+), 5 deletions(-)kernel/memremap.c +0
-0
kernel/memremap.c void put_zone_device_private_or_public_page(struct page *page) · line 483
Quoted 5 lines
kernel/memremap.c +2
-0@@ -479,6 +479,8 @@ void put_zone_device_private_or_public_page(struct page *page)__ClearPageActive (page);__ClearPageWaiters (page); +mem_cgroup_uncharge (page); +
A zone device page could have a mem_cgroup charge if
1. The old page was charged to a cgroup and the new page from ZONE_DEVICE then gets the charge that we need to drop here
And should not be charged
2. If the driver allowed mmap based allocation (these pages are not on LRU
Since put_zone_device_private_or_public_page() is called from release_pages(), I think the assumption is that 2 is not a problem? I've not tested the mmap bits yet.
Quoted 89 lines
kernel/memremap.c +0
-0page->pgmap->page_free (page, page->pgmap->data); }else if (!count)mm/memcontrol.c +33
-3@@ -4391,12 +4391,13 @@ enum mc_target_type {MC_TARGET_NONE =0 ,MC_TARGET_PAGE ,MC_TARGET_SWAP , + MC_TARGET_DEVICE, };static struct page *mc_handle_present_pte (struct vm_area_struct *vma,unsigned long addr,pte_t ptent) { -struct page *page =vm_normal_page (vma, addr, ptent); +struct page *page =_vm_normal_page (vma, addr, ptent, true);if (!page || !page_mapped (page))return NULL ;@@ -4407,13 +4408,20 @@ static struct page *mc_handle_present_pte(struct vm_area_struct *vma,if (!(mc.flags &MOVE_FILE ))return NULL ; } -if (!get_page_unless_zero (page)) +if (is_device_public_page (page)) { +/* +* MEMORY_DEVICE_PUBLIC means ZONE_DEVICE page and which have a +* refcount of 1 when free (unlike normal page) +*/ +if (!page_ref_add_unless (page,1 ,1 )) +return NULL ; + }else if (!get_page_unless_zero (page))return NULL ;return page; } -#ifdef CONFIG_SWAP +#if defined(CONFIG_SWAP ) || defined(CONFIG_DEVICE_PRIVATE )static struct page *mc_handle_swap_pte (struct vm_area_struct *vma,pte_t ptent,swp_entry_t *entry) {@@ -4422,6 +4430,23 @@ static struct page *mc_handle_swap_pte(struct vm_area_struct *vma,if (!(mc.flags &MOVE_ANON ) ||non_swap_entry (ent))return NULL ; + +/* +* Handle MEMORY_DEVICE_PRIVATE which are ZONE_DEVICE page belonging to +* a device and because they are not accessible by CPU they are store +* as special swap entry in the CPU page table. +*/ +if (is_device_private_entry (ent)) { + page =device_private_entry_to_page (ent); +/* +* MEMORY_DEVICE_PRIVATE means ZONE_DEVICE page and which have +* a refcount of 1 when free (unlike normal page) +*/ +if (!page_ref_add_unless (page,1 ,1 )) +return NULL ; +return page; + } +/* * Because lookup_swap_cache() updates some statistics counter, * we call find_get_page() with swapper_space directly. @@ -4582,6 +4607,8 @@ static int mem_cgroup_move_account(struct page *page,* 2(MC_TARGET_SWAP): if the swap entry corresponding to this pte is a * target for charge migration. if @target is not NULL, the entry is stored * in target->ent. +* 3(MC_TARGET_DEVICE): like MC_TARGET_PAGE but page is MEMORY_DEVICE_PUBLIC +* or MEMORY_DEVICE_PRIVATE (so ZONE_DEVICE page and thus not on the lru). * * Called with pte lock held. */ @@ -4610,6 +4637,9 @@ static enum mc_target_type get_mctgt_type(struct vm_area_struct *vma,*/ if (page->mem_cgroup == mc.from) { ret =MC_TARGET_PAGE ; +if (is_device_private_page (page) || +is_device_public_page (page)) + ret =MC_TARGET_DEVICE ;if (target) target->page = page; }
mm/memcontrol.c static int mem_cgroup_count_precharge_pte_range(pmd_t *pmd, · line 4703
Quoted 5 lines
mm/memcontrol.c +2
-0@@ -4669,6 +4699,11 @@ static int mem_cgroup_count_precharge_pte_range(pmd_t *pmd, ptl =pmd_trans_huge_lock (pmd, vma);if (ptl) { +/* +* Note their can not be MC_TARGET_DEVICE for now as we do not
there
mm/memcontrol.c static int mem_cgroup_count_precharge_pte_range(pmd_t *pmd, · line 4705
Quoted 2 lines
mm/memcontrol.c +2
-0+* support transparent huge page with MEMORY_DEVICE_PUBLIC or +* MEMORY_DEVICE_PRIVATE but this might change.
I am trying to remind myself why THP and MEMORY_DEVICE_* pages don't work well together today, the driver could allocate a THP size set of pages and migrate it. There are patches to do THP migration, not upstream yet. Could you remind me of any other limitations?
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>
Re: [HMM-CDM 5/5] mm/hmm: simplify kconfig and enable HMM and DEVICE_PUBLIC for ppc64
In reply to Jérôme GlisseQuoted 43 lines · On Wed, 14 Jun 2017 16:11:44 -0400 Jérôme Glisse <[email protected]> wrote:
This just simplify kconfig and allow HMM and
DEVICE_PUBLICto be selected for ppc64 onceZONE_DEVICEis allowed on ppc64 (different patchset).Signed-off-by Jérôme Glisse <[email protected]>Signed-off-by John Hubbard <[email protected]>Cc Balbir Singh <[email protected]>Cc Aneesh Kumar <[email protected]>Cc Paul E. McKenney <[email protected]>Cc Benjamin Herrenschmidt <[email protected]>--- include/linux/hmm.h | 4 ++-- mm/Kconfig | 27 ++++++--------------------- mm/hmm.c | 4 ++-- 3 files changed, 10 insertions(+), 25 deletions(-)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_HMM_DEVMEM ) +#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,@@ -456,7 +456,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_HMM_DEVMEM) */ +#endif /* CONFIG_DEVICE_PRIVATE || CONFIG_DEVICE_PUBLIC */ /* Below are for HMM internal use only! Not to be used by device driver! */ mm/Kconfig +0
-0
mm/Kconfig config ARCH_ENABLE_HUGEPAGE_MIGRATION · line 268
Quoted 5 lines
mm/Kconfig +1
-1@@ -265,7 +265,7 @@ config ARCH_ENABLE_HUGEPAGE_MIGRATION config ARCH_HAS_HMM bool default y - depends on X86_64 + depends on X86_64 || PPC64
Ideally we want to make this (PPC64 && PPC_BOOK3S)
mm/Kconfig config HMM · line 280
Quoted 9 lines
mm/Kconfig +1
-1depends on ZONE_DEVICE depends on MMU && 64BIT depends on MEMORY_HOTPLUG@@ -277,7 +277,7 @@ config HMM config HMM_MIRROR bool "HMM mirror CPU page table into a device page table" - depends on ARCH_HAS_HMM + depends on ARCH_HAS_HMM && X86_64
We would need HMM_MIRROR for the generation of hardware that does not have CDM
Quoted 20 lines
mm/Kconfig +0
-9select MMU_NOTIFIER select HMM help@@ -287,15 +287,6 @@ config HMM_MIRROR page tables (at PAGE_SIZE granularity), and must be able to recover from the resulting potential page faults. -config HMM_DEVMEM - bool "HMM device memory helpers (to leverage ZONE_DEVICE)" - depends on ARCH_HAS_HMM - select HMM - help - HMM devmem is a set of helper routines to leverage the ZONE_DEVICE - feature. This is just to avoid having device drivers to replicating a lot - of boiler plate code. See Documentation/vm/hmm.txt. - config PHYS_ADDR_T_64BIT def_bool 64BIT || ARCH_PHYS_ADDR_T_64BIT
mm/Kconfig config ZONE_DEVICE · line 714
Quoted 9 lines
mm/Kconfig +1
-5@@ -720,11 +711,8 @@ config ZONE_DEVICE config DEVICE_PRIVATE bool "Unaddressable device memory (GPU memory, ...)" - depends on X86_64 - depends on ZONE_DEVICE - depends on MEMORY_HOTPLUG - depends on MEMORY_HOTREMOVE - depends on SPARSEMEM_VMEMMAP + depends on ARCH_HAS_HMM && X86_64
Same as above
mm/Kconfig config DEVICE_PRIVATE · line 723
Quoted 8 lines
mm/Kconfig +1
-0+ select HMM help Allows creation of struct pages to represent unaddressable device@@ -733,11 +721,8 @@ config DEVICE_PRIVATE config DEVICE_PUBLIC bool "Unaddressable device memory (GPU memory, ...)"
The unaddressable is a typo from above.
mm/Kconfig config DEVICE_PRIVATE · line 726
Quoted 8 lines
mm/Kconfig +2
-5- depends on X86_64 - depends on ZONE_DEVICE - depends on MEMORY_HOTPLUG - depends on MEMORY_HOTREMOVE - depends on SPARSEMEM_VMEMMAP + depends on ARCH_HAS_HMM + select HMM
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>
Re: [HMM-CDM 4/5] mm/memcontrol: support MEMORY_DEVICE_PRIVATE and MEMORY_DEVICE_PUBLIC
In reply to Balbir SinghQuoted 37 lines · Balbir Singh
Quoted 23 lines · On Wed, 14 Jun 2017 16:11:43 -0400 Jérôme Glisse…
HMM pages (private or public device pages) are
ZONE_DEVICEpage 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.Signed-off-by Jérôme Glisse <[email protected]>Cc Johannes Weiner <[email protected]>Cc Michal Hocko <[email protected]>Cc Vladimir Davydov <[email protected]>--- kernel/memremap.c | 2 ++ mm/memcontrol.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 55 insertions(+), 5 deletions(-)kernel/memremap.c +0
-0kernel/memremap.c void put_zone_device_private_or_public_page(struct page *page) · line 483
Quoted 5 lines
kernel/memremap.c +2
-0@@ -479,6 +479,8 @@ void put_zone_device_private_or_public_page(struct page *page)__ClearPageActive (page);__ClearPageWaiters (page); +mem_cgroup_uncharge (page); +A zone device page could have a
mem_cgroupcharge if1. The old page was charged to a cgroup and the new page from
ZONE_DEVICEthen gets the charge that we need to drop here
Quoted 8 lines
And should not be charged
2. If the driver allowed mmap based allocation (these pages are not on LRU
Since
put_zone_device_private_or_public_page()is called fromrelease_pages(), I think the assumption is that 2 is not a problem? I've not tested the mmap bits yet.
Well that is one of the big question. Do we care about memory cgroup despite page not being on lru and thus not being reclaimable through the usual path ?
I believe we do want to keep charging ZONE_DEVICE page against memory cgroup so that userspace limit are enforced. This is important especialy for device private when migrating back to system memory due to CPU page fault. We do not want the migration back to fail because of memory cgroup limit.
Hence why i do want to charge ZONE_DEVICE page just like regular page. If we have people that run into OOM because of this then we can start thinking about how to account those pages slightly differently inside the memory cgroup.
For now i believe we do want this patch.
[...]
Quoted 17 lines
Quoted 11 lines
kernel/memremap.c +3
-0@@ -4610,6 +4637,9 @@ static enum mc_target_type get_mctgt_type(struct vm_area_struct *vma,*/ if (page->mem_cgroup == mc.from) { ret =MC_TARGET_PAGE ; +if (is_device_private_page (page) || +is_device_public_page (page)) + ret =MC_TARGET_DEVICE ;if (target) target->page = page; }kernel/memremap.c static int mem_cgroup_count_precharge_pte_range(pmd_t *pmd, · line 4703
Quoted 5 lines
kernel/memremap.c +2
-0@@ -4669,6 +4699,11 @@ static int mem_cgroup_count_precharge_pte_range(pmd_t *pmd, ptl =pmd_trans_huge_lock (pmd, vma);if (ptl) { +/* +* Note their can not be MC_TARGET_DEVICE for now as we do not there
Quoted 7 lines
kernel/memremap.c static int mem_cgroup_count_precharge_pte_range(pmd_t *pmd, · line 4705
Quoted 2 lines
kernel/memremap.c +2
-0+* support transparent huge page with MEMORY_DEVICE_PUBLIC or +* MEMORY_DEVICE_PRIVATE but this might change. I am trying to remind myself why THP and MEMORY_DEVICE_* pages don't work well together today, the driver could allocate a THP size set of pages and migrate it. There are patches to do THP migration, not upstream yet. Could you remind me of any other limitations?
No there is nothing that would be problematic AFAICT. Persistent memory already use huge page so we should be in the clear. But i would rather enable that as a separate patchset alltogether and have proper testing specificaly for such scenario.
Jérôme
Re: [HMM-CDM 5/5] mm/hmm: simplify kconfig and enable HMM and DEVICE_PUBLIC for ppc64
In reply to Balbir SinghQuoted 40 lines · Balbir Singh
Quoted 37 lines · On Wed, 14 Jun 2017 16:11:44 -0400 Jerome Glisse <[email protected]> wrote:
This just simplify kconfig and allow HMM and
DEVICE_PUBLICto be selected for ppc64 onceZONE_DEVICEis allowed on ppc64 (different patchset).Signed-off-by Jerome Glisse <[email protected]>Signed-off-by John Hubbard <[email protected]>Cc Balbir Singh <[email protected]>Cc Aneesh Kumar <[email protected]>Cc Paul E. McKenney <[email protected]>Cc Benjamin Herrenschmidt <[email protected]>--- include/linux/hmm.h | 4 ++-- mm/Kconfig | 27 ++++++--------------------- mm/hmm.c | 4 ++-- 3 files changed, 10 insertions(+), 25 deletions(-)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_HMM_DEVMEM ) +#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,@@ -456,7 +456,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_HMM_DEVMEM) */ +#endif /* CONFIG_DEVICE_PRIVATE || CONFIG_DEVICE_PUBLIC */
Quoted 13 lines
mm/Kconfig config ARCH_ENABLE_HUGEPAGE_MIGRATION · line 268
Quoted 11 lines
include/linux/hmm.h +0
-0/* Below are for HMM internal use only! Not to be used by device driver! */ mm/Kconfig +1
-1@@ -265,7 +265,7 @@ config ARCH_ENABLE_HUGEPAGE_MIGRATION config ARCH_HAS_HMM bool default y - depends on X86_64 + depends on X86_64 || PPC64Ideally we want to make this (PPC64 &&
PPC_BOOK3S)
BOOK3S really ? :)
Quoted 6 lines
Quoted 6 lines
mm/Kconfig +0
-0depends on ZONE_DEVICE depends on MMU && 64BIT depends on MEMORY_HOTPLUG@@ -277,7 +277,7 @@ config HMM
Quoted 7 lines
mm/Kconfig config HMM · line 280
Quoted 4 lines
mm/Kconfig +1
-1config HMM_MIRROR bool "HMM mirror CPU page table into a device page table" - depends on ARCH_HAS_HMM + depends on ARCH_HAS_HMM && X86_64We would need
HMM_MIRRORfor the generation of hardware that does not have CDM
That would require could change to mirror code mostly ppc is missing something like pmd_index() iirc. So best to tackle that as separate patchset.
Quoted 35 lines
Quoted 21 lines
mm/Kconfig +0
-9select MMU_NOTIFIER select HMM help@@ -287,15 +287,6 @@ config HMM_MIRROR page tables (at PAGE_SIZE granularity), and must be able to recover from the resulting potential page faults. -config HMM_DEVMEM - bool "HMM device memory helpers (to leverage ZONE_DEVICE)" - depends on ARCH_HAS_HMM - select HMM - help - HMM devmem is a set of helper routines to leverage the ZONE_DEVICE - feature. This is just to avoid having device drivers to replicating a lot - of boiler plate code. See Documentation/vm/hmm.txt. - config PHYS_ADDR_T_64BIT def_bool 64BIT || ARCH_PHYS_ADDR_T_64BITmm/Kconfig config ZONE_DEVICE · line 714
Quoted 9 lines
mm/Kconfig +1
-5@@ -720,11 +711,8 @@ config ZONE_DEVICE config DEVICE_PRIVATE bool "Unaddressable device memory (GPU memory, ...)" - depends on X86_64 - depends on ZONE_DEVICE - depends on MEMORY_HOTPLUG - depends on MEMORY_HOTREMOVE - depends on SPARSEMEM_VMEMMAP + depends on ARCH_HAS_HMM && X86_64Same as above
Quoted 2 lines
mm/Kconfig +1
-0+ select HMM
Quoted 8 lines
mm/Kconfig config DEVICE_PRIVATE · line 723
Quoted 6 lines
mm/Kconfig +0
-0help Allows creation of struct pages to represent unaddressable device@@ -733,11 +721,8 @@ config DEVICE_PRIVATE config DEVICE_PUBLIC bool "Unaddressable device memory (GPU memory, ...)"The unaddressable is a typo from above.
Yup cut and paste thank for catching that.
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>
Re: [HMM-CDM 5/5] mm/hmm: simplify kconfig and enable HMM and DEVICE_PUBLIC for ppc64
In reply to John HubbardQuoted 85 lines · John Hubbard
Quoted 47 lines · Jérôme Glisse
This just simplify kconfig and allow HMM and
DEVICE_PUBLICto be selected for ppc64 onceZONE_DEVICEis allowed on ppc64 (different patchset).Signed-off-by Jérôme Glisse <[email protected]>Signed-off-by John Hubbard <[email protected]>Cc Balbir Singh <[email protected]>Cc Aneesh Kumar <[email protected]>Cc Paul E. McKenney <[email protected]>Cc Benjamin Herrenschmidt <[email protected]>--- include/linux/hmm.h | 4 ++-- mm/Kconfig | 27 ++++++--------------------- mm/hmm.c | 4 ++-- 3 files changed, 10 insertions(+), 25 deletions(-)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_HMM_DEVMEM ) +#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,@@ -456,7 +456,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_HMM_DEVMEM) */ +#endif /* CONFIG_DEVICE_PRIVATE || CONFIG_DEVICE_PUBLIC */ /* Below are for HMM internal use only! Not to be used by device driver! */ mm/Kconfig +1
-1@@ -265,7 +265,7 @@ config ARCH_ENABLE_HUGEPAGE_MIGRATION config ARCH_HAS_HMM bool default y - depends on X86_64 + depends on X86_64 || PPC64 depends on ZONE_DEVICE depends on MMU && 64BIT depends on MEMORY_HOTPLUGmm/Kconfig config HMM · line 282
Quoted 7 lines
mm/Kconfig +1
-1@@ -277,7 +277,7 @@ config HMM config HMM_MIRROR bool "HMM mirror CPU page table into a device page table" - depends on ARCH_HAS_HMM + depends on ARCH_HAS_HMM && X86_64 select MMU_NOTIFIER select HMM helpHi Jerome,
There are still some problems with using this configuration. First and foremost, it is still possible (and likely, given the complete dissimilarity in naming, and difference in location on the screen) to choose
HMM_MIRROR, and *not* to choose eitherDEVICE_PRIVATEorDEVICE_PUBLIC. And then we end up with a swath of important page fault handling code being ifdef'd out, and one ends up having to investigate why.As for solutions, at least for the x86 (DEVICE_PRIVATE)case, we could do this:
mm/Kconfig +1
-0@@ -279,6 +279,7 @@ config HMM_MIRROR bool "HMM mirror CPU page table into a device page table" depends on ARCH_HAS_HMM && X86_64 select MMU_NOTIFIER + select DEVICE_PRIVATE select HMM help Select HMM_MIRROR if you want to mirror range of the CPU page table of a...and that is better than the other direction (having
HMM_MIRRORdepend onDEVICE_PRIVATE), because in the latter case,HMM_MIRRORwill disappear (and it's several lines above) until you selectDEVICE_PRIVATE. That is hard to work with for the user.
Quoted 7 lines
The user will tend to select
HMM_MIRROR, but it is *not* obvious that he/she should also selectDEVICE_PRIVATE. SoKconfigshould do it for them.In fact, I'm not even sure if the
DEVICE_PRIVATEandDEVICE_PUBLICactually needKconfigprotection, but if they don't, then life would be easier for whoever is configuring their kernel.
We do need Kconfig for DEVICE_PRIVATE and DEVICE_PUBLIC. I can remove HMM_MIRROR and have HMM mirror code ifdef on DEVICE_PRIVATE.
Cheers,
Jérôme
Re: [HMM-CDM 5/5] mm/hmm: simplify kconfig and enable HMM and DEVICE_PUBLIC for ppc64
In reply to Jerome GlisseQuoted 55 lines · On Wed, 14 Jun 2017 22:07:09 -0400 Jerome Glisse <[email protected]> wrote:
Quoted 40 lines · Balbir Singh
Quoted 37 lines · On Wed, 14 Jun 2017 16:11:44 -0400 Jérôme Glisse <[email protected]> wrote:
This just simplify kconfig and allow HMM and
DEVICE_PUBLICto be selected for ppc64 onceZONE_DEVICEis allowed on ppc64 (different patchset).Signed-off-by Jérôme Glisse <[email protected]>Signed-off-by John Hubbard <[email protected]>Cc Balbir Singh <[email protected]>Cc Aneesh Kumar <[email protected]>Cc Paul E. McKenney <[email protected]>Cc Benjamin Herrenschmidt <[email protected]>--- include/linux/hmm.h | 4 ++-- mm/Kconfig | 27 ++++++--------------------- mm/hmm.c | 4 ++-- 3 files changed, 10 insertions(+), 25 deletions(-)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_HMM_DEVMEM ) +#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,@@ -456,7 +456,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_HMM_DEVMEM) */ +#endif /* CONFIG_DEVICE_PRIVATE || CONFIG_DEVICE_PUBLIC */ Quoted 13 lines
mm/Kconfig config ARCH_ENABLE_HUGEPAGE_MIGRATION · line 268
Quoted 11 lines
include/linux/hmm.h +0
-0/* Below are for HMM internal use only! Not to be used by device driver! */ mm/Kconfig +1
-1@@ -265,7 +265,7 @@ config ARCH_ENABLE_HUGEPAGE_MIGRATION config ARCH_HAS_HMM bool default y - depends on X86_64 + depends on X86_64 || PPC64Ideally we want to make this (PPC64 &&
PPC_BOOK3S)
Quoted 1 line
BOOK3S really ? :)
Sorry what's wrong with that? I am not sure we want it for BOOK3E 64 bit Or may be would just make ARCH_HAS_HMM a config set by the ARCH, like ARCH_HAS_SET_MEMORY
Quoted 15 lines
Quoted 7 lines
Quoted 7 lines
mm/Kconfig +0
-0depends on ZONE_DEVICE depends on MMU && 64BIT depends on MEMORY_HOTPLUG@@ -277,7 +277,7 @@ config HMMQuoted 7 lines
mm/Kconfig config HMM · line 280
Quoted 4 lines
mm/Kconfig +1
-1config HMM_MIRROR bool "HMM mirror CPU page table into a device page table" - depends on ARCH_HAS_HMM + depends on ARCH_HAS_HMM && X86_64We would need
HMM_MIRRORfor the generation of hardware that does not have CDM
Quoted 4 lines
That would require could change to mirror code mostly ppc is missing something like
pmd_index()iirc. So best to tackle that as separate patchset.
We do have pmd_index() and I think Reza's got the whole hmm to compile on powerpc. I am OK tackling it later. Do you suspect there is a compile time dependency? I got HMM_MIRROR to compile for me as well
Quoted 39 lines
Quoted 39 lines
Quoted 21 lines
mm/Kconfig +0
-9select MMU_NOTIFIER select HMM help@@ -287,15 +287,6 @@ config HMM_MIRROR page tables (at PAGE_SIZE granularity), and must be able to recover from the resulting potential page faults. -config HMM_DEVMEM - bool "HMM device memory helpers (to leverage ZONE_DEVICE)" - depends on ARCH_HAS_HMM - select HMM - help - HMM devmem is a set of helper routines to leverage the ZONE_DEVICE - feature. This is just to avoid having device drivers to replicating a lot - of boiler plate code. See Documentation/vm/hmm.txt. - config PHYS_ADDR_T_64BIT def_bool 64BIT || ARCH_PHYS_ADDR_T_64BITmm/Kconfig config ZONE_DEVICE · line 714
Quoted 9 lines
mm/Kconfig +1
-5@@ -720,11 +711,8 @@ config ZONE_DEVICE config DEVICE_PRIVATE bool "Unaddressable device memory (GPU memory, ...)" - depends on X86_64 - depends on ZONE_DEVICE - depends on MEMORY_HOTPLUG - depends on MEMORY_HOTREMOVE - depends on SPARSEMEM_VMEMMAP + depends on ARCH_HAS_HMM && X86_64Same as above
Quoted 6 lines
mm/Kconfig +1
-0+ select HMM help Allows creation of struct pages to represent unaddressable device@@ -733,11 +721,8 @@ config DEVICE_PRIVATE
Quoted 6 lines
Quoted 4 lines
mm/Kconfig config DEVICE_PRIVATE · line 723
Quoted 2 lines
mm/Kconfig +0
-0config DEVICE_PUBLIC bool "Unaddressable device memory (GPU memory, ...)"The unaddressable is a typo from above.
Yup cut and paste thank for catching that.
Your welcome
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>
Re: [HMM-CDM 4/5] mm/memcontrol: support MEMORY_DEVICE_PRIVATE and MEMORY_DEVICE_PUBLIC
In reply to Jerome GlisseQuoted 55 lines · On Wed, 14 Jun 2017 22:04:55 -0400 Jerome Glisse <[email protected]> wrote:
Quoted 37 lines · Balbir Singh
Quoted 23 lines · On Wed, 14 Jun 2017 16:11:43 -0400 Jérôme Glisse <[email protected]> wrote:
HMM pages (private or public device pages) are
ZONE_DEVICEpage 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.Signed-off-by Jérôme Glisse <[email protected]>Cc Johannes Weiner <[email protected]>Cc Michal Hocko <[email protected]>Cc Vladimir Davydov <[email protected]>--- kernel/memremap.c | 2 ++ mm/memcontrol.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 55 insertions(+), 5 deletions(-)kernel/memremap.c +0
-0kernel/memremap.c void put_zone_device_private_or_public_page(struct page *page) · line 483
Quoted 5 lines
kernel/memremap.c +2
-0@@ -479,6 +479,8 @@ void put_zone_device_private_or_public_page(struct page *page)__ClearPageActive (page);__ClearPageWaiters (page); +mem_cgroup_uncharge (page); +A zone device page could have a
mem_cgroupcharge if1. The old page was charged to a cgroup and the new page from
ZONE_DEVICEthen gets the charge that we need to drop hereQuoted 8 lines
And should not be charged
2. If the driver allowed mmap based allocation (these pages are not on LRU
Since
put_zone_device_private_or_public_page()is called fromrelease_pages(), I think the assumption is that 2 is not a problem? I've not tested the mmap bits yet.Well that is one of the big question. Do we care about memory cgroup despite page not being on lru and thus not being reclaimable through the usual path ?
I believe we do want to keep charging
ZONE_DEVICEpage against memory cgroup so that userspace limit are enforced. This is important especialy for device private when migrating back to system memory due to CPU page fault. We do not want the migration back to fail because of memory cgroup limit.
Quoted 6 lines
Hence why i do want to charge
ZONE_DEVICEpage just like regular page. If we have people that run into OOM because of this then we can start thinking about how to account those pages slightly differently inside the memory cgroup.For now i believe we do want this patch.
Yes, we do need the patch, I was trying to check if we'll end up trying to uncharge a page that is not charged, just double checking
Quoted 28 lines
[...]
Quoted 17 lines
Quoted 11 lines
kernel/memremap.c +3
-0@@ -4610,6 +4637,9 @@ static enum mc_target_type get_mctgt_type(struct vm_area_struct *vma,*/ if (page->mem_cgroup == mc.from) { ret =MC_TARGET_PAGE ; +if (is_device_private_page (page) || +is_device_public_page (page)) + ret =MC_TARGET_DEVICE ;if (target) target->page = page; }kernel/memremap.c static int mem_cgroup_count_precharge_pte_range(pmd_t *pmd, · line 4703
Quoted 5 lines
kernel/memremap.c +2
-0@@ -4669,6 +4699,11 @@ static int mem_cgroup_count_precharge_pte_range(pmd_t *pmd, ptl =pmd_trans_huge_lock (pmd, vma);if (ptl) { +/* +* Note their can not be MC_TARGET_DEVICE for now as we do not there
Quoted 7 lines
kernel/memremap.c static int mem_cgroup_count_precharge_pte_range(pmd_t *pmd, · line 4705
Quoted 2 lines
kernel/memremap.c +2
-0+* support transparent huge page with MEMORY_DEVICE_PUBLIC or +* MEMORY_DEVICE_PRIVATE but this might change. I am trying to remind myself why THP and MEMORY_DEVICE_* pages don't work well together today, the driver could allocate a THP size set of pages and migrate it. There are patches to do THP migration, not upstream yet. Could you remind me of any other limitations?
Quoted 4 lines
No there is nothing that would be problematic AFAICT. Persistent memory already use huge page so we should be in the clear. But i would rather enable that as a separate patchset alltogether and have proper testing specificaly for such scenario.
Agreed
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>
John Hubbard
reviewerRe: [HMM-CDM 5/5] mm/hmm: simplify kconfig and enable HMM and DEVICE_PUBLIC for ppc64
In reply to Jerome GlisseQuoted 2 lines · Jerome Glisse
Quoted 1 line · John Hubbard
On 06/14/2017 01:11 PM, Jérôme Glisse wrote:
[...]
Quoted 40 lines
Quoted 29 lines
Hi Jerome,
There are still some problems with using this configuration. First and foremost, it is still possible (and likely, given the complete dissimilarity in naming, and difference in location on the screen) to choose
HMM_MIRROR, and *not* to choose eitherDEVICE_PRIVATEorDEVICE_PUBLIC. And then we end up with a swath of important page fault handling code being ifdef'd out, and one ends up having to investigate why.As for solutions, at least for the x86 (DEVICE_PRIVATE)case, we could do this:
mm/Kconfig +1
-0@@ -279,6 +279,7 @@ config HMM_MIRROR bool "HMM mirror CPU page table into a device page table" depends on ARCH_HAS_HMM && X86_64 select MMU_NOTIFIER + select DEVICE_PRIVATE select HMM help Select HMM_MIRROR if you want to mirror range of the CPU page table of a...and that is better than the other direction (having
HMM_MIRRORdepend onDEVICE_PRIVATE), because in the latter case,HMM_MIRRORwill disappear (and it's several lines above) until you selectDEVICE_PRIVATE. That is hard to work with for the user.Quoted 7 lines
The user will tend to select
HMM_MIRROR, but it is *not* obvious that he/she should also selectDEVICE_PRIVATE. SoKconfigshould do it for them.In fact, I'm not even sure if the
DEVICE_PRIVATEandDEVICE_PUBLICactually needKconfigprotection, but if they don't, then life would be easier for whoever is configuring their kernel.We do need
KconfigforDEVICE_PRIVATEandDEVICE_PUBLIC. I can removeHMM_MIRRORand have HMM mirror code ifdef onDEVICE_PRIVATE.
Quoted 2 lines
Cheers,
Jérôme
That's probably fine.
(I see that you may have missed the rest of my response, but looks like Balbir covered it.)
thanks,
john h
--
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>
Re: [HMM-CDM 3/5] mm/memcontrol: allow to uncharge page without using page->lru field
In reply to Jérôme GlisseQuoted 38 lines · On Wed, 14 Jun 2017 16:11:42 -0400 Jérôme Glisse…
HMM pages (private or public device pages) are
ZONE_DEVICEpage and thus you can not usepage->lrufields 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.
Signed-off-by Jérôme Glisse <[email protected]>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 +9
-4@@ -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;
mm/memcontrol.c void mem_cgroup_cancel_charge(struct page *page, struct mem_cgroup *memcg, · line 5529
Quoted 10 lines
mm/memcontrol.c +8
-1+}; + +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) +{
Can we pass page as an argument so that we can do check events on the page?
Quoted 48 lines
mm/memcontrol.c +25
-15+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 ;
mm/memcontrol.c void mem_cgroup_cancel_charge(struct page *page, struct mem_cgroup *memcg, · line 5572
Quoted 10 lines
mm/memcontrol.c +10
-0+ +/* +* 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);
What is ug->dummy_page set to at this point? ug->dummy_page is assigned below
Quoted 47 lines
mm/memcontrol.c +30
-8+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
mm/memcontrol.c static void uncharge_list(struct list_head *page_list) · line 5616
Quoted 5 lines
mm/memcontrol.c +2
-0@@ -5558,57 +5612,16 @@ static void uncharge_list(struct list_head *page_list)*/ next = page_list->next; do { + struct page *page; +
Nit pick
VM_WARN_ON(is_zone_device_page(page));
Quoted 67 lines
mm/memcontrol.c +5
-46page = 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 ;
mm/memcontrol.c void mem_cgroup_uncharge(struct page *page) · line 5648
Quoted 9 lines
mm/memcontrol.c +3
-2@@ -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); }
Balbir Singh.
Re: [HMM-CDM 2/5] mm/hmm: add new helper to hotplug CDM memory region
In reply to Jérôme GlisseQuoted 7 lines · On Wed, 14 Jun 2017 16:11:41 -0400 Jérôme Glisse <[email protected]> wrote:
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.
Signed-off-by Jérôme Glisse <[email protected]>---
Looks good to me
Re: [HMM-CDM 3/5] mm/memcontrol: allow to uncharge page without using page->lru field
In reply to Balbir SinghQuoted 45 lines · Balbir Singh
Quoted 42 lines · On Wed, 14 Jun 2017 16:11:42 -0400 Jérôme Glisse…
HMM pages (private or public device pages) are
ZONE_DEVICEpage and thus you can not usepage->lrufields 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.
Signed-off-by Jérôme Glisse <[email protected]>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 +12
-4@@ -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) {
Quoted 8 lines
mm/memcontrol.c void mem_cgroup_cancel_charge(struct page *page, struct mem_cgroup *memcg, · line 5529
Quoted 6 lines
mm/memcontrol.c +5
-1-unsigned long nr_pages = nr_anon + nr_file + nr_kmem; +memset (ug,0 ,sizeof (*ug)); +} + +static void uncharge_batch (const struct uncharge_gather *ug) +{Can we pass page as an argument so that we can do check events on the page?
Well it is what dummy page is for, i wanted to keep code as close to existing to make it easier for people to see that there was no logic change with that patch.
[...]
Quoted 11 lines
Quoted 11 lines
mm/memcontrol.c +11
-0+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
Quoted 8 lines
mm/memcontrol.c void mem_cgroup_cancel_charge(struct page *page, struct mem_cgroup *memcg, · line 5572
Quoted 6 lines
mm/memcontrol.c +6
-0+* exclusive access to the page. +*/ + +if (ug->memcg != page->mem_cgroup) { +if (ug->memcg) { +uncharge_batch (ug);What is
ug->dummy_pageset to at this point?ug->dummy_pageis assigned below
So at begining ug->memcg is NULL and so is ug->dummy_page, after first call to uncharge_page() if ug->memcg isn't NULL then ug->dummy_page points to a valid page. So uncharge_batch() can never be call with dummy_page == NULL same as before this patch.
[...]
Quoted 26 lines
Quoted 18 lines
mm/memcontrol.c +3
-8static 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 mm/memcontrol.c static void uncharge_list(struct list_head *page_list) · line 5616
Quoted 5 lines
mm/memcontrol.c +2
-0@@ -5558,57 +5612,16 @@ static void uncharge_list(struct list_head *page_list)*/ next = page_list->next; do { + struct page *page; +Nit pick
Quoted 1 line
VM_WARN_ON(is_zone_device_page(page));
Yeah probably good thing to add. I will add it as part of the other memcontrol patch as i want to keep this one about moving stuff around with no logic change.
Thanks for reviewing
Jérôme