more page migration: Do not dec/inc rss counters
Subsystems (3)
PATCH 1/3 more page migration: Do not dec/inc rss counters
more page migration: Do not dec/inc rss counters
If we install a migration entry then the rss not really decreases since the page is just moved somewhere else. We can save ourselves the work of decrementing and later incrementing which will just eventually cause cacheline bouncing.
mm/migrate.c +0 -1
@@ -166,7 +166,6 @@if (!is_migration_entry (entry) ||migration_entry_to_page (entry) != old) goto out; -inc_mm_counter (mm, anon_rss);get_page (new); pte =pte_mkold (mk_pte (new, vma->vm_page_prot));if (is_write_migration_entry (entry))
mm/rmap.c +1 -1
@@ -595,6 +595,7 @@list_add (&mm->mmlist, &init_mm.mmlist);spin_unlock (&mmlist_lock); } +dec_mm_counter (mm, anon_rss); }else {/* * Store the pfn of the page in a special migration
@@ -606,7 +607,6 @@ }set_pte_at (mm, address, pte,swp_entry_to_pte (entry));BUG_ON (pte_file (*pte)); -dec_mm_counter (mm, anon_rss); }else dec_mm_counter (mm, file_rss);
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 2/3 more page migration: move common code to migrate pages()
more page migration: move common code from migration functions to migrate pages()
All migration functions start by unmapping ptes and thereby potentially creating migration ptes. They all end by replacing the migration ptes with real ones.
So extract the common code and put it into migrate_pages().
mm/migrate.c +25 -26
@@ -258,17 +258,11 @@ {struct page **radix_pointer; -/* -* Retry if we were unable to remove all mappings. -*/ -if (page_mapcount (page)) -return -EAGAIN ; -if (!mapping) {/* * Anonymous page without swap mapping. */ -if (page_count (page) !=1 ) +if (page_count (page) !=1 || !page->mapping)return -EAGAIN ;return 0 ;
@@ -371,21 +365,12 @@BUG_ON (PageWriteback (page));/* Writeback must be complete */ -if (try_to_unmap (page,1 ) ==SWAP_FAIL ) { -remove_migration_ptes (page, page); -return -EPERM ; - } - rc =migrate_page_move_mapping (mapping, newpage, page); -if (rc) { -remove_migration_ptes (page, page); -return rc; - } +if (!rc) +migrate_page_copy (newpage, page); -migrate_page_copy (newpage, page); -remove_migration_ptes (page, newpage); -return 0 ; +return rc; }EXPORT_SYMBOL (migrate_page);
@@ -403,9 +388,6 @@if (!page_has_buffers (page))return migrate_page (mapping, newpage, page); -if (try_to_unmap (page,1 ) ==SWAP_FAIL ) -return -EPERM ; - head =page_buffers (page); rc =migrate_page_move_mapping (mapping, newpage, page);
@@ -455,10 +437,6 @@ {int rc; -if (try_to_unmap (page,1 ) ==SWAP_FAIL ) -/* A vma has VM_LOCKED set -> permanent failure */ -return -EPERM ; -/* * Removing the ptes may have dirtied the page */
@@ -590,6 +568,21 @@else if (PageWriteback (page)) goto unlock_page; +/* +* Establish migration entries or unmap file ptes. +*/ + rc = -EPERM ; +if (try_to_unmap (page,1 ) ==SWAP_FAIL ) +/* A vma has VM_LOCKED set -> permanent failure */ + goto remove_migentry; + +/* +* Retry if we were unable to remove all mappings. +*/ + rc = -EAGAIN ; +if (page_mapcount (page)) + goto remove_migentry; +lock_page (newpage);/* Prepare mapping for the new page.*/ newpage->index = page->index;
@@ -609,7 +602,13 @@else rc =fallback_migrate_page (mapping, newpage, page); +if (rc ==0 ) +remove_migration_ptes (page, newpage);unlock_page (newpage); + +remove_migentry: +if (rc) +remove_migration_ptes (page, page); unlock_page:unlock_page (page);
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 3/3 more page migration: migration entries for file backed pages
In reply to Christoph Lametermore page migration: Use migration entries for file backed pages
This implements the use of migration entries to preserve ptes of file backed pages during migration. Processes can therefore be migrated back and forth without loosing their connection to pagecache pages.
Note that we implement the migration entries only for linear mappings. Nonlinear mappings still require the unmapping of the ptes for migration.
And another writepage() ugliness shows up. writepage() can drop the page lock. Therefore we have to remove migration ptes before calling writepages() in order to avoid having migration entries point to unlocked pages.
mm/migrate.c +49 -5
@@ -171,19 +171,44 @@if (is_write_migration_entry (entry)) pte =pte_mkwrite (pte);set_pte_at (mm, addr, ptep, pte); -page_add_anon_rmap (new, vma, addr); + +if (PageAnon (new)) +page_add_anon_rmap (new, vma, addr); +else +page_add_file_rmap (new); + out:pte_unmap_unlock (pte, ptl); }/* -* Get rid of all migration entries and replace them by -* references to the indicated page. -* +* Note that remove_file_migration_ptes will only work on regular mappings +* specialized other mappings will simply be unmapped and do not use +* migration entries. +*/ +static void remove_file_migration_ptes (struct page *old,struct page *new) +{ +struct vm_area_struct *vma; +struct address_space *mapping =page_mapping (new); +struct prio_tree_iter iter; +pgoff_t pgoff = new->index << (PAGE_CACHE_SHIFT -PAGE_SHIFT ); + +if (!mapping) +return ; + +spin_lock (&mapping->i_mmap_lock); + + vma_prio_tree_foreach(vma, &iter, &mapping->i_mmap, pgoff, pgoff) +remove_migration_pte (vma,page_address_in_vma (new, vma), old, new); + +spin_unlock (&mapping->i_mmap_lock); +} + +/* * Must hold mmap_sem lock on at least one of the vmas containing * the page so that the anon_vma cannot vanish. */ -static void remove_migration_ptes (struct page *old,struct page *new) +static void remove_anon_migration_ptes (struct page *old,struct page *new) {struct anon_vma *anon_vma;struct vm_area_struct *vma;
@@ -208,6 +233,18 @@ }/* +* Get rid of all migration entries and replace them by +* references to the indicated page. +*/ +static void remove_migration_ptes (struct page *old,struct page *new) +{ +if (PageAnon (new)) +remove_anon_migration_ptes (old, new); +else +remove_file_migration_ptes (old, new); +} + +/* * Something used the pte of a page under migration. We need to * get to the page and wait until migration is finished. * When we return from this function the fault will be retried.
@@ -450,6 +487,13 @@ .for_reclaim = 1 }; +/* +* Remove the migration entries because writepage() may +* unlock which may result in migration entries +* pointing to unlocked pages. +*/ +remove_migration_ptes (page, page); +if (!mapping->a_ops->writepage)/* No write method for the address space */ return -EINVAL ;
mm/rmap.c +7 -1
@@ -607,8 +607,14 @@ }set_pte_at (mm, address, pte,swp_entry_to_pte (entry));BUG_ON (pte_file (*pte)); - }else + }else if (!migration)dec_mm_counter (mm, file_rss); +else { +/* Establish migration entry for a file page */ +swp_entry_t entry; + entry =make_migration_entry (page,pte_write (pteval)); +set_pte_at (mm, address, pte,swp_entry_to_pte (entry)); + }page_remove_rmap (page);page_cache_release (page);
--
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>