summaryrefslogtreecommitdiffstats
path: root/mm/swapfile.c
diff options
context:
space:
mode:
authorOmar Sandoval <osandov@fb.com>2018-10-26 18:10:51 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2018-10-26 19:38:15 -0400
commitbc4ae27d817a4e92071ef67cb6368120cfabe7ec (patch)
treeaaa6b5b87cad72a3839ed10f9b06ea21030759dc /mm/swapfile.c
parent91cbacc34512e37c9bb89125ca4b224ca6459245 (diff)
mm: split SWP_FILE into SWP_ACTIVATED and SWP_FS
The SWP_FILE flag serves two purposes: to make swap_{read,write}page() go through the filesystem, and to make swapoff() call ->swap_deactivate(). For Btrfs, we want the latter but not the former, so split this flag into two. This makes us always call ->swap_deactivate() if ->swap_activate() succeeded, not just if it didn't add any swap extents itself. This also resolves the issue of the very misleading name of SWP_FILE, which is only used for swap files over NFS. Link: http://lkml.kernel.org/r/6d63d8668c4287a4f6d203d65696e96f80abdfc7.1536704650.git.osandov@fb.com Signed-off-by: Omar Sandoval <osandov@fb.com> Reviewed-by: Nikolay Borisov <nborisov@suse.com> Reviewed-by: Andrew Morton <akpm@linux-foundation.org> Cc: Johannes Weiner <hannes@cmpxchg.org> Cc: David Sterba <dsterba@suse.cz> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'mm/swapfile.c')
-rw-r--r--mm/swapfile.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/mm/swapfile.c b/mm/swapfile.c
index 2681e50592c5..f0c7e4c11bab 100644
--- a/mm/swapfile.c
+++ b/mm/swapfile.c
@@ -1003,7 +1003,7 @@ start_over:
1003 goto nextsi; 1003 goto nextsi;
1004 } 1004 }
1005 if (size == SWAPFILE_CLUSTER) { 1005 if (size == SWAPFILE_CLUSTER) {
1006 if (!(si->flags & SWP_FILE)) 1006 if (!(si->flags & SWP_FS))
1007 n_ret = swap_alloc_cluster(si, swp_entries); 1007 n_ret = swap_alloc_cluster(si, swp_entries);
1008 } else 1008 } else
1009 n_ret = scan_swap_map_slots(si, SWAP_HAS_CACHE, 1009 n_ret = scan_swap_map_slots(si, SWAP_HAS_CACHE,
@@ -2299,12 +2299,13 @@ static void destroy_swap_extents(struct swap_info_struct *sis)
2299 kfree(se); 2299 kfree(se);
2300 } 2300 }
2301 2301
2302 if (sis->flags & SWP_FILE) { 2302 if (sis->flags & SWP_ACTIVATED) {
2303 struct file *swap_file = sis->swap_file; 2303 struct file *swap_file = sis->swap_file;
2304 struct address_space *mapping = swap_file->f_mapping; 2304 struct address_space *mapping = swap_file->f_mapping;
2305 2305
2306 sis->flags &= ~SWP_FILE; 2306 sis->flags &= ~SWP_ACTIVATED;
2307 mapping->a_ops->swap_deactivate(swap_file); 2307 if (mapping->a_ops->swap_deactivate)
2308 mapping->a_ops->swap_deactivate(swap_file);
2308 } 2309 }
2309} 2310}
2310 2311
@@ -2400,8 +2401,10 @@ static int setup_swap_extents(struct swap_info_struct *sis, sector_t *span)
2400 2401
2401 if (mapping->a_ops->swap_activate) { 2402 if (mapping->a_ops->swap_activate) {
2402 ret = mapping->a_ops->swap_activate(sis, swap_file, span); 2403 ret = mapping->a_ops->swap_activate(sis, swap_file, span);
2404 if (ret >= 0)
2405 sis->flags |= SWP_ACTIVATED;
2403 if (!ret) { 2406 if (!ret) {
2404 sis->flags |= SWP_FILE; 2407 sis->flags |= SWP_FS;
2405 ret = add_swap_extent(sis, 0, sis->max, 0); 2408 ret = add_swap_extent(sis, 0, sis->max, 0);
2406 *span = sis->pages; 2409 *span = sis->pages;
2407 } 2410 }