Commit 2f772e6c authored by Seth Jennings's avatar Seth Jennings Committed by Linus Torvalds

mm: break up swap_writepage() for frontswap backends

swap_writepage() is currently where frontswap hooks into the swap write
path to capture pages with the frontswap_store() function.  However, if
a frontswap backend wants to "resume" the writeback of a page to the
swap device, it can't call swap_writepage() as the page will simply
reenter the backend.

This patch separates swap_writepage() into a top and bottom half, the
bottom half named __swap_writepage() to allow a frontswap backend, like
zswap, to resume writeback beyond the frontswap_store() hook.

__add_to_swap_cache() is also made non-static so that the page for which
writeback is to be resumed can be added to the swap cache.
Signed-off-by: default avatarSeth Jennings <sjenning@linux.vnet.ibm.com>
Signed-off-by: default avatarBob Liu <bob.liu@oracle.com>
Acked-by: default avatarMinchan Kim <minchan@kernel.org>
Reviewed-by: default avatarDan Magenheimer <dan.magenheimer@oracle.com>
Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent e8420a8e
...@@ -330,6 +330,7 @@ static inline void mem_cgroup_uncharge_swap(swp_entry_t ent) ...@@ -330,6 +330,7 @@ static inline void mem_cgroup_uncharge_swap(swp_entry_t ent)
/* linux/mm/page_io.c */ /* linux/mm/page_io.c */
extern int swap_readpage(struct page *); extern int swap_readpage(struct page *);
extern int swap_writepage(struct page *page, struct writeback_control *wbc); extern int swap_writepage(struct page *page, struct writeback_control *wbc);
extern int __swap_writepage(struct page *page, struct writeback_control *wbc);
extern int swap_set_page_dirty(struct page *page); extern int swap_set_page_dirty(struct page *page);
extern void end_swap_bio_read(struct bio *bio, int err); extern void end_swap_bio_read(struct bio *bio, int err);
...@@ -345,6 +346,7 @@ extern unsigned long total_swapcache_pages(void); ...@@ -345,6 +346,7 @@ extern unsigned long total_swapcache_pages(void);
extern void show_swap_cache_info(void); extern void show_swap_cache_info(void);
extern int add_to_swap(struct page *); extern int add_to_swap(struct page *);
extern int add_to_swap_cache(struct page *, swp_entry_t, gfp_t); extern int add_to_swap_cache(struct page *, swp_entry_t, gfp_t);
extern int __add_to_swap_cache(struct page *page, swp_entry_t entry);
extern void __delete_from_swap_cache(struct page *); extern void __delete_from_swap_cache(struct page *);
extern void delete_from_swap_cache(struct page *); extern void delete_from_swap_cache(struct page *);
extern void free_page_and_swap_cache(struct page *); extern void free_page_and_swap_cache(struct page *);
......
...@@ -185,9 +185,7 @@ int generic_swapfile_activate(struct swap_info_struct *sis, ...@@ -185,9 +185,7 @@ int generic_swapfile_activate(struct swap_info_struct *sis,
*/ */
int swap_writepage(struct page *page, struct writeback_control *wbc) int swap_writepage(struct page *page, struct writeback_control *wbc)
{ {
struct bio *bio; int ret = 0;
int ret = 0, rw = WRITE;
struct swap_info_struct *sis = page_swap_info(page);
if (try_to_free_swap(page)) { if (try_to_free_swap(page)) {
unlock_page(page); unlock_page(page);
...@@ -199,6 +197,16 @@ int swap_writepage(struct page *page, struct writeback_control *wbc) ...@@ -199,6 +197,16 @@ int swap_writepage(struct page *page, struct writeback_control *wbc)
end_page_writeback(page); end_page_writeback(page);
goto out; goto out;
} }
ret = __swap_writepage(page, wbc);
out:
return ret;
}
int __swap_writepage(struct page *page, struct writeback_control *wbc)
{
struct bio *bio;
int ret = 0, rw = WRITE;
struct swap_info_struct *sis = page_swap_info(page);
if (sis->flags & SWP_FILE) { if (sis->flags & SWP_FILE) {
struct kiocb kiocb; struct kiocb kiocb;
......
...@@ -78,7 +78,7 @@ void show_swap_cache_info(void) ...@@ -78,7 +78,7 @@ void show_swap_cache_info(void)
* __add_to_swap_cache resembles add_to_page_cache_locked on swapper_space, * __add_to_swap_cache resembles add_to_page_cache_locked on swapper_space,
* but sets SwapCache flag and private instead of mapping and index. * but sets SwapCache flag and private instead of mapping and index.
*/ */
static int __add_to_swap_cache(struct page *page, swp_entry_t entry) int __add_to_swap_cache(struct page *page, swp_entry_t entry)
{ {
int error; int error;
struct address_space *address_space; struct address_space *address_space;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment