* [PATCH 01/15] mm: Implement find_get_pages_range_tag()
  2017-09-27 16:03 [PATCH 0/15 v2] Ranged pagevec tagged lookup Jan Kara
@ 2017-09-27 16:03 ` Jan Kara
  2017-09-27 16:03 ` [PATCH 02/15] btrfs: Use pagevec_lookup_range_tag() Jan Kara
                   ` (13 subsequent siblings)
  14 siblings, 0 replies; 27+ messages in thread
From: Jan Kara @ 2017-09-27 16:03 UTC (permalink / raw)
  To: Andrew Morton; +Cc: linux-mm, linux-fsdevel, Jan Kara
Implement a variant of find_get_pages_tag() that stops iterating at
given index. Lots of users of this function (through pagevec_lookup())
actually want a range lookup and all of them are currently open-coding
this.
Also create corresponding pagevec_lookup_range_tag() function.
Signed-off-by: Jan Kara <jack@suse.cz>
---
 include/linux/pagemap.h | 12 ++++++++++--
 include/linux/pagevec.h | 11 +++++++++--
 mm/filemap.c            | 33 ++++++++++++++++++++++++---------
 mm/swap.c               |  9 +++++----
 4 files changed, 48 insertions(+), 17 deletions(-)
diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h
index 5bbd6780f205..75cd074a23b4 100644
--- a/include/linux/pagemap.h
+++ b/include/linux/pagemap.h
@@ -365,8 +365,16 @@ static inline unsigned find_get_pages(struct address_space *mapping,
 }
 unsigned find_get_pages_contig(struct address_space *mapping, pgoff_t start,
 			       unsigned int nr_pages, struct page **pages);
-unsigned find_get_pages_tag(struct address_space *mapping, pgoff_t *index,
-			int tag, unsigned int nr_pages, struct page **pages);
+unsigned find_get_pages_range_tag(struct address_space *mapping, pgoff_t *index,
+			pgoff_t end, int tag, unsigned int nr_pages,
+			struct page **pages);
+static inline unsigned find_get_pages_tag(struct address_space *mapping,
+			pgoff_t *index, int tag, unsigned int nr_pages,
+			struct page **pages)
+{
+	return find_get_pages_range_tag(mapping, index, (pgoff_t)-1, tag,
+					nr_pages, pages);
+}
 unsigned find_get_entries_tag(struct address_space *mapping, pgoff_t start,
 			int tag, unsigned int nr_entries,
 			struct page **entries, pgoff_t *indices);
diff --git a/include/linux/pagevec.h b/include/linux/pagevec.h
index 4dcd5506f1ed..371edacc10d5 100644
--- a/include/linux/pagevec.h
+++ b/include/linux/pagevec.h
@@ -37,9 +37,16 @@ static inline unsigned pagevec_lookup(struct pagevec *pvec,
 	return pagevec_lookup_range(pvec, mapping, start, (pgoff_t)-1);
 }
 
-unsigned pagevec_lookup_tag(struct pagevec *pvec,
+unsigned pagevec_lookup_range_tag(struct pagevec *pvec,
+		struct address_space *mapping, pgoff_t *index, pgoff_t end,
+		int tag, unsigned nr_pages);
+static inline unsigned pagevec_lookup_tag(struct pagevec *pvec,
 		struct address_space *mapping, pgoff_t *index, int tag,
-		unsigned nr_pages);
+		unsigned nr_pages)
+{
+	return pagevec_lookup_range_tag(pvec, mapping, index, (pgoff_t)-1, tag,
+					nr_pages);
+}
 
 static inline void pagevec_init(struct pagevec *pvec, int cold)
 {
diff --git a/mm/filemap.c b/mm/filemap.c
index 9d21afd692b9..fe20329c83cd 100644
--- a/mm/filemap.c
+++ b/mm/filemap.c
@@ -1726,9 +1726,10 @@ unsigned find_get_pages_contig(struct address_space *mapping, pgoff_t index,
 EXPORT_SYMBOL(find_get_pages_contig);
 
 /**
- * find_get_pages_tag - find and return pages that match @tag
+ * find_get_pages_range_tag - find and return pages in given range matching @tag
  * @mapping:	the address_space to search
  * @index:	the starting page index
+ * @end:	The final page index (inclusive)
  * @tag:	the tag index
  * @nr_pages:	the maximum number of pages
  * @pages:	where the resulting pages are placed
@@ -1736,8 +1737,9 @@ EXPORT_SYMBOL(find_get_pages_contig);
  * Like find_get_pages, except we only return pages which are tagged with
  * @tag.   We update @index to index the next page for the traversal.
  */
-unsigned find_get_pages_tag(struct address_space *mapping, pgoff_t *index,
-			int tag, unsigned int nr_pages, struct page **pages)
+unsigned find_get_pages_range_tag(struct address_space *mapping, pgoff_t *index,
+			pgoff_t end, int tag, unsigned int nr_pages,
+			struct page **pages)
 {
 	struct radix_tree_iter iter;
 	void **slot;
@@ -1750,6 +1752,9 @@ unsigned find_get_pages_tag(struct address_space *mapping, pgoff_t *index,
 	radix_tree_for_each_tagged(slot, &mapping->page_tree,
 				   &iter, *index, tag) {
 		struct page *head, *page;
+
+		if (iter.index > end)
+			break;
 repeat:
 		page = radix_tree_deref_slot(slot);
 		if (unlikely(!page))
@@ -1791,18 +1796,28 @@ unsigned find_get_pages_tag(struct address_space *mapping, pgoff_t *index,
 		}
 
 		pages[ret] = page;
-		if (++ret == nr_pages)
-			break;
+		if (++ret == nr_pages) {
+			*index = pages[ret - 1]->index + 1;
+			goto out;
+		}
 	}
 
+	/*
+	 * We come here when we got at @end. We take care to not overflow the
+	 * index @index as it confuses some of the callers. This breaks the
+	 * iteration when there is page at index -1 but that is already broken
+	 * anyway.
+	 */
+	if (end == (pgoff_t)-1)
+		*index = (pgoff_t)-1;
+	else
+		*index = end + 1;
+out:
 	rcu_read_unlock();
 
-	if (ret)
-		*index = pages[ret - 1]->index + 1;
-
 	return ret;
 }
-EXPORT_SYMBOL(find_get_pages_tag);
+EXPORT_SYMBOL(find_get_pages_range_tag);
 
 /**
  * find_get_entries_tag - find and return entries that match @tag
diff --git a/mm/swap.c b/mm/swap.c
index 9295ae960d66..a00065f2a8f2 100644
--- a/mm/swap.c
+++ b/mm/swap.c
@@ -986,14 +986,15 @@ unsigned pagevec_lookup_range(struct pagevec *pvec,
 }
 EXPORT_SYMBOL(pagevec_lookup_range);
 
-unsigned pagevec_lookup_tag(struct pagevec *pvec, struct address_space *mapping,
-		pgoff_t *index, int tag, unsigned nr_pages)
+unsigned pagevec_lookup_range_tag(struct pagevec *pvec,
+		struct address_space *mapping, pgoff_t *index, pgoff_t end,
+		int tag, unsigned nr_pages)
 {
-	pvec->nr = find_get_pages_tag(mapping, index, tag,
+	pvec->nr = find_get_pages_range_tag(mapping, index, end, tag,
 					nr_pages, pvec->pages);
 	return pagevec_count(pvec);
 }
-EXPORT_SYMBOL(pagevec_lookup_tag);
+EXPORT_SYMBOL(pagevec_lookup_range_tag);
 
 /*
  * Perform any setup for the swap system
-- 
2.12.3
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply related	[flat|nested] 27+ messages in thread* [PATCH 02/15] btrfs: Use pagevec_lookup_range_tag()
  2017-09-27 16:03 [PATCH 0/15 v2] Ranged pagevec tagged lookup Jan Kara
  2017-09-27 16:03 ` [PATCH 01/15] mm: Implement find_get_pages_range_tag() Jan Kara
