MMU Notifiers V6
Subsystems (9)
cover MMU Notifiers V6
This is a patchset implementing MMU notifier callbacks based on Andrea's earlier work. These are needed if Linux pages are referenced from something else than tracked by the rmaps of the kernel (an external MMU). MMU notifiers allow us to get rid of the page pinning for RDMA and various other purposes. It gets rid of the broken use of mlock for page pinning. (mlock really does *not* pin pages....)
More information on the rationale and the technical details can be found in the first patch and the README provided by that patch in Documentation/mmu_notifiers.
The known immediate users are
KVM
- Establishes a refcount to the page via get_user_pages().
- External references are called spte.
- Has page tables to track pages whose refcount was elevated but no reverse maps.
GRU
- Simple additional hardware TLB (possibly covering multiple instances of Linux)
- Needs TLB shootdown when the VM unmaps pages.
- Determines page address via follow_page (from interrupt context) but can fall back to get_user_pages().
- No page reference possible since no page status is kept..
XPmem
- Allows use of a processes memory by remote instances of Linux.
- Provides its own reverse mappings to track remote pte.
- Established refcounts on the exported pages.
- Must sleep in order to wait for remote acks of ptes that are being cleared.
Andrea's mmu_notifier #4 -> RFC V1
- Merge subsystem rmap based with Linux rmap based approach
- Move Linux rmap based notifiers out of macro
- Try to account for what locks are held while the notifiers are called.
- Develop a patch sequence that separates out the different types of hooks so that we can review their use.
- Avoid adding include to linux/mm_types.h
- Integrate RCU logic suggested by Peter.
V1->V2:
- Improve RCU support
- Use mmap_sem for mmu_notifier register / unregister
- Drop invalidate_page from COW, mm/fremap.c and mm/rmap.c since we already have invalidate_range() callbacks there.
- Clean compile for !MMU_NOTIFIER
- Isolate filemap_xip strangeness into its own diff
- Pass a the flag to invalidate_range to indicate if a spinlock is held.
- Add invalidate_all()
V2->V3:
- Further RCU fixes
- Fixes from Andrea to fixup aging and move invalidate_range() in do_wp_page and sys_remap_file_pages() after the pte clearing.
V3->V4:
- Drop locking and synchronize_rcu() on ->release since we know on release that we are the only executing thread. This is also true for invalidate_all() so we could drop off the mmu_notifier there early. Use hlist_del_init instead of hlist_del_rcu.
- Do the invalidation as begin/end pairs with the requirement that the driver holds off new references in between.
- Fixup filemap_xip.c
- Figure out a potential way in which XPmem can deal with locks that are held.
- Robin's patches to make the mmu_notifier logic manage the PageRmapExported bit.
- Strip cc list down a bit.
- Drop Peters new rcu list macro
- Add description to the core patch
V4->V5:
- Provide missing callouts for mremap.
- Provide missing callouts for copy_page_range.
- Reduce mm_struct space to zero if !MMU_NOTIFIER by #ifdeffing out structure contents.
- Get rid of the invalidate_all() callback by moving ->release in place of invalidate_all.
- Require holding mmap_sem on register/unregister instead of acquiring it ourselves. In some contexts where we want to register/unregister we are already holding mmap_sem.
- Split out the rmap support patch so that there is no need to apply all patches for KVM and GRU.
V5->V6:
- Provide missing range callouts for mprotect
- Fix do_wp_page control path sequencing
- Clarify locking conventions
- GRU and XPmem confirmed to work with this patchset.
- Provide skeleton code for GRU/KVM type callback and for XPmem type.
- Rework documentation and put it into Documentation/mmu_notifier.
Signature · 4 lines
------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
PATCH 1/6 mmu_notifier: Core code
MMU notifiers are used for hardware and software that establishes external references to pages managed by the Linux kernel. These are page table entriews or tlb entries or something else that allows hardware (such as DMA engines, scatter gather devices, networking, sharing of address spaces across operating system boundaries) and software (Virtualization solutions such as KVM, Xen etc) to access memory managed by the Linux kernel.
The MMU notifier will notify the device driver that subscribes to such a notifier that the VM is going to do something with the memory mapped by that device. The device must then drop references for the indicated memory area. The references may be reestablished later.
The notification scheme is much better than the current scheme of avoiding the danger of the VM removing pages that are externally mapped. We currently mlock pages used for RDMA, XPmem etc in memory.
Mlock causes problems with reclaim and may lead to OOM if too many pages are pinned in memory. It is also incorrect in terms what the POSIX specificies for what role mlock should play. Mlock does *not* pin pages in memory. Mlock just means do not allow the page to be moved to swap.
Linux can move pages in memory (for example through the page migration mechanism). These pages can be moved even if they are mlocked(!!!!). The current approach of page pinning in use by RDMA etc is conceptually broken but there are currently no other easy solutions.
The solution here allows us to finally fix this issue by requiring such devices to subscribe to a notification chain that will allow them to work without pinning.
This patch: Core portion
--- Documentation/mmu_notifier/README | 99 +++++++++++++++++++++ include/linux/mm_types.h | 7 + include/linux/mmu_notifier.h | 175 ++++++++++++++++++++++++++++++++++++++ kernel/fork.c | 2 mm/Kconfig | 4 mm/Makefile | 1 mm/mmap.c | 2 mm/mmu_notifier.c | 76 ++++++++++++++++ 8 files changed, 366 insertions(+)
Documentation/mmu_notifier/README new file +99 -0
@@ -0,0 +1,99 @@ +Linux MMU Notifiers +------------------- + +MMU notifiers are used for hardware and software that establishes +external references to pages managed by the Linux kernel. These are +page table entriews or tlb entries or something else that allows +hardware (such as DMA engines, scatter gather devices, networking, +sharing of address spaces across operating system boundaries) and +software (Virtualization solutions such as KVM, Xen etc) to +access memory managed by the Linux kernel. + +The MMU notifier will notify the device driver that subscribes to such +a notifier that the VM is going to do something with the memory +mapped by that device. The device must then drop references for the +indicated memory area. The references may be reestablished later. + +The notification scheme is much better than the current scheme of +dealing with the danger of the VM removing pages. +We currently mlock pages used for RDMA, XPmem etc in memory. + +Mlock causes problems with reclaim and may lead to OOM if too many +pages are pinned in memory. It is also incorrect in terms of the POSIX +specification of the role of mlock. Mlock does *not* pin pages in +memory. It just does not allow the page to be moved to swap. + +Linux can move pages in memory (for example through the page migration +mechanism). These pages can be moved even if they are mlocked(!!!!). +So the current approach in use by RDMA etc etc is conceptually broken +but there are currently no other easy solutions. + +The solution here allows us to finally fix this issue by requiring +such devices to subscribe to a notification chain that will allow +them to work without pinning. + +The notifier chains provide two callback mechanisms. The +first one is required for any device that establishes external mappings. +The second (rmap) mechanism is required if a device needs to be +able to sleep when invalidating references. Sleeping may be necessary +if we are mapping across a network or to different Linux instances +in the same address space. + +mmu_notifier mechanism (for KVM/GRU etc) +---------------------------------------- +Callbacks are registered with an mm_struct from a device driver using +mmu_notifier_register(). When the VM removes pages (or changes +permissions on pages etc) then callbacks are triggered. + +The invalidation function for a single page (*invalidate_page) +is called with spinlocks (in particular the pte lock) held. This allow +for an easy implementation of external ptes that are on the local system. + +The invalidation mechanism for a range (*invalidate_range_begin/end*) is +called most of the time without any locks held. It is only called with +locks held for file backed mappings that are truncated. A flag indicates +in which mode we are. A driver can use that mechanism to f.e. +delay the freeing of the pages during truncate until no locks are held. + +Pages must be marked dirty if dirty bits are found to be set in +the external ptes during unmap. + +The *release* method is called when a Linux process exits. It is run before +the pages and mappings of a process are torn down and gives the device driver +a chance to zap all the external mappings in one go. + +An example for a code that can be used to build a notifier mechanism into +a device driver can be found in the file +Documentation/mmu_notifier/skeleton.c + +mmu_rmap_notifier mechanism (XPMEM etc) +--------------------------------------- +The mmu_rmap_notifier allows the device driver to implement their own rmap +and allows the device driver to sleep during page eviction. This is necessary +for complex drivers that f.e. allow the sharing of memory between processes +running on different Linux instances (typically over a network or in a +partitioned NUMA system). + +The mmu_rmap_notifier adds another invalidate_page() callout that is called +*before* the Linux rmaps are walked. At that point only the page lock is +held. The invalidate_page() function must walk the driver rmaps and evict +all the references to the page. + +There is no process information available before the rmaps are consulted. +The notifier mechanism can therefore not be attached to an mm_struct. Instead +it is a global callback list. Having to perform a callback for each and every +page that is reclaimed would be inefficient. Therefore we add an additional +page flag: PageRmapExternal(). Only pages that are marked with this bit can +be exported and the rmap callbacks will only be performed for pages marked +that way. + +The required additional Page flag is only availabe in 64 bit mode and +therefore the mmu_rmap_notifier portion is not available on 32 bit platforms. + +An example of code to build a mmu_notifier mechanism with rmap capabilty +can be found in Documentation/mmu_notifier/skeleton_rmap.c + +February 9, 2008, + Christoph Lameter <clameter-sJ/[email protected] + +Index: linux-2.6/include/linux/mm_types.h
include/linux/mm_types.h +7 -0
@@ -159,6 +159,12 @@ struct vm_area_struct {#endif }; +struct mmu_notifier_head { +#ifdef CONFIG_MMU_NOTIFIER +struct hlist_head head; +#endif +}; +struct mm_struct {struct vm_area_struct * mmap;/* list of VMAs */ struct rb_root mm_rb;
@@ -228,6 +234,7 @@ struct mm_struct {#ifdef CONFIG_CGROUP_MEM_CONT struct mem_cgroup *mem_cgroup;#endif + struct mmu_notifier_head mmu_notifier; /* MMU notifier list */ };#endif /* _LINUX_MM_TYPES_H */
include/linux/mmu_notifier.h new file +175 -0
175 lines not on this page · raw message
mm/Kconfig +4 -0
@@ -193,3 +193,7 @@ config NR_QUICK config VIRT_TO_BUS def_bool y depends on !ARCH_NO_VIRT_TO_BUS + +config MMU_NOTIFIER + def_bool y + bool "MMU notifier, for paging KVM/RDMA"
mm/Makefile +1 -0
@@ -33,4 +33,5 @@ obj-$(CONFIG_MIGRATION) += migrate.o obj-$(CONFIG_SMP) += allocpercpu.o obj-$(CONFIG_QUICKLIST) += quicklist.o obj-$(CONFIG_CGROUP_MEM_CONT) += memcontrol.o +obj-$(CONFIG_MMU_NOTIFIER) += mmu_notifier.o
mm/mmu_notifier.c new file +76 -0
76 lines not on this page · raw message
kernel/fork.c +2 -0
@@ -53,6 +53,7 @@#include <linux/tty.h> #include <linux/proc_fs.h> #include <linux/blkdev.h> +#include <linux/mmu_notifier.h> #include <asm/pgtable.h> #include <asm/pgalloc.h>
@@ -362,6 +363,7 @@ static struct mm_struct * mm_init(structif (likely (!mm_alloc_pgd (mm))) { mm->def_flags =0 ; +mmu_notifier_head_init (&mm->mmu_notifier);return mm; }
mm/mmap.c +2 -0
@@ -26,6 +26,7 @@#include <linux/mount.h> #include <linux/mempolicy.h> #include <linux/rmap.h> +#include <linux/mmu_notifier.h> #include <asm/uaccess.h> #include <asm/cacheflush.h>
@@ -2037,6 +2038,7 @@ void exit_mmap(struct mm_struct *mm)unsigned long end;/* mm's last user has gone, and its about to be pulled down */ +mmu_notifier_release (mm);arch_exit_mmap (mm); lru_add_drain();`
Signature · 4 lines
------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
PATCH 2/6 mmu_notifier: Callbacks to invalidate address ranges
In reply to Christoph LameterThe invalidation of address ranges in a mm_struct needs to be performed when pages are removed or permissions etc change.
If invalidate_range_begin() is called with locks held then we pass a flag into invalidate_range() to indicate that no sleeping is possible. Locks are only held for truncate and huge pages.
In two cases we use invalidate_range_begin/end to invalidate single pages because the pair allows holding off new references (idea by Robin Holt).
do_wp_page(): We hold off new references while we update the pte.
xip_unmap: We are not taking the PageLock so we cannot
use the invalidate_page mmu_rmap_notifier. invalidate_range_begin/end stands in.
--- mm/filemap_xip.c | 5 +++++ mm/fremap.c | 3 +++ mm/hugetlb.c | 3 +++ mm/memory.c | 35 +++++++++++++++++++++++++++++------ mm/mmap.c | 2 ++ mm/mprotect.c | 3 +++ mm/mremap.c | 7 ++++++- 7 files changed, 51 insertions(+), 7 deletions(-)
mm/fremap.c +3 -0
@@ -15,6 +15,7 @@#include <linux/rmap.h> #include <linux/module.h> #include <linux/syscalls.h> +#include <linux/mmu_notifier.h> #include <asm/mmu_context.h> #include <asm/cacheflush.h>
@@ -214,7 +215,9 @@ asmlinkage long sys_remap_file_pages(unsspin_unlock (&mapping->i_mmap_lock); } +mmu_notifier (invalidate_range_begin, mm, start, start + size,0 ); err =populate_range (mm, vma, start, size, pgoff); +mmu_notifier (invalidate_range_end, mm, start, start + size,0 );if (!err && !(flags &MAP_NONBLOCK )) {if (unlikely (has_write_lock)) {downgrade_write (&mm->mmap_sem);
mm/memory.c +29 -6
@@ -51,6 +51,7 @@#include <linux/init.h> #include <linux/writeback.h> #include <linux/memcontrol.h> +#include <linux/mmu_notifier.h> #include <asm/pgalloc.h> #include <asm/uaccess.h>
@@ -611,6 +612,9 @@ int copy_page_range(struct mm_struct *dsif (is_vm_hugetlb_page (vma))return copy_hugetlb_page_range (dst_mm, src_mm, vma); +if (is_cow_mapping (vma->vm_flags)) +mmu_notifier (invalidate_range_begin, src_mm, addr, end,0 ); + dst_pgd =pgd_offset (dst_mm, addr); src_pgd =pgd_offset (src_mm, addr); do {
@@ -621,6 +625,11 @@ int copy_page_range(struct mm_struct *ds vma, addr, next))return -ENOMEM ; }while (dst_pgd++, src_pgd++, addr = next, addr != end); + +if (is_cow_mapping (vma->vm_flags)) +mmu_notifier (invalidate_range_end, src_mm, + vma->vm_start, end,0 ); +return 0 ; }
@@ -893,13 +902,16 @@ unsigned long zap_page_range(struct vm_astruct mmu_gather *tlb;unsigned long end = address + size;unsigned long nr_accounted =0 ; +int atomic = details ? (details->i_mmap_lock !=0 ) :0 ;lru_add_drain (); tlb =tlb_gather_mmu (mm,0 );update_hiwater_rss (mm); +mmu_notifier (invalidate_range_begin, mm, address, end, atomic); end =unmap_vmas (&tlb, vma, address, end, &nr_accounted, details);if (tlb)tlb_finish_mmu (tlb, address, end); +mmu_notifier (invalidate_range_end, mm, address, end, atomic);return end; }
@@ -1337,7 +1349,7 @@ int remap_pfn_range(struct vm_area_struc {pgd_t *pgd;unsigned long next; -unsigned long end = addr +PAGE_ALIGN (size); +unsigned long start = addr, end = addr +PAGE_ALIGN (size);struct mm_struct *mm = vma->vm_mm;int err;
@@ -1371,6 +1383,7 @@ int remap_pfn_range(struct vm_area_struc pfn -= addr >>PAGE_SHIFT ; pgd =pgd_offset (mm, addr);flush_cache_range (vma, addr, end); +mmu_notifier (invalidate_range_begin, mm, start, end,0 ); do { next = pgd_addr_end(addr, end); err = remap_pud_range(mm, pgd, addr, next,
@@ -1378,6 +1391,7 @@ int remap_pfn_range(struct vm_area_strucif (err)break ; }while (pgd++, addr = next, addr != end); +mmu_notifier (invalidate_range_end, mm, start, end,0 );return err; }EXPORT_SYMBOL (remap_pfn_range);
@@ -1461,10 +1475,11 @@ int apply_to_page_range(struct mm_struct {pgd_t *pgd;unsigned long next; -unsigned long end = addr + size; +unsigned long start = addr, end = addr + size;int err;BUG_ON (addr >= end); +mmu_notifier (invalidate_range_begin, mm, start, end,0 ); pgd =pgd_offset (mm, addr); do { next = pgd_addr_end(addr, end);
@@ -1472,6 +1487,7 @@ int apply_to_page_range(struct mm_structif (err)break ; }while (pgd++, addr = next, addr != end); +mmu_notifier (invalidate_range_end, mm, start, end,0 );return err; }EXPORT_SYMBOL_GPL (apply_to_page_range);
@@ -1612,8 +1628,10 @@ static int do_wp_page(struct mm_struct * page_table =pte_offset_map_lock (mm, pmd, address, &ptl);page_cache_release (old_page); -if (!pte_same (*page_table, orig_pte)) - goto unlock; +if (!pte_same (*page_table, orig_pte)) { +pte_unmap_unlock (page_table, ptl); + goto check_dirty; + } page_mkwrite =1 ; }
@@ -1629,7 +1647,8 @@ static int do_wp_page(struct mm_struct *if (ptep_set_access_flags (vma, address, page_table, entry,1 ))update_mmu_cache (vma, address, entry); ret |=VM_FAULT_WRITE ; - goto unlock; +pte_unmap_unlock (page_table, ptl); + goto check_dirty; }/*
@@ -1651,6 +1670,8 @@ gotten:if (mem_cgroup_charge (new_page, mm,GFP_KERNEL )) goto oom_free_new; +mmu_notifier (invalidate_range_begin, mm, address, + address +PAGE_SIZE ,0 );/* * Re-check the pte - we dropped the lock */
@@ -1689,8 +1710,10 @@ gotten:page_cache_release (new_page);if (old_page)page_cache_release (old_page); -unlock:pte_unmap_unlock (page_table, ptl); +mmu_notifier (invalidate_range_end, mm, + address, address +PAGE_SIZE ,0 ); +check_dirty:if (dirty_page) {if (vma->vm_file)file_update_time (vma->vm_file);
mm/mmap.c +2 -0
@@ -1748,11 +1748,13 @@ static void unmap_region(struct mm_struclru_add_drain (); tlb =tlb_gather_mmu (mm,0 );update_hiwater_rss (mm); +mmu_notifier (invalidate_range_begin, mm, start, end,0 );unmap_vmas (&tlb, vma, start, end, &nr_accounted,NULL );vm_unacct_memory (nr_accounted);free_pgtables (&tlb, vma, prev? prev->vm_end:FIRST_USER_ADDRESS , next? next->vm_start:0 );tlb_finish_mmu (tlb, start, end); +mmu_notifier (invalidate_range_end, mm, start, end,0 ); }/*
mm/hugetlb.c +3 -0
@@ -14,6 +14,7 @@#include <linux/mempolicy.h> #include <linux/cpuset.h> #include <linux/mutex.h> +#include <linux/mmu_notifier.h> #include <asm/page.h> #include <asm/pgtable.h>
@@ -753,6 +754,7 @@ void __unmap_hugepage_range(struct vm_arBUG_ON (start & ~HPAGE_MASK );BUG_ON (end & ~HPAGE_MASK ); +mmu_notifier (invalidate_range_begin, mm, start, end,1 );spin_lock (&mm->page_table_lock);for (address = start; address < end; address +=HPAGE_SIZE ) { ptep =huge_pte_offset (mm, address);
@@ -773,6 +775,7 @@ void __unmap_hugepage_range(struct vm_ar }spin_unlock (&mm->page_table_lock);flush_tlb_range (vma, start, end); +mmu_notifier (invalidate_range_end, mm, start, end,1 );list_for_each_entry_safe (page, tmp, &page_list, lru) {list_del (&page->lru);put_page (page);
mm/filemap_xip.c +5 -0
@@ -13,6 +13,7 @@#include <linux/module.h> #include <linux/uio.h> #include <linux/rmap.h> +#include <linux/mmu_notifier.h> #include <linux/sched.h> #include <asm/tlbflush.h>
@@ -190,6 +191,8 @@ __xip_unmap (struct address_space * mapp address = vma->vm_start + ((pgoff - vma->vm_pgoff) <<PAGE_SHIFT );BUG_ON (address < vma->vm_start || address >= vma->vm_end); +mmu_notifier (invalidate_range_begin, mm, address, + address +PAGE_SIZE ,1 ); pte =page_check_address (page, mm, address, &ptl);if (pte) {/* Nuke the page table entry. */
@@ -201,6 +204,8 @@ __xip_unmap (struct address_space * mapppte_unmap_unlock (pte, ptl);page_cache_release (page); } +mmu_notifier (invalidate_range_end, mm, + address, address +PAGE_SIZE ,1 ); }spin_unlock (&mapping->i_mmap_lock); }
mm/mremap.c +6 -1
@@ -18,6 +18,7 @@#include <linux/highmem.h> #include <linux/security.h> #include <linux/syscalls.h> +#include <linux/mmu_notifier.h> #include <asm/uaccess.h> #include <asm/cacheflush.h>
@@ -124,12 +125,15 @@ unsigned long move_page_tables(struct vm unsigned long old_addr, struct vm_area_struct *new_vma, unsigned long new_addr, unsigned long len) { - unsigned long extent, next, old_end; + unsigned long extent, next, old_start, old_end;pmd_t *old_pmd, *new_pmd; + old_start = old_addr; old_end = old_addr + len;flush_cache_range (vma, old_addr, old_end); +mmu_notifier (invalidate_range_begin, vma->vm_mm, + old_addr, old_end,0 );for (; old_addr < old_end; old_addr += extent, new_addr += extent) {cond_resched (); next = (old_addr +PMD_SIZE ) &PMD_MASK ;
@@ -150,6 +154,7 @@ unsigned long move_page_tables(struct vmmove_ptes (vma, old_pmd, old_addr, old_addr + extent, new_vma, new_pmd, new_addr); } +mmu_notifier (invalidate_range_end, vma->vm_mm, old_start, old_end,0 );return len + old_addr - old_end;/* how much done */ }
mm/mprotect.c +3 -0
@@ -21,6 +21,7 @@#include <linux/syscalls.h> #include <linux/swap.h> #include <linux/swapops.h> +#include <linux/mmu_notifier.h> #include <asm/uaccess.h> #include <asm/pgtable.h> #include <asm/cacheflush.h>
@@ -198,10 +199,12 @@ success: dirty_accountable =1 ; } +mmu_notifier (invalidate_range_begin, mm, start, end,0 );if (is_vm_hugetlb_page (vma))hugetlb_change_protection (vma, start, end, vma->vm_page_prot);else change_protection (vma, start, end, vma->vm_page_prot, dirty_accountable); +mmu_notifier (invalidate_range_end, mm, start, end,0 );vm_stat_account (mm, oldflags, vma->vm_file, -nrpages);vm_stat_account (mm, newflags, vma->vm_file, nrpages);return 0 ;
Signature · 4 lines
------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
PATCH 3/6 mmu_notifier: invalidate_page callbacks
In reply to Christoph LameterTwo callbacks to remove individual pages as done in rmap code
invalidate_page()
Called from the inner loop of rmap walks to invalidate pages.
age_page()
Called for the determination of the page referenced status.
If we do not care about page referenced status then an age_page callback may be be omitted. PageLock and pte lock are held when either of the functions is called.
--- mm/rmap.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)
mm/rmap.c +10 -3
@@ -49,6 +49,7 @@#include <linux/module.h> #include <linux/kallsyms.h> #include <linux/memcontrol.h> +#include <linux/mmu_notifier.h> #include <asm/tlbflush.h>
@@ -287,7 +288,8 @@ static int page_referenced_one(struct paif (vma->vm_flags &VM_LOCKED ) { referenced++; *mapcount =1 ;/* break early from loop */ - }else if (ptep_clear_flush_young (vma, address, pte)) + }else if (ptep_clear_flush_young (vma, address, pte) | +mmu_notifier_age_page (mm, address)) referenced++;/* Pretend the page is referenced if the task has the
@@ -455,6 +457,7 @@ static int page_mkclean_one(struct pageflush_cache_page (vma, address,pte_pfn (*pte)); entry =ptep_clear_flush (vma, address, pte); +mmu_notifier (invalidate_page, mm, address); entry =pte_wrprotect (entry); entry =pte_mkclean (entry);set_pte_at (mm, address, pte, entry);
@@ -712,7 +715,8 @@ static int try_to_unmap_one(struct page* skipped over this mm) then we should reactivate it. */ if (!migration && ((vma->vm_flags &VM_LOCKED ) || - (ptep_clear_flush_young (vma, address, pte)))) { + (ptep_clear_flush_young (vma, address, pte) | +mmu_notifier_age_page (mm, address)))) { ret =SWAP_FAIL ; goto out_unmap; }
@@ -720,6 +724,7 @@ static int try_to_unmap_one(struct page/* Nuke the page table entry. */ flush_cache_page (vma, address,page_to_pfn (page)); pteval =ptep_clear_flush (vma, address, pte); +mmu_notifier (invalidate_page, mm, address);/* Move the dirty bit to the physical page now the pte is gone. */ if (pte_dirty (pteval))
@@ -844,12 +849,14 @@ static void try_to_unmap_cluster(unsigne page =vm_normal_page (vma, address, *pte);BUG_ON (!page ||PageAnon (page)); -if (ptep_clear_flush_young (vma, address, pte)) +if (ptep_clear_flush_young (vma, address, pte) | +mmu_notifier_age_page (mm, address))continue ;/* Nuke the page table entry. */ flush_cache_page (vma, address,pte_pfn (*pte)); pteval =ptep_clear_flush (vma, address, pte); +mmu_notifier (invalidate_page, mm, address);/* If nonlinear, store the file page offset in the pte. */ if (page->index !=linear_page_index (vma, address))
Signature · 4 lines
------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
PATCH 4/6 mmu_notifier: Skeleton driver for a simple mmu_notifier
In reply to Christoph LameterThis is example code for a simple device driver interface to unmap pages that were externally mapped.
Locking is simple through a single lock that is used to protect the device drivers data structures as well as a counter that tracks the active invalidates on a single address space.
The invalidation of extern ptes must be possible with code that does not require sleeping. The lock is taken for all driver operations on the mmu that the driver manages. Locking could be made more sophisticated but I think this is going to be okay for most uses.
--- Documentation/mmu_notifier/skeleton.c | 239 ++++++++++++++++++++++++++++++++++ 1 file changed, 239 insertions(+)
Documentation/mmu_notifier/skeleton.c new file +239 -0
@@ -0,0 +1,239 @@ +#include <linux/mm.h> +#include <linux/mmu_notifier.h> +#include <linux/err.h> +#include <linux/init.h> +#include <linux/pagemap.h> + +/* +* Skeleton for an mmu notifier without rmap callbacks and no need to slepp +* during invalidate_page(). +* +* (C) 2008 Silicon Graphics, Inc. +* Christoph Lameter <clameter-sJ/[email protected]> +* +* Note that the locking is fairly basic. One can add various optimizations +* here and there. There is a single lock for an address space which should be +* satisfactory for most cases. If not then the lock can be split like the +* pte_lock in Linux. It is most likely best to place the locks in the +* page table structure or into whatever the external mmu uses to +* track the mappings. +*/ + +struct my_mmu { +/* MMU notifier specific fields */ +struct mmu_notifier notifier; +spinlock_t lock;/* Protects counter and invidual zaps */ +int invalidates;/* Number of active range_invalidates */ +}; + +/* +* Called with m->lock held +*/ +static void my_mmu_insert_page (struct my_mmu *m, +unsigned long address,unsigned long pfn) +{ +/* Must be provided */ +printk (KERN_INFO "insert page %p address=%lx pfn=%ld\n" , + m, address, pfn); +} + +/* +* Called with m->lock held (optional but usually required to +* protect data structures of the driver). +*/ +static void my_mmu_zap_page (struct my_mmu *m,unsigned long address) +{ +/* Must be provided */ +printk (KERN_INFO "zap page %p address=%lx\n" , m, address); +} + +/* +* Called with m->lock held +*/ +static void my_mmu_zap_range (struct my_mmu *m, +unsigned long start,unsigned long end,int atomic) +{ +/* Must be provided */ +printk (KERN_INFO "zap range %p address=%lx-%lx atomic=%d\n" , + m, start, end, atomic); +} + +/* +* Zap an individual page. +* +* The page must be locked and a refcount on the page must +* be held when this function is called. The page lock is also +* acquired when new references are established and the +* page lock effecively takes on the role of synchronization. +* +* The m->lock is only taken to preserve the integrity fo the +* drivers data structures since we may also race with +* invalidate_range() which will likely access the same mmu +* control structures. +* m->lock is therefore optional here. +*/ +static void my_mmu_invalidate_page (struct mmu_notifier *mn, +struct mm_struct *mm,unsigned long address) +{ + struct my_mmu *m = container_of(mn, struct my_mmu, notifier); + +spin_lock (&m->lock); +my_mmu_zap_page (m, address); +spin_unlock (&m->lock); +} + +/* +* Increment and decrement of the number of range invalidates +*/ +static inline void inc_active (struct my_mmu *m) +{ +spin_lock (&m->lock); + m->invalidates++; +spin_unlock (&m->lock); +} + +static inline void dec_active (struct my_mmu *m) +{ +spin_lock (&m->lock); + m->invalidates--; +spin_unlock (&m->lock); +} + +static void my_mmu_invalidate_range_begin (struct mmu_notifier *mn, +struct mm_struct *mm,unsigned long start,unsigned long end, +int atomic) +{ + struct my_mmu *m = container_of(mn, struct my_mmu, notifier); + +inc_active (m);/* Holds off new references */ +my_mmu_zap_range (m, start, end, atomic); +} + +static void my_mmu_invalidate_range_end (struct mmu_notifier *mn, +struct mm_struct *mm,unsigned long start,unsigned long end, +int atomic) +{ + struct my_mmu *m = container_of(mn, struct my_mmu, notifier); + +dec_active (m);/* Enables new references */ +} + +/* +* Populate a page. +* +* A return value of-EAGAIN means please retry this operation. +* +* Acquisition of mmap_sem can be omitted if the caller already holds +* the semaphore. +*/ +struct page *my_mmu_populate_page (struct my_mmu *m, +struct vm_area_struct *vma, +unsigned long address,int atomic,int write) +{ +struct page *page =ERR_PTR (-EAGAIN ); +int err; + +/* No need to do anything if a range invalidate is running */ +if (m->invalidates) + goto out; + +if (atomic) { + +if (!down_read_trylock (&vma->vm_mm->mmap_sem)) + goto out; + +/* No concurrent invalidates */ + page =follow_page (vma, address,FOLL_GET + + (write ?FOLL_WRITE :0 )); + +up_read (&vma->vm_mm->mmap_sem); +if (!page ||IS_ERR (page) ||TestSetPageLocked (page)) + goto out; + + }else { + +down_read (&vma->vm_mm->mmap_sem); + err =get_user_pages (current, vma->vm_mm, address,1 , + write,1 , &page,NULL ); + +up_read (&vma->vm_mm->mmap_sem); +if (err <0 ) { + page =ERR_PTR (err); + goto out; + } +lock_page (page); + + } + +/* +* The page is now locked and we are holding a refcount on it. +* So things are tied down. Now we can check the page status. +*/ +if (page_mapped (page)) { +/* +* Must take the m->lock here to hold off concurrent +* invalidate_range_b/e. Serialization with invalidate_page() +* occurs because we are holding the page lock. +*/ +spin_lock (&m->lock); +if (!m->invalidates) +my_mmu_insert_page (m, address,page_to_pfn (page)); +spin_unlock (&m->lock); + } +unlock_page (page); +put_page (page); +out: +return page; +} + +/* +* All other threads accessing this mm_struct must have terminated by now. +*/ +static void my_mmu_release (struct mmu_notifier *mn,struct mm_struct *mm) +{ + struct my_mmu *m = container_of(mn, struct my_mmu, notifier); + +my_mmu_zap_range (m,0 ,TASK_SIZE ,0 ); +kfree (m); +printk (KERN_INFO "MMU Notifier detaching\n" ); +} + +static struct mmu_notifier_ops my_mmu_ops = { + my_mmu_release, +NULL ,/* No aging function */ + my_mmu_invalidate_page, + my_mmu_invalidate_range_begin, + my_mmu_invalidate_range_end +}; + +/* +* This function must be called to activate callbacks from a process +*/ +int my_mmu_attach_to_process (struct mm_struct *mm) +{ +struct my_mmu *m =kzalloc (sizeof (struct my_mmu ),GFP_KERNEL ); + +if (!m) +return -ENOMEM ; + + m->notifier.ops = &my_mmu_ops; +spin_lock_init (&mm->lock); + +/* +* mmap_sem handling can be omitted if it is guaranteed that +* the context from which my_mmu_attach_to_process is called +* is already holding a writelock on mmap_sem. +*/ +down_write (&mm->mmap_sem); +mmu_notifier_register (&m->notifier, mm); +up_write (&mm->mmap_sem); + +/* +* RCU sync is expensive but necessary if we need to guarantee +* that multiple threads running on other cpus have seen the +* notifier changes. +*/ +synchronize_rcu (); +return 0 ; +} +
Signature · 4 lines
------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
PATCH 5/6 mmu_notifier: Support for drivers with revers maps (f.e. for XPmem)
In reply to Christoph LameterThese special additional callbacks are required because XPmem (and likely other mechanisms) do use their own rmap (multiple processes on a series of remote Linux instances may be accessing the memory of a process). F.e. XPmem may have to send out notifications to remote Linux instances and receive confirmation before a page can be freed.
So we handle this like an additional Linux reverse map that is walked after the existing rmaps have been walked. We leave the walking to the driver that is then able to use something else than a spinlock to walk its reverse maps. So we can actually call the driver without holding spinlocks while we hold the Pagelock.
However, we cannot determine the mm_struct that a page belongs to at that point. The mm_struct can only be determined from the rmaps by the device driver.
We add another pageflag (PageExternalRmap) that is set if a page has been remotely mapped (f.e. by a process from another Linux instance). We can then only perform the callbacks for pages that are actually in remote use.
Rmap notifiers need an extra page bit and are only available on 64 bit platforms. This functionality is not available on 32 bit!
A notifier that uses the reverse maps callbacks does not need to provide the invalidate_page() method that is called when locks are held.
--- include/linux/mmu_notifier.h | 65 +++++++++++++++++++++++++++++++++++++++++++ include/linux/page-flags.h | 11 +++++++ mm/mmu_notifier.c | 34 ++++++++++++++++++++++ mm/rmap.c | 9 +++++ 4 files changed, 119 insertions(+)
include/linux/page-flags.h +11 -0
@@ -105,6 +105,7 @@* 64 bit | FIELDS | ?????? FLAGS | * 63 32 0 */ +#define PG_external_rmap 30/* Page has external rmap */ #define PG_uncached 31/* Page has been mapped as uncached */ #endif
@@ -296,6 +297,16 @@ static inline void __ClearPageTail(struc#define SetPageUncached (page) set_bit(PG_uncached, &(page)->flags)#define ClearPageUncached (page) clear_bit(PG_uncached, &(page)->flags) +#if defined(CONFIG_MMU_NOTIFIER ) && defined(CONFIG_64BIT ) +#define PageExternalRmap (page) test_bit(PG_external_rmap, &(page)->flags) +#define SetPageExternalRmap (page) set_bit(PG_external_rmap, &(page)->flags) +#define ClearPageExternalRmap (page) clear_bit(PG_external_rmap, \ + &(page)->flags) +#else +#define ClearPageExternalRmap (page) do {} while (0) +#define PageExternalRmap (page) 0 +#endif +struct page ;/* forward declaration */ extern void cancel_dirty_page (struct page *page,unsigned int account_size);
include/linux/mmu_notifier.h +65 -0
95 lines not on this page · raw message
mm/mmu_notifier.c +34 -0
@@ -74,3 +74,37 @@ void mmu_notifier_unregister(struct mmu_ }EXPORT_SYMBOL_GPL (mmu_notifier_unregister); +#ifdef CONFIG_64BIT +static DEFINE_SPINLOCK (mmu_notifier_list_lock); +HLIST_HEAD (mmu_rmap_notifier_list); + +void mmu_rmap_notifier_register (struct mmu_rmap_notifier *mrn) +{ +spin_lock (&mmu_notifier_list_lock); +hlist_add_head_rcu (&mrn->hlist, &mmu_rmap_notifier_list); +spin_unlock (&mmu_notifier_list_lock); +} +EXPORT_SYMBOL (mmu_rmap_notifier_register); + +void mmu_rmap_notifier_unregister (struct mmu_rmap_notifier *mrn) +{ +spin_lock (&mmu_notifier_list_lock); +hlist_del_rcu (&mrn->hlist); +spin_unlock (&mmu_notifier_list_lock); +} +EXPORT_SYMBOL (mmu_rmap_notifier_unregister); + +/* +* Export a page. +* +* Pagelock must be held. +* Must be called before a page is put on an external rmap. +*/ +void mmu_rmap_export_page (struct page *page) +{ +BUG_ON (!PageLocked (page)); +SetPageExternalRmap (page); +} +EXPORT_SYMBOL (mmu_rmap_export_page); + +#endif
mm/rmap.c +9 -0
@@ -497,6 +497,10 @@ int page_mkclean(struct page *page)struct address_space *mapping =page_mapping (page);if (mapping) { ret =page_mkclean_file (mapping, page); +if (unlikely (PageExternalRmap (page))) { +mmu_rmap_notifier (invalidate_page, page); +ClearPageExternalRmap (page); + }if (page_test_dirty (page)) {page_clear_dirty (page); ret =1 ;
@@ -1013,6 +1017,11 @@ int try_to_unmap(struct page *page, intelse ret =try_to_unmap_file (page, migration); +if (unlikely (PageExternalRmap (page))) { +mmu_rmap_notifier (invalidate_page, page); +ClearPageExternalRmap (page); + } +if (!page_mapped (page)) ret =SWAP_SUCCESS ;return ret;
Signature · 4 lines
------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
PATCH 6/6 mmu_rmap_notifier: Skeleton for complex driver that uses its own rmaps
In reply to Christoph LameterThe skeleton for the rmap notifier leaves the invalidate_page method of the mmu_notifier empty and hooks a new invalidate_page callback into the global chain for mmu_rmap_notifiers.
There are seveal simplifications in here to avoid making this too complex. The reverse maps need to consit of references to vma f.e.
--- Documentation/mmu_notifier/skeleton_rmap.c | 265 +++++++++++++++++++++++++++++ 1 file changed, 265 insertions(+)
Documentation/mmu_notifier/skeleton_rmap.c new file +265 -0
@@ -0,0 +1,265 @@ +#include <linux/mm.h> +#include <linux/mmu_notifier.h> +#include <linux/err.h> +#include <linux/init.h> +#include <linux/pagemap.h> + +/* +* Skeleton for an mmu notifier with rmap callbacks and sleeping during +* invalidate_page. +* +* (C) 2008 Silicon Graphics, Inc. +* Christoph Lameter <clameter-sJ/[email protected]> +* +* Note that the locking is fairly basic. One can add various optimizations +* here and there. There is a single lock for an address space which should be +* satisfactory for most cases. If not then the lock can be split like the +* pte_lock in Linux. It is most likely best to place the locks in the +* page table structure or into whatever the external mmu uses to +* track the mappings. +*/ + +struct my_mmu { +/* MMU notifier specific fields */ +struct mmu_notifier notifier; +spinlock_t lock;/* Protects counter and invidual zaps */ +int invalidates;/* Number of active range_invalidate */ + +/* Rmap support */ +struct list_head list;/* rmap list of my_mmu structs */ +unsigned long base; +}; + +/* +* Called with m->lock held +*/ +static void my_mmu_insert_page (struct my_mmu *m, +unsigned long address,unsigned long pfn) +{ +/* Must be provided */ +printk (KERN_INFO "insert page %p address=%lx pfn=%ld\n" , + m, address, pfn); +} + +/* +* Called with m->lock held +*/ +static void my_mmu_zap_range (struct my_mmu *m, +unsigned long start,unsigned long end,int atomic) +{ +/* Must be provided */ +printk (KERN_INFO "zap range %p address=%lx-%lx atomic=%d\n" , + m, start, end, atomic); +} + +/* +* Called with m->lock held (optional but usually required to +* protect data structures of the driver). +*/ +static void my_mmu_zap_page (struct my_mmu *m,unsigned long address) +{ +/* Must be provided */ +printk (KERN_INFO "zap page %p address=%lx\n" , m, address); +} + +/* +* Increment and decrement of the number of range invalidates +*/ +static inline void inc_active (struct my_mmu *m) +{ +spin_lock (&m->lock); + m->invalidates++; +spin_unlock (&m->lock); +} + +static inline void dec_active (struct my_mmu *m) +{ +spin_lock (&m->lock); + m->invalidates--; +spin_unlock (&m->lock); +} + +static void my_mmu_invalidate_range_begin (struct mmu_notifier *mn, +struct mm_struct *mm,unsigned long start,unsigned long end, +int atomic) +{ + struct my_mmu *m = container_of(mn, struct my_mmu, notifier); + +inc_active (m);/* Holds off new references */ +my_mmu_zap_range (m, start, end, atomic); +} + +static void my_mmu_invalidate_range_end (struct mmu_notifier *mn, +struct mm_struct *mm,unsigned long start,unsigned long end, +int atomic) +{ + struct my_mmu *m = container_of(mn, struct my_mmu, notifier); + +dec_active (m);/* Enables new references */ +} + +/* +* Populate a page. +* +* A return value of-EAGAIN means please retry this operation. +* +* Acuisition of mmap_sem can be omitted if the caller already holds +* the semaphore. +*/ +struct page *my_mmu_populate_page (struct my_mmu *m, +struct vm_area_struct *vma, +unsigned long address,int write) +{ +struct page *page =ERR_PTR (-EAGAIN ); +int err; + +/* +* No need to do anything if a range invalidate is running +* Could use a wait queue here to avoid returning -EAGAIN. +*/ +if (m->invalidates) + goto out; + +down_read (&vma->vm_mm->mmap_sem); + err =get_user_pages (current, vma->vm_mm, address,1 , + write,1 , &page,NULL ); + +up_read (&vma->vm_mm->mmap_sem); +if (err <0 ) { + page =ERR_PTR (err); + goto out; + } +lock_page (page); + +/* +* The page is now locked and we are holding a refcount on it. +* So things are tied down. Now we can check the page status. +*/ +if (page_mapped (page)) { +/* Could do some preprocessing here. Can sleep */ +spin_lock (&m->lock); +if (!m->invalidates) +my_mmu_insert_page (m, address,page_to_pfn (page)); +spin_unlock (&m->lock); +/* Could do some postprocessing here. Can sleep */ + } +unlock_page (page); +put_page (page); +out: +return page; +} + +/* +* All other threads accessing this mm_struct must have terminated by now. +*/ +static void my_mmu_release (struct mmu_notifier *mn,struct mm_struct *mm) +{ + struct my_mmu *m = container_of(mn, struct my_mmu, notifier); + +my_mmu_zap_range (m,0 ,TASK_SIZE ,0 ); +/* No concurrent processes thus no worries about RCU */ +list_del (&m->list); +kfree (m); +printk (KERN_INFO "MMU Notifier terminating\n" ); +} + +static struct mmu_notifier_ops my_mmu_ops = { + my_mmu_release, +NULL ,/* No aging function */ +NULL ,/* No atomic invalidate_page function */ + my_mmu_invalidate_range_begin, + my_mmu_invalidate_range_end +}; + +/* Rmap specific fields */ +static LIST_HEAD (my_mmu_list); +static struct rw_semaphore listlock; + +/* +* This function must be called to activate callbacks from a process +*/ +int my_mmu_attach_to_process (struct mm_struct *mm) +{ +struct my_mmu *m =kzalloc (sizeof (struct my_mmu ),GFP_KERNEL ); + +if (!m) +return -ENOMEM ; + + m->notifier.ops = &my_mmu_ops; +spin_lock_init (&m->lock); + +/* +* mmap_sem handling can be omitted if it is guaranteed that +* the context from which my_mmu_attach_to_process is called +* is already holding a writelock on mmap_sem. +*/ +down_write (&mm->mmap_sem); +mmu_notifier_register (&m->notifier, mm); +up_write (&mm->mmap_sem); +down_write (&listlock); +list_add (&m->list, &my_mmu_list); +up_write (&listlock); + +/* +* RCU sync is expensive but necessary if we need to guarantee +* that multiple threads running on other cpus have seen the +* notifier changes. +*/ +synchronize_rcu (); +return 0 ; +} + + +static void my_sleeping_invalidate_page (struct my_mmu *m,unsigned long address) +{ +/* Must be provided */ +spin_lock (&m->lock);/* Only taken to ensure mmu data integrity */ +my_mmu_zap_page (m, address); +spin_unlock (&m->lock); +printk (KERN_INFO "Sleeping invalidate_page %p address=%lx\n" , + m, address); +} + +static unsigned long my_mmu_find_addr (struct my_mmu *m,struct page *page) +{ +/* Determine the address of a page in a mmu segment */ +return -EFAULT ; +} + +/* +* A reference must be held on the page passed and the page passed +* must be locked. No spinlocks are held. invalidate_page() is held +* off by us holding the page lock. +*/ +static void my_mmu_rmap_invalidate_page (struct mmu_rmap_notifier *mrn, +struct page *page) +{ +struct my_mmu *m; + +BUG_ON (!PageLocked (page)); +down_read (&listlock); +list_for_each_entry (m, &my_mmu_list, list) { +unsigned long address =my_mmu_find_addr (m, page); + +if (address != -EFAULT ) +my_sleeping_invalidate_page (m, address); + } +up_read (&listlock); +} + +static struct mmu_rmap_notifier_ops my_mmu_rmap_ops = { + .invalidate_page = my_mmu_rmap_invalidate_page +}; + +static struct mmu_rmap_notifier my_mmu_rmap_notifier = { + .ops = &my_mmu_rmap_ops +}; + +static int __init my_mmu_init (void ) +{ +mmu_rmap_notifier_register (&my_mmu_rmap_notifier); +return 0 ; +} + +late_initcall (my_mmu_init); +
Signature · 4 lines
------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
Andrew Morton
maintainerQuoted 27 lines · On Fri, 08 Feb 2008 14:06:16 -0800 Christoph Lameter <[email protected]> wrote:
This is a patchset implementing MMU notifier callbacks based on Andrea's earlier work. These are needed if Linux pages are referenced from something else than tracked by the rmaps of the kernel (an external MMU). MMU notifiers allow us to get rid of the page pinning for RDMA and various other purposes. It gets rid of the broken use of mlock for page pinning. (mlock really does *not* pin pages....)
More information on the rationale and the technical details can be found in the first patch and the README provided by that patch in
Documentation/mmu_notifiers.The known immediate users are
KVM
- Establishes a refcount to the page viaget_user_pages().
- External references are called spte.
- Has page tables to track pages whose refcount was elevated but no reverse maps.GRU
- Simple additional hardware TLB (possibly covering multiple instances of Linux)
- Needs TLB shootdown when the VM unmaps pages.
- Determines page address viafollow_page(from interrupt context) but can fall back toget_user_pages().
- No page reference possible since no page status is kept..
Quoted 7 lines
XPmem
- Allows use of a processes memory by remote instances of Linux.
- Provides its own reverse mappings to track remote pte.
- Established refcounts on the exported pages.
- Must sleep in order to wait for remote acks of ptes that are being cleared.
What about ib_umem_get()?
Quoted 1 line · Andrew Morton
What about
ib_umem_get()?
Ok. It pins using an elevated refcount. Same as XPmem right now. With that we effectively pin a page (page migration will fail) but we will continually be reclaiming the page and may repeatedly try to move it. We have issues with XPmem causing too many pages to be pinned and thus the OOM getting into weird behavior modes (OOM or stop lru scanning due to all_reclaimable set).
An elevated refcount will also not be noticed by any of the schemes under consideration to improve LRU scanning performance.
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
Quoted 11 lines · Christoph Lameter
Quoted 1 line · Andrew Morton
What about
ib_umem_get()?Ok. It pins using an elevated refcount. Same as XPmem right now. With that we effectively pin a page (page migration will fail) but we will continually be reclaiming the page and may repeatedly try to move it. We have issues with XPmem causing too many pages to be pinned and thus the OOM getting into weird behavior modes (OOM or stop lru scanning due to
all_reclaimableset).
Quoted 2 lines
An elevated refcount will also not be noticed by any of the schemes under consideration to improve LRU scanning performance.
Christoph, I am not sure what you are saying here. With v4 and later, I thought we were able to use the rmap invalidation to remove the ref count that XPMEM was holding and therefore be able to swapout. Did I miss something? I agree the existing XPMEM does pin. I hope we are not saying the XPMEM based upon these patches will not be able to swap/migrate.
Thanks,
Robin
Quoted 9 lines · Robin Holt
Quoted 9 lines
Quoted 1 line
What about
ib_umem_get()?Ok. It pins using an elevated refcount. Same as XPmem right now. With that we effectively pin a page (page migration will fail) but we will continually be reclaiming the page and may repeatedly try to move it. We have issues with XPmem causing too many pages to be pinned and thus the OOM getting into weird behavior modes (OOM or stop lru scanning due to
all_reclaimableset).
Quoted 8 lines
Quoted 2 lines
An elevated refcount will also not be noticed by any of the schemes under consideration to improve LRU scanning performance.
Christoph, I am not sure what you are saying here. With v4 and later, I thought we were able to use the rmap invalidation to remove the ref count that XPMEM was holding and therefore be able to swapout. Did I miss something? I agree the existing XPMEM does pin. I hope we are not saying the XPMEM based upon these patches will not be able to swap/migrate.
Correct.
You missed the turn of the conversation to how ib_umem_get() works. Currently it seems to pin the same way that the SLES10 XPmem works.
Quoted 8 lines · Christoph Lameter
Quoted 1 line · Robin Holt
Quoted 1 line
Quoted 1 line
What about
ib_umem_get()?Correct.
You missed the turn of the conversation to how
ib_umem_get()works. Currently it seems to pin the same way that the SLES10 XPmem works.
Ah. I took Andrew's question as more of a probe about whether we had worked with the IB folks to ensure this fits the ib_umem_get needs as well.
Thanks,
Robin
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
Andrew Morton
maintainerQuoted 5 lines · On Fri, 8 Feb 2008 17:43:02 -0600 Robin Holt <[email protected]> wrote:
Quoted 4 lines · Christoph Lameter
Quoted 1 line · Robin Holt
Quoted 1 line
Quoted 1 line
What about
ib_umem_get()?
Quoted 9 lines
Quoted 4 lines
Correct.
You missed the turn of the conversation to how
ib_umem_get()works. Currently it seems to pin the same way that the SLES10 XPmem works.Ah. I took Andrew's question as more of a probe about whether we had worked with the IB folks to ensure this fits the
ib_umem_getneeds as well.
You took it correctly, and I didn't understand the answer ;)
Quoted 1 line · Andrew Morton
You took it correctly, and I didn't understand the answer ;)
We have done several rounds of discussion on linux-kernel about this so far and the IB folks have not shown up to join in. I have tried to make this as general as possible.
Quoted 3 lines
We have done several rounds of discussion on linux-kernel about this so far and the IB folks have not shown up to join in. I have tried to make this as general as possible.
Sorry, this has been on my "things to look at" list for a while, but I haven't gotten a chance to really understand where things are yet.
In general, this MMU notifier stuff will only be useful to a subset of InfiniBand/RDMA hardware. Some adapters are smart enough to handle changing the IO virtual -> bus/physical mapping on the fly, but some aren't. For the dumb adapters, I think the current ib_umem_get() is pretty close to as good as we can get: we have to keep the physical pages pinned for as long as the adapter is allowed to DMA into the memory region.
For the smart adapters, we just need a chance to change the adapter's page table when the kernel/CPU's mapping changes, and naively, this stuff looks like it would work.
Andrew, does that help?
- R.
Quoted 7 lines · Roland Dreier
In general, this MMU notifier stuff will only be useful to a subset of InfiniBand/RDMA hardware. Some adapters are smart enough to handle changing the IO virtual -> bus/physical mapping on the fly, but some aren't. For the dumb adapters, I think the current
ib_umem_get()is pretty close to as good as we can get: we have to keep the physical pages pinned for as long as the adapter is allowed to DMA into the memory region.
I thought the adaptor can always remove the mapping by renegotiating with the remote side? Even if its dumb then a callback could notify the driver that it may be required to tear down the mapping. We then hold the pages until we get okay by the driver that the mapping has been removed.
We could also let the unmapping fail if the driver indicates that the mapping must stay.
[ofa-general] trying to get of all lists
unsubscribe
Quoted 1 line
Date: Fri, 8 Feb 2008 16:16:34 -0800> From: [email protected]> To: [email protected]> CC: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]> Subject: Re: [ofa-general] Re: [patch 0/6] MMU Notifiers V6> > On Fri, 8 Feb 2008, Roland Dreier wrote:> > > In general, this MMU notifier stuff will only be useful to a subset of> > InfiniBand/RDMA hardware. Some adapters are smart enough to handle> > changing the IO virtual -> bus/physical mapping on the fly, but some> > aren't. For the dumb adapters, I think the current
ib_umem_get()is> > pretty close to as good as we can get: we have to keep the physical> > pages pinned for as long as the adapter is allowed to DMA into the> > memory region.> > I thought the adaptor can always remove the mapping by renegotiating > with the remote side? Even if its dumb then a callback could notify the > driver that it may be required to tear down the mapping. We then hold the > pages until we get okay by the driver that the mapping has been removed.> > We could also let the unmapping fail if the driver indicates that the > mapping must stay.> --> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in> the body of a message to [email protected]> More majordomo info at http://vger.kernel.org/majordomo-info.html> Please read the FAQ at http://www.tux.org/lkml/
_________________________________________________________________
Shed those extra pounds with MSN and The Biggest Loser!
http://biggestloser.msn.com/
Quoted 4 lines
I thought the adaptor can always remove the mapping by renegotiating with the remote side? Even if its dumb then a callback could notify the driver that it may be required to tear down the mapping. We then hold the pages until we get okay by the driver that the mapping has been removed.
Of course we can always destroy the memory region but that would break the semantics that applications expect. Basically an application can register some chunk of its memory and get a key that it can pass to a remote peer to let the remote peer operate on its memory via RDMA. And that memory region/key is expected to stay valid until there is an application-level operation to destroy it (or until the app crashes or gets killed, etc).
Quoted 2 lines
We could also let the unmapping fail if the driver indicates that the mapping must stay.
That would of course work -- dumb adapters would just always fail, which might be inefficient.
Quoted 2 lines · Roland Dreier
That would of course work -- dumb adapters would just always fail, which might be inefficient.
Hmmmm.. that means we need something that actually pins pages for good so that the VM can avoid reclaiming it and so that page migration can avoid trying to migrate them. Something like yet another page flag.
Ccing Rik.
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
Quoted 8 lines · Christoph Lameter
Quoted 2 lines · Roland Dreier
That would of course work -- dumb adapters would just always fail, which might be inefficient.
Hmmmm.. that means we need something that actually pins pages for good so that the VM can avoid reclaiming it and so that page migration can avoid trying to migrate them. Something like yet another page flag.
What's wrong with pinning with the page count like now? Dumb adapters would simply not register themself in the mmu notifier list no?
Quoted 2 lines
Ccing Rik.
Quoted 6 lines · Andrea Arcangeli
Quoted 3 lines
Hmmmm.. that means we need something that actually pins pages for good so that the VM can avoid reclaiming it and so that page migration can avoid trying to migrate them. Something like yet another page flag.
What's wrong with pinning with the page count like now? Dumb adapters would simply not register themself in the mmu notifier list no?
Pages will still be on the LRU and cycle through rmap again and again. If page migration is used on those pages then the code may make repeated attempt to migrate the page thinking that the page count must at some point drop.
I do not think that the page count was intended to be used to pin pages permanently. If we had a marker on such pages then we could take them off the LRU and not try to migrate them.
Quoted 8 lines · Christoph Lameter
Pages will still be on the LRU and cycle through rmap again and again. If page migration is used on those pages then the code may make repeated attempt to migrate the page thinking that the page count must at some point drop.
I do not think that the page count was intended to be used to pin pages permanently. If we had a marker on such pages then we could take them off the LRU and not try to migrate them.
The VM shouldn't break if try_to_unmap doesn't actually make the page freeable for whatever reason. Permanent pins shouldn't happen anyway, so defining an ad-hoc API for that doesn't sound too appealing. Not sure if old hardware deserves those special lru-size-reduction optimizations but it's not my call (certainly swapoff/mlock would get higher priority in that lru-size-reduction area).
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
Quoted 2 lines · Andrea Arcangeli
The VM shouldn't break if
try_to_unmapdoesn't actually make the page freeable for whatever reason. Permanent pins shouldn't happen anyway,
VM is livelocking if too many page are pinned that way right now. The higher the processors per node the higher the risk of livelock because more processors are in the process of cycling through pages that have an elevated refcount.
Quoted 4 lines
so defining an ad-hoc API for that doesn't sound too appealing. Not sure if old hardware deserves those special lru-size-reduction optimizations but it's not my call (certainly swapoff/mlock would get higher priority in that lru-size-reduction area).
Rik has a patchset under development that addresses issues like this. The elevated refcount pin problem is not really relevant to the patchset we are discussing here.
Quoted 8 lines · On Fri, 8 Feb 2008 18:16:16 -0800 (PST) Christoph Lameter <[email protected]>…
Quoted 2 lines · Andrea Arcangeli
The VM shouldn't break if
try_to_unmapdoesn't actually make the page freeable for whatever reason. Permanent pins shouldn't happen anyway,VM is livelocking if too many page are pinned that way right now.
Rik has a patchset under development that addresses issues like this
PG_mlock is on the way and can easily be reused for this, too.
Signature · 1 line
All rights reversed.
Quoted 1 line · Rik van Riel
PG_mlockis on the way and can easily be reused for this, too.
Note that a pinned page is different from an mlocked page. A mlocked page can be moved through page migration and/or memory hotplug. A pinned page must make both fail.
Demand paging for memory regions (was Re: MMU Notifiers V6)
[Adding [email protected] to get the IB/RDMA people involved]
This thread has patches that add support for notifying drivers when a process's memory map changes. The hope is that this is useful for letting RDMA devices handle registered memory without pinning the underlying pages, by updating the RDMA device's translation tables whenever the host kernel's tables change.
Is anyone interested in working on using this for drivers/infiniband? I am interested in participating, but I don't think I have enough time to do this by myself.
Also, at least naively it seems that this is only useful for hardware that has support for this type of demand paging, and can handle not-present pages, generating interrupts for page faults, etc. I know that Mellanox HCAs should have this support; are there any other devices that can do this?
The beginning of this thread is at <http://lkml.org/lkml/2008/2/8/458>.
- R.
Re: Demand paging for memory regions (was Re: MMU Notifiers V6)
Quoted 11 lines · Roland Dreier
[Adding [email protected] to get the IB/RDMA people involved]
This thread has patches that add support for notifying drivers when a process's memory map changes. The hope is that this is useful for letting RDMA devices handle registered memory without pinning the underlying pages, by updating the RDMA device's translation tables whenever the host kernel's tables change.
Is anyone interested in working on using this for
drivers/infiniband? I am interested in participating, but I don't think I have enough time to do this by myself.
I don't have time, although it would be interesting work!
Quoted 7 lines
Also, at least naively it seems that this is only useful for hardware that has support for this type of demand paging, and can handle not-present pages, generating interrupts for page faults, etc. I know that Mellanox HCAs should have this support; are there any other devices that can do this?
Chelsio's T3 HW doesn't support this.
Steve.
Re: Demand paging for memory regions (was Re: MMU Notifiers V6)
Quoted 1 line · Steve Wise
Chelsio's T3 HW doesn't support this.
Not so far I guess but it could be equipped with these features right?
Having the VM manage the memory area for Infiniband allows more reliable system operations and enables the sharing of large memory areas via Infiniband without the risk of livelocks or OOMs.
Re: [ofa-general] Re: Demand paging for memory regions
Quoted 3 lines
Quoted 1 line
Chelsio's T3 HW doesn't support this.
Not so far I guess but it could be equipped with these features right?
I don't know anything about the T3 internals, but it's not clear that you could do this without a new chip design in general. Lot's of RDMA devices were designed expecting that when a packet arrives, the HW can look up the bus address for a given memory region/offset and place the packet immediately. It seems like a major change to be able to generate a "page fault" interrupt when a page isn't present, or even just wait to scatter some data until the host finishes updating page tables when the HW needs the translation.
- R.
RE: [ofa-general] Re: Demand paging for memory regions
Quoted 11 lines
-----Original Message-----
From: [email protected] [mailto:general- [email protected]] On Behalf Of Roland Dreier
Sent: Tuesday, February 12, 2008 2:42 PM
To: Christoph Lameter
Cc: Rik van Riel; [email protected]; Andrea Arcangeli; [email protected]; [email protected]; linux- [email protected]; [email protected]; [email protected]; [email protected]; Robin Holt;
Quoted 8 lines
Andrew Morton; [email protected]
Subject: Re: [ofa-general] Re: Demand paging for memory regionsQuoted 3 lines
Quoted 1 line
Chelsio's T3 HW doesn't support this.
Not so far I guess but it could be equipped with these features
right?
Quoted 8 lines
I don't know anything about the T3 internals, but it's not clear that you could do this without a new chip design in general. Lot's of RDMA devices were designed expecting that when a packet arrives, the HW can look up the bus address for a given memory region/offset and place the packet immediately. It seems like a major change to be able to generate a "page fault" interrupt when a page isn't present, or even just wait to scatter some data until the host finishes updating page tables when the HW needs the translation.
That is correct, not a change we can make for T3. We could, in theory, deal with changing mappings though. The change would need to be synchronized though: the VM would need to tell us which mapping were about to change and the driver would then need to disable DMA to/from it, do the change and resume DMA.
Quoted 9 lines
- R.
_______________________________________________
general mailing list
[email protected]
http://lists.openfabrics.org/cgi-bin/mailman/listinfo/generalTo unsubscribe, please visit
http://openib.org/mailman/listinfo/openib-
Quoted 1 line
general
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
RE: [ofa-general] Re: Demand paging for memory regions
Quoted 9 lines · Felix Marti
Quoted 8 lines
I don't know anything about the T3 internals, but it's not clear that you could do this without a new chip design in general. Lot's of RDMA devices were designed expecting that when a packet arrives, the HW can look up the bus address for a given memory region/offset and place the packet immediately. It seems like a major change to be able to generate a "page fault" interrupt when a page isn't present, or even just wait to scatter some data until the host finishes updating page tables when the HW needs the translation.
Quoted 5 lines
That is correct, not a change we can make for T3. We could, in theory, deal with changing mappings though. The change would need to be synchronized though: the VM would need to tell us which mapping were about to change and the driver would then need to disable DMA to/from it, do the change and resume DMA.
Right. That is the intend of the patchset.
Re: [ofa-general] Re: Demand paging for memory regions
In reply to Felix MartiQuoted 7 lines · Felix Marti
That is correct, not a change we can make for T3. We could, in theory, deal with changing mappings though. The change would need to be synchronized though: the VM would need to tell us which mapping were about to change and the driver would then need to disable DMA to/from it, do the change and resume DMA.
Note that for T3, this involves suspending _all_ rdma connections that are in the same PD as the MR being remapped. This is because the driver doesn't know who the application advertised the rkey/stag to. So without that knowledge, all connections that _might_ rdma into the MR must be suspended. If the MR was only setup for local access, then the driver could track the connections with references to the MR and only quiesce those connections.
Point being, it will stop probably all connections that an application is using (assuming the application uses a single PD).
Steve.
Re: [ofa-general] Re: Demand paging for memory regions
Quoted 3 lines · Steve Wise
Note that for T3, this involves suspending _all_ rdma connections that are in the same PD as the MR being remapped. This is because the driver doesn't know who the application advertised the rkey/stag to. So without
Is there a reason the driver can not track these.
Quoted 2 lines
Point being, it will stop probably all connections that an application is using (assuming the application uses a single PD).
It seems like the need to not stop all would be a compelling enough reason to modify the driver to track which processes have received the rkey/stag.
Thanks,
Robin
Re: [ofa-general] Re: Demand paging for memory regions
Quoted 5 lines · Robin Holt
Quoted 1 line · Steve Wise
Note that for T3, this involves suspending _all_ rdma connections that are in the same PD as the MR being remapped. This is because the driver doesn't know who the application advertised the rkey/stag to. So without
Is there a reason the driver can not track these.
Because advertising of a MR (ie telling the peer about your rkey/stag, offset and length) is application-specific and can be done out of band, or in band as simple SEND/RECV payload. Either way, the driver has no way of tracking this because the protocol used is application-specific.
Quoted 5 lines
Quoted 1 line
Point being, it will stop probably all connections that an application is using (assuming the application uses a single PD).
It seems like the need to not stop all would be a compelling enough reason to modify the driver to track which processes have received the rkey/stag.
Yes, _if_ the driver could track this.
And _if_ the rdma API and paradigm was such that the kernel/driver could keep track, then remote revokations of MR tags could be supported.
Stevo
Re: [ofa-general] Re: Demand paging for memory regions
Quoted 6 lines · Steve Wise
Quoted 5 lines · Robin Holt
Quoted 3 lines · Steve Wise
Note that for T3, this involves suspending _all_ rdma connections that are in the same PD as the MR being remapped. This is because the driver doesn't know who the application advertised the rkey/stag to. So without
Quoted 9 lines
Quoted 2 lines
Is there a reason the driver can not track these.
Because advertising of a MR (ie telling the peer about your rkey/stag, offset and length) is application-specific and can be done out of band, or in band as simple SEND/RECV payload. Either way, the driver has no way of tracking this because the protocol used is application-specific.
I fully agree. If there is one important thing about RDMA and other fastpath solutions that must be understood is that the driver does not see the payload. This is a fundamental strength, but it means that you have to identify what if any intercept points there are in advance.
You also raise a good point on the scope of any suspend/resume API. Device reporting of this capability would not be a simple boolean, but more of a suspend/resume scope. A minimal scope would be any connection that actually attempts to use the suspended MR. Slightly wider would be any connection *allowed* to use the MR, which could expand all the way to any connection under the same PD. Convievably I could imagine an RDMA device reporting that it could support suspend/ resume, but only at the scope of the entire device.
But even at such a wide scope, suspend/resume could be useful to a Memory Manager. The pages could be fully migrated to the new location, and the only work that was still required during the critical suspend/resume region was to actually shift to the new map. That might be short enough that not accepting *any* incoming RDMA packet would be acceptable.
And if the goal is to replace a memory card the alternative might be migrating the applications to other physical servers, which would mean a much longer period of not accepting incoming RDMA packets.
But the broader question is what the goal is here. Allowing memory to be shuffled is valuable, and perhaps even ultimately a requirement for high availability systems. RDMA and other direct-access APIs should be evolving their interfaces to accommodate these needs.
Oversubscribing memory is a totally different matter. If an application is working with memory that is oversubscribed by a factor of 2 or more can it really benefit from zero-copy direct placement? At first glance I can't see what RDMA could be bringing of value when the overhead of swapping is going to be that large.
If it really does make sense, then explicitly registering the portion of memory that should be enabled to receive incoming traffic while the application is swapped out actually makes sense.
Current Memory Registration methods force applications to either register too much or too often. They register too much when the cost of registration is high, and the application responds by registering its entire buffer pool permanently. This is a problem when it overstates the amount of memory that the application needs to have resident, or when the device imposes limits on the size of memory maps that it can know. The alternative is to register too often, that is on a per-operation basis.
To me that suggests the solutions lie in making it more reasonable to register more memory, or in making it practical to register memory on-the-fly on a per-operation basis with low enough overhead that applications don't feel the need to build elaborate registration caching schemes.
As has been pointed out a few times in this thread, the RDMA and transport layers simply do not have enough information to know which portion of registered memory *really* had to be registered. So any back-pressure scheme where the Memory Manager is asking for pinned memory to be "given back" would have to go all the way to the application. Only the application knows what it is "really" using.
I also suspect that most applications that are interested in using RDMA would rather be told they can allocate 200M indefinitely (and with real memory backing it) than be given 1GB of virtual memory that is backed by 200-300M of physical memory, especially if it meant dealing with memory pressure upcalls.
Quoted 22 lines
Quoted 6 lines
Quoted 2 lines
Point being, it will stop probably all connections that an application is using (assuming the application uses a single PD).
It seems like the need to not stop all would be a compelling enough reason to modify the driver to track which processes have received the rkey/stag.
Yes, _if_ the driver could track this.
And _if_ the rdma API and paradigm was such that the kernel/driver could keep track, then remote revokations of MR tags could be supported.
Stevo
_______________________________________________
general mailing list
[email protected]
http://lists.openfabrics.org/cgi-bin/mailman/listinfo/generalTo unsubscribe, please visit http://openib.org/mailman/listinfo/openib-general
Re: [ofa-general] Re: Demand paging for memory regions
Quoted 6 lines · Caitlin Bestler
But the broader question is what the goal is here. Allowing memory to be shuffled is valuable, and perhaps even ultimately a requirement for high availability systems. RDMA and other direct-access APIs should be evolving their interfaces to accommodate these needs.
Quoted 6 lines
Oversubscribing memory is a totally different matter. If an application is working with memory that is oversubscribed by a factor of 2 or more can it really benefit from zero-copy direct placement? At first glance I can't see what RDMA could be bringing of value when the overhead of swapping is going to be that large.
A related use case from HPC. Some of us have batch scheduling systems based on suspend/resume of jobs (which is really just SIGSTOP and SIGCONT of all job processes). The value of this system is enhanced greatly by being able to page out the suspended job (just normal Linux demand paging caused by the incoming job is OK). Apart from this (relatively) brief period of paging, both jobs benefit from RDMA.
SGI kindly implemented a /proc mechanism for unpinning of XPMEM pages to allow suspended jobs to be paged on their Altix system.
Note that this use case would not benefit from Pete Wyckoff's approach of notifying user applications/libraries of VM changes.
And one of the grand goal of HPC developers has always been to have checkpoint/restart of jobs ....
David
--
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: [ofa-general] Re: Demand paging for memory regions
Quoted 19 lines · David Singleton
Quoted 9 lines · Caitlin Bestler
But the broader question is what the goal is here. Allowing memory to be shuffled is valuable, and perhaps even ultimately a requirement for high availability systems. RDMA and other direct-access APIs should be evolving their interfaces to accommodate these needs. Oversubscribing memory is a totally different matter. If an application is working with memory that is oversubscribed by a factor of 2 or more can it really benefit from zero-copy direct placement? At first glance I can't see what RDMA could be bringing of value when the overhead of swapping is going to be that large.
A related use case from HPC. Some of us have batch scheduling systems based on suspend/resume of jobs (which is really just SIGSTOP and SIGCONT of all job processes). The value of this system is enhanced greatly by being able to page out the suspended job (just normal Linux demand paging caused by the incoming job is OK). Apart from this (relatively) brief period of paging, both jobs benefit from RDMA.
Quoted 5 lines
SGI kindly implemented a /proc mechanism for unpinning of XPMEM pages to allow suspended jobs to be paged on their Altix system.
Note that this use case would not benefit from Pete Wyckoff's approach of notifying user applications/libraries of VM changes.
We will be implementing xpmem on top of mmu_notifiers (actively working on that now) so in that case, you would no longer need to use the /proc/xpmem/<pid> mechanism for unpinning. Hopefully, we will have xpmem in before 2.6.26 and get it into the base OS now instead of an add-on. Oh yeah, and memory migration will not need the unpin thing either so you can move smaller jobs around more easily.
Thanks,
Robin
--
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: [ofa-general] Re: Demand paging for memory regions
In reply to Steve WiseQuoted 9 lines · Steve Wise
Note that for T3, this involves suspending _all_ rdma connections that are in the same PD as the MR being remapped. This is because the driver doesn't know who the application advertised the rkey/stag to. So without that knowledge, all connections that _might_ rdma into the MR must be suspended. If the MR was only setup for local access, then the driver could track the connections with references to the MR and only quiesce those connections.
Point being, it will stop probably all connections that an application is using (assuming the application uses a single PD).
Right but if the system starts reclaiming pages of the application then we have a memory shortage. So the user should address that by not running other apps concurrently. The stopping of all connections is still better than the VM getting into major trouble. And the stopping of connections in order to move the process memory into a more advantageous memory location (f.e. using page migration) or stopping of connections in order to be able to move the process memory out of a range of failing memory is certainly good.
Re: [ofa-general] Re: Demand paging for memory regions
Quoted 12 lines · Christoph Lameter
Quoted 9 lines · Steve Wise
Note that for T3, this involves suspending _all_ rdma connections that are in the same PD as the MR being remapped. This is because the driver doesn't know who the application advertised the rkey/stag to. So without that knowledge, all connections that _might_ rdma into the MR must be suspended. If the MR was only setup for local access, then the driver could track the connections with references to the MR and only quiesce those connections.
Point being, it will stop probably all connections that an application is using (assuming the application uses a single PD).
Quoted 9 lines
Right but if the system starts reclaiming pages of the application then we have a memory shortage. So the user should address that by not running other apps concurrently. The stopping of all connections is still better than the VM getting into major trouble. And the stopping of connections in order to move the process memory into a more advantageous memory location (f.e. using page migration) or stopping of connections in order to be able to move the process memory out of a range of failing memory is certainly good.
In that spirit, there are two important aspects of a suspend/resume API that would enable the memory manager to solve problems most effectively:
1) The device should be allowed flexibility to extend the scope of the suspend to what it is capable of implementing -- rather than being forced
to say that
it does not support suspend/;resume merely because it does so at a different granularity.
2) It is very important that users of this API understand that it is only the RDMA
device handling of incoming packets and WQEs that is being suspended. The peers are not suspended by this API, or even told that this end is
suspending.
Unless the suspend is kept *extremely* short there will be adverse impacts. And "short" here is measured in network terms, not human terms. The blink of any eye is *way* too long. Any external dependencies between "suspend" and "resume" will probably mean that things will not work, especially if the external entities involve a disk drive.
So suspend/resume to re-arrange pages is one thing. Suspend/resume to cover swapping out pages so they can be reallocated is an exercise in futility. By the time you resume the connections will be broken or at the minimum damaged.
Re: [ofa-general] Re: Demand paging for memory regions
Quoted 3 lines · Caitlin Bestler
So suspend/resume to re-arrange pages is one thing. Suspend/resume to cover swapping out pages so they can be reallocated is an exercise in futility. By the time you resume the connections will be broken or at the minimum damaged.
The connections would then have to be torn down before swap out and would have to be reestablished after the pages have been brought back from swap.
Re: [ofa-general] Re: Demand paging for memory regions
Quoted 10 lines · Christoph Lameter
Quoted 3 lines · Caitlin Bestler
So suspend/resume to re-arrange pages is one thing. Suspend/resume to cover swapping out pages so they can be reallocated is an exercise in futility. By the time you resume the connections will be broken or at the minimum damaged.
The connections would then have to be torn down before swap out and would have to be reestablished after the pages have been brought back from swap.
I have no problem with that, as long as the application layer is responsible for tearing down and re-establishing the connections. The RDMA/transport layers are incapable of tearing down and re-establishing a connection transparently because connections need to be approved above the RDMA layer.
Further the teardown will have visible artificats that the application must deal with,
such as flushed Recv WQEs.
This is still, the RDMA device will do X and will not worry about Y. The reasons for not worrying about Y could be that the suspend will be very short, or that other mechanisms have taken care of all the Ys independently.
For example, an HPC cluster that suspended the *entire* cluster would not have to worry about dropped packets.
Re: [ofa-general] Re: Demand paging for memory regions
Quoted 4 lines · Caitlin Bestler
I have no problem with that, as long as the application layer is responsible for tearing down and re-establishing the connections. The RDMA/transport layers are incapable of tearing down and re-establishing a connection transparently because connections need to be approved above the RDMA layer.
I am not that familiar with the RDMA layers but it seems that RDMA has a library that does device driver like things right? So the logic would best fit in there I guess.
If you combine mlock with the mmu notifier then you can actually guarantee that a certain memory range will not be swapped out. The notifier will then only be called if the memory range will need to be moved for page migration, memory unplug etc etc. There may be a limit on the percentage of memory that you can mlock in the future. This may be done to guarantee that the VM still has memory to work with.
RE: [ofa-general] Re: Demand paging for memory regions
Quoted 7 lines
-----Original Message-----
From: Christoph Lameter [mailto:[email protected]]
Sent: Thursday, February 14, 2008 2:49 PM
To: Caitlin Bestler
Cc: [email protected]; [email protected];
Quoted 7 lines
[email protected]; [email protected]
Subject: Re: [ofa-general] Re: Demand paging for memory regionsQuoted 1 line · Caitlin Bestler
I have no problem with that, as long as the application layer is
responsible for
Quoted 8 lines
Quoted 1 line
tearing down and re-establishing the connections. The RDMA/transport
layers
Quoted 1 line
are incapable of tearing down and re-establishing a connection
transparently
Quoted 1 line
because connections need to be approved above the RDMA layer.
I am not that familiar with the RDMA layers but it seems that RDMA has a library that does device driver like things right? So the logic
would
Quoted 10 lines
best fit in there I guess.
If you combine mlock with the mmu notifier then you can actually guarantee that a certain memory range will not be swapped out. The notifier will then only be called if the memory range will need to be moved for page migration, memory unplug etc etc. There may be a limit on
the percentage of memory that you can mlock in the future. This may be done to guarantee that the VM still has memory to work with.
The problem is that with existing APIs, or even slightly modified APIs, the RDMA layer will not be able to figure out which connections need to be "interrupted" in order to deal with what memory suspensions.
Further, because any request for a new connection will be handled by the remote *application layer* peer there is no way for the two RDMA layers to agree to covertly tear down and re-establish the connection. Nor really should there be, connections should be approved by OS layer networking controls. RDMA should not be able to tell the network stack, "trust me, you don't have to check if this connection is legitimate".
Another example, if you terminate a connection pending receive operations
complete *to the user* in a Completion Queue. Those completions are NOT seen by the RDMA layer, and especially not by the Connection Manager. It has absolutely no way to repost them transparently to the same connection
when the connection is re-established.
Even worse, some portions of a receive operation might have been placed in the receive buffer and acknowledged to the remote peer. But there is no mechanism to report this fact in the CQE. A receive operation that is aborted is aborted. There is no concept of partial success. Therefore you
cannot covertly terminate a connection mid-operation and covertly re-establish
it later. Data will be lost, it will no longer be a reliable connection, and
therefore it needs to be torn down anyway.
The RDMA layers also cannot tell the other side not to transmit. Flow control is the responsibility of the application layer, not RDMA.
What the RDMA layer could do is this: once you tell it to suspend a given
memory region it can either tell you that it doesn't know how to do that or it can instruct the device to stop processing a set of connections that will ceases all access for a given Memory Region. When you resume it can guarantee that it is no longer using any cached older mappings for the memory region (assuming it was capable of doing the suspend), and then because RDMA connections are reliable everything will recover unless the connection timed-out. The chance that it will time-out is probably low, but the chance that the underlying connection will be in slow start or equivalent is much higher.
So any solution that requires the upper layers to suspend operations for a brief bit will require explicit interaction with those layers. No RDMA layer can perform the sleight of hand tricks that you seem to want it to perform.
AT the RDMA layer the best you could get is very brief suspensions for the purpose of *re-arranging* memory, not of reducing the amount of registered memory. If you need to reduce the amount of registered memory then you have to talk to the application. Discussions on making it easier for the application to trim a memory region dynamically might be in order, but you will not work around the fact that the application layer needs to determine what pages are registered. And they would really
prefer just to be told how much memory they can have up front, they can figure out how to deal with that amount of memory on their own.
RE: [ofa-general] Re: Demand paging for memory regions
Quoted 4 lines · Caitlin Bestler
So any solution that requires the upper layers to suspend operations for a brief bit will require explicit interaction with those layers. No RDMA layer can perform the sleight of hand tricks that you seem to want it to perform.
Looks like it has to be up there right.
Quoted 9 lines
AT the RDMA layer the best you could get is very brief suspensions for the purpose of *re-arranging* memory, not of reducing the amount of registered memory. If you need to reduce the amount of registered memory then you have to talk to the application. Discussions on making it easier for the application to trim a memory region dynamically might be in order, but you will not work around the fact that the application layer needs to determine what pages are registered. And they would really prefer just to be told how much memory they can have up front, they can figure out how to deal with that amount of memory on their own.
What does it mean that the "application layer has to be determine what pages are registered"? The application does not know which of its pages are currently in memory. It can only force these pages to stay in memory if their are mlocked.
RE: [ofa-general] Re: Demand paging for memory regions
Christoph Lameter asked:
Quoted 3 lines
What does it mean that the "application layer has to be determine what pages are registered"? The application does not know which of its
pages
Quoted 3 lines
are currently in memory. It can only force these pages to stay in memory if their are mlocked.
An application that advertises an RDMA accessible buffer to a remote peer *does* have to know that its pages *are* currently in memory.
The application does *not* need for the virtual-to-physical mapping of those pages to be frozen for the lifespan of the Memory Region. But it is issuing an invitation to its peer to perform direct writes to the advertised buffer. When the peer decides to exercise that invitation the pages have to be there.
An analogy: when you write a check for $100 you do not have to identify the serial numbers of ten $10 bills, but you are expected to have the funds in your account.
Issuing a buffer advertisement for memory you do not have is the network equivalent of writing a check that you do not have funds for.
Now, just as your bank may offer overdraft protection, an RDMA device could merely report a page fault rather than tearing down the connection itself. But that does not grant permission for applications to advertise buffer space that they do not have committed, it merely helps recovery from a programming fault.
A suspend/resume interface between the Virtual Memory Manager and the RDMA layer allows pages to be re-arranged at the convenience of the Virtual Memory Manager without breaking the application layer peer-to-peer contract. The current interfaces that pin exact pages are really the equivalent of having to tell the bank that when Joe cashes this $100 check that you should give him *these* ten $10 bills. It works, but it adds too much overhead and is very inflexible. So there are a lot of good reasons to evolve this interface to better deal with these issues. Other areas of possible evolution include allowing growing or trimming of Memory Regions without invalidating their advertised handles.
But the more fundamental issue is recognizing that applications that use direct interfaces need to know that buffers that they enable truly have committed resources. They need a way to ask for twenty *real* pages, not twenty pages of address space. And they need to do it in a way that allows memory to be rearranged or even migrated with them to a new host.
RE: [ofa-general] Re: Demand paging for memory regions
Quoted 10 lines · Caitlin Bestler
Quoted 2 lines
What does it mean that the "application layer has to be determine what pages are registered"? The application does not know which of its
pages
Quoted 3 lines
are currently in memory. It can only force these pages to stay in memory if their are mlocked.
An application that advertises an RDMA accessible buffer to a remote peer *does* have to know that its pages *are* currently in memory.
Ok that would mean it needs to inform the VM of that issue by mlocking these pages.
Quoted 6 lines
But the more fundamental issue is recognizing that applications that use direct interfaces need to know that buffers that they enable truly have committed resources. They need a way to ask for twenty *real* pages, not twenty pages of address space. And they need to do it in a way that allows memory to be rearranged or even migrated with them to a new host.
mlock will force the pages to stay in memory without requiring the OS to keep them where they are.
RE: [ofa-general] Re: Demand paging for memory regions
Quoted 7 lines
-----Original Message-----
From: Christoph Lameter [mailto:[email protected]]
Sent: Friday, February 15, 2008 10:46 AM
To: Caitlin Bestler
Cc: [email protected]; [email protected];
Quoted 27 lines
[email protected]; [email protected]
Subject: RE: [ofa-general] Re: Demand paging for memory regionsQuoted 1 line · Caitlin Bestler
Quoted 1 line
What does it mean that the "application layer has to be determine
what
Quoted 9 lines
Quoted 1 line
pages are registered"? The application does not know which of its
pages
Quoted 3 lines
are currently in memory. It can only force these pages to stay in memory if their are mlocked.
An application that advertises an RDMA accessible buffer to a remote peer *does* have to know that its pages *are* currently in memory.
Ok that would mean it needs to inform the VM of that issue by mlocking these pages.
Quoted 6 lines
But the more fundamental issue is recognizing that applications that use direct interfaces need to know that buffers that they enable truly have committed resources. They need a way to ask for twenty *real* pages, not twenty pages of address space. And they need to do it in a way that allows memory to be rearranged or even migrated with them to a new host.
Quoted 2 lines
mlock will force the pages to stay in memory without requiring the OS to keep them where they are.
So that would mean that mlock is used by the application before it registers memory for direct access, and then it is up to the RDMA layer and the OS to negotiate actual pinning of the addresses for whatever duration is required.
There is no *protocol* barrier to replacing pages within a Memory Region as long as it is done in a way that keeps the content of those page coherent. But existing devices have their own ideas on how this is done and existing devices are notoriously poor at learning new tricks.
Merely mlocking pages deals with the end-to-end RDMA semantics. What still needs to be addressed is how a fastpath interface would dynamically pin and unpin. Yielding pins for short-term suspensions (and flushing cached translations) deals with the rest. Understanding the range of support that existing devices could provide with software updates would be the next step if you wanted to pursue this.
RE: [ofa-general] Re: Demand paging for memory regions
Quoted 4 lines · Caitlin Bestler
So that would mean that mlock is used by the application before it registers memory for direct access, and then it is up to the RDMA layer and the OS to negotiate actual pinning of the addresses for whatever duration is required.
Right.
Quoted 5 lines
There is no *protocol* barrier to replacing pages within a Memory Region as long as it is done in a way that keeps the content of those page coherent. But existing devices have their own ideas on how this is done and existing devices are notoriously poor at learning new tricks.
Hmmmm.. Okay. But that is mainly a device driver maintenance issue.
Quoted 7 lines
Merely mlocking pages deals with the end-to-end RDMA semantics. What still needs to be addressed is how a fastpath interface would dynamically pin and unpin. Yielding pins for short-term suspensions (and flushing cached translations) deals with the rest. Understanding the range of support that existing devices could provide with software updates would be the next step if you wanted to pursue this.
That is addressed on the VM level by the mmu_notifier which started this whole thread. The RDMA layers need to subscribe to this notifier and then do whatever the hardware requires to unpin and pin memory. I can only go as far as dealing with the VM layer. If you have any issues there I'd be glad to help.
RE: [ofa-general] Re: Demand paging for memory regions
Christoph Lameter wrote
Quoted 9 lines
Quoted 8 lines
Merely mlocking pages deals with the end-to-end RDMA semantics. What still needs to be addressed is how a fastpath interface would dynamically pin and unpin. Yielding pins for short-term suspensions (and flushing cached translations) deals with the rest. Understanding the range of support that existing devices could provide with software updates would be the next step if you wanted to pursue this.
Quoted 5 lines
That is addressed on the VM level by the
mmu_notifierwhich started this whole thread. The RDMA layers need to subscribe to this notifier and then do whatever the hardware requires to unpin and pin memory. I can only go as far as dealing with the VM layer. If you have any issues there I'd be glad to help.
There isn't much point in the RDMA layer subscribing to mmu notifications
if the specific RDMA device will not be able to react appropriately when the notification occurs. I don't see how you get around needing to know which devices are capable of supporting page migration (via suspend/resume
or other mechanisms) and which can only respond to a page migration by aborting connections.
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
RE: [ofa-general] Re: Demand paging for memory regions
Quoted 8 lines · Caitlin Bestler
There isn't much point in the RDMA layer subscribing to mmu notifications
if the specific RDMA device will not be able to react appropriately when the notification occurs. I don't see how you get around needing to know which devices are capable of supporting page migration (via suspend/resume
or other mechanisms) and which can only respond to a page migration by aborting connections.
You either register callbacks if the device can react properly or you dont. If you dont then the device will continue to have the problem with page pinning etc until someone comes around and implements the mmu callbacks to fix these issues.
I have doubts regarding the claim that some devices just cannot be made to suspend and resume appropriately. They obviously can be shutdown and so its a matter of sequencing the things the right way. I.e. stop the app wait for a quiet period then release resources etc.
RE: [ofa-general] Re: Demand paging for memory regions
Quoted 7 lines
-----Original Message-----
From: Christoph Lameter [mailto:[email protected]]
Sent: Friday, February 15, 2008 2:50 PM
To: Caitlin Bestler
Cc: [email protected]; [email protected];
Quoted 17 lines
[email protected]; [email protected]
Subject: RE: [ofa-general] Re: Demand paging for memory regionsQuoted 3 lines · Caitlin Bestler
There isn't much point in the RDMA layer subscribing to mmu notifications
if the specific RDMA device will not be able to react appropriatelywhen
Quoted 1 line
the notification occurs. I don't see how you get around needing to
know
Quoted 3 lines
which devices are capable of supporting page migration (via suspend/resume
or other mechanisms) and which can only respond to a page migrationby
Quoted 1 line
aborting connections.
Quoted 7 lines
You either register callbacks if the device can react properly or you dont. If you dont then the device will continue to have the problem with
page pinning etc until someone comes around and implements the mmu callbacks to fix these issues.I have doubts regarding the claim that some devices just cannot be
made
Quoted 2 lines
to
suspend and resume appropriately. They obviously can be shutdown and
so
Quoted 4 lines
its a matter of sequencing the things the right way. I.e. stop the app wait for a quiet period then release resources etc.
That is true. What some devices will be unable to do is suspend and resume in a manner that is transparent to the application. However, for the duration required to re-arrange pages it is definitely feasible to do so transparently to the application.
Presumably the Virtual Memory Manager would be more willing to take an action that is transparent to the user than one that is disruptive, although obviously as the owner of the physical memory it has the right to do either.
Re: [ofa-general] Re: Demand paging for memory regions
In reply to Roland DreierQuoted 9 lines · Roland Dreier
Quoted 3 lines
Quoted 1 line
Chelsio's T3 HW doesn't support this.
Not so far I guess but it could be equipped with these features right?
I don't know anything about the T3 internals, but it's not clear that you could do this without a new chip design in general. Lot's of RDMA devices were designed expecting that when a packet arrives, the HW can look up the bus address for a given memory region/offset and place the
Well, certainly today the memfree IB devices store the page tables in host memory so they are already designed to hang onto packets during the page lookup over PCIE, adding in faulting makes this time larger.
But this is not a good thing at all, IB's congestion model is based on the notion that end ports can always accept packets without making input contigent on output. If you take a software interrupt to fill in the page pointer then you could potentially deadlock on the fabric. For example using this mechanism to allow swap-in of RDMA target pages and then putting the storage over IB would be deadlock prone. Even without deadlock slowing down the input path will cause network congestion and poor performance for other nodes. It is not a desirable thing to do..
I expect that iwarp running over flow controlled ethernet has similar kinds of problems for similar reasons..
In general the best I think you can hope for with RDMA hardware is page migration using some atomic operations with the adaptor and a cpu page copy with retry sort of scheme - but is pure page migration interesting at all?
Jason
Re: [ofa-general] Re: Demand paging for memory regions
Quoted 4 lines · Jason Gunthorpe
Well, certainly today the memfree IB devices store the page tables in host memory so they are already designed to hang onto packets during the page lookup over PCIE, adding in faulting makes this time larger.
You really do not need a page table to use it. What needs to be maintained is knowledge on both side about what pages are currently shared across RDMA. If the VM decides to reclaim a page then the notification is used to remove the remote entry. If the remote side then tries to access the page again then the page fault on the remote side will stall until the local page has been brought back. RDMA can proceed after both sides again agree on that page now being sharable.
Re: [ofa-general] Re: Demand paging for memory regions
Quoted 7 lines · Christoph Lameter
Quoted 4 lines · Jason Gunthorpe
Well, certainly today the memfree IB devices store the page tables in host memory so they are already designed to hang onto packets during the page lookup over PCIE, adding in faulting makes this time larger.
Quoted 7 lines
You really do not need a page table to use it. What needs to be maintained is knowledge on both side about what pages are currently shared across RDMA. If the VM decides to reclaim a page then the notification is used to remove the remote entry. If the remote side then tries to access the page again then the page fault on the remote side will stall until the local page has been brought back. RDMA can proceed after both sides again agree on that page now being sharable.
The problem is that the existing wire protocols do not have a provision for doing an 'are you ready' or 'I am not ready' exchange and they are not designed to store page tables on both sides as you propose. The remote side can send RDMA WRITE traffic at any time after the RDMA region is established. The local side must be able to handle it. There is no way to signal that a page is not ready and the remote should not send.
This means the only possible implementation is to stall/discard at the local adaptor when a RDMA WRITE is recieved for a page that has been reclaimed. This is what leads to deadlock/poor performance..
Jason
Re: [ofa-general] Re: Demand paging for memory regions
Quoted 17 lines · Jason Gunthorpe
Quoted 7 lines · Christoph Lameter
Quoted 4 lines · Jason Gunthorpe
Well, certainly today the memfree IB devices store the page tables in host memory so they are already designed to hang onto packets during the page lookup over PCIE, adding in faulting makes this time larger.
You really do not need a page table to use it. What needs to be maintained is knowledge on both side about what pages are currently shared across RDMA. If the VM decides to reclaim a page then the notification is used to remove the remote entry. If the remote side then tries to access the page again then the page fault on the remote side will stall until the local page has been brought back. RDMA can proceed after both sides again agree on that page now being sharable.
The problem is that the existing wire protocols do not have a provision for doing an 'are you ready' or 'I am not ready' exchange and they are not designed to store page tables on both sides as you propose. The remote side can send RDMA WRITE traffic at any time after the RDMA region is established. The local side must be able to handle it. There is no way to signal that a page is not ready and the remote should not send.
Quoted 4 lines
This means the only possible implementation is to stall/discard at the local adaptor when a RDMA WRITE is recieved for a page that has been reclaimed. This is what leads to deadlock/poor performance..
If the events are few and far between then this model is probably ok. For iWARP, it means TCP retransmit and slow start and all that, but if its an infrequent event, then its ok if it helps the host better manage memory.
Maybe... ;-)
Steve.
Re: [ofa-general] Re: Demand paging for memory regions
In reply to Jason GunthorpeQuoted 11 lines · Jason Gunthorpe
The problem is that the existing wire protocols do not have a provision for doing an 'are you ready' or 'I am not ready' exchange and they are not designed to store page tables on both sides as you propose. The remote side can send RDMA WRITE traffic at any time after the RDMA region is established. The local side must be able to handle it. There is no way to signal that a page is not ready and the remote should not send.
This means the only possible implementation is to stall/discard at the local adaptor when a RDMA WRITE is recieved for a page that has been reclaimed. This is what leads to deadlock/poor performance..
You would only use the wire protocols *after* having established the RDMA region. The notifier chains allows a RDMA region (or parts thereof) to be down on demand by the VM. The region can be reestablished if one of the side accesses it. I hope I got that right. Not much exposure to Infiniband so far.
Lets say you have a two systems A and B. Each has their memory region MemA and MemB. Each side also has page tables for this region PtA and PtB.
Now you establish a RDMA connection between both side. The pages in both MemB and MemA are present and so are entries in PtA and PtB. RDMA traffic can proceed.
The VM on system A now gets into a situation in which memory becomes heavily used by another (maybe non RDMA process) and after checking that there was no recent reference to MemA and MemB (via a notifier aging callback) decides to reclaim the memory from MemA.
In that case it will notify the RDMA subsystem on A that it is trying to reclaim a certain page.
The RDMA subsystem on A will then send a message to B notifying it that the memory will be going away. B now has to remove its corresponding page from memory (and drop the entry in PtB) and confirm to A that this has happened. RDMA traffic is then stopped for this page. Then A can also remove its page, the corresponding entry in PtA and the page is reclaimed or pushed out to swap completing the page reclaim.
If either side then accesses the page again then the reverse process happens. If B accesses the page then it wil first of all incur a page fault because the entry in PtB is missing. The fault will then cause a message to be send to A to establish the page again. A will create an entry in PtA and will then confirm to B that the page was established. At that point RDMA operations can occur again.
So the whole scheme does not really need a hardware page table in the RDMA hardware. The page tables of the two systems A and B are sufficient.
The scheme can also be applied to a larger range than only a single page. The RDMA subsystem could tear down a large section when reclaim is pushing on it and then reestablish it as needed.
Swapping and page reclaim is certainly not something that improves the speed of the application affected by swapping and page reclaim but it allows the VM to manage memory effectively if multiple loads are runing on a system.
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
Re: [ofa-general] Re: Demand paging for memory regions
Quoted 14 lines · Christoph Lameter
Quoted 11 lines · Jason Gunthorpe
The problem is that the existing wire protocols do not have a provision for doing an 'are you ready' or 'I am not ready' exchange and they are not designed to store page tables on both sides as you propose. The remote side can send RDMA WRITE traffic at any time after the RDMA region is established. The local side must be able to handle it. There is no way to signal that a page is not ready and the remote should not send.
This means the only possible implementation is to stall/discard at the local adaptor when a RDMA WRITE is recieved for a page that has been reclaimed. This is what leads to deadlock/poor performance..
Quoted 5 lines
You would only use the wire protocols *after* having established the RDMA region. The notifier chains allows a RDMA region (or parts thereof) to be down on demand by the VM. The region can be reestablished if one of the side accesses it. I hope I got that right. Not much exposure to Infiniband so far.
[clip explaination]
But this isn't how IB or iwarp work at all. What you describe is a significant change to the general RDMA operation and requires changes to both sides of the connection and the wire protocol.
A few comments on RDMA operation that might clarify things a little bit more:
- In RDMA (iwarp and IB versions) the hardware page tables exist to linearize the local memory so the remote does not need to be aware of non-linearities in the physical address space. The main motivation for this is kernel bypass where the user space app wants to instruct the remote side to DMA into memory using user space addresses. Hardware provides the page tables to switch from incoming user space virtual addresses to physical addresess.
This greatly simplifies the user space programming model since you don't need to pass around or create s/g lists for memory that is already virtually continuous.
Many kernel RDMA drivers (SCSI, NFS) only use the HW page tables for access control and enforcing the liftime of the mapping.
The page tables in the RDMA hardware exist primarily to support this, and not for other reasons. The pinning of pages is one part to support the HW page tables and one part to support the RDMA lifetime rules, the liftime rules are what cause problems for the VM.
- The wire protocol consists of packets that say 'Write XXX bytes to offset YY in Region RRR'. Creating a region produces the RRR label and currently pins the pages. So long as the RRR label is valid the remote side can issue write packets at any time without any further synchronization. There is no wire level events associated with creating RRR. You can pass RRR to the other machine in any fashion, even using carrier pigeons :)
- The RDMA layer is very general (ala TCP), useful protocols (like SCSI) are built on top of it and they specify the lifetime rules and protocol for exchanging RRR.
Every protocol is different. In kernel protocols like SRP and NFS RDMA seem to have very short lifetimes for RRR and work more like pci_map_* in real SCSI hardware.
- HPC userspace apps, like MPI apps, have different lifetime rules and tend to be really long lived. These people will not want anything that makes their OPs more expensive and also probably don't care too much about the VM problems you are looking at (?)
- There is no protocol support to exchange RRR. This is all done by upper level protocols (ala HTTP vs TCP). You cannot assert and revoke RRR in a general way. Every protocol is different and optimized.
This is your step 'A will then send a message to B notifying..'. It simply does not exist in the protocol specifications
I don't know much about Quadrics, but I would be hesitant to lump it in too much with these RDMA semantics. Christian's comments sound like they operate closer to what you described and that is why the have an existing patch set. I don't know :)
What it boils down to is that to implement true removal of pages in a general way the kernel and HCA must either drop packets or stall incoming packets, both are big performance problems - and I can't see many users wanting this. Enterprise style people using SCSI, NFS, etc already have short pin periods and HPC MPI users probably won't care about the VM issues enough to warrent the performance overhead.
Regards,
Jason
Re: [ofa-general] Re: Demand paging for memory regions
Jason,
Quoted 4 lines · Jason Gunthorpe
I don't know much about Quadrics, but I would be hesitant to lump it in too much with these RDMA semantics. Christian's comments sound like they operate closer to what you described and that is why the have an existing patch set. I don't know :)
The Quadrics folks have been doing RDMA for 10 years, there is a reason why they maintained a patch.
Quoted 6 lines
What it boils down to is that to implement true removal of pages in a general way the kernel and HCA must either drop packets or stall incoming packets, both are big performance problems - and I can't see many users wanting this. Enterprise style people using SCSI, NFS, etc already have short pin periods and HPC MPI users probably won't care about the VM issues enough to warrent the performance overhead.
This is not true, HPC people do care about the VM issues a lot. Memory registration (pinning and translating) is usually too expensive to be performed in the critical path before and after each send or receive. So they factor it out by registering a buffer the first time it is used, and keeping it registered in a registration cache. However, the application may free() a buffer that is in the registration cache, so HPC people provide their own malloc to catch free(). They also try to catch sbrk() and munmap() to deregister memory before it is released to the OS. This is a Major pain that a VM notifier would easily solve. Being able to swap registered pages to disk or migrate them in a NUMA system is a welcome bonus.
Patrick
Signature · 9 lines
Patrick Geoffray Myricom, Inc. http://www.myri.com -- 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: [ofa-general] Re: Demand paging for memory regions
[mangled CC list trimmed]
Quoted 8 lines · Patrick Geoffray
Quoted 4 lines · Jason Gunthorpe
I don't know much about Quadrics, but I would be hesitant to lump it in too much with these RDMA semantics. Christian's comments sound like they operate closer to what you described and that is why the have an existing patch set. I don't know :)
The Quadrics folks have been doing RDMA for 10 years, there is a reason why they maintained a patch.
This wasn't ment as a slight against Quadrics, only to point out that the specific wire protcols used by IB and iwarp are what cause this limitation, it would be easy to imagine that Quadrics has some additional twist that can make this easier..
Quoted 9 lines
Quoted 6 lines
What it boils down to is that to implement true removal of pages in a general way the kernel and HCA must either drop packets or stall incoming packets, both are big performance problems - and I can't see many users wanting this. Enterprise style people using SCSI, NFS, etc already have short pin periods and HPC MPI users probably won't care about the VM issues enough to warrent the performance overhead.
This is not true, HPC people do care about the VM issues a lot. Memory registration (pinning and translating) is usually too expensive to
I ment that HPC users are unlikely to want to swap active RDMA pages if this causes a performance cost on normal operations. None of my comments are ment to imply that lazy de-registration or page migration are not good things.
Regards,
Jason
--
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: [ofa-general] Re: Demand paging for memory regions
Quoted 1 line · Jason Gunthorpe
[mangled CC list trimmed]
Thanks, noticed that afterwards.
Quoted 4 lines
This wasn't ment as a slight against Quadrics, only to point out that the specific wire protcols used by IB and iwarp are what cause this limitation, it would be easy to imagine that Quadrics has some additional twist that can make this easier..
The wire protocols are similar, nothing fancy. The specificity of Quadrics (and many others) is that they can change the behavior of the NIC in firmware, so they adapt to what the OS offers. They had the VM notifier support in Tru64 back in the days, they just ported the functionality to Linux.
Quoted 2 lines
I ment that HPC users are unlikely to want to swap active RDMA pages if this causes a performance cost on normal operations. None of my
Swapping to disk is not a normal operations in HPC, it's going to be slow anyway. The main problem for HPC users is not swapping, it's that they do not know when a registered page is released to the OS through free(), sbrk() or munmap(). Like swapping, they don't expect that it will happen often, but they have to handle it gracefully.
Patrick
Signature · 9 lines
Patrick Geoffray Myricom, Inc. http://www.myri.com -- 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: [ofa-general] Re: Demand paging for memory regions
In reply to Jason GunthorpeQuoted 3 lines · Jason Gunthorpe
But this isn't how IB or iwarp work at all. What you describe is a significant change to the general RDMA operation and requires changes to both sides of the connection and the wire protocol.
Yes it may require a separate connection between both sides where a kind of VM notification protocol is established to tear these things down and set them up again. That is if there is nothing in the RDMA protocol that allows a notification to the other side that the mapping is being down down.
Quoted 7 lines
- In RDMA (iwarp and IB versions) the hardware page tables exist to linearize the local memory so the remote does not need to be aware of non-linearities in the physical address space. The main motivation for this is kernel bypass where the user space app wants to instruct the remote side to DMA into memory using user space addresses. Hardware provides the page tables to switch from incoming user space virtual addresses to physical addresess.
s/switch/translate I guess. That is good and those page tables could be used for the notification scheme to enable reclaim. But they are optional and are maintaining the driver state. The linearization could be reconstructed from the kernel page tables on demand.
Quoted 2 lines
Many kernel RDMA drivers (SCSI, NFS) only use the HW page tables for access control and enforcing the liftime of the mapping.
Well the mapping would have to be on demand to avoid the issues that we currently have with pinning. The user API could stay the same. If the driver tracks the mappings using the notifier then the VM can make sure that the right things happen on exit etc etc.
Quoted 5 lines
The page tables in the RDMA hardware exist primarily to support this, and not for other reasons. The pinning of pages is one part to support the HW page tables and one part to support the RDMA lifetime rules, the liftime rules are what cause problems for the VM.
So the driver software can tear down and establish page tables entries at will? I do not see the problem. The RDMA hardware is one thing, the way things are visible to the user another. If the driver can establish and remove mappings as needed via RDMA then the user can have the illusion of persistent RDMA memory. This is the same as virtual memory providing the illusion of a process having lots of memory all for itself.
Quoted 10 lines
- The wire protocol consists of packets that say 'Write XXX bytes to offset YY in Region RRR'. Creating a region produces the RRR label and currently pins the pages. So long as the RRR label is valid the remote side can issue write packets at any time without any further synchronization. There is no wire level events associated with creating RRR. You can pass RRR to the other machine in any fashion, even using carrier pigeons :)
- The RDMA layer is very general (ala TCP), useful protocols (like SCSI) are built on top of it and they specify the lifetime rules and protocol for exchanging RRR.
Well yes of course. What is proposed here is an additional notification mechanism (could even be via tcp/udp to simplify things) that would manage the mappings at a higher level. The writes would not occur if the mapping has not been established.
Quoted 2 lines
This is your step 'A will then send a message to B notifying..'. It simply does not exist in the protocol specifications
Of course. You need to create an additional communication layer to get that.
Quoted 6 lines
What it boils down to is that to implement true removal of pages in a general way the kernel and HCA must either drop packets or stall incoming packets, both are big performance problems - and I can't see many users wanting this. Enterprise style people using SCSI, NFS, etc already have short pin periods and HPC MPI users probably won't care about the VM issues enough to warrent the performance overhead.
True maybe you cannot do this by simply staying within the protocol bounds of RDMA that is based on page pinning if the RDMA protocol does not support a notification to the other side that the mapping is going away.
If RDMA cannot do this then you would need additional ways of notifying the remote side that pages/mappings are invalidated.
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
Re: [ofa-general] Re: Demand paging for memory regions
Quoted 11 lines · Christoph Lameter
Quoted 3 lines · Jason Gunthorpe
But this isn't how IB or iwarp work at all. What you describe is a significant change to the general RDMA operation and requires changes to both sides of the connection and the wire protocol.
Yes it may require a separate connection between both sides where a kind of VM notification protocol is established to tear these things down and set them up again. That is if there is nothing in the RDMA protocol that allows a notification to the other side that the mapping is being down down.
Well, yes, you could build this thing you are describing on top of the RDMA protocol and get some support from some of the hardware - but it is a new set of protocols and they would need to be implemented in several places. It is not transparent to userspace and it is not compatible with existing implementations.
Unfortunately it really has little to do with the drivers - changes, for instance, need to be made to support this in the user space MPI libraries. The RDMA ops do not pass through the kernel, userspace talks directly to the hardware which complicates building any sort of abstraction.
That is where I think you run into trouble, if you ask the MPI people to add code to their critical path to support swapping they probably will not be too interested. At a minimum to support your idea you need to check on every RDMA if the remote page is mapped... Plus the overheads Christian was talking about in the OOB channel(s).
Jason
Re: [ofa-general] Re: Demand paging for memory regions
Quoted 5 lines · Jason Gunthorpe
Unfortunately it really has little to do with the drivers - changes, for instance, need to be made to support this in the user space MPI libraries. The RDMA ops do not pass through the kernel, userspace talks directly to the hardware which complicates building any sort of abstraction.
Ok so the notifiers have to be handed over to the user space library that has the function of the device driver here...
Quoted 5 lines
That is where I think you run into trouble, if you ask the MPI people to add code to their critical path to support swapping they probably will not be too interested. At a minimum to support your idea you need to check on every RDMA if the remote page is mapped... Plus the overheads Christian was talking about in the OOB channel(s).
You only need to check if a handle has been receiving invalidates. If not then you can just go ahead as now. You can use the notifier to take down the whole region if any reclaim occur against it (probably best and simples to implement approach). Then you mark the handle so that the mapping is reestablished before the next operation.
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
Re: [ofa-general] Re: Demand paging for memory regions
In reply to Christoph LameterQuoted 10 lines · Christoph Lameter
Quoted 8 lines · Jason Gunthorpe
The problem is that the existing wire protocols do not have a provision for doing an 'are you ready' or 'I am not ready' exchange and they are not designed to store page tables on both sides as you propose. The remote side can send RDMA WRITE traffic at any time after the RDMA region is established. The local side must be able to handle it. There is no way to signal that a page is not ready and the remote should not send.
Quoted 3 lines
Quoted 3 lines
This means the only possible implementation is to stall/discard at the local adaptor when a RDMA WRITE is recieved for a page that has been reclaimed. This is what leads to deadlock/poor performance..
You're arguing that a HW page table is not needed by describing a use case that is essentially what all RDMA solutions already do above the wire protocols (all solutions except Quadrics, of course).
Quoted 5 lines
You would only use the wire protocols *after* having established the RDMA region. The notifier chains allows a RDMA region (or parts thereof) to be down on demand by the VM. The region can be reestablished if one of the side accesses it. I hope I got that right. Not much exposure to Infiniband so far.
RDMA is already always used *after* memory regions are set up -- they are set up out-of-band w.r.t RDMA but essentially this is the "before" part.
Quoted 22 lines
Lets say you have a two systems A and B. Each has their memory region MemA and MemB. Each side also has page tables for this region PtA and PtB.
Now you establish a RDMA connection between both side. The pages in both MemB and MemA are present and so are entries in PtA and PtB. RDMA traffic can proceed.
The VM on system A now gets into a situation in which memory becomes heavily used by another (maybe non RDMA process) and after checking that there was no recent reference to MemA and MemB (via a notifier aging callback) decides to reclaim the memory from MemA.
In that case it will notify the RDMA subsystem on A that it is trying to reclaim a certain page.
The RDMA subsystem on A will then send a message to B notifying it that the memory will be going away. B now has to remove its corresponding page from memory (and drop the entry in PtB) and confirm to A that this has happened. RDMA traffic is then stopped for this page. Then A can also remove its page, the corresponding entry in PtA and the page is reclaimed or pushed out to swap completing the page reclaim.
Quoted 6 lines
If either side then accesses the page again then the reverse process happens. If B accesses the page then it wil first of all incur a page fault because the entry in PtB is missing. The fault will then cause a message to be send to A to establish the page again. A will create an entry in PtA and will then confirm to B that the page was established. At that point RDMA operations can occur again.
The notifier-reclaim cycle you describe is akin to the out-of-band pin-unpin control messages used by existing communication libraries. Also, I think what you are proposing can have problems at scale -- A must keep track of all of the (potentially many systems) of memA and cooperatively get an agreement from all these systems before reclaiming the page.
When messages are sufficiently large, the control messaging necessary to setup/teardown the regions is relatively small. This is not always the case however -- in programming models that employ smaller messages, the one-sided nature of RDMA is the most attractive part of it.
Quoted 6 lines
So the whole scheme does not really need a hardware page table in the RDMA hardware. The page tables of the two systems A and B are sufficient.
The scheme can also be applied to a larger range than only a single page. The RDMA subsystem could tear down a large section when reclaim is pushing on it and then reestablish it as needed.
Nothing any communication/runtime system can't already do today. The point of RDMA demand paging is enabling the possibility of using RDMA without the implied synchronization -- the optimistic part. Using the notifiers to duplicate existing memory region handling for RDMA hardware that doesn't have HW page tables is possible but undermines the more important consumer of your patches in my opinion.
One other area that has not been brought up yet (I think) is the applicability of notifiers in letting users know when pinned memory is reclaimed by the kernel. This is useful when a lower-level library employs lazy deregistration strategies on memory regions that are subsequently released to the kernel via the application's use of munmap or sbrk. Ohio Supercomputing Center has work in this area but a generalized approach in the kernel would certainly be welcome.
. . christian
Signature · 2 lines
[email protected] (QLogic Host Solutions Group, formerly Pathscale)
Re: [ofa-general] Re: Demand paging for memory regions
Quoted 3 lines · Christian Bell
You're arguing that a HW page table is not needed by describing a use case that is essentially what all RDMA solutions already do above the wire protocols (all solutions except Quadrics, of course).
The HW page table is not essential to the notification scheme. That the RDMA uses the page table for linearization is another issue. A chip could just have a TLB cache and lookup the entries using the OS page table f.e.
Quoted 9 lines
Quoted 8 lines
Lets say you have a two systems A and B. Each has their memory region MemA and MemB. Each side also has page tables for this region PtA and PtB. If either side then accesses the page again then the reverse process happens. If B accesses the page then it wil first of all incur a page fault because the entry in PtB is missing. The fault will then cause a message to be send to A to establish the page again. A will create an entry in PtA and will then confirm to B that the page was established. At that point RDMA operations can occur again.
Quoted 6 lines
The notifier-reclaim cycle you describe is akin to the out-of-band pin-unpin control messages used by existing communication libraries. Also, I think what you are proposing can have problems at scale -- A must keep track of all of the (potentially many systems) of memA and cooperatively get an agreement from all these systems before reclaiming the page.
Right. We (SGI) have done something like this for a long time with XPmem and it scales ok.
Quoted 5 lines
When messages are sufficiently large, the control messaging necessary to setup/teardown the regions is relatively small. This is not always the case however -- in programming models that employ smaller messages, the one-sided nature of RDMA is the most attractive part of it.
The messaging would only be needed if a process comes under memory pressure. As long as there is enough memory nothing like this will occur.
Quoted 6 lines
Nothing any communication/runtime system can't already do today. The point of RDMA demand paging is enabling the possibility of using RDMA without the implied synchronization -- the optimistic part. Using the notifiers to duplicate existing memory region handling for RDMA hardware that doesn't have HW page tables is possible but undermines the more important consumer of your patches in my opinion.
The notifier schemet should integrate into existing memory region handling and not cause a duplication. If you already have library layers that do this then it should be possible to integrate it.
Quoted 7 lines
One other area that has not been brought up yet (I think) is the applicability of notifiers in letting users know when pinned memory is reclaimed by the kernel. This is useful when a lower-level library employs lazy deregistration strategies on memory regions that are subsequently released to the kernel via the application's use of munmap or sbrk. Ohio Supercomputing Center has work in this area but a generalized approach in the kernel would certainly be welcome.
The driver gets the notifications about memory being reclaimed. The driver could then notify user code about the release as well.
Pinned memory current *cannot* be reclaimed by the kernel. The refcount is elevated. This means that the VM tries to remove the mappings and then sees that it was not able to remove all references. Then it gives up and tries again and again and again.... Thus the potential for livelock.
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
Re: [ofa-general] Re: Demand paging for memory regions
Quoted 2 lines · Christoph Lameter
Right. We (SGI) have done something like this for a long time with XPmem and it scales ok.
I'd dispute this based on experience developing PGAS language support on the Altix but more importantly (and less subjectively), I think that "scales ok" refers to a very specific case. Sure, pages (and/or regions) can be large on some systems and the number of systems may not always be in the thousands but you're still claiming scalability for a mechanism that essentially logs who accesses the regions. Then there's the fact that reclaim becomes a collective communication operation over all region accessors. Makes me nervous.
Quoted 17 lines
Quoted 5 lines
When messages are sufficiently large, the control messaging necessary to setup/teardown the regions is relatively small. This is not always the case however -- in programming models that employ smaller messages, the one-sided nature of RDMA is the most attractive part of it.
The messaging would only be needed if a process comes under memory pressure. As long as there is enough memory nothing like this will occur.
Quoted 6 lines
Nothing any communication/runtime system can't already do today. The point of RDMA demand paging is enabling the possibility of using RDMA without the implied synchronization -- the optimistic part. Using the notifiers to duplicate existing memory region handling for RDMA hardware that doesn't have HW page tables is possible but undermines the more important consumer of your patches in my opinion.
Quoted 3 lines
The notifier schemet should integrate into existing memory region handling and not cause a duplication. If you already have library layers that do this then it should be possible to integrate it.
I appreciate that you're trying to make a general case for the applicability of notifiers on all types of existing RDMA hardware and wire protocols. Also, I'm not disagreeing whether a HW page table is required or not: clearly it's not required to make *some* use of the notifier scheme.
However, short of providing user-level notifications for pinned pages that are inadvertently released to the O/S, I don't believe that the patchset provides any significant added value for the HPC community that can't optimistically do RDMA demand paging.
. . christian
Re: [ofa-general] Re: Demand paging for memory regions
Quoted 4 lines · Christian Bell
not always be in the thousands but you're still claiming scalability for a mechanism that essentially logs who accesses the regions. Then there's the fact that reclaim becomes a collective communication operation over all region accessors. Makes me nervous.
Well reclaim is not a very fast process (and we usually try to avoid it as much as possible for our HPC). Essentially its only there to allow shifts of processing loads and to allow efficient caching of application data.
Quoted 4 lines
However, short of providing user-level notifications for pinned pages that are inadvertently released to the O/S, I don't believe that the patchset provides any significant added value for the HPC community that can't optimistically do RDMA demand paging.
We currently also run XPmem with pinning. Its great as long as you just run one load on the system. No reclaim ever iccurs.
However, if you do things that require lots of allocations etc etc then the page pinning can easily lead to livelock if reclaim is finally triggerd and also strange OOM situations since the VM cannot free any pages. So the main issue that is addressed here is reliability of pinned page operations. Better VM integration avoids these issues because we can unpin on request to deal with memory shortages.
Re: [ofa-general] Re: Demand paging for memory regions
Quoted 31 lines · --- Christoph Lameter
Quoted 1 line · Christian Bell
not always be in the thousands but you're still
claiming scalability
Quoted 1 line
for a mechanism that essentially logs who accesses
the regions. Then
Quoted 1 line
there's the fact that reclaim becomes a collective
communication
Quoted 1 line
operation over all region accessors. Makes me
nervous.
Well reclaim is not a very fast process (and we
usually try to avoid it
as much as possible for our HPC). Essentially its
only there to allow
shifts of processing loads and to allow efficient
caching of application
data.Quoted 1 line
However, short of providing user-level
notifications for pinned pages
Quoted 1 line
that are inadvertently released to the O/S, I
don't believe that the
Quoted 1 line
patchset provides any significant added value for
the HPC community
Quoted 1 line
that can't optimistically do RDMA demand paging.
We currently also run XPmem with pinning. Its great as long as you just
run one load on the system. No reclaim ever iccurs.
Quoted 13 lines
However, if you do things that require lots of allocations etc etc then
the page pinning can easily lead to livelock if reclaim is finally
triggerd and also strange OOM situations since the VM cannot free any
pages. So the main issue that is addressed here is reliability of pinned
page operations. Better VM integration avoids these issues because we can
unpin on request to deal with memory shortages.
I have a question on the basic need for the mmu notifier stuff wrt rdma hardware and pinning memory.
It seems that the need is to solve potential memory shortage and overcommit issues by being able to reclaim pages pinned by rdma driver/hardware. Is my understanding correct?
If I do understand correctly, then why is rdma page pinning any different than eg mlock pinning? I imagine Oracle pins lots of memory (using mlock), how come they do not run into vm overcommit issues?
Are we up against some kind of breaking c-o-w issue here that is different between mlock and rdma pinning?
Asked another way, why should effort be spent on a notifier scheme, and rather not on fixing any memory accounting problems and unifying how pin pages are accounted for that get pinned via mlock() or rdma drivers?
Startup benefits are well understood with the notifier scheme (ie, not all pages need to be faulted in at memory region creation time), specially when most of the memory region is not accessed at all. I would imagine most of HPC does not work this way though. Then again, as rdma hardware is applied (increasingly?) towards apps with short lived connections, the notifier scheme will help with startup times.
Kanoj
____________________________________________________________________________________
Be a better friend, newshound, and
know-it-all with Yahoo! Mobile. Try it now. http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
Re: [ofa-general] Re: Demand paging for memory regions
Quoted 4 lines · Kanoj Sarcar
It seems that the need is to solve potential memory shortage and overcommit issues by being able to reclaim pages pinned by rdma driver/hardware. Is my understanding correct?
Correct.
Quoted 4 lines
If I do understand correctly, then why is rdma page pinning any different than eg mlock pinning? I imagine Oracle pins lots of memory (using mlock), how come they do not run into vm overcommit issues?
Mlocked pages are not pinned. They are movable by f.e. page migration and will be potentially be moved by future memory defrag approaches. Currently we have the same issues with mlocked pages as with pinned pages. There is work in progress to put mlocked pages onto a different lru so that reclaim exempts these pages and more work on limiting the percentage of memory that can be mlocked.
Quoted 2 lines
Are we up against some kind of breaking c-o-w issue here that is different between mlock and rdma pinning?
Not that I know.
Quoted 5 lines
Asked another way, why should effort be spent on a notifier scheme, and rather not on fixing any memory accounting problems and unifying how pin pages are accounted for that get pinned via
mlock()or rdma drivers?
There are efforts underway to account for and limit mlocked pages as described above. Page pinning the way it is done by Infiniband through increasing the page refcount is treated by the VM as a temporary condition not as a permanent pin. The VM will continually try to reclaim these pages thinking that the temporary usage of the page must cease soon. This is why the use of large amounts of pinned pages can lead to livelock situations.
If we want to have pinning behavior then we could mark pinned pages specially so that the VM will not continually try to evict these pages. We could manage them similar to mlocked pages but just not allow page migration, memory unplug and defrag to occur on pinned memory. All of theses would have to fail. With the notifier scheme the device driver could be told to get rid of the pinned memory. This would make these 3 techniques work despite having an RDMA memory section.
Quoted 5 lines
Startup benefits are well understood with the notifier scheme (ie, not all pages need to be faulted in at memory region creation time), specially when most of the memory region is not accessed at all. I would imagine most of HPC does not work this way though.
No for optimal performance you would want to prefault all pages like it is now. The notifier scheme would only become relevant in memory shortage situations.
Quoted 3 lines
Then again, as rdma hardware is applied (increasingly?) towards apps with short lived connections, the notifier scheme will help with startup times.
The main use of the notifier scheme is for stability and reliability. The "pinned" pages become unpinnable on request by the VM. So the VM can work itself out of memory shortage situations in cooperation with the RDMA logic instead of simply failing.
Re: [ofa-general] Re: Demand paging for memory regions
Quoted 44 lines · --- Christoph Lameter
Quoted 1 line · Kanoj Sarcar
It seems that the need is to solve potential
memory
Quoted 2 lines
shortage and overcommit issues by being able to reclaim pages pinned by rdma driver/hardware. Is
my
Quoted 1 line
understanding correct?
Correct.
Quoted 1 line
If I do understand correctly, then why is rdma
page
Quoted 1 line
pinning any different than eg mlock pinning? I
imagine
Quoted 2 lines
Oracle pins lots of memory (using mlock), how come they do not run into vm overcommit issues?
Mlocked pages are not pinned. They are movable by f.e. page migration and
will be potentially be moved by future memory defrag approaches. Currently
we have the same issues with mlocked pages as with pinned pages. There is
work in progress to put mlocked pages onto a different lru so that reclaim
exempts these pages and more work on limiting the percentage of memory
that can be mlocked.Quoted 1 line
Are we up against some kind of breaking c-o-w
issue
Quoted 1 line
here that is different between mlock and rdma
pinning?
Not that I know.
Quoted 2 lines
Asked another way, why should effort be spent on a notifier scheme, and rather not on fixing any
memory
Quoted 3 lines
accounting problems and unifying how pin pages are accounted for that get pinned via
mlock()or rdma drivers?
Quoted 13 lines
There are efforts underway to account for and limit mlocked pages as
described above. Page pinning the way it is done by Infiniband through
increasing the page refcount is treated by the VM as a temporary
condition not as a permanent pin. The VM will continually try to reclaim
these pages thinking that the temporary usage of the page must cease
soon. This is why the use of large amounts of pinned pages can lead to
livelock situations.
Oh ok, yes, I did see the discussion on this; sorry I missed it. I do see what notifiers bring to the table now (without endorsing it :-)).
An orthogonal question is this: is IB/rdma the only "culprit" that elevates page refcounts? Are there no other subsystems which do a similar thing?
The example I am thinking about is rawio (Oracle's mlock'ed SHM regions are handed to rawio, isn't it?). My understanding of how rawio works in Linux is quite dated though ...
Kanoj
Quoted 44 lines
If we want to have pinning behavior then we could mark pinned pages
specially so that the VM will not continually try to evict these pages. We
could manage them similar to mlocked pages but just not allow page
migration, memory unplug and defrag to occur on pinned memory. All of
theses would have to fail. With the notifier scheme the device driver
could be told to get rid of the pinned memory. This would make these 3
techniques work despite having an RDMA memory section.Quoted 1 line
Startup benefits are well understood with the
notifier
Quoted 2 lines
scheme (ie, not all pages need to be faulted in at memory region creation time), specially when most
of
Quoted 2 lines
the memory region is not accessed at all. I would imagine most of HPC does not work this way though.
No for optimal performance you would want to
prefault all pages like
it is now. The notifier scheme would only become
relevant in memory
shortage situations.Quoted 1 line
Then again, as rdma hardware is applied
(increasingly?) towards apps
Quoted 1 line
with short lived connections, the notifier scheme
will help with startup
Quoted 1 line
times.
The main use of the notifier scheme is for stability and reliability. The
"pinned" pages become unpinnable on request by the VM. So the VM can work
itself out of memory shortage situations in cooperation with the
RDMA logic instead of simply failing.
Quoted 9 lines
--
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>
____________________________________________________________________________________
Looking for last minute shopping deals?
Find them fast with Yahoo! Search. http://tools.search.yahoo.com/newsearch/category.php?category=shopping
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
Re: Demand paging for memory regions
Quoted 4 lines · Kanoj Sarcar
Oh ok, yes, I did see the discussion on this; sorry I missed it. I do see what notifiers bring to the table now (without endorsing it :-)).
Quoted 8 lines
An orthogonal question is this: is IB/rdma the only "culprit" that elevates page refcounts? Are there no other subsystems which do a similar thing?
The example I am thinking about is rawio (Oracle's mlock'ed SHM regions are handed to rawio, isn't it?). My understanding of how rawio works in Linux is quite dated though ...
We're doing something similar in the DRM these days... We need big chunks of memory to be pinned so that the GPU can operate on them, but when the operation completes we can allow them to be swappable again. I think with the current implementation, allocations are always pinned, but we'll definitely want to change that soon.
Dave?
Jesse
Re: [ofa-general] Re: Demand paging for memory regions
In reply to Kanoj SarcarHi Kanoj,
Quoted 3 lines · Kanoj Sarcar
Oh ok, yes, I did see the discussion on this; sorry I missed it. I do see what notifiers bring to the table now (without endorsing it :-)).
I'm not really livelocks are really the big issue here.
I'm running N 1G VM on a 1G ram system, with N-1G swapped out. Combining this with auto-ballooning, rss limiting, and ksm ram sharing, provides really advanced and lowlevel virtualization VM capabilities to the linux kernel while at the same time guaranteeing no oom failures as long as the guest pages are lower than ram+swap (just slower runtime if too many pages are unshared or if the balloons are deflated etc..).
Swapping the virtual machine in the host may be more efficient than having the guest swapping over a virtual swap paravirt storage for example. As more management features are added admins will gain more experience in handling those new features and they'll find what's best for them. mmu notifiers and real reliable swapping are the enabler for those more advanced VM features.
oom livelocks wouldn't happen anyway with KVM as long as the maximimal number of guest physical is lower than RAM.
Quoted 8 lines
An orthogonal question is this: is IB/rdma the only "culprit" that elevates page refcounts? Are there no other subsystems which do a similar thing?
The example I am thinking about is rawio (Oracle's mlock'ed SHM regions are handed to rawio, isn't it?). My understanding of how rawio works in Linux is quite dated though ...
rawio in flight I/O shall be limited. As long as each task can't pin more than X ram, and the ram is released when the task is oom killed, and the first get_user_pages/alloc_pages/slab_alloc that returns -ENOMEM takes an oom fail path that returns failure to userland, everything is ok.
Even with IB deadlock could only happen if IB would allow unlimited memory to be pinned down by unprivileged users.
If IB is insecure and DoSable without mmu notifiers, then I'm not sure how enabling swapping of the IB memory could be enough to fix the DoS. Keep in mind that even tmpfs can't be safe allowing all ram+swap to be allocated in a tmpfs file (despite the tmpfs file storage includes swap and not only ram). Pinning the whole ram+swap with tmpfs livelocks the same way of pinning the whole ram with ramfs. So if you add mmu notifier support to IB, you only need to RDMA an area as large as ram+swap to livelock again as before... no difference at all.
I don't think livelocks have anything to do with mmu notifiers (other than to deferring the livelock to the "swap+ram" point of no return instead of the current "ram" point of no return). Livelocks have to be solved the usual way: handling alloc_pages/get_user_pages/slab allocation failures with a fail path that returns to userland and allows the ram to be released if the task was selected for oom-killage.
The real benefit of the mmu notifiers for IB would be to allow the rdma region to be larger than RAM without triggering the oom killer (or without triggering a livelock if it's DoSable but then the livelock would need fixing to be converted in a regular oom-killing by some other mean not related to the mmu-notifier, it's really an orthogonal problem).
So suppose you've a MPI simulation that requires a 10G array and you've only 1G of ram, then you can rdma over 10G like if you had 10G of ram. Things will preform ok only if there's some huge locality of the computations. For virtualization it's orders of magnitude more useful than for computer clusters but certain simulations really swaps so I don't exclude certain RDMA apps will also need this (dunno about IB).
Re: [ofa-general] Re: Demand paging for memory regions
In reply to Kanoj SarcarQuoted 7 lines · Kanoj Sarcar
Oh ok, yes, I did see the discussion on this; sorry I missed it. I do see what notifiers bring to the table now (without endorsing it :-)).
An orthogonal question is this: is IB/rdma the only "culprit" that elevates page refcounts? Are there no other subsystems which do a similar thing?
Yes there are actually two projects by SGI that also ran into the same issue that motivated the work on this. One is XPmem which allows sharing of process memory between different Linux instances and then there is the GRU which is a kind of DMA engine. Then there is KVM and probably multiple other drivers.
Re: [ofa-general] Re: Demand paging for memory regions
In reply to Christian Bell[email protected] wrote on Tue, 12 Feb 2008 20:09 -0800:
Quoted 7 lines
One other area that has not been brought up yet (I think) is the applicability of notifiers in letting users know when pinned memory is reclaimed by the kernel. This is useful when a lower-level library employs lazy deregistration strategies on memory regions that are subsequently released to the kernel via the application's use of munmap or sbrk. Ohio Supercomputing Center has work in this area but a generalized approach in the kernel would certainly be welcome.
The whole need for memory registration is a giant pain. There is no motivating application need for it---it is simply a hack around virtual memory and the lack of full VM support in current hardware. There are real hardware issues that interact poorly with virtual memory, as discussed previously in this thread.
The way a messaging cycle goes in IB is:
register buf
post send from buf
wait for completion
deregister buf
This tends to get hidden via userspace software libraries into a single call:
MPI_send(buf)
Now if you actually do the reg/dereg every time, things are very slow. So userspace library writers came up with the idea of caching registrations:
if buf is not registered:
register buf
post send from buf
wait for completion
The second time that the app happens to do a send from the same buffer, it proceeds much faster. Spatial locality applies here, and this caching is generally worth it. Some libraries have schemes to limit the size of the registration cache too.
But there are plenty of ways to hurt yourself with such a scheme. The first being a huge pool of unused but registered memory, as the library doesn't know the app patterns, and it doesn't know the VM pressure level in the kernel.
There are plenty of subtle ways that this breaks too. If the registered buf is removed from the address space via munmap() or sbrk() or other ways, the mapping and registration are gone, but the library has no way of knowing that the app just did this. Sure the physical page is still there and pinned, but the app cannot get at it. Later if new address space arrives at the same virtual address but a different physical page, the library will mistakenly think it already has it registered properly, and data is transferred from this old now-unmapped physical page.
The whole situation is rather ridiculuous, but we are quite stuck with it for current generation IB and iWarp hardware. If we can't have the kernel interact with the device directly, we could at least manage state in these multiple userspace registration caches. The VM could ask for certain (or any) pages to be released, and the library would respond if they are indeed not in use by the device. The app itself does not know about pinned regions, and the library is aware of exactly which regions are potentially in use.
Since the great majority of userspace messaging over IB goes through middleware like MPI or PGAS languages, and they all have the same approach to registration caching, this approach could fix the problem for a big segment of use cases.
More text on the registration caching problem is here:
http://www.osc.edu/~pw/papers/wyckoff-memreg-ccgrid05.pdf
with an approach using vm_ops open and close operations in a kernel module here:
http://www.osc.edu/~pw/dreg/
There is a place for VM notifiers in RDMA messaging, but not in talking to devices, at least not the current set. If you can define a reasonable userspace interface for VM notifiers, libraries can manage registration caches more efficiently, letting the kernel unmap pinned pages as it likes.
-- Pete
Re: [ofa-general] Re: Demand paging for memory regions
Quoted 9 lines · Pete Wyckoff
[email protected] wrote on Tue, 12 Feb 2008 20:09 -0800:
Quoted 7 lines
One other area that has not been brought up yet (I think) is the applicability of notifiers in letting users know when pinned memory is reclaimed by the kernel. This is useful when a lower-level library employs lazy deregistration strategies on memory regions that are subsequently released to the kernel via the application's use of munmap or sbrk. Ohio Supercomputing Center has work in this area but a generalized approach in the kernel would certainly be welcome.
Quoted 5 lines
The whole need for memory registration is a giant pain. There is no motivating application need for it---it is simply a hack around virtual memory and the lack of full VM support in current hardware. There are real hardware issues that interact poorly with virtual memory, as discussed previously in this thread.
Well, the registrations also exist to provide protection against rouge/faulty remotes, but for the purposes of MPI that is probably not important.
Here is a thought.. Some RDMA hardware can change the page tables on the fly. What if the kernel had a mechanism to dynamically maintain a full registration of the processes entire address space ('mlocked' but able to be migrated)? MPI would never need to register a buffer, and all the messy cases with munmap/sbrk/etc go away - the risk is that other MPI nodes can randomly scribble all over the process :)
Christoph: It seemed to me you were first talking about freeing/swapping/faulting RDMA'able pages - but would pure migration as a special hardware supported case be useful like Catilan suggested?
Regards,
Jason
Re: [ofa-general] Re: Demand paging for memory regions
Quoted 3 lines · Jason Gunthorpe
Christoph: It seemed to me you were first talking about freeing/swapping/faulting RDMA'able pages - but would pure migration as a special hardware supported case be useful like Catilan suggested?
That is a special case of the proposed solution. You could mlock the regions of interest. Those can then only be migrated but not swapped out.
However, I think we need some limit on the number of pages one can mlock. Otherwise the VM can get into a situation where reclaim is not possible because the majority of memory is either mlocked or pinned by I/O etc.
Re: [ofa-general] Re: Demand paging for memory regions
In reply to Christoph LameterQuoted 7 lines · Christoph Lameter
Quoted 4 lines · Jason Gunthorpe
Well, certainly today the memfree IB devices store the page tables in host memory so they are already designed to hang onto packets during the page lookup over PCIE, adding in faulting makes this time larger.
Quoted 7 lines
You really do not need a page table to use it. What needs to be maintained is knowledge on both side about what pages are currently shared across RDMA. If the VM decides to reclaim a page then the notification is used to remove the remote entry. If the remote side then tries to access the page again then the page fault on the remote side will stall until the local page has been brought back. RDMA can proceed after both sides again agree on that page now being sharable.
HPC environments won't be amenable to a pessimistic approach of synchronizing before every data transfer. RDMA is assumed to be a low-level data movement mechanism that has no implied synchronization. In some parallel programming models, it's not uncommon to use RDMA to send 8-byte messages. It can be difficult to make and hold guarantees about in-memory pages when many concurrent RDMA operations are in flight (not uncommon in reasonably large machines). Some of the in-memory page information could be shared with some form of remote caching strategy but then it's a different problem with its own scalability challenges.
I think there are very potential clients of the interface when an optimistic approach is used. Part of the trick, however, has to do with being able to re-start transfers instead of buffering the data or making guarantees about delivery that could cause deadlock (as was alluded to earlier in this thread). InfiniBand is constrained in this regard since it requires message-ordering between endpoints (or queue pairs). One could argue that this is still possible with IB, at the cost of throwing more packets away when a referenced page is not in memory. With this approach, the worse case demand paging scenario is met when the active working set of referenced pages is larger than the amount physical memory -- but HPC applications are already bound by this anyway.
You'll find that Quadrics has the most experience in this area and that their entire architecture is adapted to being optimistic about demand paging in RDMA transfers -- they've been maintaining a patchset to do this for years.
. . christian
Re: [ofa-general] Re: Demand paging for memory regions
Quoted 13 lines · Christian Bell
I think there are very potential clients of the interface when an optimistic approach is used. Part of the trick, however, has to do with being able to re-start transfers instead of buffering the data or making guarantees about delivery that could cause deadlock (as was alluded to earlier in this thread). InfiniBand is constrained in this regard since it requires message-ordering between endpoints (or queue pairs). One could argue that this is still possible with IB, at the cost of throwing more packets away when a referenced page is not in memory. With this approach, the worse case demand paging scenario is met when the active working set of referenced pages is larger than the amount physical memory -- but HPC applications are already bound by this anyway.
Quoted 4 lines
You'll find that Quadrics has the most experience in this area and that their entire architecture is adapted to being optimistic about demand paging in RDMA transfers -- they've been maintaining a patchset to do this for years.
The notifier patchset that we are discussing here was mostly inspired by their work.
There is no need to restart transfers that you have never started in the first place. The remote side would never start a transfer if the page reference has been torn down. In order to start the transfer a fault handler on the remote side would have to setup the association between the memory on both ends again.
Re: [ofa-general] Re: Demand paging for memory regions
In reply to Roland DreierQuoted 8 lines · Roland Dreier
I don't know anything about the T3 internals, but it's not clear that you could do this without a new chip design in general. Lot's of RDMA devices were designed expecting that when a packet arrives, the HW can look up the bus address for a given memory region/offset and place the packet immediately. It seems like a major change to be able to generate a "page fault" interrupt when a page isn't present, or even just wait to scatter some data until the host finishes updating page tables when the HW needs the translation.
Well if the VM wants to invalidate a page then the remote end first has to remove its mapping.
If a page has been removed then the remote end would encounter a fault and then would have to wait for the local end to reestablish its mapping before proceeding.
So the packet would only be generated when both ends are in sync.
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
Re: [ofa-general] Re: Demand paging for memory regions
In reply to Roland DreierQuoted 2 lines
Quoted 2 lines
Quoted 2 lines
Chelsio's T3 HW doesn't support this.
For ehca we currently can't modify a large MR when it has been allocated. EHCA Hardware expects the pages to be there (MRs must not have "holes"). This is also true for the global MR covering all kernel space. Therefore we still need the memory to be "pinned" if ib_umem_get() is called.
So with the current implementation we don't have much use for a notifier.
"It is difficult to make predictions, especially about the future" Gruss / Regards
Christoph Raisch + Hoang-Nam Nguyen
Re: [ofa-general] Re: Demand paging for memory regions
Quoted 5 lines · Christoph Raisch
For ehca we currently can't modify a large MR when it has been allocated. EHCA Hardware expects the pages to be there (MRs must not have "holes"). This is also true for the global MR covering all kernel space. Therefore we still need the memory to be "pinned" if
ib_umem_get()is called.
It cannot be freed and then reallocated? What happens when a process exists?
Andrew Morton
maintainerQuoted 7 lines · On Fri, 8 Feb 2008 16:05:00 -0800 (PST) Christoph Lameter <[email protected]>…
Quoted 1 line · Andrew Morton
You took it correctly, and I didn't understand the answer ;)
We have done several rounds of discussion on linux-kernel about this so far and the IB folks have not shown up to join in. I have tried to make this as general as possible.
infiniband would appear to be the major present in-kernel client of this new interface. So as a part of proving its usefulness, correctness, etc we should surely work on converting infiniband to use it, and prove its goodness.
Quite possibly none of the infiniband developers even know about it..
Quoted 1 line · Andrew Morton
Quite possibly none of the infiniband developers even know about it..
Well Andrea's initial approach was even featured on LWN a couple of weeks back.
Quoted 7 lines
GRU
- Simple additional hardware TLB (possibly covering multiple instances of Linux)
- Needs TLB shootdown when the VM unmaps pages.
- Determines page address viafollow_page(from interrupt context) but can fall back toget_user_pages().
- No page reference possible since no page status is kept..
I applied the latest mmuops patch to a 2.6.24 kernel & updated the GRU driver to use it. As far as I can tell, everything works ok. Although more testing is needed, all current tests of driver functionality are working on both a system simulator and a hardware simulator.
The driver itself is still a few weeks from being ready to post but I can send code fragments of the portions related to mmuops or external TLB management if anyone is interested.
--- jack