diff options
author | Dmitry Safonov <0x7f454c46@gmail.com> | 2015-09-08 18:05:00 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2015-09-08 18:35:28 -0400 |
commit | 5b999aadbae65696a148f55250d94b6f3d74071e (patch) | |
tree | 3148d29e63658131dd762df51403bdba5bc77502 /mm/swap_state.c | |
parent | 708649694a8699ff91d395c4aef5ecea3ade14bc (diff) |
mm: swap: zswap: maybe_preload & refactoring
zswap_get_swap_cache_page and read_swap_cache_async have pretty much the
same code with only significant difference in return value and usage of
swap_readpage.
I a helper __read_swap_cache_async() with the common code. Behavior
change: now zswap_get_swap_cache_page will use radix_tree_maybe_preload
instead radix_tree_preload. Looks like, this wasn't changed only by the
reason of code duplication.
Signed-off-by: Dmitry Safonov <0x7f454c46@gmail.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Vladimir Davydov <vdavydov@parallels.com>
Cc: Michal Hocko <mhocko@suse.cz>
Cc: Hugh Dickins <hughd@google.com>
Cc: Minchan Kim <minchan@kernel.org>
Cc: Tejun Heo <tj@kernel.org>
Cc: Jens Axboe <axboe@fb.com>
Cc: Christoph Hellwig <hch@lst.de>
Cc: David Herrmann <dh.herrmann@gmail.com>
Cc: Seth Jennings <sjennings@variantweb.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'mm/swap_state.c')
-rw-r--r-- | mm/swap_state.c | 37 |
1 files changed, 26 insertions, 11 deletions
diff --git a/mm/swap_state.c b/mm/swap_state.c index 8bc8e66138da..d504adb7fa5f 100644 --- a/mm/swap_state.c +++ b/mm/swap_state.c | |||
@@ -288,17 +288,14 @@ struct page * lookup_swap_cache(swp_entry_t entry) | |||
288 | return page; | 288 | return page; |
289 | } | 289 | } |
290 | 290 | ||
291 | /* | 291 | struct page *__read_swap_cache_async(swp_entry_t entry, gfp_t gfp_mask, |
292 | * Locate a page of swap in physical memory, reserving swap cache space | 292 | struct vm_area_struct *vma, unsigned long addr, |
293 | * and reading the disk if it is not already cached. | 293 | bool *new_page_allocated) |
294 | * A failure return means that either the page allocation failed or that | ||
295 | * the swap entry is no longer in use. | ||
296 | */ | ||
297 | struct page *read_swap_cache_async(swp_entry_t entry, gfp_t gfp_mask, | ||
298 | struct vm_area_struct *vma, unsigned long addr) | ||
299 | { | 294 | { |
300 | struct page *found_page, *new_page = NULL; | 295 | struct page *found_page, *new_page = NULL; |
296 | struct address_space *swapper_space = swap_address_space(entry); | ||
301 | int err; | 297 | int err; |
298 | *new_page_allocated = false; | ||
302 | 299 | ||
303 | do { | 300 | do { |
304 | /* | 301 | /* |
@@ -306,8 +303,7 @@ struct page *read_swap_cache_async(swp_entry_t entry, gfp_t gfp_mask, | |||
306 | * called after lookup_swap_cache() failed, re-calling | 303 | * called after lookup_swap_cache() failed, re-calling |
307 | * that would confuse statistics. | 304 | * that would confuse statistics. |
308 | */ | 305 | */ |
309 | found_page = find_get_page(swap_address_space(entry), | 306 | found_page = find_get_page(swapper_space, entry.val); |
310 | entry.val); | ||
311 | if (found_page) | 307 | if (found_page) |
312 | break; | 308 | break; |
313 | 309 | ||
@@ -366,7 +362,7 @@ struct page *read_swap_cache_async(swp_entry_t entry, gfp_t gfp_mask, | |||
366 | * Initiate read into locked page and return. | 362 | * Initiate read into locked page and return. |
367 | */ | 363 | */ |
368 | lru_cache_add_anon(new_page); | 364 | lru_cache_add_anon(new_page); |
369 | swap_readpage(new_page); | 365 | *new_page_allocated = true; |
370 | return new_page; | 366 | return new_page; |
371 | } | 367 | } |
372 | radix_tree_preload_end(); | 368 | radix_tree_preload_end(); |
@@ -384,6 +380,25 @@ struct page *read_swap_cache_async(swp_entry_t entry, gfp_t gfp_mask, | |||
384 | return found_page; | 380 | return found_page; |
385 | } | 381 | } |
386 | 382 | ||
383 | /* | ||
384 | * Locate a page of swap in physical memory, reserving swap cache space | ||
385 | * and reading the disk if it is not already cached. | ||
386 | * A failure return means that either the page allocation failed or that | ||
387 | * the swap entry is no longer in use. | ||
388 | */ | ||
389 | struct page *read_swap_cache_async(swp_entry_t entry, gfp_t gfp_mask, | ||
390 | struct vm_area_struct *vma, unsigned long addr) | ||
391 | { | ||
392 | bool page_was_allocated; | ||
393 | struct page *retpage = __read_swap_cache_async(entry, gfp_mask, | ||
394 | vma, addr, &page_was_allocated); | ||
395 | |||
396 | if (page_was_allocated) | ||
397 | swap_readpage(retpage); | ||
398 | |||
399 | return retpage; | ||
400 | } | ||
401 | |||
387 | static unsigned long swapin_nr_pages(unsigned long offset) | 402 | static unsigned long swapin_nr_pages(unsigned long offset) |
388 | { | 403 | { |
389 | static unsigned long prev_offset; | 404 | static unsigned long prev_offset; |