Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932566AbZJAOIc (ORCPT ); Thu, 1 Oct 2009 10:08:32 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S932527AbZJAOIb (ORCPT ); Thu, 1 Oct 2009 10:08:31 -0400 Received: from victor.provo.novell.com ([137.65.250.26]:58505 "EHLO victor.provo.novell.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932557AbZJAOI0 (ORCPT ); Thu, 1 Oct 2009 10:08:26 -0400 From: Suresh Jayaraman To: Linus Torvalds , Andrew Morton , linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: netdev@vger.kernel.org, Neil Brown , Miklos Szeredi , Wouter Verhelst , Peter Zijlstra , trond.myklebust@fys.uio.no, Suresh Jayaraman Subject: [PATCH 24/31] mm: methods for teaching filesystems about PG_swapcache pages Date: Thu, 1 Oct 2009 19:39:43 +0530 Message-Id: <1254406183-16519-1-git-send-email-sjayaraman@suse.de> X-Mailer: git-send-email 1.6.0.2 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3827 Lines: 121 From: Peter Zijlstra In order to teach filesystems to handle swap cache pages, three new page functions are introduced: pgoff_t page_file_index(struct page *); loff_t page_file_offset(struct page *); struct address_space *page_file_mapping(struct page *); page_file_index() - gives the offset of this page in the file in PAGE_CACHE_SIZE blocks. Like page->index is for mapped pages, this function also gives the correct index for PG_swapcache pages. page_file_offset() - uses page_file_index(), so that it will give the expected result, even for PG_swapcache pages. page_file_mapping() - gives the mapping backing the actual page; that is for swap cache pages it will give swap_file->f_mapping. Signed-off-by: Peter Zijlstra Signed-off-by: Suresh Jayaraman --- include/linux/mm.h | 25 +++++++++++++++++++++++++ include/linux/pagemap.h | 5 +++++ mm/swapfile.c | 19 +++++++++++++++++++ 3 files changed, 49 insertions(+) Index: mmotm/include/linux/mm.h =================================================================== --- mmotm.orig/include/linux/mm.h +++ mmotm/include/linux/mm.h @@ -634,6 +634,17 @@ static inline struct address_space *page return mapping; } +extern struct address_space *__page_file_mapping(struct page *); + +static inline +struct address_space *page_file_mapping(struct page *page) +{ + if (unlikely(PageSwapCache(page))) + return __page_file_mapping(page); + + return page->mapping; +} + static inline int PageAnon(struct page *page) { return ((unsigned long)page->mapping & PAGE_MAPPING_ANON) != 0; @@ -650,6 +661,20 @@ static inline pgoff_t page_index(struct return page->index; } +extern pgoff_t __page_file_index(struct page *page); + +/* + * Return the file index of the page. Regular pagecache pages use ->index + * whereas swapcache pages use swp_offset(->private) + */ +static inline pgoff_t page_file_index(struct page *page) +{ + if (unlikely(PageSwapCache(page))) + return __page_file_index(page); + + return page->index; +} + /* * The atomic page->_mapcount, like _count, starts from -1: * so that transitions both from it and to it can be tracked, Index: mmotm/include/linux/pagemap.h =================================================================== --- mmotm.orig/include/linux/pagemap.h +++ mmotm/include/linux/pagemap.h @@ -279,6 +279,11 @@ static inline loff_t page_offset(struct return ((loff_t)page->index) << PAGE_CACHE_SHIFT; } +static inline loff_t page_file_offset(struct page *page) +{ + return ((loff_t)page_file_index(page)) << PAGE_CACHE_SHIFT; +} + static inline pgoff_t linear_page_index(struct vm_area_struct *vma, unsigned long address) { Index: mmotm/mm/swapfile.c =================================================================== --- mmotm.orig/mm/swapfile.c +++ mmotm/mm/swapfile.c @@ -2190,6 +2190,25 @@ struct swap_info_struct *page_swap_info( } /* + * out-of-line __page_file_ methods to avoid include hell. + */ + +struct address_space *__page_file_mapping(struct page *page) +{ + VM_BUG_ON(!PageSwapCache(page)); + return page_swap_info(page)->swap_file->f_mapping; +} +EXPORT_SYMBOL_GPL(__page_file_mapping); + +pgoff_t __page_file_index(struct page *page) +{ + swp_entry_t swap = { .val = page_private(page) }; + VM_BUG_ON(!PageSwapCache(page)); + return swp_offset(swap); +} +EXPORT_SYMBOL_GPL(__page_file_index); + +/* * swap_lock prevents swap_map being freed. Don't grab an extra * reference on the swaphandle, it doesn't matter if it becomes unused. */ -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/