From: Christoph Lameter Add remove_from_swap remove_from_swap() allows the restoration of the pte entries that existed before page migration occurred for anonymous pages by walking the reverse maps. This reduces swap use and establishes regular pte's without the need for page faults. Signed-off-by: Christoph Lameter Signed-off-by: Andrew Morton --- include/linux/rmap.h | 3 +++ include/linux/swap.h | 3 +++ mm/rmap.c | 29 +++++++++++++++++++++++++++++ mm/swapfile.c | 10 ++++++++++ mm/vmscan.c | 9 +++++++++ 5 files changed, 54 insertions(+) diff -puN include/linux/rmap.h~direct-migration-v9-remove_from_swap-to-remove-swap-ptes include/linux/rmap.h --- devel/include/linux/rmap.h~direct-migration-v9-remove_from_swap-to-remove-swap-ptes 2006-01-23 16:41:24.000000000 -0800 +++ devel-akpm/include/linux/rmap.h 2006-01-23 16:41:24.000000000 -0800 @@ -92,6 +92,9 @@ static inline void page_dup_rmap(struct */ int page_referenced(struct page *, int is_locked); int try_to_unmap(struct page *, int ignore_refs); +#ifdef CONFIG_MIGRATION +void remove_from_swap(struct page *page); +#endif /* * Called from mm/filemap_xip.c to unmap empty zero page diff -puN include/linux/swap.h~direct-migration-v9-remove_from_swap-to-remove-swap-ptes include/linux/swap.h --- devel/include/linux/swap.h~direct-migration-v9-remove_from_swap-to-remove-swap-ptes 2006-01-23 16:41:24.000000000 -0800 +++ devel-akpm/include/linux/swap.h 2006-01-23 16:41:24.000000000 -0800 @@ -247,6 +247,9 @@ extern int remove_exclusive_swap_page(st struct backing_dev_info; extern spinlock_t swap_lock; +#ifdef CONFIG_MIGRATION +extern int remove_vma_swap(struct vm_area_struct *vma, struct page *page); +#endif /* linux/mm/thrash.c */ extern struct mm_struct * swap_token_mm; diff -puN mm/rmap.c~direct-migration-v9-remove_from_swap-to-remove-swap-ptes mm/rmap.c --- devel/mm/rmap.c~direct-migration-v9-remove_from_swap-to-remove-swap-ptes 2006-01-23 16:41:24.000000000 -0800 +++ devel-akpm/mm/rmap.c 2006-01-23 16:41:24.000000000 -0800 @@ -206,6 +206,35 @@ out: return anon_vma; } +#ifdef CONFIG_MIGRATION +/* + * Remove an anonymous page from swap replacing the swap pte's + * through real pte's pointing to valid pages and then releasing + * the page from the swap cache. + * + * Must hold page lock on page. + */ +void remove_from_swap(struct page *page) +{ + struct anon_vma *anon_vma; + struct vm_area_struct *vma; + + if (!PageAnon(page) || !PageSwapCache(page)) + return; + + anon_vma = page_lock_anon_vma(page); + if (!anon_vma) + return; + + list_for_each_entry(vma, &anon_vma->head, anon_vma_node) + remove_vma_swap(vma, page); + + spin_unlock(&anon_vma->lock); + + delete_from_swap_cache(page); +} +#endif + /* * At what user virtual address is page expected in vma? */ diff -puN mm/swapfile.c~direct-migration-v9-remove_from_swap-to-remove-swap-ptes mm/swapfile.c --- devel/mm/swapfile.c~direct-migration-v9-remove_from_swap-to-remove-swap-ptes 2006-01-23 16:41:24.000000000 -0800 +++ devel-akpm/mm/swapfile.c 2006-01-23 16:41:24.000000000 -0800 @@ -554,6 +554,16 @@ static int unuse_mm(struct mm_struct *mm return 0; } +#ifdef CONFIG_MIGRATION +int remove_vma_swap(struct vm_area_struct *vma, struct page *page) +{ + swp_entry_t entry = { .val = page_private(page) }; + + return unuse_vma(vma, entry, page); +} +#endif + + /* * Scan swap_map from current position to next entry still in use. * Recycle to start on reaching the end, returning 0 when empty. diff -puN mm/vmscan.c~direct-migration-v9-remove_from_swap-to-remove-swap-ptes mm/vmscan.c --- devel/mm/vmscan.c~direct-migration-v9-remove_from_swap-to-remove-swap-ptes 2006-01-23 16:41:24.000000000 -0800 +++ devel-akpm/mm/vmscan.c 2006-01-23 16:41:24.000000000 -0800 @@ -798,6 +798,15 @@ int migrate_page(struct page *newpage, s migrate_page_copy(newpage, page); + /* + * Remove auxiliary swap entries and replace + * them with real ptes. + * + * Note that a real pte entry will allow processes that are not + * waiting on the page lock to use the new page via the page tables + * before the new page is unlocked. + */ + remove_from_swap(newpage); return 0; } _