{
        struct zoneref *z;
        struct zone *zone;
-       bool fair_skipped;
-       bool zonelist_rescan;
+       bool fair_skipped = false;
+       bool apply_fair = (alloc_flags & ALLOC_FAIR);
 
 zonelist_scan:
-       zonelist_rescan = false;
-
        /*
         * Scan zonelist, looking for a zone with enough free.
         * See also __cpuset_node_allowed() comment in kernel/cpuset.c.
                 * page was allocated in should have no effect on the
                 * time the page has in memory before being reclaimed.
                 */
-               if (alloc_flags & ALLOC_FAIR) {
-                       if (!zone_local(ac->preferred_zone, zone))
-                               break;
+               if (apply_fair) {
                        if (test_bit(ZONE_FAIR_DEPLETED, &zone->flags)) {
                                fair_skipped = true;
                                continue;
                        }
+                       if (!zone_local(ac->preferred_zone, zone)) {
+                               if (fair_skipped)
+                                       goto reset_fair;
+                               apply_fair = false;
+                       }
                }
                /*
                 * When allocating a page cache page for writing, we
         * include remote zones now, before entering the slowpath and waking
         * kswapd: prefer spilling to a remote zone over swapping locally.
         */
-       if (alloc_flags & ALLOC_FAIR) {
-               alloc_flags &= ~ALLOC_FAIR;
-               if (fair_skipped) {
-                       zonelist_rescan = true;
-                       reset_alloc_batches(ac->preferred_zone);
-               }
-               if (nr_online_nodes > 1)
-                       zonelist_rescan = true;
-       }
-
-       if (zonelist_rescan)
+       if (fair_skipped) {
+reset_fair:
+               apply_fair = false;
+               fair_skipped = false;
+               reset_alloc_batches(ac->preferred_zone);
                goto zonelist_scan;
+       }
 
        return NULL;
 }