Move around the swap entry methods in preparation for use from page methods. Also provide a function to obtain the swap_info_struct backing a swap cache page. Signed-off-by: Peter Zijlstra CC: Trond Myklebust --- include/linux/mm.h | 8 ++++++++ include/linux/swap.h | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/swapops.h | 44 -------------------------------------------- mm/swapfile.c | 1 + 4 files changed, 57 insertions(+), 44 deletions(-) Index: linux-2.6-git/include/linux/mm.h =================================================================== --- linux-2.6-git.orig/include/linux/mm.h 2007-02-21 12:15:00.000000000 +0100 +++ linux-2.6-git/include/linux/mm.h 2007-02-21 12:15:01.000000000 +0100 @@ -17,6 +17,7 @@ #include #include #include +#include struct mempolicy; struct anon_vma; @@ -586,6 +587,13 @@ static inline struct address_space *page return mapping; } +static inline struct swap_info_struct *page_swap_info(struct page *page) +{ + swp_entry_t swap = { .val = page_private(page) }; + BUG_ON(!PageSwapCache(page)); + return get_swap_info_struct(swp_type(swap)); +} + static inline int PageAnon(struct page *page) { return ((unsigned long)page->mapping & PAGE_MAPPING_ANON) != 0; Index: linux-2.6-git/include/linux/swap.h =================================================================== --- linux-2.6-git.orig/include/linux/swap.h 2007-02-21 12:15:00.000000000 +0100 +++ linux-2.6-git/include/linux/swap.h 2007-02-21 12:15:01.000000000 +0100 @@ -79,6 +79,50 @@ typedef struct { } swp_entry_t; /* + * swapcache pages are stored in the swapper_space radix tree. We want to + * get good packing density in that tree, so the index should be dense in + * the low-order bits. + * + * We arrange the `type' and `offset' fields so that `type' is at the five + * high-order bits of the swp_entry_t and `offset' is right-aligned in the + * remaining bits. + * + * swp_entry_t's are *never* stored anywhere in their arch-dependent format. + */ +#define SWP_TYPE_SHIFT(e) (sizeof(e.val) * 8 - MAX_SWAPFILES_SHIFT) +#define SWP_OFFSET_MASK(e) ((1UL << SWP_TYPE_SHIFT(e)) - 1) + +/* + * Store a type+offset into a swp_entry_t in an arch-independent format + */ +static inline swp_entry_t swp_entry(unsigned long type, pgoff_t offset) +{ + swp_entry_t ret; + + ret.val = (type << SWP_TYPE_SHIFT(ret)) | + (offset & SWP_OFFSET_MASK(ret)); + return ret; +} + +/* + * Extract the `type' field from a swp_entry_t. The swp_entry_t is in + * arch-independent format + */ +static inline unsigned swp_type(swp_entry_t entry) +{ + return (entry.val >> SWP_TYPE_SHIFT(entry)); +} + +/* + * Extract the `offset' field from a swp_entry_t. The swp_entry_t is in + * arch-independent format + */ +static inline pgoff_t swp_offset(swp_entry_t entry) +{ + return entry.val & SWP_OFFSET_MASK(entry); +} + +/* * current->reclaim_state points to one of these when a task is running * memory reclaim */ @@ -326,6 +370,10 @@ static inline int valid_swaphandles(swp_ return 0; } +static inline struct swap_info_struct *get_swap_info_struct(unsigned type) +{ + return NULL; +} #define can_share_swap_page(p) (page_mapcount(p) == 1) static inline int move_to_swap_cache(struct page *page, swp_entry_t entry) Index: linux-2.6-git/include/linux/swapops.h =================================================================== --- linux-2.6-git.orig/include/linux/swapops.h 2007-02-21 12:15:00.000000000 +0100 +++ linux-2.6-git/include/linux/swapops.h 2007-02-21 12:15:01.000000000 +0100 @@ -1,48 +1,4 @@ /* - * swapcache pages are stored in the swapper_space radix tree. We want to - * get good packing density in that tree, so the index should be dense in - * the low-order bits. - * - * We arrange the `type' and `offset' fields so that `type' is at the five - * high-order bits of the swp_entry_t and `offset' is right-aligned in the - * remaining bits. - * - * swp_entry_t's are *never* stored anywhere in their arch-dependent format. - */ -#define SWP_TYPE_SHIFT(e) (sizeof(e.val) * 8 - MAX_SWAPFILES_SHIFT) -#define SWP_OFFSET_MASK(e) ((1UL << SWP_TYPE_SHIFT(e)) - 1) - -/* - * Store a type+offset into a swp_entry_t in an arch-independent format - */ -static inline swp_entry_t swp_entry(unsigned long type, pgoff_t offset) -{ - swp_entry_t ret; - - ret.val = (type << SWP_TYPE_SHIFT(ret)) | - (offset & SWP_OFFSET_MASK(ret)); - return ret; -} - -/* - * Extract the `type' field from a swp_entry_t. The swp_entry_t is in - * arch-independent format - */ -static inline unsigned swp_type(swp_entry_t entry) -{ - return (entry.val >> SWP_TYPE_SHIFT(entry)); -} - -/* - * Extract the `offset' field from a swp_entry_t. The swp_entry_t is in - * arch-independent format - */ -static inline pgoff_t swp_offset(swp_entry_t entry) -{ - return entry.val & SWP_OFFSET_MASK(entry); -} - -/* * Convert the arch-dependent pte representation of a swp_entry_t into an * arch-independent swp_entry_t. */ Index: linux-2.6-git/mm/swapfile.c =================================================================== --- linux-2.6-git.orig/mm/swapfile.c 2007-02-21 12:15:00.000000000 +0100 +++ linux-2.6-git/mm/swapfile.c 2007-02-21 12:15:01.000000000 +0100 @@ -1764,6 +1764,7 @@ get_swap_info_struct(unsigned type) { return &swap_info[type]; } +EXPORT_SYMBOL_GPL(get_swap_info_struct); /* * swap_lock prevents swap_map being freed. Don't grab an extra -- - 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/