]> git.karo-electronics.de Git - karo-tx-linux.git/blobdiff - mm/swapfile.c
Merge tag 'xtensa-20170507' of git://github.com/jcmvbkbc/linux-xtensa
[karo-tx-linux.git] / mm / swapfile.c
index 178130880b908515a105eccf9fa428f7cf61719a..b86b2aca3fb9b10321ea8f6770c7d10905724b2d 100644 (file)
@@ -335,7 +335,7 @@ static void cluster_list_add_tail(struct swap_cluster_list *list,
                ci_tail = ci + tail;
                spin_lock_nested(&ci_tail->lock, SINGLE_DEPTH_NESTING);
                cluster_set_next(ci_tail, idx);
-               unlock_cluster(ci_tail);
+               spin_unlock(&ci_tail->lock);
                cluster_set_next_flag(&list->tail, idx, 0);
        }
 }
@@ -672,6 +672,9 @@ checks:
                else
                        goto done;
        }
+       si->swap_map[offset] = usage;
+       inc_cluster_info_page(si, si->cluster_info, offset);
+       unlock_cluster(ci);
 
        if (offset == si->lowest_bit)
                si->lowest_bit++;
@@ -685,9 +688,6 @@ checks:
                plist_del(&si->avail_list, &swap_avail_head);
                spin_unlock(&swap_avail_lock);
        }
-       si->swap_map[offset] = usage;
-       inc_cluster_info_page(si, si->cluster_info, offset);
-       unlock_cluster(ci);
        si->cluster_next = offset + 1;
        slots[n_ret++] = swp_entry(si->type, offset);
 
@@ -1079,8 +1079,6 @@ void swapcache_free_entries(swp_entry_t *entries, int n)
                p = swap_info_get_cont(entries[i], prev);
                if (p)
                        swap_entry_free(p, entries[i]);
-               else
-                       break;
                prev = p;
        }
        if (p)
@@ -1111,6 +1109,18 @@ int page_swapcount(struct page *page)
        return count;
 }
 
+static int swap_swapcount(struct swap_info_struct *si, swp_entry_t entry)
+{
+       int count = 0;
+       pgoff_t offset = swp_offset(entry);
+       struct swap_cluster_info *ci;
+
+       ci = lock_cluster_or_swap_info(si, offset);
+       count = swap_count(si->swap_map[offset]);
+       unlock_cluster_or_swap_info(si, ci);
+       return count;
+}
+
 /*
  * How many references to @entry are currently swapped out?
  * This does not give an exact answer when swap count is continued,
@@ -1119,17 +1129,11 @@ int page_swapcount(struct page *page)
 int __swp_swapcount(swp_entry_t entry)
 {
        int count = 0;
-       pgoff_t offset;
        struct swap_info_struct *si;
-       struct swap_cluster_info *ci;
 
        si = __swap_info_get(entry);
-       if (si) {
-               offset = swp_offset(entry);
-               ci = lock_cluster_or_swap_info(si, offset);
-               count = swap_count(si->swap_map[offset]);
-               unlock_cluster_or_swap_info(si, ci);
-       }
+       if (si)
+               count = swap_swapcount(si, entry);
        return count;
 }
 
@@ -1291,7 +1295,8 @@ int free_swap_and_cache(swp_entry_t entry)
                 * Also recheck PageSwapCache now page is locked (above).
                 */
                if (PageSwapCache(page) && !PageWriteback(page) &&
-                   (!page_mapped(page) || mem_cgroup_swap_full(page))) {
+                   (!page_mapped(page) || mem_cgroup_swap_full(page)) &&
+                   !swap_swapcount(p, entry)) {
                        delete_from_swap_cache(page);
                        SetPageDirty(page);
                }