]> asedeno.scripts.mit.edu Git - linux.git/blobdiff - mm/swapfile.c
Merge tag 'ceph-for-4.20-rc1' of git://github.com/ceph/ceph-client
[linux.git] / mm / swapfile.c
index eaa5e2e55cabecd344263e6ea8839917ac2b9eeb..644f746e167acd65e8244088f483e50c71afbf20 100644 (file)
@@ -932,6 +932,7 @@ static void swap_free_cluster(struct swap_info_struct *si, unsigned long idx)
        struct swap_cluster_info *ci;
 
        ci = lock_cluster(si, offset);
+       memset(si->swap_map + offset, 0, SWAPFILE_CLUSTER);
        cluster_set_count_flag(ci, 0, 0);
        free_cluster(si, idx);
        unlock_cluster(ci);
@@ -1002,7 +1003,7 @@ int get_swap_pages(int n_goal, swp_entry_t swp_entries[], int entry_size)
                        goto nextsi;
                }
                if (size == SWAPFILE_CLUSTER) {
-                       if (!(si->flags & SWP_FILE))
+                       if (!(si->flags & SWP_FS))
                                n_ret = swap_alloc_cluster(si, swp_entries);
                } else
                        n_ret = scan_swap_map_slots(si, SWAP_HAS_CACHE,
@@ -1250,9 +1251,6 @@ void put_swap_page(struct page *page, swp_entry_t entry)
                if (free_entries == SWAPFILE_CLUSTER) {
                        unlock_cluster_or_swap_info(si, ci);
                        spin_lock(&si->lock);
-                       ci = lock_cluster(si, offset);
-                       memset(map, 0, SWAPFILE_CLUSTER);
-                       unlock_cluster(ci);
                        mem_cgroup_uncharge_swap(entry, SWAPFILE_CLUSTER);
                        swap_free_cluster(si, idx);
                        spin_unlock(&si->lock);
@@ -2301,12 +2299,13 @@ static void destroy_swap_extents(struct swap_info_struct *sis)
                kfree(se);
        }
 
-       if (sis->flags & SWP_FILE) {
+       if (sis->flags & SWP_ACTIVATED) {
                struct file *swap_file = sis->swap_file;
                struct address_space *mapping = swap_file->f_mapping;
 
-               sis->flags &= ~SWP_FILE;
-               mapping->a_ops->swap_deactivate(swap_file);
+               sis->flags &= ~SWP_ACTIVATED;
+               if (mapping->a_ops->swap_deactivate)
+                       mapping->a_ops->swap_deactivate(swap_file);
        }
 }
 
@@ -2355,6 +2354,7 @@ add_swap_extent(struct swap_info_struct *sis, unsigned long start_page,
        list_add_tail(&new_se->list, &sis->first_swap_extent.list);
        return 1;
 }
+EXPORT_SYMBOL_GPL(add_swap_extent);
 
 /*
  * A `swap extent' is a simple thing which maps a contiguous range of pages
@@ -2402,8 +2402,10 @@ static int setup_swap_extents(struct swap_info_struct *sis, sector_t *span)
 
        if (mapping->a_ops->swap_activate) {
                ret = mapping->a_ops->swap_activate(sis, swap_file, span);
+               if (ret >= 0)
+                       sis->flags |= SWP_ACTIVATED;
                if (!ret) {
-                       sis->flags |= SWP_FILE;
+                       sis->flags |= SWP_FS;
                        ret = add_swap_extent(sis, 0, sis->max, 0);
                        *span = sis->pages;
                }