]> asedeno.scripts.mit.edu Git - linux.git/blobdiff - mm/swapfile.c
mm: nobootmem: remove bootmem allocation APIs
[linux.git] / mm / swapfile.c
index 0d44179213ed0cbf96923b53c505f949ff3090f6..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,
@@ -1182,6 +1183,8 @@ static unsigned char __swap_entry_free(struct swap_info_struct *p,
        ci = lock_cluster_or_swap_info(p, offset);
        usage = __swap_entry_free_locked(p, offset, usage);
        unlock_cluster_or_swap_info(p, ci);
+       if (!usage)
+               free_swap_slot(entry);
 
        return usage;
 }
@@ -1212,10 +1215,8 @@ void swap_free(swp_entry_t entry)
        struct swap_info_struct *p;
 
        p = _swap_info_get(entry);
-       if (p) {
-               if (!__swap_entry_free(p, entry, 1))
-                       free_swap_slot(entry);
-       }
+       if (p)
+               __swap_entry_free(p, entry, 1);
 }
 
 /*
@@ -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);
@@ -1637,8 +1635,6 @@ int free_swap_and_cache(swp_entry_t entry)
                    !swap_page_trans_huge_swapped(p, entry))
                        __try_to_reclaim_swap(p, swp_offset(entry),
                                              TTRS_UNMAPPED | TTRS_FULL);
-               else if (!count)
-                       free_swap_slot(entry);
        }
        return p != NULL;
 }
@@ -2303,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);
        }
 }
 
@@ -2357,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
@@ -2404,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;
                }