pgoff_t uninitialized_var(writeback_index);
        pgoff_t index;
        pgoff_t end;            /* Inclusive */
+       pgoff_t done_index;
        int cycled;
        int range_whole = 0;
        long nr_to_write = wbc->nr_to_write;
                cycled = 1; /* ignore range_cyclic tests */
        }
 retry:
+       done_index = index;
        while (!done && (index <= end) &&
               (nr_pages = pagevec_lookup_tag(&pvec, mapping, &index,
                                              PAGECACHE_TAG_DIRTY,
                for (i = 0; i < nr_pages; i++) {
                        struct page *page = pvec.pages[i];
 
+                       done_index = page->index + 1;
+
                        /*
                         * At this point we hold neither mapping->tree_lock nor
                         * lock on the page itself: the page may be truncated or
        }
        if (!wbc->no_nrwrite_index_update) {
                if (wbc->range_cyclic || (range_whole && nr_to_write > 0))
-                       mapping->writeback_index = index;
+                       mapping->writeback_index = done_index;
                wbc->nr_to_write = nr_to_write;
        }