Merge git://www.linux-watchdog.org/linux-watchdog
[linux-block.git] / mm / memory-failure.c
index e4683459ab26357090f02bed8f7a2c2628f8cd40..df0694c6adefccfafdc18b0ca7926b900f982234 100644 (file)
@@ -784,12 +784,12 @@ static struct page_state {
        { sc|dirty,     sc|dirty,       "dirty swapcache",      me_swapcache_dirty },
        { sc|dirty,     sc,             "clean swapcache",      me_swapcache_clean },
 
-       { unevict|dirty, unevict|dirty, "dirty unevictable LRU", me_pagecache_dirty },
-       { unevict,      unevict,        "clean unevictable LRU", me_pagecache_clean },
-
        { mlock|dirty,  mlock|dirty,    "dirty mlocked LRU",    me_pagecache_dirty },
        { mlock,        mlock,          "clean mlocked LRU",    me_pagecache_clean },
 
+       { unevict|dirty, unevict|dirty, "dirty unevictable LRU", me_pagecache_dirty },
+       { unevict,      unevict,        "clean unevictable LRU", me_pagecache_clean },
+
        { lru|dirty,    lru|dirty,      "dirty LRU",    me_pagecache_dirty },
        { lru|dirty,    lru,            "clean LRU",    me_pagecache_clean },
 
@@ -1021,6 +1021,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
        struct page *hpage;
        int res;
        unsigned int nr_pages;
+       unsigned long page_flags;
 
        if (!sysctl_memory_failure_recovery)
                panic("Memory failure from trap %d on page %lx", trapno, pfn);
@@ -1128,6 +1129,15 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
         */
        lock_page(hpage);
 
+       /*
+        * We use page flags to determine what action should be taken, but
+        * the flags can be modified by the error containment action.  One
+        * example is an mlocked page, where PG_mlocked is cleared by
+        * page_remove_rmap() in try_to_unmap_one(). So to determine page status
+        * correctly, we save a copy of the page flags at this time.
+        */
+       page_flags = p->flags;
+
        /*
         * unpoison always clear PG_hwpoison inside page lock
         */
@@ -1186,12 +1196,19 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
        }
 
        res = -EBUSY;
-       for (ps = error_states;; ps++) {
-               if ((p->flags & ps->mask) == ps->res) {
-                       res = page_action(ps, p, pfn);
+       /*
+        * The first check uses the current page flags which may not have any
+        * relevant information. The second check with the saved page flagss is
+        * carried out only if the first check can't determine the page status.
+        */
+       for (ps = error_states;; ps++)
+               if ((p->flags & ps->mask) == ps->res)
                        break;
-               }
-       }
+       if (!ps->mask)
+               for (ps = error_states;; ps++)
+                       if ((page_flags & ps->mask) == ps->res)
+                               break;
+       res = page_action(ps, p, pfn);
 out:
        unlock_page(hpage);
        return res;