From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56303) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X2Nkz-0003Z2-33 for qemu-devel@nongnu.org; Wed, 02 Jul 2014 12:51:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1X2Nkr-0007zJ-Ib for qemu-devel@nongnu.org; Wed, 02 Jul 2014 12:51:41 -0400 Received: from mx1.redhat.com ([209.132.183.28]:48210) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X2Nkr-0007ym-9r for qemu-devel@nongnu.org; Wed, 02 Jul 2014 12:51:33 -0400 From: Andrea Arcangeli Date: Wed, 2 Jul 2014 18:50:11 +0200 Message-Id: <1404319816-30229-6-git-send-email-aarcange@redhat.com> In-Reply-To: <1404319816-30229-1-git-send-email-aarcange@redhat.com> References: <1404319816-30229-1-git-send-email-aarcange@redhat.com> Subject: [Qemu-devel] [PATCH 05/10] mm: swp_entry_swapcount List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org, kvm@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Robert Love , Dave Hansen , Jan Kara , Neil Brown , Stefan Hajnoczi , Andrew Jones , KOSAKI Motohiro , Michel Lespinasse , Andrea Arcangeli , Taras Glek , Juan Quintela , Hugh Dickins , Isaku Yamahata , Mel Gorman , Android Kernel Team , Mel Gorman , "\\\"Dr. David Alan Gilbert\\\"" , "Huangpeng (Peter)" , Anthony Liguori , Mike Hommey , Keith Packard , Wenchao Xia , Minchan Kim , Dmitry Adamushko , Johannes Weiner , Paolo Bonzini , Andrew Morton Provide a new swapfile method for remap_anon_pages to verify the swap entry is mapped only in one vma before relocating the swap entry in a different virtual address. Otherwise if the swap entry is mapped in multiple vmas, when the page is swapped back in, it could get mapped in a non linear way in some anon_vma. Signed-off-by: Andrea Arcangeli --- include/linux/swap.h | 6 ++++++ mm/swapfile.c | 13 +++++++++++++ 2 files changed, 19 insertions(+) diff --git a/include/linux/swap.h b/include/linux/swap.h index 3d86a9a..3d7cae5 100644 --- a/include/linux/swap.h +++ b/include/linux/swap.h @@ -452,6 +452,7 @@ extern unsigned int count_swap_pages(int, int); extern sector_t map_swap_page(struct page *, struct block_device **); extern sector_t swapdev_block(int, pgoff_t); extern int page_swapcount(struct page *); +extern int swp_entry_swapcount(swp_entry_t entry); extern struct swap_info_struct *page_swap_info(struct page *); extern int reuse_swap_page(struct page *); extern int try_to_free_swap(struct page *); @@ -553,6 +554,11 @@ static inline int page_swapcount(struct page *page) return 0; } +static inline int swp_entry_swapcount(swp_entry_t entry) +{ + return 0; +} + #define reuse_swap_page(page) (page_mapcount(page) == 1) static inline int try_to_free_swap(struct page *page) diff --git a/mm/swapfile.c b/mm/swapfile.c index 4c524f7..f516555 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -877,6 +877,19 @@ int page_swapcount(struct page *page) return count; } +int swp_entry_swapcount(swp_entry_t entry) +{ + int count = 0; + struct swap_info_struct *p; + + p = swap_info_get(entry); + if (p) { + count = swap_count(p->swap_map[swp_offset(entry)]); + spin_unlock(&p->lock); + } + return count; +} + /* * We can write to an anon page without COW if there are no other references * to it. And as a side-effect, free up its swap: because the old content