Ranged pagevec tagged lookup
Subsystems (12)
Jan Kara
maintainerv3 cover Ranged pagevec tagged lookup
Hello,
This is second part of the split out of the larger series to clean up pagevec APIs and provide ranged lookups. In this series I provide a ranged variant of pagevec_lookup_tag() and use it in places where it makes sense. This series removes some common code and it also has a potential for speeding up some operations similarly as for pagevec_lookup_range() (but for now I can think of only artificial cases where this happens).
The patches where filesystem changes are non-trivial got reviewed so I'm confident enough that this can get merged. Andrew can you consider picking these patches up please?
Full series including dependencies can be also obtained from my git tree:
git://git.kernel.org/pub/scm/linux/kernel/git/jack/linux-fs.git find_get_pages_range
Opinions and review welcome!
Honza
Changes since v2:
* style fixup in __filemap_fdatawait_range() suggested by Dave Chinner
* added couple of Reviewed-by tags
* fixed wrong EXPORT_SYMBOL spotted by Daniel Jordan
* added missed Ceph conversion spotted by Daniel Jordan
* added conversion of Cifs suggested by Daniel Jordan
* rebased on top of 4.14-rc4
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Jan Kara
maintainerPATCH v3 1/16 mm: Implement find_get_pages_range_tag()
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.
--- 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(-)
include/linux/pagemap.h +10 -2
@@ -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);
include/linux/pagevec.h +9 -2
@@ -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) {
mm/filemap.c +24 -9
@@ -1754,9 +1754,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
@@ -1764,8 +1765,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;
@@ -1778,6 +1780,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))
@@ -1819,18 +1824,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
mm/swap.c +5 -4
@@ -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
Signature · 7 lines
2.12.3 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Jan Kara
maintainerPATCH v3 2/16 btrfs: Use pagevec_lookup_range_tag()
In reply to Jan KaraWe 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.
--- fs/btrfs/extent_io.c | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-)
fs/btrfs/extent_io.c +4 -15
@@ -3818,8 +3818,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 ;
@@ -3829,11 +3829,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);
@@ -3965,8 +3960,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 ;
@@ -3991,12 +3986,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);
Signature · 7 lines
2.12.3 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Jan Kara
maintainerPATCH v3 3/16 ceph: Use pagevec_lookup_range_tag()
In reply to Jan KaraWe want only pages from given range in ceph_writepages_start(). Use pagevec_lookup_range_tag() instead of pagevec_lookup_tag() and remove unnecessary code.
--- fs/ceph/addr.c | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-)
fs/ceph/addr.c +3 -16
@@ -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);
Signature · 7 lines
2.12.3 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Jan Kara
maintainerPATCH v3 4/16 ext4: Use pagevec_lookup_range_tag()
In reply to Jan KaraWe want only pages from given range in ext4_writepages(). Use pagevec_lookup_range_tag() instead of pagevec_lookup_tag() and remove unnecessary code.
--- fs/ext4/inode.c | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-)
fs/ext4/inode.c +2 -12
@@ -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
Signature · 7 lines
2.12.3 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Jan Kara
maintainerPATCH v3 5/16 f2fs: Use pagevec_lookup_range_tag()
In reply to Jan KaraWe 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.
--- fs/f2fs/data.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-)
fs/f2fs/data.c +2 -7
@@ -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);
Signature · 7 lines
2.12.3 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Jan Kara
maintainerPATCH v3 6/16 f2fs: Simplify page iteration loops
In reply to Jan KaraIn 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.
--- fs/f2fs/checkpoint.c | 13 ++++------- fs/f2fs/node.c | 65 +++++++++++++++++++--------------------------------- 2 files changed, 28 insertions(+), 50 deletions(-)
fs/f2fs/checkpoint.c +5 -8
@@ -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];
fs/f2fs/node.c +23 -42
124 lines not on this page · raw message
Signature · 7 lines
2.12.3 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Jan Kara
maintainerPATCH v3 7/16 f2fs: Use find_get_pages_tag() for looking up single page
In reply to Jan Kara__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.
--- fs/f2fs/file.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)
fs/f2fs/file.c +7 -6
@@ -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; }
Signature · 7 lines
2.12.3 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Jan Kara
maintainerPATCH v3 8/16 gfs2: Use pagevec_lookup_range_tag()
In reply to Jan KaraWe 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.
--- fs/gfs2/aops.c | 20 ++------------------ 1 file changed, 2 insertions(+), 18 deletions(-)
fs/gfs2/aops.c +2 -18
@@ -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 ;
Signature · 1 line
2.12.3
Jan Kara
maintainerPATCH v3 9/16 nilfs2: Use pagevec_lookup_range_tag()
In reply to Jan KaraWe 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.
--- fs/nilfs2/segment.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)
fs/nilfs2/segment.c +2 -6
@@ -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 );
Signature · 6 lines
2.12.3 -- To unsubscribe from this list: send the line "unsubscribe linux-nilfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Jan Kara
maintainerPATCH v3 10/16 mm: Use pagevec_lookup_range_tag() in __filemap_fdatawait_range()
In reply to Jan KaraUse pagevec_lookup_range_tag() in __filemap_fdatawait_range() as it is interested only in pages from given range. Remove unnecessary code resulting from this.
--- mm/filemap.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-)
mm/filemap.c +6 -8
@@ -420,19 +420,17 @@ static void __filemap_fdatawait_range(struct address_space *mapping,return ;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 ) { +while (index <= end) {unsigned i; + nr_pages =pagevec_lookup_range_tag (&pvec, mapping, &index, + end,PAGECACHE_TAG_WRITEBACK ,PAGEVEC_SIZE ); +if (!nr_pages) +break ; +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); }
Signature · 7 lines
2.12.3 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Jan Kara
maintainerPATCH v3 11/16 mm: Use pagevec_lookup_range_tag() in write_cache_pages()
In reply to Jan KaraUse pagevec_lookup_range_tag() in write_cache_pages() as it is interested only in pages from given range. Remove unnecessary code resulting from this.
--- mm/page-writeback.c | 20 ++------------------ 1 file changed, 2 insertions(+), 18 deletions(-)
mm/page-writeback.c +2 -18
@@ -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);
Signature · 7 lines
2.12.3 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Jan Kara
maintainerPATCH v3 12/16 mm: Add variant of pagevec_lookup_range_tag() taking number of pages
In reply to Jan KaraCurrently 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().
--- include/linux/pagevec.h | 3 +++ mm/swap.c | 9 +++++++++ 2 files changed, 12 insertions(+)
include/linux/pagevec.h +3 -0
@@ -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)
mm/swap.c +9 -0
@@ -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_nr_tag);/* * Perform any setup for the swap system */
Signature · 7 lines
2.12.3 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Jan Kara
maintainerPATCH v3 13/16 ceph: Use pagevec_lookup_range_nr_tag()
In reply to Jan KaraUse new function for looking up pages since nr_pages argument from pagevec_lookup_range_tag() is going away.
--- fs/ceph/addr.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
fs/ceph/addr.c +2 -4
@@ -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 ;
Signature · 7 lines
2.12.3 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Jan Kara
maintainerPATCH v3 14/16 mm: Remove nr_pages argument from pagevec_lookup_{,range}_tag()
In reply to Jan KaraAll users of pagevec_lookup() and pagevec_lookup_range() now pass PAGEVEC_SIZE as a desired number of pages. Just drop the argument.
--- fs/btrfs/extent_io.c | 6 +++--- fs/ceph/addr.c | 3 +-- 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 ++-- 14 files changed, 27 insertions(+), 31 deletions(-)
fs/btrfs/extent_io.c +3 -3
@@ -3819,7 +3819,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 ;
@@ -3960,8 +3960,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 ;
fs/ceph/addr.c +1 -2
@@ -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)
fs/ext4/inode.c +1 -1
@@ -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;
fs/f2fs/checkpoint.c +1 -1
@@ -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++) {
fs/f2fs/data.c +1 -1
@@ -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 ;
fs/f2fs/node.c +4 -4
@@ -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++) {
fs/gfs2/aops.c +1 -1
@@ -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 ;
fs/nilfs2/btree.c +2 -2
@@ -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 {
fs/nilfs2/page.c +3 -4
@@ -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];
fs/nilfs2/segment.c +3 -3
@@ -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 {
include/linux/pagevec.h +3 -5
@@ -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)
mm/filemap.c +1 -1
@@ -424,7 +424,7 @@ static void __filemap_fdatawait_range(struct address_space *mapping,unsigned i; nr_pages =pagevec_lookup_range_tag (&pvec, mapping, &index, - end,PAGECACHE_TAG_WRITEBACK ,PAGEVEC_SIZE ); + end,PAGECACHE_TAG_WRITEBACK );if (!nr_pages)break ;
mm/page-writeback.c +1 -1
@@ -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 ;
mm/swap.c +2 -2
@@ -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);
Signature · 1 line
2.12.3
Jan Kara
maintainerPATCH v3 15/16 afs: Use find_get_pages_range_tag()
In reply to Jan KaraUse 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.
--- fs/afs/write.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-)
fs/afs/write.c +2 -9
@@ -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
Signature · 7 lines
2.12.3 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Jan Kara
maintainerPATCH v3 16/16 cifs: Use find_get_pages_range_tag()
In reply to Jan Karawdata_alloc_and_fillpages() needlessly iterates calls to find_get_pages_tag(). Also it wants only pages from given range. Make it use find_get_pages_range_tag().
--- fs/cifs/file.c | 21 ++------------------- 1 file changed, 2 insertions(+), 19 deletions(-)
fs/cifs/file.c +2 -19
@@ -1963,8 +1963,6 @@ 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,
@@ -1972,23 +1970,8 @@ wdata_alloc_and_fillpages(pgoff_t tofind, struct address_space *mapping,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; }
Signature · 1 line
2.12.3
Re: [PATCH 16/16] cifs: Use find_get_pages_range_tag()
Hi Jan,
Quoted 3 lines · Jan Kara
wdata_alloc_and_fillpages()needlessly iterates calls tofind_get_pages_tag(). Also it wants only pages from given range. Make it usefind_get_pages_range_tag().
Looks good, so
The rest of the v3 updates seem fine, too.
Daniel
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>