ceph: have ceph_writepages_start call pagevec_lookup_range_tag
authorJeff Layton <jlayton@kernel.org>
Mon, 14 Sep 2020 17:30:36 +0000 (13:30 -0400)
committerIlya Dryomov <idryomov@gmail.com>
Mon, 12 Oct 2020 13:29:26 +0000 (15:29 +0200)
Currently it calls pagevec_lookup_range_nr_tag(), but that may be
inefficient, as we might end up having to search several times as we get
down to looking for fewer pages to fill the array.

Thus spake Willy:

"I think ceph is misusing pagevec_lookup_range_nr_tag().  Let's suppose
 you get a range which is AAAAbbbbAAAAbbbbAAAAbbbbbbbb(...)bbbbAAAA and
 you try to fetch max_pages=13.  First loop will get AAAAbbbbAAAAb and
 have 8 locked_pages.  The next call will get bbbAA and now
 locked_pages=10.  Next call gets AAb ... and now you're iterating your
 way through all the 'b' one page at a time until you find that first A."

'A' here refers to pages that are eligible for writeback and 'b'
represents ones that aren't (for whatever reason).

Not capping the number of return pages may mean that we sometimes find
more pages than are needed, but the extra references will just get put
at the end.

Ceph is also the only caller of pagevec_lookup_range_nr_tag(), so this
change should allow us to eliminate that call as well. That will be done
in a follow-on patch.

Reported-by: Matthew Wilcox <willy@infradead.org>
Signed-off-by: Jeff Layton <jlayton@kernel.org>
Reviewed-by: Matthew Wilcox <willy@infradead.org>
Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
fs/ceph/addr.c

index 6ea761c..b03dbaa 100644 (file)
@@ -962,9 +962,8 @@ retry:
                max_pages = wsize >> PAGE_SHIFT;
 
 get_more_pages:
                max_pages = wsize >> PAGE_SHIFT;
 
 get_more_pages:
-               pvec_pages = pagevec_lookup_range_nr_tag(&pvec, mapping, &index,
-                                               end, PAGECACHE_TAG_DIRTY,
-                                               max_pages - locked_pages);
+               pvec_pages = pagevec_lookup_range_tag(&pvec, mapping, &index,
+                                               end, PAGECACHE_TAG_DIRTY);
                dout("pagevec_lookup_range_tag got %d\n", pvec_pages);
                if (!pvec_pages && !locked_pages)
                        break;
                dout("pagevec_lookup_range_tag got %d\n", pvec_pages);
                if (!pvec_pages && !locked_pages)
                        break;