mm/truncate: bail out early from invalidate_inode_pages2_range() if mapping is empty
authorAndrey Ryabinin <aryabinin@virtuozzo.com>
Wed, 3 May 2017 21:56:06 +0000 (14:56 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Wed, 3 May 2017 22:52:12 +0000 (15:52 -0700)
If mapping is empty (both ->nrpages and ->nrexceptional is zero) we can
avoid pointless lookups in empty radix tree and bail out immediately
after cleancache invalidation.

Link: http://lkml.kernel.org/r/20170424164135.22350-4-aryabinin@virtuozzo.com
Signed-off-by: Andrey Ryabinin <aryabinin@virtuozzo.com>
Reviewed-by: Jan Kara <jack@suse.cz>
Acked-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
Cc: Ross Zwisler <ross.zwisler@linux.intel.com>
Cc: Jens Axboe <axboe@kernel.dk>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Alexey Kuznetsov <kuznet@virtuozzo.com>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Nikolay Borisov <n.borisov.lkml@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
mm/truncate.c

index 6263affdef8866135f28256b5b1f5e598515d204..8f12b0e2e85f9a55efa2a82d839f3233233b7118 100644 (file)
@@ -624,6 +624,9 @@ int invalidate_inode_pages2_range(struct address_space *mapping,
        int did_range_unmap = 0;
 
        cleancache_invalidate_inode(mapping);
+       if (mapping->nrpages == 0 && mapping->nrexceptional == 0)
+               return 0;
+
        pagevec_init(&pvec, 0);
        index = start;
        while (index <= end && pagevec_lookup_entries(&pvec, mapping, index,