@ 2017-09-27 16:03 ` Jan Kara
  2017-09-27 16:03 ` [PATCH 03/15] ceph: " Jan Kara
                   ` (12 subsequent siblings)
  14 siblings, 0 replies; 27+ messages in thread
From: Jan Kara @ 2017-09-27 16:03 UTC (permalink / raw)
  To: Andrew Morton
  Cc: linux-mm, linux-fsdevel, Jan Kara, linux-btrfs, David Sterba
We want only pages from given range in btree_write_cache_pages() and
extent_write_cache_pages(). Use pagevec_lookup_range_tag() instead of
pagevec_lookup_tag() and remove unnecessary code.
CC: linux-btrfs@vger.kernel.org
CC: David Sterba <dsterba@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: Jan Kara <jack@suse.cz>
---
 fs/btrfs/extent_io.c | 19 ++++---------------
 1 file changed, 4 insertions(+), 15 deletions(-)
diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
index 0f077c5db58e..9b7936ea3a88 100644
--- a/fs/btrfs/extent_io.c
+++ b/fs/btrfs/extent_io.c
@@ -3819,8 +3819,8 @@ int btree_write_cache_pages(struct address_space *mapping,
 	if (wbc->sync_mode == WB_SYNC_ALL)
 		tag_pages_for_writeback(mapping, index, end);
 	while (!done && !nr_to_write_done && (index <= end) &&
-	       (nr_pages = pagevec_lookup_tag(&pvec, mapping, &index, tag,
-			min(end - index, (pgoff_t)PAGEVEC_SIZE-1) + 1))) {
+	       (nr_pages = pagevec_lookup_range_tag(&pvec, mapping, &index, end,
+			tag, PAGEVEC_SIZE))) {
 		unsigned i;
 
 		scanned = 1;
@@ -3830,11 +3830,6 @@ int btree_write_cache_pages(struct address_space *mapping,
 			if (!PagePrivate(page))
 				continue;
 
-			if (!wbc->range_cyclic && page->index > end) {
-				done = 1;
-				break;
-			}
-
 			spin_lock(&mapping->private_lock);
 			if (!PagePrivate(page)) {
 				spin_unlock(&mapping->private_lock);
@@ -3966,8 +3961,8 @@ static int extent_write_cache_pages(struct address_space *mapping,
 		tag_pages_for_writeback(mapping, index, end);
 	done_index = index;
 	while (!done && !nr_to_write_done && (index <= end) &&
-	       (nr_pages = pagevec_lookup_tag(&pvec, mapping, &index, tag,
-			min(end - index, (pgoff_t)PAGEVEC_SIZE-1) + 1))) {
+	       (nr_pages = pagevec_lookup_range_tag(&pvec, mapping, &index, end,
+			tag, PAGEVEC_SIZE))) {
 		unsigned i;
 
 		scanned = 1;
@@ -3992,12 +3987,6 @@ static int extent_write_cache_pages(struct address_space *mapping,
 				continue;
 			}
 
-			if (!wbc->range_cyclic && page->index > end) {
-				done = 1;
-				unlock_page(page);
-				continue;
-			}
-
 			if (wbc->sync_mode != WB_SYNC_NONE) {
 				if (PageWriteback(page))
 					flush_fn(data);
-- 
2.12.3
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply related	[flat|nested] 27+ messages in thread* [PATCH 03/15] ceph: Use pagevec_lookup_range_tag()
  2017-09-27 16:03 [PATCH 0/15 v2] Ranged pagevec tagged lookup Jan Kara
  2017-09-27 16:03 ` [PATCH 01/15] mm: Implement find_get_pages_range_tag() Jan Kara
  2017-09-27 16:03 ` [PATCH 02/15] btrfs: Use pagevec_lookup_range_tag() Jan Kara
@ 2017-09-27 16:03 ` Jan Kara
  2017-09-29  1:20   ` Yan, Zheng
  2017-09-27 16:03 ` [PATCH 04/15] ext4: " Jan Kara
                   ` (11 subsequent siblings)
  14 siblings, 1 reply; 27+ messages in thread
From: Jan Kara @ 2017-09-27 16:03 UTC (permalink / raw)
  To: Andrew Morton
  Cc: linux-mm, linux-fsdevel, Jan Kara, Ilya Dryomov, Yan, Zheng,
	ceph-devel
We want only pages from given range in ceph_writepages_start(). Use
pagevec_lookup_range_tag() instead of pagevec_lookup_tag() and remove
unnecessary code.
CC: Ilya Dryomov <idryomov@gmail.com>
CC: "Yan, Zheng" <zyan@redhat.com>
CC: ceph-devel@vger.kernel.org
Signed-off-by: Jan Kara <jack@suse.cz>
---
 fs/ceph/addr.c | 19 +++----------------
 1 file changed, 3 insertions(+), 16 deletions(-)
diff --git a/fs/ceph/addr.c b/fs/ceph/addr.c
index b3e3edc09d80..e57e9d37bf2d 100644
--- a/fs/ceph/addr.c
+++ b/fs/ceph/addr.c
@@ -871,13 +871,10 @@ static int ceph_writepages_start(struct address_space *mapping,
 get_more_pages:
 		pvec_pages = min_t(unsigned, PAGEVEC_SIZE,
 				   max_pages - locked_pages);
-		if (end - index < (u64)(pvec_pages - 1))
-			pvec_pages = (unsigned)(end - index) + 1;
-
-		pvec_pages = pagevec_lookup_tag(&pvec, mapping, &index,
-						PAGECACHE_TAG_DIRTY,
+		pvec_pages = pagevec_lookup_range_tag(&pvec, mapping, &index,
+						end, PAGECACHE_TAG_DIRTY,
 						pvec_pages);
-		dout("pagevec_lookup_tag got %d\n", pvec_pages);
+		dout("pagevec_lookup_range_tag got %d\n", pvec_pages);
 		if (!pvec_pages && !locked_pages)
 			break;
 		for (i = 0; i < pvec_pages && locked_pages < max_pages; i++) {
@@ -895,16 +892,6 @@ static int ceph_writepages_start(struct address_space *mapping,
 				unlock_page(page);
 				continue;
 			}
-			if (page->index > end) {
-				dout("end of range %p\n", page);
-				/* can't be range_cyclic (1st pass) because
-				 * end == -1 in that case. */
-				stop = true;
-				if (ceph_wbc.head_snapc)
-					done = true;
-				unlock_page(page);
-				break;
-			}
 			if (strip_unit_end && (page->index > strip_unit_end)) {
 				dout("end of strip unit %p\n", page);
 				unlock_page(page);
-- 
2.12.3
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply related	[flat|nested] 27+ messages in thread* Re: [PATCH 03/15] ceph: Use pagevec_lookup_range_tag()
  2017-09-27 16:03 ` [PATCH 03/15] ceph: " Jan Kara
@ 2017-09-29  1:20   ` Yan, Zheng
  0 siblings, 0 replies; 27+ messages in thread
From: Yan, Zheng @ 2017-09-29  1:20 UTC (permalink / raw)
  To: Jan Kara; +Cc: Andrew Morton, linux-mm, linux-fsdevel, Ilya Dryomov, ceph-devel
> On 28 Sep 2017, at 00:03, Jan Kara <jack@suse.cz> wrote:
> 
> We want only pages from given range in ceph_writepages_start(). Use
> pagevec_lookup_range_tag() instead of pagevec_lookup_tag() and remove
> unnecessary code.
> 
> CC: Ilya Dryomov <idryomov@gmail.com>
> CC: "Yan, Zheng" <zyan@redhat.com>
> CC: ceph-devel@vger.kernel.org
> Signed-off-by: Jan Kara <jack@suse.cz>
> ---
> fs/ceph/addr.c | 19 +++----------------
> 1 file changed, 3 insertions(+), 16 deletions(-)
> 
> diff --git a/fs/ceph/addr.c b/fs/ceph/addr.c
> index b3e3edc09d80..e57e9d37bf2d 100644
> --- a/fs/ceph/addr.c
> +++ b/fs/ceph/addr.c
> @@ -871,13 +871,10 @@ static int ceph_writepages_start(struct address_space *mapping,
> get_more_pages:
> 		pvec_pages = min_t(unsigned, PAGEVEC_SIZE,
> 				   max_pages - locked_pages);
> -		if (end - index < (u64)(pvec_pages - 1))
> -			pvec_pages = (unsigned)(end - index) + 1;
> -
> -		pvec_pages = pagevec_lookup_tag(&pvec, mapping, &index,
> -						PAGECACHE_TAG_DIRTY,
> +		pvec_pages = pagevec_lookup_range_tag(&pvec, mapping, &index,
> +						end, PAGECACHE_TAG_DIRTY,
> 						pvec_pages);
> -		dout("pagevec_lookup_tag got %d\n", pvec_pages);
> +		dout("pagevec_lookup_range_tag got %d\n", pvec_pages);
> 		if (!pvec_pages && !locked_pages)
> 			break;
> 		for (i = 0; i < pvec_pages && locked_pages < max_pages; i++) {
> @@ -895,16 +892,6 @@ static int ceph_writepages_start(struct address_space *mapping,
> 				unlock_page(page);
> 				continue;
> 			}
> -			if (page->index > end) {
> -				dout("end of range %p\n", page);
> -				/* can't be range_cyclic (1st pass) because
> -				 * end == -1 in that case. */
> -				stop = true;
> -				if (ceph_wbc.head_snapc)
> -					done = true;
> -				unlock_page(page);
> -				break;
> -			}
> 			if (strip_unit_end && (page->index > strip_unit_end)) {
> 				dout("end of strip unit %p\n", page);
> 				unlock_page(page);
> -- 
> 2.12.3
> 
Reviewed-by: "Yan, Zheng" <zyan@redhat.com>
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply	[flat|nested] 27+ messages in thread
* [PATCH 04/15] ext4: Use pagevec_lookup_range_tag()
  2017-09-27 16:03 [PATCH 0/15 v2] Ranged pagevec tagged lookup Jan Kara
                   ` (2 preceding siblings ...)
  2017-09-27 16:03 ` [PATCH 03/15] ceph: " Jan Kara
@ 2017-09-27 16:03 ` Jan Kara
  2017-09-27 16:03 ` [PATCH 05/15] f2fs: " Jan Kara
                   ` (10 subsequent siblings)
  14 siblings, 0 replies; 27+ messages in thread
From: Jan Kara @ 2017-09-27 16:03 UTC (permalink / raw)
  To: Andrew Morton
  Cc: linux-mm, linux-fsdevel, Jan Kara, Theodore Ts'o, linux-ext4
