From 73b1262fa43a778b1e154deea632cdef5009d6a1 Mon Sep 17 00:00:00 2001 From: Hugh Dickins Date: Mon, 4 Feb 2008 22:28:50 -0800 Subject: tmpfs: move swap swizzling into shmem move_to_swap_cache and move_from_swap_cache functions (which swizzle a page between tmpfs page cache and swap cache, to avoid page copying) are only used by shmem.c; and our subsequent fix for unionfs needs different treatments in the two instances of move_from_swap_cache. Move them from swap_state.c into their callsites shmem_writepage, shmem_unuse_inode and shmem_getpage, making add_to_swap_cache externally visible. shmem.c likes to say set_page_dirty where swap_state.c liked to say SetPageDirty: respect that diversity, which __set_page_dirty_no_writeback makes moot (and implies we should lose that "shift page from clean_pages to dirty_pages list" comment: it's on neither). Signed-off-by: Hugh Dickins Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- mm/shmem.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'mm/shmem.c') diff --git a/mm/shmem.c b/mm/shmem.c index 7be94342bf06..e577adf4ae85 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -884,7 +884,9 @@ lost2: found: idx += offset; inode = &info->vfs_inode; - if (move_from_swap_cache(page, idx, inode->i_mapping) == 0) { + if (add_to_page_cache(page, inode->i_mapping, idx, GFP_ATOMIC) == 0) { + delete_from_swap_cache(page); + set_page_dirty(page); info->flags |= SHMEM_PAGEIN; shmem_swp_set(info, ptr + offset, 0); } @@ -972,7 +974,8 @@ static int shmem_writepage(struct page *page, struct writeback_control *wbc) BUG_ON(!entry); BUG_ON(entry->val); - if (move_to_swap_cache(page, swap) == 0) { + if (add_to_swap_cache(page, swap, GFP_ATOMIC) == 0) { + remove_from_page_cache(page); shmem_swp_set(info, entry, swap.val); shmem_swp_unmap(entry); spin_unlock(&info->lock); @@ -982,6 +985,9 @@ static int shmem_writepage(struct page *page, struct writeback_control *wbc) list_move_tail(&info->swaplist, &shmem_swaplist); spin_unlock(&shmem_swaplist_lock); } + swap_duplicate(swap); + page_cache_release(page); /* pagecache ref */ + set_page_dirty(page); unlock_page(page); return 0; } @@ -1217,13 +1223,15 @@ repeat: SetPageUptodate(filepage); set_page_dirty(filepage); swap_free(swap); - } else if (!(error = move_from_swap_cache( - swappage, idx, mapping))) { + } else if (!(error = add_to_page_cache( + swappage, mapping, idx, GFP_ATOMIC))) { info->flags |= SHMEM_PAGEIN; shmem_swp_set(info, entry, 0); shmem_swp_unmap(entry); + delete_from_swap_cache(swappage); spin_unlock(&info->lock); filepage = swappage; + set_page_dirty(filepage); swap_free(swap); } else { shmem_swp_unmap(entry); -- cgit v1.2.3-70-g09d2