Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/linville/wirel...
[pandora-kernel.git] / mm / filemap.c
index 76bfb64..645a080 100644 (file)
@@ -33,7 +33,6 @@
 #include <linux/cpuset.h>
 #include <linux/hardirq.h> /* for BUG_ON(!in_atomic()) only */
 #include <linux/memcontrol.h>
-#include <linux/mm_inline.h> /* for page_is_file_cache() */
 #include <linux/cleancache.h>
 #include "internal.h"
 
@@ -462,6 +461,7 @@ int add_to_page_cache_locked(struct page *page, struct address_space *mapping,
        int error;
 
        VM_BUG_ON(!PageLocked(page));
+       VM_BUG_ON(PageSwapBacked(page));
 
        error = mem_cgroup_cache_charge(page, current->mm,
                                        gfp_mask & GFP_RECLAIM_MASK);
@@ -479,8 +479,6 @@ int add_to_page_cache_locked(struct page *page, struct address_space *mapping,
                if (likely(!error)) {
                        mapping->nrpages++;
                        __inc_zone_page_state(page, NR_FILE_PAGES);
-                       if (PageSwapBacked(page))
-                               __inc_zone_page_state(page, NR_SHMEM);
                        spin_unlock_irq(&mapping->tree_lock);
                } else {
                        page->mapping = NULL;
@@ -502,22 +500,9 @@ int add_to_page_cache_lru(struct page *page, struct address_space *mapping,
 {
        int ret;
 
-       /*
-        * Splice_read and readahead add shmem/tmpfs pages into the page cache
-        * before shmem_readpage has a chance to mark them as SwapBacked: they
-        * need to go on the anon lru below, and mem_cgroup_cache_charge
-        * (called in add_to_page_cache) needs to know where they're going too.
-        */
-       if (mapping_cap_swap_backed(mapping))
-               SetPageSwapBacked(page);
-
        ret = add_to_page_cache(page, mapping, offset, gfp_mask);
-       if (ret == 0) {
-               if (page_is_file_cache(page))
-                       lru_cache_add_file(page);
-               else
-                       lru_cache_add_anon(page);
-       }
+       if (ret == 0)
+               lru_cache_add_file(page);
        return ret;
 }
 EXPORT_SYMBOL_GPL(add_to_page_cache_lru);
@@ -715,10 +700,14 @@ repeat:
                if (unlikely(!page))
                        goto out;
                if (radix_tree_exception(page)) {
-                       if (radix_tree_exceptional_entry(page))
-                               goto out;
-                       /* radix_tree_deref_retry(page) */
-                       goto repeat;
+                       if (radix_tree_deref_retry(page))
+                               goto repeat;
+                       /*
+                        * Otherwise, shmem/tmpfs must be storing a swap entry
+                        * here as an exceptional entry: so return it without
+                        * attempting to raise page count.
+                        */
+                       goto out;
                }
                if (!page_cache_get_speculative(page))
                        goto repeat;
@@ -853,15 +842,21 @@ repeat:
                        continue;
 
                if (radix_tree_exception(page)) {
-                       if (radix_tree_exceptional_entry(page))
-                               continue;
+                       if (radix_tree_deref_retry(page)) {
+                               /*
+                                * Transient condition which can only trigger
+                                * when entry at index 0 moves out of or back
+                                * to root: none yet gotten, safe to restart.
+                                */
+                               WARN_ON(start | i);
+                               goto restart;
+                       }
                        /*
-                        * radix_tree_deref_retry(page):
-                        * can only trigger when entry at index 0 moves out of
-                        * or back to root: none yet gotten, safe to restart.
+                        * Otherwise, shmem/tmpfs must be storing a swap entry
+                        * here as an exceptional entry: so skip over it -
+                        * we only reach this from invalidate_mapping_pages().
                         */
-                       WARN_ON(start | i);
-                       goto restart;
+                       continue;
                }
 
                if (!page_cache_get_speculative(page))
@@ -919,14 +914,20 @@ repeat:
                        continue;
 
                if (radix_tree_exception(page)) {
-                       if (radix_tree_exceptional_entry(page))
-                               break;
+                       if (radix_tree_deref_retry(page)) {
+                               /*
+                                * Transient condition which can only trigger
+                                * when entry at index 0 moves out of or back
+                                * to root: none yet gotten, safe to restart.
+                                */
+                               goto restart;
+                       }
                        /*
-                        * radix_tree_deref_retry(page):
-                        * can only trigger when entry at index 0 moves out of
-                        * or back to root: none yet gotten, safe to restart.
+                        * Otherwise, shmem/tmpfs must be storing a swap entry
+                        * here as an exceptional entry: so stop looking for
+                        * contiguous pages.
                         */
-                       goto restart;
+                       break;
                }
 
                if (!page_cache_get_speculative(page))
@@ -988,13 +989,19 @@ repeat:
                        continue;
 
                if (radix_tree_exception(page)) {
-                       BUG_ON(radix_tree_exceptional_entry(page));
+                       if (radix_tree_deref_retry(page)) {
+                               /*
+                                * Transient condition which can only trigger
+                                * when entry at index 0 moves out of or back
+                                * to root: none yet gotten, safe to restart.
+                                */
+                               goto restart;
+                       }
                        /*
-                        * radix_tree_deref_retry(page):
-                        * can only trigger when entry at index 0 moves out of
-                        * or back to root: none yet gotten, safe to restart.
+                        * This function is never used on a shmem/tmpfs
+                        * mapping, so a swap entry won't be found here.
                         */
-                       goto restart;
+                       BUG();
                }
 
                if (!page_cache_get_speculative(page))