mm/shmem: use pagevec_lookup in shmem_unlock_mapping
authorMatthew Wilcox (Oracle) <willy@infradead.org>
Fri, 26 Feb 2021 01:15:29 +0000 (17:15 -0800)
committerLinus Torvalds <torvalds@linux-foundation.org>
Fri, 26 Feb 2021 17:40:59 +0000 (09:40 -0800)
The comment shows that the reason for using find_get_entries() is now
stale; find_get_pages() will not return 0 if it hits a consecutive run of
swap entries, and I don't believe it has since 2011.  pagevec_lookup() is
a simpler function to use than find_get_pages(), so use it instead.

Link: https://lkml.kernel.org/r/20201112212641.27837-3-willy@infradead.org
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Reviewed-by: Jan Kara <jack@suse.cz>
Reviewed-by: William Kucharski <william.kucharski@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Cc: Dave Chinner <dchinner@redhat.com>
Cc: Hugh Dickins <hughd@google.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Cc: Yang Shi <yang.shi@linux.alibaba.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
mm/shmem.c

index ff741d2..5ea1fa5 100644 (file)
@@ -842,7 +842,6 @@ unsigned long shmem_swap_usage(struct vm_area_struct *vma)
 void shmem_unlock_mapping(struct address_space *mapping)
 {
        struct pagevec pvec;
-       pgoff_t indices[PAGEVEC_SIZE];
        pgoff_t index = 0;
 
        pagevec_init(&pvec);
@@ -850,16 +849,8 @@ void shmem_unlock_mapping(struct address_space *mapping)
         * Minor point, but we might as well stop if someone else SHM_LOCKs it.
         */
        while (!mapping_unevictable(mapping)) {
-               /*
-                * Avoid pagevec_lookup(): find_get_pages() returns 0 as if it
-                * has finished, if it hits a row of PAGEVEC_SIZE swap entries.
-                */
-               pvec.nr = find_get_entries(mapping, index,
-                                          PAGEVEC_SIZE, pvec.pages, indices);
-               if (!pvec.nr)
+               if (!pagevec_lookup(&pvec, mapping, &index))
                        break;
-               index = indices[pvec.nr - 1] + 1;
-               pagevec_remove_exceptionals(&pvec);
                check_move_unevictable_pages(&pvec);
                pagevec_release(&pvec);
                cond_resched();