We want only pages from given range in ext4_writepages(). Use
pagevec_lookup_range_tag() instead of pagevec_lookup_tag() and remove
unnecessary code.
CC: "Theodore Ts'o" <tytso@mit.edu>
CC: linux-ext4@vger.kernel.org
Signed-off-by: Jan Kara <jack@suse.cz>
---
 fs/ext4/inode.c | 14 ++------------
 1 file changed, 2 insertions(+), 12 deletions(-)
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index 31db875bc7a1..69f11233d0d6 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -2619,8 +2619,8 @@ static int mpage_prepare_extent_to_map(struct mpage_da_data *mpd)
 	mpd->map.m_len = 0;
 	mpd->next_page = index;
 	while (index <= end) {
-		nr_pages = pagevec_lookup_tag(&pvec, mapping, &index, tag,
-			      min(end - index, (pgoff_t)PAGEVEC_SIZE-1) + 1);
+		nr_pages = pagevec_lookup_range_tag(&pvec, mapping, &index, end,
+				tag, PAGEVEC_SIZE);
 		if (nr_pages == 0)
 			goto out;
 
@@ -2628,16 +2628,6 @@ static int mpage_prepare_extent_to_map(struct mpage_da_data *mpd)
 			struct page *page = pvec.pages[i];
 
 			/*
-			 * At this point, the page may be truncated or
-			 * invalidated (changing page->mapping to NULL), or
-			 * even swizzled back from swapper_space to tmpfs file
-			 * mapping. However, page->index will not change
-			 * because we have a reference on the page.
-			 */
-			if (page->index > end)
-				goto out;
-
-			/*
 			 * Accumulated enough dirty pages? This doesn't apply
 			 * to WB_SYNC_ALL mode. For integrity sync we have to
 			 * keep going because someone may be concurrently
-- 
2.12.3
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply related	[flat|nested] 27+ messages in thread* [PATCH 05/15] f2fs: Use pagevec_lookup_range_tag()
  2017-09-27 16:03 [PATCH 0/15 v2] Ranged pagevec tagged lookup Jan Kara
                   ` (3 preceding siblings ...)
  2017-09-27 16:03 ` [PATCH 04/15] ext4: " Jan Kara
@ 2017-09-27 16:03 ` Jan Kara
  2017-09-27 16:03 ` [PATCH 06/15] f2fs: Simplify page iteration loops Jan Kara
                   ` (9 subsequent siblings)
  14 siblings, 0 replies; 27+ messages in thread
From: Jan Kara @ 2017-09-27 16:03 UTC (permalink / raw)
  To: Andrew Morton
  Cc: linux-mm, linux-fsdevel, Jan Kara, Jaegeuk Kim, linux-f2fs-devel
We want only pages from given range in f2fs_write_cache_pages(). Use
pagevec_lookup_range_tag() instead of pagevec_lookup_tag() and remove
unnecessary code.
CC: Jaegeuk Kim <jaegeuk@kernel.org>
CC: linux-f2fs-devel@lists.sourceforge.net
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jan Kara <jack@suse.cz>
---
 fs/f2fs/data.c | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)
diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
index 36b535207c88..17d2c2997ddd 100644
--- a/fs/f2fs/data.c
+++ b/fs/f2fs/data.c
@@ -1669,8 +1669,8 @@ static int f2fs_write_cache_pages(struct address_space *mapping,
 	while (!done && (index <= end)) {
 		int i;
 
-		nr_pages = pagevec_lookup_tag(&pvec, mapping, &index, tag,
-			      min(end - index, (pgoff_t)PAGEVEC_SIZE - 1) + 1);
+		nr_pages = pagevec_lookup_range_tag(&pvec, mapping, &index, end,
+				tag, PAGEVEC_SIZE);
 		if (nr_pages == 0)
 			break;
 
@@ -1678,11 +1678,6 @@ static int f2fs_write_cache_pages(struct address_space *mapping,
 			struct page *page = pvec.pages[i];
 			bool submitted = false;
 
-			if (page->index > end) {
-				done = 1;
-				break;
-			}
-
 			done_index = page->index;
 retry_write:
 			lock_page(page);
-- 
2.12.3
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply related	[flat|nested] 27+ messages in thread* [PATCH 06/15] f2fs: Simplify page iteration loops
  2017-09-27 16:03 [PATCH 0/15 v2] Ranged pagevec tagged lookup Jan Kara
                   ` (4 preceding siblings ...)
  2017-09-27 16:03 ` [PATCH 05/15] f2fs: " Jan Kara
@ 2017-09-27 16:03 ` Jan Kara
  2017-09-27 16:03 ` [PATCH 07/15] f2fs: Use find_get_pages_tag() for looking up single page Jan Kara
                   ` (8 subsequent siblings)
  14 siblings, 0 replies; 27+ messages in thread
From: Jan Kara @ 2017-09-27 16:03 UTC (permalink / raw)
  To: Andrew Morton
  Cc: linux-mm, linux-fsdevel, Jan Kara, Jaegeuk Kim, linux-f2fs-devel
In several places we want to iterate over all tagged pages in a mapping.
However the code was apparently copied from places that iterate only
over a limited range and thus it checks for index <= end, optimizes the
case where we are coming close to range end which is all pointless when
end == ULONG_MAX. So just remove this dead code.
CC: Jaegeuk Kim <jaegeuk@kernel.org>
CC: linux-f2fs-devel@lists.sourceforge.net
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jan Kara <jack@suse.cz>
---
 fs/f2fs/checkpoint.c | 13 ++++-------
 fs/f2fs/node.c       | 65 +++++++++++++++++++---------------------------------
 2 files changed, 28 insertions(+), 50 deletions(-)
diff --git a/fs/f2fs/checkpoint.c b/fs/f2fs/checkpoint.c
index 04fe1df052b2..54ccf5ba8191 100644
--- a/fs/f2fs/checkpoint.c
+++ b/fs/f2fs/checkpoint.c
@@ -305,9 +305,10 @@ long sync_meta_pages(struct f2fs_sb_info *sbi, enum page_type type,
 				long nr_to_write, enum iostat_type io_type)
 {
 	struct address_space *mapping = META_MAPPING(sbi);
-	pgoff_t index = 0, end = ULONG_MAX, prev = ULONG_MAX;
+	pgoff_t index = 0, prev = ULONG_MAX;
 	struct pagevec pvec;
 	long nwritten = 0;
+	int nr_pages;
 	struct writeback_control wbc = {
 		.for_reclaim = 0,
 	};
@@ -317,13 +318,9 @@ long sync_meta_pages(struct f2fs_sb_info *sbi, enum page_type type,
 
 	blk_start_plug(&plug);
 
-	while (index <= end) {
-		int i, nr_pages;
-		nr_pages = pagevec_lookup_tag(&pvec, mapping, &index,
-				PAGECACHE_TAG_DIRTY,
-				min(end - index, (pgoff_t)PAGEVEC_SIZE-1) + 1);
-		if (unlikely(nr_pages == 0))
-			break;
+	while (nr_pages = pagevec_lookup_tag(&pvec, mapping, &index,
+				PAGECACHE_TAG_DIRTY, PAGEVEC_SIZE)) {
+		int i;
 
 		for (i = 0; i < nr_pages; i++) {
 			struct page *page = pvec.pages[i];
diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c
index fca87835a1da..f9ccbda73ea9 100644
--- a/fs/f2fs/node.c
+++ b/fs/f2fs/node.c
@@ -1277,21 +1277,17 @@ void move_node_page(struct page *node_page, int gc_type)
 
 static struct page *last_fsync_dnode(struct f2fs_sb_info *sbi, nid_t ino)
 {
-	pgoff_t index, end;
+	pgoff_t index;
 	struct pagevec pvec;
 	struct page *last_page = NULL;
+	int nr_pages;
 
 	pagevec_init(&pvec, 0);
 	index = 0;
-	end = ULONG_MAX;
-
-	while (index <= end) {
-		int i, nr_pages;
-		nr_pages = pagevec_lookup_tag(&pvec, NODE_MAPPING(sbi), &index,
-				PAGECACHE_TAG_DIRTY,
-				min(end - index, (pgoff_t)PAGEVEC_SIZE-1) + 1);
-		if (nr_pages == 0)
-			break;
+
+	while (nr_pages = pagevec_lookup_tag(&pvec, NODE_MAPPING(sbi), &index,
+				PAGECACHE_TAG_DIRTY, PAGEVEC_SIZE)) {
+		int i;
 
 		for (i = 0; i < nr_pages; i++) {
 			struct page *page = pvec.pages[i];
@@ -1425,13 +1421,14 @@ static int f2fs_write_node_page(struct page *page,
 int fsync_node_pages(struct f2fs_sb_info *sbi, struct inode *inode,
 			struct writeback_control *wbc, bool atomic)
 {
-	pgoff_t index, end;
+	pgoff_t index;
 	pgoff_t last_idx = ULONG_MAX;
 	struct pagevec pvec;
 	int ret = 0;
 	struct page *last_page = NULL;
 	bool marked = false;
 	nid_t ino = inode->i_ino;
+	int nr_pages;
 
 	if (atomic) {
 		last_page = last_fsync_dnode(sbi, ino);
@@ -1441,15 +1438,10 @@ int fsync_node_pages(struct f2fs_sb_info *sbi, struct inode *inode,
 retry:
 	pagevec_init(&pvec, 0);
 	index = 0;
-	end = ULONG_MAX;
-
-	while (index <= end) {
-		int i, nr_pages;
-		nr_pages = pagevec_lookup_tag(&pvec, NODE_MAPPING(sbi), &index,
-				PAGECACHE_TAG_DIRTY,
-				min(end - index, (pgoff_t)PAGEVEC_SIZE-1) + 1);
-		if (nr_pages == 0)
-			break;
+
+	while (nr_pages = pagevec_lookup_tag(&pvec, NODE_MAPPING(sbi), &index,
+				PAGECACHE_TAG_DIRTY, PAGEVEC_SIZE)) {
+		int i;
 
 		for (i = 0; i < nr_pages; i++) {
 			struct page *page = pvec.pages[i];
@@ -1548,25 +1540,21 @@ int fsync_node_pages(struct f2fs_sb_info *sbi, struct inode *inode,
 int sync_node_pages(struct f2fs_sb_info *sbi, struct writeback_control *wbc,
 				bool do_balance, enum iostat_type io_type)
 {
-	pgoff_t index, end;
+	pgoff_t index;
 	struct pagevec pvec;
 	int step = 0;
 	int nwritten = 0;
 	int ret = 0;
+	int nr_pages;
 
 	pagevec_init(&pvec, 0);
 
 next_step:
 	index = 0;
-	end = ULONG_MAX;
-
-	while (index <= end) {
-		int i, nr_pages;
-		nr_pages = pagevec_lookup_tag(&pvec, NODE_MAPPING(sbi), &index,
-				PAGECACHE_TAG_DIRTY,
-				min(end - index, (pgoff_t)PAGEVEC_SIZE-1) + 1);
-		if (nr_pages == 0)
-			break;
+
+	while (nr_pages = pagevec_lookup_tag(&pvec, NODE_MAPPING(sbi), &index,
+				PAGECACHE_TAG_DIRTY, PAGEVEC_SIZE)) {
+		int i;
 
 		for (i = 0; i < nr_pages; i++) {
 			struct page *page = pvec.pages[i];
@@ -1655,27 +1643,20 @@ int sync_node_pages(struct f2fs_sb_info *sbi, struct writeback_control *wbc,
 
 int wait_on_node_pages_writeback(struct f2fs_sb_info *sbi, nid_t ino)
 {
-	pgoff_t index = 0, end = ULONG_MAX;
+	pgoff_t index = 0;
 	struct pagevec pvec;
 	int ret2, ret = 0;
+	int nr_pages;
 
 	pagevec_init(&pvec, 0);
 
-	while (index <= end) {
-		int i, nr_pages;
-		nr_pages = pagevec_lookup_tag(&pvec, NODE_MAPPING(sbi), &index,
-				PAGECACHE_TAG_WRITEBACK,
-				min(end - index, (pgoff_t)PAGEVEC_SIZE-1) + 1);
-		if (nr_pages == 0)
-			break;
+	while (nr_pages = pagevec_lookup_tag(&pvec, NODE_MAPPING(sbi), &index,
+				PAGECACHE_TAG_WRITEBACK, PAGEVEC_SIZE)) {
+		int i;
 
 		for (i = 0; i < nr_pages; i++) {
 			struct page *page = pvec.pages[i];
 
-			/* until radix tree lookup accepts end_index */
-			if (unlikely(page->index > end))
-				continue;
-
 			if (ino && ino_of_node(page) == ino) {
 				f2fs_wait_on_page_writeback(page, NODE, true);
 				if (TestClearPageError(page))
-- 
2.12.3
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply related	[flat|nested] 27+ messages in thread* [PATCH 07/15] f2fs: Use find_get_pages_tag() for looking up single page
  2017-09-27 16:03 [PATCH 0/15 v2] Ranged pagevec tagged lookup Jan Kara
                   ` (5 preceding siblings ...)
  2017-09-27 16:03 ` [PATCH 06/15] f2fs: Simplify page iteration loops Jan Kara
@ 2017-09-27 16:03 ` Jan Kara
  2017-09-27 16:03 ` [PATCH 08/15] gfs2: Use pagevec_lookup_range_tag() Jan Kara
                   ` (7 subsequent siblings)
  14 siblings, 0 replies; 27+ messages in thread
From: Jan Kara @ 2017-09-27 16:03 UTC (permalink / raw)
  To: Andrew Morton
  Cc: linux-mm, linux-fsdevel, Jan Kara, Jaegeuk Kim, linux-f2fs-devel
__get_first_dirty_index() wants to lookup only the first dirty page
after given index. There's no point in using pagevec_lookup_tag() for
that. Just use find_get_pages_tag() directly.
CC: Jaegeuk Kim <jaegeuk@kernel.org>
CC: linux-f2fs-devel@lists.sourceforge.net
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jan Kara <jack@suse.cz>
---
 fs/f2fs/file.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
index 517e112c8a9a..f78b76ec4707 100644
--- a/fs/f2fs/file.c
+++ b/fs/f2fs/file.c
@@ -313,18 +313,19 @@ int f2fs_sync_file(struct file *file, loff_t start, loff_t end, int datasync)
 static pgoff_t __get_first_dirty_index(struct address_space *mapping,
 						pgoff_t pgofs, int whence)
 {
-	struct pagevec pvec;
+	struct page *page;
 	int nr_pages;
 
 	if (whence != SEEK_DATA)
 		return 0;
 
 	/* find first dirty page index */
-	pagevec_init(&pvec, 0);
-	nr_pages = pagevec_lookup_tag(&pvec, mapping, &pgofs,
-					PAGECACHE_TAG_DIRTY, 1);
-	pgofs = nr_pages ? pvec.pages[0]->index : ULONG_MAX;
-	pagevec_release(&pvec);
+	nr_pages = find_get_pages_tag(mapping, &pgofs, PAGECACHE_TAG_DIRTY,
+				      1, &page);
+	if (!nr_pages)
+		return ULONG_MAX;
+	pgofs = page->index;
+	put_page(page);
 	return pgofs;
 }
 
-- 
2.12.3
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply related	[flat|nested] 27+ messages in thread* [PATCH 08/15] gfs2: Use pagevec_lookup_range_tag()
  2017-09-27 16:03 [PATCH 0/15 v2] Ranged pagevec tagged lookup Jan Kara
                   ` (6 preceding siblings ...)
  2017-09-27 16:03 ` [PATCH 07/15] f2fs: Use find_get_pages_tag() for looking up single page Jan Kara
@ 2017-09-27 16:03 ` Jan Kara
  2017-09-27 16:03 ` [PATCH 09/15] nilfs2: " Jan Kara
                   ` (6 subsequent siblings)
  14 siblings, 0 replies; 27+ messages in thread
From: Jan Kara @ 2017-09-27 16:03 UTC (permalink / raw)
  To: Andrew Morton
  Cc: linux-mm, linux-fsdevel, Jan Kara, Bob Peterson, cluster-devel
We want only pages from given range in gfs2_write_cache_jdata(). Use
pagevec_lookup_range_tag() instead of pagevec_lookup_tag() and remove
unnecessary code.
CC: Bob Peterson <rpeterso@redhat.com>
CC: cluster-devel@redhat.com
Signed-off-by: Jan Kara <jack@suse.cz>
---
 fs/gfs2/aops.c | 20 ++------------------
 1 file changed, 2 insertions(+), 18 deletions(-)
diff --git a/fs/gfs2/aops.c b/fs/gfs2/aops.c
index 68ed06962537..d0848d9623fb 100644
--- a/fs/gfs2/aops.c
+++ b/fs/gfs2/aops.c
@@ -280,22 +280,6 @@ static int gfs2_write_jdata_pagevec(struct address_space *mapping,
 	for(i = 0; i < nr_pages; i++) {
 		struct page *page = pvec->pages[i];
 
-		/*
-		 * At this point, the page may be truncated or
-		 * invalidated (changing page->mapping to NULL), or
-		 * even swizzled back from swapper_space to tmpfs file
-		 * mapping. However, page->index will not change
-		 * because we have a reference on the page.
-		 */
-		if (page->index > end) {
-			/*
-			 * can't be range_cyclic (1st pass) because
-			 * end == -1 in that case.
-			 */
-			ret = 1;
-			break;
-		}
-
 		*done_index = page->index;
 
 		lock_page(page);
@@ -413,8 +397,8 @@ static int gfs2_write_cache_jdata(struct address_space *mapping,
 		tag_pages_for_writeback(mapping, index, end);
 	done_index = index;
 	while (!done && (index <= end)) {
-		nr_pages = pagevec_lookup_tag(&pvec, mapping, &index, tag,
-			      min(end - index, (pgoff_t)PAGEVEC_SIZE-1) + 1);
+		nr_pages = pagevec_lookup_range_tag(&pvec, mapping, &index, end,
+				tag, PAGEVEC_SIZE);
 		if (nr_pages == 0)
 			break;
 
-- 
2.12.3
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply related	[flat|nested] 27+ messages in thread* [PATCH 09/15] nilfs2: Use pagevec_lookup_range_tag()
  2017-09-27 16:03 [PATCH 0/15 v2] Ranged pagevec tagged lookup Jan Kara
                   ` (7 preceding siblings ...)
  2017-09-27 16:03 ` [PATCH 08/15] gfs2: Use pagevec_lookup_range_tag() Jan Kara
@ 2017-09-27 16:03 ` Jan Kara
  2017-09-28  1:40   ` Ryusuke Konishi
  2017-09-27 16:03 ` [PATCH 10/15] mm: Use pagevec_lookup_range_tag() in __filemap_fdatawait_range() Jan Kara
                   ` (5 subsequent siblings)
  14 siblings, 1 reply; 27+ messages in thread
From: Jan Kara @ 2017-09-27 16:03 UTC (permalink / raw)
  To: Andrew Morton
  Cc: linux-mm, linux-fsdevel, Jan Kara, Ryusuke Konishi, linux-nilfs
We want only pages from given range in
nilfs_lookup_dirty_data_buffers(). Use pagevec_lookup_range_tag()
instead of pagevec_lookup_tag() and remove unnecessary code.
CC: Ryusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>
CC: linux-nilfs@vger.kernel.org
Signed-off-by: Jan Kara <jack@suse.cz>
---
 fs/nilfs2/segment.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
diff --git a/fs/nilfs2/segment.c b/fs/nilfs2/segment.c
index 70ded52dc1dd..68e5769cef3b 100644
--- a/fs/nilfs2/segment.c
+++ b/fs/nilfs2/segment.c
@@ -711,18 +711,14 @@ static size_t nilfs_lookup_dirty_data_buffers(struct inode *inode,
 	pagevec_init(&pvec, 0);
  repeat:
 	if (unlikely(index > last) ||
-	    !pagevec_lookup_tag(&pvec, mapping, &index, PAGECACHE_TAG_DIRTY,
-				min_t(pgoff_t, last - index,
-				      PAGEVEC_SIZE - 1) + 1))
+	    !pagevec_lookup_range_tag(&pvec, mapping, &index, last,
+				PAGECACHE_TAG_DIRTY, PAGEVEC_SIZE))
 		return ndirties;
 
 	for (i = 0; i < pagevec_count(&pvec); i++) {
 		struct buffer_head *bh, *head;
 		struct page *page = pvec.pages[i];
 
-		if (unlikely(page->index > last))
-			break;
-
 		lock_page(page);
 		if (!page_has_buffers(page))
 			create_empty_buffers(page, i_blocksize(inode), 0);
-- 
2.12.3
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply related	[flat|nested] 27+ messages in thread* Re: [PATCH 09/15] nilfs2: Use pagevec_lookup_range_tag()
  2017-09-27 16:03 ` [PATCH 09/15] nilfs2: " Jan Kara
@ 2017-09-28  1:40   ` Ryusuke Konishi
  0 siblings, 0 replies; 27+ messages in thread
From: Ryusuke Konishi @ 2017-09-28  1:40 UTC (permalink / raw)
  To: Jan Kara, Andrew Morton; +Cc: linux-mm, linux-fsdevel, linux-nilfs
On 2017/09/28 1:03, Jan Kara wrote:
> We want only pages from given range in
> nilfs_lookup_dirty_data_buffers(). Use pagevec_lookup_range_tag()
> instead of pagevec_lookup_tag() and remove unnecessary code.
> 
> CC: Ryusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>
> CC: linux-nilfs@vger.kernel.org
> Signed-off-by: Jan Kara <jack@suse.cz>
> ---
>   fs/nilfs2/segment.c | 8 ++------
>   1 file changed, 2 insertions(+), 6 deletions(-)
Nice patch. Thanks.
Acked-by: Ryusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>
> 
> diff --git a/fs/nilfs2/segment.c b/fs/nilfs2/segment.c
> index 70ded52dc1dd..68e5769cef3b 100644
> --- a/fs/nilfs2/segment.c
> +++ b/fs/nilfs2/segment.c
> @@ -711,18 +711,14 @@ static size_t nilfs_lookup_dirty_data_buffers(struct inode *inode,
>   	pagevec_init(&pvec, 0);
>    repeat:
>   	if (unlikely(index > last) ||
> -	    !pagevec_lookup_tag(&pvec, mapping, &index, PAGECACHE_TAG_DIRTY,
> -				min_t(pgoff_t, last - index,
> -				      PAGEVEC_SIZE - 1) + 1))
> +	    !pagevec_lookup_range_tag(&pvec, mapping, &index, last,
> +				PAGECACHE_TAG_DIRTY, PAGEVEC_SIZE))
>   		return ndirties;
>   
>   	for (i = 0; i < pagevec_count(&pvec); i++) {
>   		struct buffer_head *bh, *head;
>   		struct page *page = pvec.pages[i];
>   
> -		if (unlikely(page->index > last))
> -			break;
> -
>   		lock_page(page);
>   		if (!page_has_buffers(page))
>   			create_empty_buffers(page, i_blocksize(inode), 0);
> 
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply	[flat|nested] 27+ messages in thread
* [PATCH 10/15] mm: Use pagevec_lookup_range_tag() in __filemap_fdatawait_range()
  2017-09-27 16:03 [PATCH 0/15 v2] Ranged pagevec tagged lookup Jan Kara
                   ` (8 preceding siblings ...)
  2017-09-27 16:03 ` [PATCH 09/15] nilfs2: " Jan Kara
@ 2017-09-27 16:03 ` Jan Kara
  2017-09-27 22:19   ` Dave Chinner
  2017-09-27 16:03 ` [PATCH 11/15] mm: Use pagevec_lookup_range_tag() in write_cache_pages() Jan Kara
                   ` (4 subsequent siblings)
  14 siblings, 1 reply; 27+ messages in thread
From: Jan Kara @ 2017-09-27 16:03 UTC (permalink / raw)
  To: Andrew Morton; +Cc: linux-mm, linux-fsdevel, Jan Kara
Use pagevec_lookup_range_tag() in __filemap_fdatawait_range() as it is
interested only in pages from given range. Remove unnecessary code
resulting from this.
Signed-off-by: Jan Kara <jack@suse.cz>
---
 mm/filemap.c | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)
diff --git a/mm/filemap.c b/mm/filemap.c
index fe20329c83cd..479fc54b7cd1 100644
--- a/mm/filemap.c
+++ b/mm/filemap.c
@@ -421,18 +421,13 @@ static void __filemap_fdatawait_range(struct address_space *mapping,
 
 	pagevec_init(&pvec, 0);
 	while ((index <= end) &&
-			(nr_pages = pagevec_lookup_tag(&pvec, mapping, &index,
-			PAGECACHE_TAG_WRITEBACK,
-			min(end - index, (pgoff_t)PAGEVEC_SIZE-1) + 1)) != 0) {
+			(nr_pages = pagevec_lookup_range_tag(&pvec, mapping,
+			&index, end, PAGECACHE_TAG_WRITEBACK, PAGEVEC_SIZE))) {
 		unsigned i;
 
 		for (i = 0; i < nr_pages; i++) {
 			struct page *page = pvec.pages[i];
 
-			/* until radix tree lookup accepts end_index */
-			if (page->index > end)
-				continue;
-
 			wait_on_page_writeback(page);
 			ClearPageError(page);
 		}
-- 
2.12.3
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply related	[flat|nested] 27+ messages in thread* Re: [PATCH 10/15] mm: Use pagevec_lookup_range_tag() in __filemap_fdatawait_range()
  2017-09-27 16:03 ` [PATCH 10/15] mm: Use pagevec_lookup_range_tag() in __filemap_fdatawait_range() Jan Kara
@ 2017-09-27 22:19   ` Dave Chinner
  2017-10-03  8:38     ` Jan Kara
  0 siblings, 1 reply; 27+ messages in thread
From: Dave Chinner @ 2017-09-27 22:19 UTC (permalink / raw)
  To: Jan Kara; +Cc: Andrew Morton, linux-mm, linux-fsdevel
On Wed, Sep 27, 2017 at 06:03:29PM +0200, Jan Kara wrote:
> Use pagevec_lookup_range_tag() in __filemap_fdatawait_range() as it is
> interested only in pages from given range. Remove unnecessary code
> resulting from this.
> 
> Signed-off-by: Jan Kara <jack@suse.cz>
> ---
>  mm/filemap.c | 9 ++-------
>  1 file changed, 2 insertions(+), 7 deletions(-)
> 
> diff --git a/mm/filemap.c b/mm/filemap.c
> index fe20329c83cd..479fc54b7cd1 100644
> --- a/mm/filemap.c
> +++ b/mm/filemap.c
> @@ -421,18 +421,13 @@ static void __filemap_fdatawait_range(struct address_space *mapping,
>  
>  	pagevec_init(&pvec, 0);
>  	while ((index <= end) &&
> -			(nr_pages = pagevec_lookup_tag(&pvec, mapping, &index,
> -			PAGECACHE_TAG_WRITEBACK,
> -			min(end - index, (pgoff_t)PAGEVEC_SIZE-1) + 1)) != 0) {
> +			(nr_pages = pagevec_lookup_range_tag(&pvec, mapping,
> +			&index, end, PAGECACHE_TAG_WRITEBACK, PAGEVEC_SIZE))) {
While touching this, can we clean this up by moving the lookup
outside the while condition? i.e:
	while (index <= end) {
		unsigned i;
		nr_pages = pagevec_lookup_range_tag(&pvec, mapping, &index,
				end, PAGECACHE_TAG_WRITEBACK, PAGEVEC_SIZE);
		if (!nr_pages)
			break;
Cheers,
Dave.
-- 
Dave Chinner
david@fromorbit.com
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply	[flat|nested] 27+ messages in thread* Re: [PATCH 10/15] mm: Use pagevec_lookup_range_tag() in __filemap_fdatawait_range()
  2017-09-27 22:19   ` Dave Chinner
@ 2017-10-03  8:38     ` Jan Kara
  0 siblings, 0 replies; 27+ messages in thread
From: Jan Kara @ 2017-10-03  8:38 UTC (permalink / raw)
  To: Dave Chinner; +Cc: Jan Kara, Andrew Morton, linux-mm, linux-fsdevel
On Thu 28-09-17 08:19:02, Dave Chinner wrote:
> On Wed, Sep 27, 2017 at 06:03:29PM +0200, Jan Kara wrote:
> > Use pagevec_lookup_range_tag() in __filemap_fdatawait_range() as it is
> > interested only in pages from given range. Remove unnecessary code
> > resulting from this.
> > 
> > Signed-off-by: Jan Kara <jack@suse.cz>
> > ---
> >  mm/filemap.c | 9 ++-------
> >  1 file changed, 2 insertions(+), 7 deletions(-)
> > 
> > diff --git a/mm/filemap.c b/mm/filemap.c
> > index fe20329c83cd..479fc54b7cd1 100644
> > --- a/mm/filemap.c
> > +++ b/mm/filemap.c
> > @@ -421,18 +421,13 @@ static void __filemap_fdatawait_range(struct address_space *mapping,
> >  
> >  	pagevec_init(&pvec, 0);
> >  	while ((index <= end) &&
> > -			(nr_pages = pagevec_lookup_tag(&pvec, mapping, &index,
> > -			PAGECACHE_TAG_WRITEBACK,
> > -			min(end - index, (pgoff_t)PAGEVEC_SIZE-1) + 1)) != 0) {
> > +			(nr_pages = pagevec_lookup_range_tag(&pvec, mapping,
> > +			&index, end, PAGECACHE_TAG_WRITEBACK, PAGEVEC_SIZE))) {
> 
> While touching this, can we clean this up by moving the lookup
> outside the while condition? i.e:
> 
> 	while (index <= end) {
> 		unsigned i;
> 
> 		nr_pages = pagevec_lookup_range_tag(&pvec, mapping, &index,
> 				end, PAGECACHE_TAG_WRITEBACK, PAGEVEC_SIZE);
> 		if (!nr_pages)
> 			break;
Yeah, that makes sense. I'll update it.
								Honza
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply	[flat|nested] 27+ messages in thread
* [PATCH 11/15] mm: Use pagevec_lookup_range_tag() in write_cache_pages()
  2017-09-27 16:03 [PATCH 0/15 v2] Ranged pagevec tagged lookup Jan Kara
                   ` (9 preceding siblings ...)
  2017-09-27 16:03 ` [PATCH 10/15] mm: Use pagevec_lookup_range_tag() in __filemap_fdatawait_range() Jan Kara
@ 2017-09-27 16:03 ` Jan Kara
  2017-09-27 16:03 ` [PATCH 12/15] mm: Add variant of pagevec_lookup_range_tag() taking number of pages Jan Kara
                   ` (3 subsequent siblings)
  14 siblings, 0 replies; 27+ messages in thread
From: Jan Kara @ 2017-09-27 16:03 UTC (permalink / raw)
  To: Andrew Morton; +Cc: linux-mm, linux-fsdevel, Jan Kara
Use pagevec_lookup_range_tag() in write_cache_pages() as it is
interested only in pages from given range. Remove unnecessary code
resulting from this.
Signed-off-by: Jan Kara <jack@suse.cz>
---
 mm/page-writeback.c | 20 ++------------------
 1 file changed, 2 insertions(+), 18 deletions(-)
diff --git a/mm/page-writeback.c b/mm/page-writeback.c
index 0b9c5cbe8eba..43b18e185fbd 100644
--- a/mm/page-writeback.c
+++ b/mm/page-writeback.c
@@ -2194,30 +2194,14 @@ int write_cache_pages(struct address_space *mapping,
 	while (!done && (index <= end)) {
 		int i;
 
-		nr_pages = pagevec_lookup_tag(&pvec, mapping, &index, tag,
-			      min(end - index, (pgoff_t)PAGEVEC_SIZE-1) + 1);
+		nr_pages = pagevec_lookup_range_tag(&pvec, mapping, &index, end,
+				tag, PAGEVEC_SIZE);
 		if (nr_pages == 0)
 			break;
 
 		for (i = 0; i < nr_pages; i++) {
 			struct page *page = pvec.pages[i];
 
-			/*
-			 * At this point, the page may be truncated or
-			 * invalidated (changing page->mapping to NULL), or
-			 * even swizzled back from swapper_space to tmpfs file
-			 * mapping. However, page->index will not change
-			 * because we have a reference on the page.
-			 */
-			if (page->index > end) {
-				/*
-				 * can't be range_cyclic (1st pass) because
-				 * end == -1 in that case.
-				 */
-				done = 1;
-				break;
-			}
-
 			done_index = page->index;
 
 			lock_page(page);
-- 
2.12.3
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply related	[flat|nested] 27+ messages in thread* [PATCH 12/15] mm: Add variant of pagevec_lookup_range_tag() taking number of pages
  2017-09-27 16:03 [PATCH 0/15 v2] Ranged pagevec tagged lookup Jan Kara
                   ` (10 preceding siblings ...)
  2017-09-27 16:03 ` [PATCH 11/15] mm: Use pagevec_lookup_range_tag() in write_cache_pages() Jan Kara
@ 2017-09-27 16:03 ` Jan Kara
  2017-09-29 21:45   ` Daniel Jordan
  2017-09-27 16:03 ` [PATCH 13/15] ceph: Use pagevec_lookup_range_nr_tag() Jan Kara
                   ` (2 subsequent siblings)
  14 siblings, 1 reply; 27+ messages in thread
From: Jan Kara @ 2017-09-27 16:03 UTC (permalink / raw)
  To: Andrew Morton; +Cc: linux-mm, linux-fsdevel, Jan Kara
Currently pagevec_lookup_range_tag() takes number of pages to look up
but most users don't need this. Create a new function
pagevec_lookup_range_nr_tag() that takes maximum number of pages to
lookup for Ceph which wants this functionality so that we can drop
nr_pages argument from pagevec_lookup_range_tag().
Signed-off-by: Jan Kara <jack@suse.cz>
---
 include/linux/pagevec.h | 3 +++
 mm/swap.c               | 9 +++++++++
 2 files changed, 12 insertions(+)
diff --git a/include/linux/pagevec.h b/include/linux/pagevec.h
index 371edacc10d5..0281b1d3a91b 100644
--- a/include/linux/pagevec.h
+++ b/include/linux/pagevec.h
@@ -40,6 +40,9 @@ static inline unsigned pagevec_lookup(struct pagevec *pvec,
 unsigned pagevec_lookup_range_tag(struct pagevec *pvec,
 		struct address_space *mapping, pgoff_t *index, pgoff_t end,
 		int tag, unsigned nr_pages);
+unsigned pagevec_lookup_range_nr_tag(struct pagevec *pvec,
+		struct address_space *mapping, pgoff_t *index, pgoff_t end,
+		int tag, unsigned max_pages);
 static inline unsigned pagevec_lookup_tag(struct pagevec *pvec,
 		struct address_space *mapping, pgoff_t *index, int tag,
 		unsigned nr_pages)
diff --git a/mm/swap.c b/mm/swap.c
index a00065f2a8f2..97186da8e5bd 100644
--- a/mm/swap.c
+++ b/mm/swap.c
@@ -996,6 +996,15 @@ unsigned pagevec_lookup_range_tag(struct pagevec *pvec,
 }
 EXPORT_SYMBOL(pagevec_lookup_range_tag);
 
+unsigned pagevec_lookup_range_nr_tag(struct pagevec *pvec,
+		struct address_space *mapping, pgoff_t *index, pgoff_t end,
+		int tag, unsigned max_pages)
+{
+	pvec->nr = find_get_pages_range_tag(mapping, index, end, tag,
+		min_t(unsigned int, max_pages, PAGEVEC_SIZE), pvec->pages);
+	return pagevec_count(pvec);
+}
+EXPORT_SYMBOL(pagevec_lookup_range_tag);
 /*
  * Perform any setup for the swap system
  */
-- 
2.12.3
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply related	[flat|nested] 27+ messages in thread* Re: [PATCH 12/15] mm: Add variant of pagevec_lookup_range_tag() taking number of pages
  2017-09-27 16:03 ` [PATCH 12/15] mm: Add variant of pagevec_lookup_range_tag() taking number of pages Jan Kara
@ 2017-09-29 21:45   ` Daniel Jordan
  2017-10-03  8:51     ` Jan Kara
  0 siblings, 1 reply; 27+ messages in thread
From: Daniel Jordan @ 2017-09-29 21:45 UTC (permalink / raw)
  To: Jan Kara; +Cc: Andrew Morton, linux-mm, linux-fsdevel
On 09/27/2017 12:03 PM, Jan Kara wrote:
> +unsigned pagevec_lookup_range_nr_tag(struct pagevec *pvec,
> +		struct address_space *mapping, pgoff_t *index, pgoff_t end,
> +		int tag, unsigned max_pages)
> +{
> +	pvec->nr = find_get_pages_range_tag(mapping, index, end, tag,
> +		min_t(unsigned int, max_pages, PAGEVEC_SIZE), pvec->pages);
> +	return pagevec_count(pvec);
> +}
> +EXPORT_SYMBOL(pagevec_lookup_range_tag);
The EXPORT_SYMBOL should be pagevec_lookup_range_nr_tag instead of 
pagevec_lookup_range_tag.
Daniel
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply	[flat|nested] 27+ messages in thread* Re: [PATCH 12/15] mm: Add variant of pagevec_lookup_range_tag() taking number of pages
  2017-09-29 21:45   ` Daniel Jordan
@ 2017-10-03  8:51     ` Jan Kara
  0 siblings, 0 replies; 27+ messages in thread
From: Jan Kara @ 2017-10-03  8:51 UTC (permalink / raw)
  To: Daniel Jordan; +Cc: Jan Kara, Andrew Morton, linux-mm, linux-fsdevel
On Fri 29-09-17 17:45:33, Daniel Jordan wrote:
> On 09/27/2017 12:03 PM, Jan Kara wrote:
> >+unsigned pagevec_lookup_range_nr_tag(struct pagevec *pvec,
> >+		struct address_space *mapping, pgoff_t *index, pgoff_t end,
> >+		int tag, unsigned max_pages)
> >+{
> >+	pvec->nr = find_get_pages_range_tag(mapping, index, end, tag,
> >+		min_t(unsigned int, max_pages, PAGEVEC_SIZE), pvec->pages);
> >+	return pagevec_count(pvec);
> >+}
> >+EXPORT_SYMBOL(pagevec_lookup_range_tag);
> 
> The EXPORT_SYMBOL should be pagevec_lookup_range_nr_tag instead of
> pagevec_lookup_range_tag.
Ah, good catch. Fixed. Thanks!
								Honza
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply	[flat|nested] 27+ messages in thread
* [PATCH 13/15] ceph: Use pagevec_lookup_range_nr_tag()
  2017-09-27 16:03 [PATCH 0/15 v2] Ranged pagevec tagged lookup Jan Kara
                   ` (11 preceding siblings ...)
  2017-09-27 16:03 ` [PATCH 12/15] mm: Add variant of pagevec_lookup_range_tag() taking number of pages Jan Kara
@ 2017-09-27 16:03 ` Jan Kara
  2017-09-27 16:03 ` [PATCH 14/15] mm: Remove nr_pages argument from pagevec_lookup_{,range}_tag() Jan Kara
  2017-09-27 16:03 ` [PATCH 15/15] afs: Use find_get_pages_range_tag() Jan Kara
  14 siblings, 0 replies; 27+ messages in thread
From: Jan Kara @ 2017-09-27 16:03 UTC (permalink / raw)
  To: Andrew Morton; +Cc: linux-mm, linux-fsdevel, Jan Kara
Use new function for looking up pages since nr_pages argument from
pagevec_lookup_range_tag() is going away.
Reviewed-by: "Yan, Zheng" <zyan@redhat.com>
Signed-off-by: Jan Kara <jack@suse.cz>
---
 fs/ceph/addr.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/fs/ceph/addr.c b/fs/ceph/addr.c
index e57e9d37bf2d..87789c477381 100644
--- a/fs/ceph/addr.c
+++ b/fs/ceph/addr.c
@@ -869,11 +869,9 @@ static int ceph_writepages_start(struct address_space *mapping,
 		max_pages = wsize >> PAGE_SHIFT;
 
 get_more_pages:
-		pvec_pages = min_t(unsigned, PAGEVEC_SIZE,
-				   max_pages - locked_pages);
-		pvec_pages = pagevec_lookup_range_tag(&pvec, mapping, &index,
+		pvec_pages = pagevec_lookup_range_nr_tag(&pvec, mapping, &index,
 						end, PAGECACHE_TAG_DIRTY,
-						pvec_pages);
+						max_pages - locked_pages);
 		dout("pagevec_lookup_range_tag got %d\n", pvec_pages);
 		if (!pvec_pages && !locked_pages)
 			break;
-- 
2.12.3
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply related	[flat|nested] 27+ messages in thread* [PATCH 14/15] mm: Remove nr_pages argument from pagevec_lookup_{,range}_tag()
  2017-09-27 16:03 [PATCH 0/15 v2] Ranged pagevec tagged lookup Jan Kara
                   ` (12 preceding siblings ...)
  2017-09-27 16:03 ` [PATCH 13/15] ceph: Use pagevec_lookup_range_nr_tag() Jan Kara
@ 2017-09-27 16:03 ` Jan Kara
  2017-09-29 21:46   ` Daniel Jordan
  2017-09-27 16:03 ` [PATCH 15/15] afs: Use find_get_pages_range_tag() Jan Kara
  14 siblings, 1 reply; 27+ messages in thread
From: Jan Kara @ 2017-09-27 16:03 UTC (permalink / raw)
  To: Andrew Morton; +Cc: linux-mm, linux-fsdevel, Jan Kara
All users of pagevec_lookup() and pagevec_lookup_range() now pass
PAGEVEC_SIZE as a desired number of pages. Just drop the argument.
Signed-off-by: Jan Kara <jack@suse.cz>
---
 fs/btrfs/extent_io.c    | 6 +++---
 fs/ext4/inode.c         | 2 +-
 fs/f2fs/checkpoint.c    | 2 +-
 fs/f2fs/data.c          | 2 +-
 fs/f2fs/node.c          | 8 ++++----
 fs/gfs2/aops.c          | 2 +-
 fs/nilfs2/btree.c       | 4 ++--
 fs/nilfs2/page.c        | 7 +++----
 fs/nilfs2/segment.c     | 6 +++---
 include/linux/pagevec.h | 8 +++-----
 mm/filemap.c            | 2 +-
 mm/page-writeback.c     | 2 +-
 mm/swap.c               | 4 ++--
 13 files changed, 26 insertions(+), 29 deletions(-)
diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
index 9b7936ea3a88..933fcfa818c4 100644
--- a/fs/btrfs/extent_io.c
+++ b/fs/btrfs/extent_io.c
@@ -3820,7 +3820,7 @@ int btree_write_cache_pages(struct address_space *mapping,
 		tag_pages_for_writeback(mapping, index, end);
 	while (!done && !nr_to_write_done && (index <= end) &&
 	       (nr_pages = pagevec_lookup_range_tag(&pvec, mapping, &index, end,
-			tag, PAGEVEC_SIZE))) {
+			tag))) {
 		unsigned i;
 
 		scanned = 1;
@@ -3961,8 +3961,8 @@ static int extent_write_cache_pages(struct address_space *mapping,
 		tag_pages_for_writeback(mapping, index, end);
 	done_index = index;
 	while (!done && !nr_to_write_done && (index <= end) &&
-	       (nr_pages = pagevec_lookup_range_tag(&pvec, mapping, &index, end,
-			tag, PAGEVEC_SIZE))) {
+			(nr_pages = pagevec_lookup_range_tag(&pvec, mapping,
+						&index, end, tag))) {
 		unsigned i;
 
 		scanned = 1;
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index 69f11233d0d6..1e2c6d6e09eb 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -2620,7 +2620,7 @@ static int mpage_prepare_extent_to_map(struct mpage_da_data *mpd)
 	mpd->next_page = index;
 	while (index <= end) {
 		nr_pages = pagevec_lookup_range_tag(&pvec, mapping, &index, end,
-				tag, PAGEVEC_SIZE);
+				tag);
 		if (nr_pages == 0)
 			goto out;
 
diff --git a/fs/f2fs/checkpoint.c b/fs/f2fs/checkpoint.c
index 54ccf5ba8191..3ed9dcbf70ae 100644
--- a/fs/f2fs/checkpoint.c
+++ b/fs/f2fs/checkpoint.c
@@ -319,7 +319,7 @@ long sync_meta_pages(struct f2fs_sb_info *sbi, enum page_type type,
 	blk_start_plug(&plug);
 
 	while (nr_pages = pagevec_lookup_tag(&pvec, mapping, &index,
-				PAGECACHE_TAG_DIRTY, PAGEVEC_SIZE)) {
+				PAGECACHE_TAG_DIRTY)) {
 		int i;
 
 		for (i = 0; i < nr_pages; i++) {
diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
index 17d2c2997ddd..687703755824 100644
--- a/fs/f2fs/data.c
+++ b/fs/f2fs/data.c
@@ -1670,7 +1670,7 @@ static int f2fs_write_cache_pages(struct address_space *mapping,
 		int i;
 
 		nr_pages = pagevec_lookup_range_tag(&pvec, mapping, &index, end,
-				tag, PAGEVEC_SIZE);
+				tag);
 		if (nr_pages == 0)
 			break;
 
diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c
index f9ccbda73ea9..d4ceb9ebfe92 100644
--- a/fs/f2fs/node.c
+++ b/fs/f2fs/node.c
@@ -1286,7 +1286,7 @@ static struct page *last_fsync_dnode(struct f2fs_sb_info *sbi, nid_t ino)
 	index = 0;
 
 	while (nr_pages = pagevec_lookup_tag(&pvec, NODE_MAPPING(sbi), &index,
-				PAGECACHE_TAG_DIRTY, PAGEVEC_SIZE)) {
+				PAGECACHE_TAG_DIRTY)) {
 		int i;
 
 		for (i = 0; i < nr_pages; i++) {
@@ -1440,7 +1440,7 @@ int fsync_node_pages(struct f2fs_sb_info *sbi, struct inode *inode,
 	index = 0;
 
 	while (nr_pages = pagevec_lookup_tag(&pvec, NODE_MAPPING(sbi), &index,
-				PAGECACHE_TAG_DIRTY, PAGEVEC_SIZE)) {
+				PAGECACHE_TAG_DIRTY)) {
 		int i;
 
 		for (i = 0; i < nr_pages; i++) {
@@ -1553,7 +1553,7 @@ int sync_node_pages(struct f2fs_sb_info *sbi, struct writeback_control *wbc,
 	index = 0;
 
 	while (nr_pages = pagevec_lookup_tag(&pvec, NODE_MAPPING(sbi), &index,
-				PAGECACHE_TAG_DIRTY, PAGEVEC_SIZE)) {
+				PAGECACHE_TAG_DIRTY)) {
 		int i;
 
 		for (i = 0; i < nr_pages; i++) {
@@ -1651,7 +1651,7 @@ int wait_on_node_pages_writeback(struct f2fs_sb_info *sbi, nid_t ino)
 	pagevec_init(&pvec, 0);
 
 	while (nr_pages = pagevec_lookup_tag(&pvec, NODE_MAPPING(sbi), &index,
-				PAGECACHE_TAG_WRITEBACK, PAGEVEC_SIZE)) {
+				PAGECACHE_TAG_WRITEBACK)) {
 		int i;
 
 		for (i = 0; i < nr_pages; i++) {
diff --git a/fs/gfs2/aops.c b/fs/gfs2/aops.c
index d0848d9623fb..3fea3d7780b0 100644
--- a/fs/gfs2/aops.c
+++ b/fs/gfs2/aops.c
@@ -398,7 +398,7 @@ static int gfs2_write_cache_jdata(struct address_space *mapping,
 	done_index = index;
 	while (!done && (index <= end)) {
 		nr_pages = pagevec_lookup_range_tag(&pvec, mapping, &index, end,
-				tag, PAGEVEC_SIZE);
+				tag);
 		if (nr_pages == 0)
 			break;
 
diff --git a/fs/nilfs2/btree.c b/fs/nilfs2/btree.c
index 06ffa135dfa6..35989c7bb065 100644
--- a/fs/nilfs2/btree.c
+++ b/fs/nilfs2/btree.c
@@ -2158,8 +2158,8 @@ static void nilfs_btree_lookup_dirty_buffers(struct nilfs_bmap *btree,
 
 	pagevec_init(&pvec, 0);
 
-	while (pagevec_lookup_tag(&pvec, btcache, &index, PAGECACHE_TAG_DIRTY,
-				  PAGEVEC_SIZE)) {
+	while (pagevec_lookup_tag(&pvec, btcache, &index,
+					PAGECACHE_TAG_DIRTY)) {
 		for (i = 0; i < pagevec_count(&pvec); i++) {
 			bh = head = page_buffers(pvec.pages[i]);
 			do {
diff --git a/fs/nilfs2/page.c b/fs/nilfs2/page.c
index 8616c46d33da..1c16726915c1 100644
--- a/fs/nilfs2/page.c
+++ b/fs/nilfs2/page.c
@@ -257,8 +257,7 @@ int nilfs_copy_dirty_pages(struct address_space *dmap,
 
 	pagevec_init(&pvec, 0);
 repeat:
-	if (!pagevec_lookup_tag(&pvec, smap, &index, PAGECACHE_TAG_DIRTY,
-				PAGEVEC_SIZE))
+	if (!pagevec_lookup_tag(&pvec, smap, &index, PAGECACHE_TAG_DIRTY))
 		return 0;
 
 	for (i = 0; i < pagevec_count(&pvec); i++) {
@@ -376,8 +375,8 @@ void nilfs_clear_dirty_pages(struct address_space *mapping, bool silent)
 
 	pagevec_init(&pvec, 0);
 
-	while (pagevec_lookup_tag(&pvec, mapping, &index, PAGECACHE_TAG_DIRTY,
-				  PAGEVEC_SIZE)) {
+	while (pagevec_lookup_tag(&pvec, mapping, &index,
+					PAGECACHE_TAG_DIRTY)) {
 		for (i = 0; i < pagevec_count(&pvec); i++) {
 			struct page *page = pvec.pages[i];
 
diff --git a/fs/nilfs2/segment.c b/fs/nilfs2/segment.c
index 68e5769cef3b..19366ab20bea 100644
--- a/fs/nilfs2/segment.c
+++ b/fs/nilfs2/segment.c
@@ -712,7 +712,7 @@ static size_t nilfs_lookup_dirty_data_buffers(struct inode *inode,
  repeat:
 	if (unlikely(index > last) ||
 	    !pagevec_lookup_range_tag(&pvec, mapping, &index, last,
-				PAGECACHE_TAG_DIRTY, PAGEVEC_SIZE))
+				PAGECACHE_TAG_DIRTY))
 		return ndirties;
 
 	for (i = 0; i < pagevec_count(&pvec); i++) {
@@ -755,8 +755,8 @@ static void nilfs_lookup_dirty_node_buffers(struct inode *inode,
 
 	pagevec_init(&pvec, 0);
 
-	while (pagevec_lookup_tag(&pvec, mapping, &index, PAGECACHE_TAG_DIRTY,
-				  PAGEVEC_SIZE)) {
+	while (pagevec_lookup_tag(&pvec, mapping, &index,
+					PAGECACHE_TAG_DIRTY)) {
 		for (i = 0; i < pagevec_count(&pvec); i++) {
 			bh = head = page_buffers(pvec.pages[i]);
 			do {
diff --git a/include/linux/pagevec.h b/include/linux/pagevec.h
index 0281b1d3a91b..553b5e6fbbc5 100644
--- a/include/linux/pagevec.h
+++ b/include/linux/pagevec.h
@@ -39,16 +39,14 @@ static inline unsigned pagevec_lookup(struct pagevec *pvec,
 
 unsigned pagevec_lookup_range_tag(struct pagevec *pvec,
 		struct address_space *mapping, pgoff_t *index, pgoff_t end,
-		int tag, unsigned nr_pages);
+		int tag);
 unsigned pagevec_lookup_range_nr_tag(struct pagevec *pvec,
 		struct address_space *mapping, pgoff_t *index, pgoff_t end,
 		int tag, unsigned max_pages);
 static inline unsigned pagevec_lookup_tag(struct pagevec *pvec,
-		struct address_space *mapping, pgoff_t *index, int tag,
-		unsigned nr_pages)
+		struct address_space *mapping, pgoff_t *index, int tag)
 {
-	return pagevec_lookup_range_tag(pvec, mapping, index, (pgoff_t)-1, tag,
-					nr_pages);
+	return pagevec_lookup_range_tag(pvec, mapping, index, (pgoff_t)-1, tag);
 }
 
 static inline void pagevec_init(struct pagevec *pvec, int cold)
diff --git a/mm/filemap.c b/mm/filemap.c
index 479fc54b7cd1..76ef52045550 100644
--- a/mm/filemap.c
+++ b/mm/filemap.c
@@ -422,7 +422,7 @@ static void __filemap_fdatawait_range(struct address_space *mapping,
 	pagevec_init(&pvec, 0);
 	while ((index <= end) &&
 			(nr_pages = pagevec_lookup_range_tag(&pvec, mapping,
-			&index, end, PAGECACHE_TAG_WRITEBACK, PAGEVEC_SIZE))) {
+			&index, end, PAGECACHE_TAG_WRITEBACK))) {
 		unsigned i;
 
 		for (i = 0; i < nr_pages; i++) {
diff --git a/mm/page-writeback.c b/mm/page-writeback.c
index 43b18e185fbd..145054a2447f 100644
--- a/mm/page-writeback.c
+++ b/mm/page-writeback.c
@@ -2195,7 +2195,7 @@ int write_cache_pages(struct address_space *mapping,
 		int i;
 
 		nr_pages = pagevec_lookup_range_tag(&pvec, mapping, &index, end,
-				tag, PAGEVEC_SIZE);
+				tag);
 		if (nr_pages == 0)
 			break;
 
diff --git a/mm/swap.c b/mm/swap.c
index 97186da8e5bd..ef3bcbab776e 100644
--- a/mm/swap.c
+++ b/mm/swap.c
@@ -988,10 +988,10 @@ EXPORT_SYMBOL(pagevec_lookup_range);
 
 unsigned pagevec_lookup_range_tag(struct pagevec *pvec,
 		struct address_space *mapping, pgoff_t *index, pgoff_t end,
-		int tag, unsigned nr_pages)
+		int tag)
 {
 	pvec->nr = find_get_pages_range_tag(mapping, index, end, tag,
-					nr_pages, pvec->pages);
+					PAGEVEC_SIZE, pvec->pages);
 	return pagevec_count(pvec);
 }
 EXPORT_SYMBOL(pagevec_lookup_range_tag);
-- 
2.12.3
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply related	[flat|nested] 27+ messages in thread* Re: [PATCH 14/15] mm: Remove nr_pages argument from pagevec_lookup_{,range}_tag()
  2017-09-27 16:03 ` [PATCH 14/15] mm: Remove nr_pages argument from pagevec_lookup_{,range}_tag() Jan Kara
@ 2017-09-29 21:46   ` Daniel Jordan
  2017-10-03  9:07     ` Jan Kara
  0 siblings, 1 reply; 27+ messages in thread
From: Daniel Jordan @ 2017-09-29 21:46 UTC (permalink / raw)
  To: Jan Kara; +Cc: Andrew Morton, linux-mm, linux-fsdevel
On 09/27/2017 12:03 PM, Jan Kara wrote:
> All users of pagevec_lookup() and pagevec_lookup_range() now pass
> PAGEVEC_SIZE as a desired number of pages. Just drop the argument.
>
> Signed-off-by: Jan Kara <jack@suse.cz>
> ---
>   fs/btrfs/extent_io.c    | 6 +++---
There's one place that got missed in fs/ceph/addr.c:
diff --git a/fs/ceph/addr.c b/fs/ceph/addr.c
index 87789c477381..ee68b3db6729 100644
--- a/fs/ceph/addr.c
+++ b/fs/ceph/addr.c
@@ -1161,8 +1161,7 @@ static int ceph_writepages_start(struct 
address_space *mapping,
                         index = 0;
                         while ((index <= end) &&
                                (nr = pagevec_lookup_tag(&pvec, mapping, 
&index,
- PAGECACHE_TAG_WRITEBACK,
- PAGEVEC_SIZE))) {
+ PAGECACHE_TAG_WRITEBACK))) {
                                 for (i = 0; i < nr; i++) {
                                         page = pvec.pages[i];
                                         if (page_snap_context(page) != 
snapc)
Daniel
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply related	[flat|nested] 27+ messages in thread* Re: [PATCH 14/15] mm: Remove nr_pages argument from pagevec_lookup_{,range}_tag()
  2017-09-29 21:46   ` Daniel Jordan
@ 2017-10-03  9:07     ` Jan Kara
  0 siblings, 0 replies; 27+ messages in thread
From: Jan Kara @ 2017-10-03  9:07 UTC (permalink / raw)
  To: Daniel Jordan; +Cc: Jan Kara, Andrew Morton, linux-mm, linux-fsdevel
On Fri 29-09-17 17:46:24, Daniel Jordan wrote:
> On 09/27/2017 12:03 PM, Jan Kara wrote:
> >All users of pagevec_lookup() and pagevec_lookup_range() now pass
> >PAGEVEC_SIZE as a desired number of pages. Just drop the argument.
> >
> >Signed-off-by: Jan Kara <jack@suse.cz>
> >---
> >  fs/btrfs/extent_io.c    | 6 +++---
> 
> There's one place that got missed in fs/ceph/addr.c:
Ah, that's probably from a rebase I did. Thanks for catching this!
								Honza
> 
> diff --git a/fs/ceph/addr.c b/fs/ceph/addr.c
> index 87789c477381..ee68b3db6729 100644
> --- a/fs/ceph/addr.c
> +++ b/fs/ceph/addr.c
> @@ -1161,8 +1161,7 @@ static int ceph_writepages_start(struct address_space
> *mapping,
>                         index = 0;
>                         while ((index <= end) &&
>                                (nr = pagevec_lookup_tag(&pvec, mapping,
> &index,
> - PAGECACHE_TAG_WRITEBACK,
> - PAGEVEC_SIZE))) {
> + PAGECACHE_TAG_WRITEBACK))) {
>                                 for (i = 0; i < nr; i++) {
>                                         page = pvec.pages[i];
>                                         if (page_snap_context(page) !=
> snapc)
> 
> 
> Daniel
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply	[flat|nested] 27+ messages in thread
* [PATCH 15/15] afs: Use find_get_pages_range_tag()
  2017-09-27 16:03 [PATCH 0/15 v2] Ranged pagevec tagged lookup Jan Kara
                   ` (13 preceding siblings ...)
  2017-09-27 16:03 ` [PATCH 14/15] mm: Remove nr_pages argument from pagevec_lookup_{,range}_tag() Jan Kara
@ 2017-09-27 16:03 ` Jan Kara
  2017-09-29 21:46   ` Daniel Jordan
  14 siblings, 1 reply; 27+ messages in thread
From: Jan Kara @ 2017-09-27 16:03 UTC (permalink / raw)
  To: Andrew Morton; +Cc: linux-mm, linux-fsdevel, Jan Kara, David Howells, linux-afs
Use find_get_pages_range_tag() in afs_writepages_region() as we are
interested only in pages from given range. Remove unnecessary code after
this conversion.
CC: David Howells <dhowells@redhat.com>
CC: linux-afs@lists.infradead.org
Signed-off-by: Jan Kara <jack@suse.cz>
---
 fs/afs/write.c | 11 ++---------
 1 file changed, 2 insertions(+), 9 deletions(-)
diff --git a/fs/afs/write.c b/fs/afs/write.c
index 106e43db1115..d62a6b54152d 100644
--- a/fs/afs/write.c
+++ b/fs/afs/write.c
@@ -497,20 +497,13 @@ static int afs_writepages_region(struct address_space *mapping,
 	_enter(",,%lx,%lx,", index, end);
 
 	do {
-		n = find_get_pages_tag(mapping, &index, PAGECACHE_TAG_DIRTY,
-				       1, &page);
+		n = find_get_pages_range_tag(mapping, &index, end,
+					PAGECACHE_TAG_DIRTY, 1, &page);
 		if (!n)
 			break;
 
 		_debug("wback %lx", page->index);
 
-		if (page->index > end) {
-			*_next = index;
-			put_page(page);
-			_leave(" = 0 [%lx]", *_next);
-			return 0;
-		}
-
 		/* at this point we hold neither mapping->tree_lock nor lock on
 		 * the page itself: the page may be truncated or invalidated
 		 * (changing page->mapping to NULL), or even swizzled back from
-- 
2.12.3
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply related	[flat|nested] 27+ messages in thread* Re: [PATCH 15/15] afs: Use find_get_pages_range_tag()
  2017-09-27 16:03 ` [PATCH 15/15] afs: Use find_get_pages_range_tag() Jan Kara
@ 2017-09-29 21:46   ` Daniel Jordan
  2017-10-03 12:03     ` Jan Kara
  0 siblings, 1 reply; 27+ messages in thread
From: Daniel Jordan @ 2017-09-29 21:46 UTC (permalink / raw)
  To: Jan Kara; +Cc: Andrew Morton, linux-mm, linux-fsdevel, David Howells, linux-afs
On 09/27/2017 12:03 PM, Jan Kara wrote:
> Use find_get_pages_range_tag() in afs_writepages_region() as we are
> interested only in pages from given range. Remove unnecessary code after
> this conversion.
>
> CC: David Howells <dhowells@redhat.com>
> CC: linux-afs@lists.infradead.org
> Signed-off-by: Jan Kara <jack@suse.cz>
> ---
>   fs/afs/write.c | 11 ++---------
>   1 file changed, 2 insertions(+), 9 deletions(-)
>
> diff --git a/fs/afs/write.c b/fs/afs/write.c
> index 106e43db1115..d62a6b54152d 100644
> --- a/fs/afs/write.c
> +++ b/fs/afs/write.c
> @@ -497,20 +497,13 @@ static int afs_writepages_region(struct address_space *mapping,
>   	_enter(",,%lx,%lx,", index, end);
>   
>   	do {
> -		n = find_get_pages_tag(mapping, &index, PAGECACHE_TAG_DIRTY,
> -				       1, &page);
> +		n = find_get_pages_range_tag(mapping, &index, end,
> +					PAGECACHE_TAG_DIRTY, 1, &page);
>   		if (!n)
>   			break;
>   
>   		_debug("wback %lx", page->index);
>   
> -		if (page->index > end) {
> -			*_next = index;
> -			put_page(page);
> -			_leave(" = 0 [%lx]", *_next);
> -			return 0;
> -		}
> -
>   		/* at this point we hold neither mapping->tree_lock nor lock on
>   		 * the page itself: the page may be truncated or invalidated
>   		 * (changing page->mapping to NULL), or even swizzled back from
There's also one other caller of find_get_pages_tag that could be 
converted, wdata_alloc_and_fillpages.  Since the 256 max mentioned in 
the comment below no longer seems to apply, maybe something like this?:
diff --git a/fs/cifs/file.c b/fs/cifs/file.c
index 92fdf9c35de2..4dbd24231e8a 100644
--- a/fs/cifs/file.c
+++ b/fs/cifs/file.c
@@ -1963,31 +1963,14 @@ wdata_alloc_and_fillpages(pgoff_t tofind, struct 
address_space *mapping,
                           pgoff_t end, pgoff_t *index,
                           unsigned int *found_pages)
  {
-       unsigned int nr_pages;
-       struct page **pages;
-       struct cifs_writedata *wdata;
-
-       wdata = cifs_writedata_alloc((unsigned int)tofind,
-                                    cifs_writev_complete);
+       struct cifs_writedata *wdata = 
cifs_writedata_alloc((unsigned)tofind,
+ cifs_writev_complete);
         if (!wdata)
                 return NULL;
-       /*
-        * find_get_pages_tag seems to return a max of 256 on each
-        * iteration, so we must call it several times in order to
-        * fill the array or the wsize is effectively limited to
-        * 256 * PAGE_SIZE.
-        */
-       *found_pages = 0;
-       pages = wdata->pages;
-       do {
-               nr_pages = find_get_pages_tag(mapping, index,
-                                             PAGECACHE_TAG_DIRTY, tofind,
-                                             pages);
-               *found_pages += nr_pages;
-               tofind -= nr_pages;
-               pages += nr_pages;
-       } while (nr_pages && tofind && *index <= end);
+       *found_pages = find_get_pages_range_tag(mapping, index, end,
+                                               PAGECACHE_TAG_DIRTY, tofind,
+                                               wdata->pages);
         return wdata;
  }
Otherwise the set looks good, so for the whole thing,
Reviewed-by: Daniel Jordan <daniel.m.jordan@oracle.com>
Daniel
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply related	[flat|nested] 27+ messages in thread* Re: [PATCH 15/15] afs: Use find_get_pages_range_tag()
  2017-09-29 21:46   ` Daniel Jordan
@ 2017-10-03 12:03     ` Jan Kara
  0 siblings, 0 replies; 27+ messages in thread
From: Jan Kara @ 2017-10-03 12:03 UTC (permalink / raw)
  To: Daniel Jordan
  Cc: Jan Kara, Andrew Morton, linux-mm, linux-fsdevel, David Howells,
	linux-afs
On Fri 29-09-17 17:46:45, Daniel Jordan wrote:
> On 09/27/2017 12:03 PM, Jan Kara wrote:
> >Use find_get_pages_range_tag() in afs_writepages_region() as we are
> >interested only in pages from given range. Remove unnecessary code after
> >this conversion.
> >
> >CC: David Howells <dhowells@redhat.com>
> >CC: linux-afs@lists.infradead.org
> >Signed-off-by: Jan Kara <jack@suse.cz>
> >---
> >  fs/afs/write.c | 11 ++---------
> >  1 file changed, 2 insertions(+), 9 deletions(-)
> >
> >diff --git a/fs/afs/write.c b/fs/afs/write.c
> >index 106e43db1115..d62a6b54152d 100644
> >--- a/fs/afs/write.c
> >+++ b/fs/afs/write.c
> >@@ -497,20 +497,13 @@ static int afs_writepages_region(struct address_space *mapping,
> >  	_enter(",,%lx,%lx,", index, end);
> >  	do {
> >-		n = find_get_pages_tag(mapping, &index, PAGECACHE_TAG_DIRTY,
> >-				       1, &page);
> >+		n = find_get_pages_range_tag(mapping, &index, end,
> >+					PAGECACHE_TAG_DIRTY, 1, &page);
> >  		if (!n)
> >  			break;
> >  		_debug("wback %lx", page->index);
> >-		if (page->index > end) {
> >-			*_next = index;
> >-			put_page(page);
> >-			_leave(" = 0 [%lx]", *_next);
> >-			return 0;
> >-		}
> >-
> >  		/* at this point we hold neither mapping->tree_lock nor lock on
> >  		 * the page itself: the page may be truncated or invalidated
> >  		 * (changing page->mapping to NULL), or even swizzled back from
> 
> There's also one other caller of find_get_pages_tag that could be converted,
> wdata_alloc_and_fillpages.  Since the 256 max mentioned in the comment below
> no longer seems to apply, maybe something like this?:
Yeah, added a patch doing something like this.
> diff --git a/fs/cifs/file.c b/fs/cifs/file.c
> index 92fdf9c35de2..4dbd24231e8a 100644
> --- a/fs/cifs/file.c
> +++ b/fs/cifs/file.c
> @@ -1963,31 +1963,14 @@ wdata_alloc_and_fillpages(pgoff_t tofind, struct
> address_space *mapping,
>                           pgoff_t end, pgoff_t *index,
>                           unsigned int *found_pages)
>  {
> -       unsigned int nr_pages;
> -       struct page **pages;
> -       struct cifs_writedata *wdata;
> -
> -       wdata = cifs_writedata_alloc((unsigned int)tofind,
> -                                    cifs_writev_complete);
> +       struct cifs_writedata *wdata =
> cifs_writedata_alloc((unsigned)tofind,
> + cifs_writev_complete);
>         if (!wdata)
>                 return NULL;
> 
> -       /*
> -        * find_get_pages_tag seems to return a max of 256 on each
> -        * iteration, so we must call it several times in order to
> -        * fill the array or the wsize is effectively limited to
> -        * 256 * PAGE_SIZE.
> -        */
> -       *found_pages = 0;
> -       pages = wdata->pages;
> -       do {
> -               nr_pages = find_get_pages_tag(mapping, index,
> -                                             PAGECACHE_TAG_DIRTY, tofind,
> -                                             pages);
> -               *found_pages += nr_pages;
> -               tofind -= nr_pages;
> -               pages += nr_pages;
> -       } while (nr_pages && tofind && *index <= end);
> +       *found_pages = find_get_pages_range_tag(mapping, index, end,
> +                                               PAGECACHE_TAG_DIRTY, tofind,
> +                                               wdata->pages);
> 
>         return wdata;
>  }
> 
> Otherwise the set looks good, so for the whole thing,
> 
> Reviewed-by: Daniel Jordan <daniel.m.jordan@oracle.com>
Thanks for review!
								Honza
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply	[flat|nested] 27+ messages in thread