pagevec API cleanups
Subsystems (19)
Jan Kara
maintainercover pagevec API cleanups
Hello,
This series cleans up pagevec API. The original motivation for the series is the patch "fs: Fix performance regression in clean_bdev_aliases()" however it has somewhat grown beyond that... The series is pretty large but most of the patches are trivial in nature. What the series does is:
* Make all pagevec_lookup_ and find_get_ functions update index to where the search terminated. Currently tagged page lookup did update the index, other variants did not...
* Implement ranged variants for pagevec_lookup and find_get_ functions. Lot of callers actually want a ranged lookup and we unnecessarily opencode this in lot of them.
* Remove nr_pages argument from pagevec_ API since after implementing ranged lookups everyone just wants to pass PAGEVEC_SIZE there.
The conversion of the APIs for entries variants is not such a clear win as for the other cases as callers tend to play more complex games with indices etc. (hello THP). I still think the conversion is worth it for consistency but I'm open to ideas (including just discarding that part) there.
The series also contains several fixes in the beginning to the bugs that I've found during these cleanups. I've included them to have a clean base (4.12-rc3) but those should get merged independently (e.g. ext4 fixes are already sitting in ext4 tree). Also it is possible to split the series in smaller parts (like convert one API at a time) however I wanted to post the full series so that people can get the full picture.
The series 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
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot
Jan Kara
maintainerPATCH 1/35 fscache: Remove unused ->now_uncached callback
The callback doesn't ever get called. Remove it.
--- Documentation/filesystems/caching/netfs-api.txt | 2 -- fs/9p/cache.c | 29 ----------------- fs/afs/cache.c | 43 ------------------------- fs/ceph/cache.c | 31 ------------------ fs/cifs/cache.c | 31 ------------------ fs/nfs/fscache-index.c | 40 ----------------------- include/linux/fscache.h | 9 ------ 7 files changed, 185 deletions(-)
Documentation/filesystems/caching/netfs-api.txt +0 -2
@@ -151,8 +151,6 @@ To define an object, a structure of the following type should be filled out: void (*mark_pages_cached)(void *cookie_netfs_data, struct address_space *mapping, struct pagevec *cached_pvec); - - void (*now_uncached)(void *cookie_netfs_data); }; This has the following fields:
fs/9p/cache.c +0 -29
@@ -151,34 +151,6 @@ fscache_checkaux v9fs_cache_inode_check_aux(void *cookie_netfs_data,return FSCACHE_CHECKAUX_OKAY ; } -static void v9fs_cache_inode_now_uncached (void *cookie_netfs_data) -{ -struct v9fs_inode *v9inode = cookie_netfs_data; -struct pagevec pvec; -pgoff_t first; -int loop, nr_pages; - -pagevec_init (&pvec,0 ); - first =0 ; - -for (;;) { - nr_pages =pagevec_lookup (&pvec, v9inode->vfs_inode.i_mapping, - first, -PAGEVEC_SIZE -pagevec_count (&pvec)); -if (!nr_pages) -break ; - -for (loop =0 ; loop < nr_pages; loop++) -ClearPageFsCache (pvec.pages[loop]); - - first = pvec.pages[nr_pages -1 ]->index +1 ; - - pvec.nr = nr_pages; -pagevec_release (&pvec); -cond_resched (); - } -} -const struct fscache_cookie_def v9fs_cache_inode_index_def = { .name ="9p.inode" , .type =FSCACHE_COOKIE_TYPE_DATAFILE ,
@@ -186,7 +158,6 @@ const struct fscache_cookie_def v9fs_cache_inode_index_def = { .get_attr = v9fs_cache_inode_get_attr, .get_aux = v9fs_cache_inode_get_aux, .check_aux = v9fs_cache_inode_check_aux, - .now_uncached = v9fs_cache_inode_now_uncached, };void v9fs_cache_inode_get_cookie (struct inode *inode)
fs/afs/cache.c +0 -43
58 lines not on this page · raw message
fs/ceph/cache.c +0 -31
@@ -137,36 +137,6 @@ static enum fscache_checkaux ceph_fscache_inode_check_aux(return FSCACHE_CHECKAUX_OKAY ; } -static void ceph_fscache_inode_now_uncached (void * cookie_netfs_data) -{ -struct ceph_inode_info * ci = cookie_netfs_data; -struct pagevec pvec; -pgoff_t first; -int loop, nr_pages; - -pagevec_init (&pvec,0 ); - first =0 ; - -dout ("ceph inode 0x%p now uncached" , ci); - -while (1 ) { - nr_pages =pagevec_lookup (&pvec, ci->vfs_inode.i_mapping, first, -PAGEVEC_SIZE -pagevec_count (&pvec)); - -if (!nr_pages) -break ; - -for (loop =0 ; loop < nr_pages; loop++) -ClearPageFsCache (pvec.pages[loop]); - - first = pvec.pages[nr_pages -1 ]->index +1 ; - - pvec.nr = nr_pages; -pagevec_release (&pvec); -cond_resched (); - } -} -static const struct fscache_cookie_def ceph_fscache_inode_object_def = { .name ="CEPH.inode" , .type =FSCACHE_COOKIE_TYPE_DATAFILE ,
@@ -174,7 +144,6 @@ static const struct fscache_cookie_def ceph_fscache_inode_object_def = { .get_attr = ceph_fscache_inode_get_attr, .get_aux = ceph_fscache_inode_get_aux, .check_aux = ceph_fscache_inode_check_aux, - .now_uncached = ceph_fscache_inode_now_uncached, };void ceph_fscache_register_inode_cookie (struct inode *inode)
fs/cifs/cache.c +0 -31
@@ -292,36 +292,6 @@ fscache_checkaux cifs_fscache_inode_check_aux(void *cookie_netfs_data,return FSCACHE_CHECKAUX_OKAY ; } -static void cifs_fscache_inode_now_uncached (void *cookie_netfs_data) -{ -struct cifsInodeInfo *cifsi = cookie_netfs_data; -struct pagevec pvec; -pgoff_t first; -int loop, nr_pages; - -pagevec_init (&pvec,0 ); - first =0 ; - -cifs_dbg (FYI ,"%s: cifs inode 0x%p now uncached\n" , __func__, cifsi); - -for (;;) { - nr_pages =pagevec_lookup (&pvec, - cifsi->vfs_inode.i_mapping, first, -PAGEVEC_SIZE -pagevec_count (&pvec)); -if (!nr_pages) -break ; - -for (loop =0 ; loop < nr_pages; loop++) -ClearPageFsCache (pvec.pages[loop]); - - first = pvec.pages[nr_pages -1 ]->index +1 ; - - pvec.nr = nr_pages; -pagevec_release (&pvec); -cond_resched (); - } -} -const struct fscache_cookie_def cifs_fscache_inode_object_def = { .name ="CIFS.uniqueid" , .type =FSCACHE_COOKIE_TYPE_DATAFILE ,
@@ -329,5 +299,4 @@ const struct fscache_cookie_def cifs_fscache_inode_object_def = { .get_attr = cifs_fscache_inode_get_attr, .get_aux = cifs_fscache_inode_get_aux, .check_aux = cifs_fscache_inode_check_aux, - .now_uncached = cifs_fscache_inode_now_uncached, };
fs/nfs/fscache-index.c +0 -40
@@ -252,45 +252,6 @@ enum fscache_checkaux nfs_fscache_inode_check_aux(void *cookie_netfs_data, }/* -* Indication from FS-Cache that the cookie is no longer cached -* - This function is called when the backing store currently caching a cookie -* is removed -* - The netfs should use this to clean up any markers indicating cached pages -* - This is mandatory for any object that may have data -*/ -static void nfs_fscache_inode_now_uncached (void *cookie_netfs_data) -{ -struct nfs_inode *nfsi = cookie_netfs_data; -struct pagevec pvec; -pgoff_t first; -int loop, nr_pages; - -pagevec_init (&pvec,0 ); - first =0 ; - -dprintk ("NFS: nfs_inode_now_uncached: nfs_inode 0x%p\n" , nfsi); - -for (;;) { -/* grab a bunch of pages to unmark */ - nr_pages =pagevec_lookup (&pvec, - nfsi->vfs_inode.i_mapping, - first, -PAGEVEC_SIZE -pagevec_count (&pvec)); -if (!nr_pages) -break ; - -for (loop =0 ; loop < nr_pages; loop++) -ClearPageFsCache (pvec.pages[loop]); - - first = pvec.pages[nr_pages -1 ]->index +1 ; - - pvec.nr = nr_pages; -pagevec_release (&pvec); -cond_resched (); - } -} - -/* * Get an extra reference on a read context. * - This function can be absent if the completion function doesn't require a * context.
@@ -330,7 +291,6 @@ const struct fscache_cookie_def nfs_fscache_inode_object_def = { .get_attr = nfs_fscache_inode_get_attr, .get_aux = nfs_fscache_inode_get_aux, .check_aux = nfs_fscache_inode_check_aux, - .now_uncached = nfs_fscache_inode_now_uncached, .get_context = nfs_fh_get_context, .put_context = nfs_fh_put_context, };
include/linux/fscache.h +0 -9
@@ -143,15 +143,6 @@ struct fscache_cookie_def {void (*mark_page_cached)(void *cookie_netfs_data,struct address_space *mapping,struct page *page); - -/* indicate the cookie is no longer cached -* - this function is called when the backing store currently caching -* a cookie is removed -* - the netfs should use this to clean up any markers indicating -* cached pages -* - this is mandatory for any object that may have data -*/ -void (*now_uncached)(void *cookie_netfs_data); };/*
Signature · 1 line
2.12.3
David Howells
maintainerRe: [PATCH 01/35] fscache: Remove unused ->now_uncached callback
Quoted 1 line · Jan Kara
The callback doesn't ever get called. Remove it.
Hmmm... I should perhaps be calling this. I'm not sure why I never did.
At the moment, it doesn't strictly matter as ops on pages marked with PG_fscache get ignored if the cache has suffered an I/O error or has been withdrawn - but it will incur a performance penalty (the PG_fscache flag is checked in the netfs before calling into fscache).
The downside of calling this is that when a cache is removed, fscache would go through all the cookies for that cache and iterate over all the pages associated with those cookies - which could cause a performance dip in the system.
David
--
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
maintainerRe: [PATCH 01/35] fscache: Remove unused ->now_uncached callback
Quoted 11 lines · David Howells
Quoted 1 line · Jan Kara
The callback doesn't ever get called. Remove it.
Hmmm... I should perhaps be calling this. I'm not sure why I never did.
At the moment, it doesn't strictly matter as ops on pages marked with
PG_fscacheget ignored if the cache has suffered an I/O error or has been withdrawn - but it will incur a performance penalty (thePG_fscacheflag is checked in the netfs before calling into fscache).
Quoted 4 lines
The downside of calling this is that when a cache is removed, fscache would go through all the cookies for that cache and iterate over all the pages associated with those cookies - which could cause a performance dip in the system.
So I know nothing about fscache. If you decide these functions should stay in as you are going to use them soon, then I can just convert them to the new API as everything else. What just caught my eye and why I had a more detailed look is that I didn't understand that 'PAGEVEC_SIZE - pagevec_count(&pvec)' as a pagevec_lookup() argument since pagevec_count() should always return 0 at that point?
Honza
Signature · 8 lines
Jan Kara <[email protected]> SUSE Labs, CR -- 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
maintainerRe: [PATCH 01/35] fscache: Remove unused ->now_uncached callback
Quoted 17 lines · Jan Kara
Quoted 11 lines · David Howells
Quoted 1 line · Jan Kara
The callback doesn't ever get called. Remove it.
Hmmm... I should perhaps be calling this. I'm not sure why I never did.
At the moment, it doesn't strictly matter as ops on pages marked with
PG_fscacheget ignored if the cache has suffered an I/O error or has been withdrawn - but it will incur a performance penalty (thePG_fscacheflag is checked in the netfs before calling into fscache).Quoted 4 lines
The downside of calling this is that when a cache is removed, fscache would go through all the cookies for that cache and iterate over all the pages associated with those cookies - which could cause a performance dip in the system.
Quoted 6 lines
So I know nothing about fscache. If you decide these functions should stay in as you are going to use them soon, then I can just convert them to the new API as everything else. What just caught my eye and why I had a more detailed look is that I didn't understand that '
PAGEVEC_SIZE-pagevec_count(&pvec)' as apagevec_lookup()argument sincepagevec_count()should always return 0 at that point?
David, what is your final decision regarding this? Do you want to keep these unused functions (and I will just update my patch to convert them to the new calling convention) or will you apply the patch to remove them?
Honza
Signature · 8 lines
Jan Kara <[email protected]> SUSE Labs, CR -- 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 2/35 ext4: Fix SEEK_HOLE
In reply to Jan KaraCurrently, SEEK_HOLE implementation in ext4 may both return that there's a hole at some offset although that offset already has data and skip some holes during a search for the next hole. The first problem is demostrated by:
xfs_io -c "falloc 0 256k" -c "pwrite 0 56k" -c "seek -h 0" file wrote 57344/57344 bytes at offset 0
56 KiB, 14 ops; 0.0000 sec (2.054 GiB/sec and 538461.5385 ops/sec)
Whence Result
HOLE 0
Where we can see that SEEK_HOLE wrongly returned offset 0 as containing a hole although we have written data there. The second problem can be demonstrated by:
xfs_io -c "falloc 0 256k" -c "pwrite 0 56k" -c "pwrite 128k 8k"
-c "seek -h 0" file
wrote 57344/57344 bytes at offset 0
56 KiB, 14 ops; 0.0000 sec (1.978 GiB/sec and 518518.5185 ops/sec) wrote 8192/8192 bytes at offset 131072
8 KiB, 2 ops; 0.0000 sec (2 GiB/sec and 500000.0000 ops/sec)
Whence Result
HOLE 139264
Where we can see that hole at offsets 56k..128k has been ignored by the SEEK_HOLE call.
The underlying problem is in the ext4_find_unwritten_pgoff() which is just buggy. In some cases it fails to update returned offset when it finds a hole (when no pages are found or when the first found page has higher index than expected), in some cases conditions for detecting hole are just missing (we fail to detect a situation where indices of returned pages are not contiguous).
Fix ext4_find_unwritten_pgoff() to properly detect non-contiguous page indices and also handle all cases where we got less pages then expected in one place and handle it properly there.
--- fs/ext4/file.c | 50 ++++++++++++++------------------------------------ 1 file changed, 14 insertions(+), 36 deletions(-)
fs/ext4/file.c +14 -36
@@ -484,47 +484,27 @@ static int ext4_find_unwritten_pgoff(struct inode *inode, num =min_t (pgoff_t, end - index,PAGEVEC_SIZE ); nr_pages =pagevec_lookup (&pvec, inode->i_mapping, index, (pgoff_t )num); -if (nr_pages ==0 ) { -if (whence ==SEEK_DATA ) -break ; - -BUG_ON (whence !=SEEK_HOLE ); -/* -* If this is the first time to go into the loop and -* offset is not beyond the end offset, it will be a -* hole at this offset -*/ -if (lastoff == startoff || lastoff < endoff) - found =1 ; -break ; - } - -/* -* If this is the first time to go into the loop and -* offset is smaller than the first page offset, it will be a -* hole at this offset. -*/ -if (lastoff == startoff && whence ==SEEK_HOLE && - lastoff <page_offset (pvec.pages[0 ])) { - found =1 ; +if (nr_pages ==0 )break ; - }for (i =0 ; i < nr_pages; i++) {struct page *page = pvec.pages[i];struct buffer_head *bh, *head;/* -* If the current offset is not beyond the end of given -* range, it will be a hole. +* If current offset is smaller than the page offset, +* there is a hole at this offset. */ -if (lastoff < endoff && whence ==SEEK_HOLE && - page->index > end) { +if (whence ==SEEK_HOLE && lastoff < endoff && + lastoff <page_offset (pvec.pages[i])) { found =1 ; *offset = lastoff; goto out; } +if (page->index > end) + goto out; +lock_page (page);if (unlikely (page->mapping != inode->i_mapping)) {
@@ -564,20 +544,18 @@ static int ext4_find_unwritten_pgoff(struct inode *inode,unlock_page (page); } -/* -* The no. of pages is less than our desired, that would be a -* hole in there. -*/ -if (nr_pages < num && whence ==SEEK_HOLE ) { - found =1 ; - *offset = lastoff; +/* The no. of pages is less than our desired, we are done. */ +if (nr_pages < num)break ; - } index = pvec.pages[i -1 ]->index +1 ;pagevec_release (&pvec); }while (index <= end); +if (whence ==SEEK_HOLE && lastoff < endoff) { + found =1 ; + *offset = lastoff; + } out:pagevec_release (&pvec);return found;
Signature · 1 line
2.12.3
Jan Kara
maintainerPATCH 3/35 ext4: Fix off-by-in in loop termination in ext4_find_unwritten_pgoff()
In reply to Jan KaraThere is an off-by-one error in loop termination conditions in ext4_find_unwritten_pgoff() since 'end' may index a page beyond end of desired range if 'endoff' is page aligned. It doesn't have any visible effects but still it is good to fix it.
--- fs/ext4/file.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/ext4/file.c +1 -1
@@ -474,7 +474,7 @@ static int ext4_find_unwritten_pgoff(struct inode *inode, endoff = (loff_t )end_blk << blkbits; index = startoff >>PAGE_SHIFT ; - end = endoff >>PAGE_SHIFT ; + end = (endoff -1 ) >>PAGE_SHIFT ;pagevec_init (&pvec,0 ); do {
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 4/35 dax: Fix inefficiency in dax_writeback_mapping_range()
In reply to Jan Karadax_writeback_mapping_range() fails to update iteration index when searching radix tree for entries needing cache flushing. Thus each pagevec worth of entries is searched starting from the start which is inefficient and prone to livelocks. Update index properly.
--- fs/dax.c | 1 + 1 file changed, 1 insertion(+)
fs/dax.c +1 -0
@@ -859,6 +859,7 @@ int dax_writeback_mapping_range(struct address_space *mapping,if (ret <0 ) goto out; } + start_index = indices[pvec.nr -1 ] +1 ; } out:put_dax (dax_dev);
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 5/35 mm: Fix THP handling in invalidate_mapping_pages()
In reply to Jan KaraThe condition checking for THP straddling end of invalidated range is wrong - it checks 'index' against 'end' but 'index' has been already advanced to point to the end of THP and thus the condition can never be true. As a result THP straddling 'end' has been fully invalidated. Given the nature of invalidate_mapping_pages(), this could be only performance issue. In fact, we are lucky the condition is wrong because if it was ever true, we'd leave locked page behind.
Fix the condition checking for THP straddling 'end' and also properly unlock the page. Also update the comment before the condition to explain why we decide not to invalidate the page as it was not clear to me and I had to ask Kirill.
--- mm/truncate.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
mm/truncate.c +8 -2
@@ -530,9 +530,15 @@ unsigned long invalidate_mapping_pages(struct address_space *mapping, }else if (PageTransHuge (page)) { index +=HPAGE_PMD_NR -1 ; i +=HPAGE_PMD_NR -1 ; -/* 'end' is in the middle of THP */ -if (index ==round_down (end,HPAGE_PMD_NR )) +/* +* 'end' is in the middle of THP. Don't +* invalidate the page as the part outside of +* 'end' could be still useful. +*/ +if (index > end) { +unlock_page (page);continue ; + } } ret =invalidate_inode_page (page);
Signature · 1 line
2.12.3
Jan Kara
maintainerPATCH 6/35 mm: Make pagevec_lookup() update index
In reply to Jan KaraMake pagevec_lookup() (and underlying find_get_pages()) update index to the next page where iteration should continue. Most callers want this and also pagevec_lookup_tag() already does this.
--- fs/buffer.c | 6 ++---- fs/ext4/file.c | 4 +--- fs/ext4/inode.c | 8 ++------ fs/fscache/page.c | 5 ++--- fs/hugetlbfs/inode.c | 17 ++++++++--------- fs/nilfs2/page.c | 3 +-- fs/ramfs/file-nommu.c | 2 +- fs/xfs/xfs_file.c | 3 +-- include/linux/pagemap.h | 2 +- include/linux/pagevec.h | 2 +- mm/filemap.c | 9 +++++++-- mm/swap.c | 5 +++-- 12 files changed, 30 insertions(+), 36 deletions(-)
fs/buffer.c +2 -4
@@ -1638,13 +1638,12 @@ void clean_bdev_aliases(struct block_device *bdev, sector_t block, sector_t len) end = (block + len -1 ) >> (PAGE_SHIFT - bd_inode->i_blkbits);pagevec_init (&pvec,0 ); -while (index <= end &&pagevec_lookup (&pvec, bd_mapping, index, +while (index <= end &&pagevec_lookup (&pvec, bd_mapping, &index,min (end - index, (pgoff_t )PAGEVEC_SIZE -1 ) +1 )) {for (i =0 ; i <pagevec_count (&pvec); i++) {struct page *page = pvec.pages[i]; - index = page->index; -if (index > end) +if (page->index > end)break ;if (!page_has_buffers (page))continue ;
@@ -1675,7 +1674,6 @@ void clean_bdev_aliases(struct block_device *bdev, sector_t block, sector_t len) }pagevec_release (&pvec);cond_resched (); - index++; } }EXPORT_SYMBOL (clean_bdev_aliases);
fs/ext4/file.c +1 -3
@@ -482,7 +482,7 @@ static int ext4_find_unwritten_pgoff(struct inode *inode,unsigned long nr_pages; num =min_t (pgoff_t, end - index,PAGEVEC_SIZE ); - nr_pages =pagevec_lookup (&pvec, inode->i_mapping, index, + nr_pages =pagevec_lookup (&pvec, inode->i_mapping, &index, (pgoff_t )num);if (nr_pages ==0 )break ;
@@ -547,8 +547,6 @@ static int ext4_find_unwritten_pgoff(struct inode *inode,/* The no. of pages is less than our desired, we are done. */ if (nr_pages < num)break ; - - index = pvec.pages[i -1 ]->index +1 ;pagevec_release (&pvec); }while (index <= end);
fs/ext4/inode.c +2 -6
@@ -1670,7 +1670,7 @@ static void mpage_release_unused_pages(struct mpage_da_data *mpd,pagevec_init (&pvec,0 );while (index <= end) { - nr_pages =pagevec_lookup (&pvec, mapping, index,PAGEVEC_SIZE ); + nr_pages =pagevec_lookup (&pvec, mapping, &index,PAGEVEC_SIZE );if (nr_pages ==0 )break ;for (i =0 ; i < nr_pages; i++) {
@@ -1687,7 +1687,6 @@ static void mpage_release_unused_pages(struct mpage_da_data *mpd, }unlock_page (page); } - index = pvec.pages[nr_pages -1 ]->index +1 ;pagevec_release (&pvec); } }
@@ -2284,7 +2283,7 @@ static int mpage_map_and_submit_buffers(struct mpage_da_data *mpd)pagevec_init (&pvec,0 );while (start <= end) { - nr_pages =pagevec_lookup (&pvec, inode->i_mapping, start, + nr_pages =pagevec_lookup (&pvec, inode->i_mapping, &start,PAGEVEC_SIZE );if (nr_pages ==0 )break ;
@@ -2293,8 +2292,6 @@ static int mpage_map_and_submit_buffers(struct mpage_da_data *mpd)if (page->index > end)break ; -/* Up to 'end' pages must be contiguous */ -BUG_ON (page->index != start); bh = head =page_buffers (page); do { if (lblk < mpd->map.m_lblk)
@@ -2339,7 +2336,6 @@ static int mpage_map_and_submit_buffers(struct mpage_da_data *mpd)pagevec_release (&pvec);return err; } - start++; }pagevec_release (&pvec); }
fs/fscache/page.c +2 -3
@@ -1178,11 +1178,10 @@ void __fscache_uncache_all_inode_pages(struct fscache_cookie *cookie,pagevec_init (&pvec,0 ); next =0 ; do { - if (!pagevec_lookup(&pvec, mapping, next, PAGEVEC_SIZE)) + if (!pagevec_lookup(&pvec, mapping, &next, PAGEVEC_SIZE)) break; for (i = 0; i < pagevec_count(&pvec); i++) { struct page *page = pvec.pages[i]; - next = page->index; if (PageFsCache(page)) { __fscache_wait_on_page_write(cookie, page); __fscache_uncache_page(cookie, page);
@@ -1190,7 +1189,7 @@ void __fscache_uncache_all_inode_pages(struct fscache_cookie *cookie, }pagevec_release (&pvec);cond_resched (); - }while (++next); + }while (next);_leave ("" ); }
fs/hugetlbfs/inode.c +8 -9
@@ -401,7 +401,7 @@ static void remove_inode_hugepages(struct inode *inode, loff_t lstart,const pgoff_t end = lend >>huge_page_shift (h);struct vm_area_struct pseudo_vma;struct pagevec pvec; -pgoff_t next; +pgoff_t next, index;int i, freed =0 ;long lookup_nr =PAGEVEC_SIZE ;bool truncate_op = (lend ==LLONG_MAX );
@@ -420,7 +420,7 @@ static void remove_inode_hugepages(struct inode *inode, loff_t lstart,/* * When no more pages are found, we are done. */ -if (!pagevec_lookup (&pvec, mapping, next, lookup_nr)) +if (!pagevec_lookup (&pvec, mapping, &next, lookup_nr))break ;for (i =0 ; i <pagevec_count (&pvec); ++i) {
@@ -432,13 +432,13 @@ static void remove_inode_hugepages(struct inode *inode, loff_t lstart,* only possible in the punch hole case as end is * max page offset in the truncate case. */ - next = page->index; -if (next >= end) + index = page->index; +if (index >= end)break ; hash =hugetlb_fault_mutex_hash (h, current->mm, &pseudo_vma, - mapping, next,0 ); + mapping, index,0 );mutex_lock (&hugetlb_fault_mutex_table[hash]);/*
@@ -455,8 +455,8 @@ static void remove_inode_hugepages(struct inode *inode, loff_t lstart,i_mmap_lock_write (mapping);hugetlb_vmdelete_list (&mapping->i_mmap, - next *pages_per_huge_page (h), - (next +1 ) *pages_per_huge_page (h)); + index *pages_per_huge_page (h), + (index +1 ) *pages_per_huge_page (h));i_mmap_unlock_write (mapping); }
@@ -475,14 +475,13 @@ static void remove_inode_hugepages(struct inode *inode, loff_t lstart, freed++;if (!truncate_op) {if (unlikely (hugetlb_unreserve_pages (inode, - next, next +1 ,1 ))) + index, index +1 ,1 )))hugetlb_fix_reserve_counts (inode); }unlock_page (page);mutex_unlock (&hugetlb_fault_mutex_table[hash]); } - ++next;huge_pagevec_release (&pvec);cond_resched (); }
fs/nilfs2/page.c +1 -2
@@ -312,10 +312,9 @@ void nilfs_copy_back_pages(struct address_space *dmap,pagevec_init (&pvec,0 ); repeat: - n =pagevec_lookup (&pvec, smap, index,PAGEVEC_SIZE ); + n =pagevec_lookup (&pvec, smap, &index,PAGEVEC_SIZE );if (!n)return ; - index = pvec.pages[n -1 ]->index +1 ;for (i =0 ; i <pagevec_count (&pvec); i++) {struct page *page = pvec.pages[i], *dpage;
fs/ramfs/file-nommu.c +1 -1
@@ -228,7 +228,7 @@ static unsigned long ramfs_nommu_get_unmapped_area(struct file *file,if (!pages) goto out_free; - nr =find_get_pages (inode->i_mapping, pgoff, lpages, pages); + nr =find_get_pages (inode->i_mapping, &pgoff, lpages, pages);if (nr != lpages) goto out_free_pages;/* leave if some pages were missing */
fs/xfs/xfs_file.c +1 -2
@@ -1050,7 +1050,7 @@ xfs_find_get_desired_pgoff(unsigned int i; want =min_t (pgoff_t, end - index,PAGEVEC_SIZE -1 ) +1 ; - nr_pages =pagevec_lookup (&pvec, inode->i_mapping, index, + nr_pages =pagevec_lookup (&pvec, inode->i_mapping, &index, want);if (nr_pages ==0 )break ;
@@ -1124,7 +1124,6 @@ xfs_find_get_desired_pgoff(if (nr_pages < want)break ; - index = pvec.pages[i -1 ]->index +1 ;pagevec_release (&pvec); }while (index <= end);
include/linux/pagemap.h +1 -1
@@ -336,7 +336,7 @@ struct page *find_lock_entry(struct address_space *mapping, pgoff_t offset);unsigned find_get_entries (struct address_space *mapping,pgoff_t start,unsigned int nr_entries,struct page **entries,pgoff_t *indices); -unsigned find_get_pages (struct address_space *mapping,pgoff_t start, +unsigned find_get_pages (struct address_space *mapping,pgoff_t *start,unsigned int nr_pages,struct page **pages);unsigned find_get_pages_contig (struct address_space *mapping,pgoff_t start,unsigned int nr_pages,struct page **pages);
include/linux/pagevec.h +1 -1
@@ -28,7 +28,7 @@ unsigned pagevec_lookup_entries(struct pagevec *pvec, pgoff_t *indices);void pagevec_remove_exceptionals (struct pagevec *pvec);unsigned pagevec_lookup (struct pagevec *pvec,struct address_space *mapping, -pgoff_t start,unsigned nr_pages); +pgoff_t *start,unsigned nr_pages);unsigned pagevec_lookup_tag (struct pagevec *pvec,struct address_space *mapping,pgoff_t *index,int tag,unsigned nr_pages);
mm/filemap.c +7 -2
@@ -1450,10 +1450,11 @@ unsigned find_get_entries(struct address_space *mapping,* * The search returns a group of mapping-contiguous pages with ascending * indexes. There may be holes in the indices due to not-present pages. +* We also update @start to index the next page for the traversal. * * find_get_pages() returns the number of pages which were found. */ -unsigned find_get_pages (struct address_space *mapping,pgoff_t start, +unsigned find_get_pages (struct address_space *mapping,pgoff_t *start,unsigned int nr_pages,struct page **pages) {struct radix_tree_iter iter;
@@ -1464,7 +1465,7 @@ unsigned find_get_pages(struct address_space *mapping, pgoff_t start,return 0 ;rcu_read_lock (); -radix_tree_for_each_slot (slot, &mapping->page_tree, &iter, start) { +radix_tree_for_each_slot (slot, &mapping->page_tree, &iter, *start) {struct page *head, *page; repeat: page =radix_tree_deref_slot (slot);
@@ -1506,6 +1507,10 @@ unsigned find_get_pages(struct address_space *mapping, pgoff_t start, }rcu_read_unlock (); + +if (ret) + *start = pages[ret -1 ]->index +1 ; +return ret; }
mm/swap.c +3 -2
@@ -951,12 +951,13 @@ void pagevec_remove_exceptionals(struct pagevec *pvec)* reference against the pages in @pvec. * * The search returns a group of mapping-contiguous pages with ascending -* indexes. There may be holes in the indices due to not-present pages. +* indexes. There may be holes in the indices due to not-present pages. We +* also update @start to index the next page for the traversal. * * pagevec_lookup() returns the number of pages which were found. */ unsigned pagevec_lookup (struct pagevec *pvec,struct address_space *mapping, -pgoff_t start,unsigned nr_pages) +pgoff_t *start,unsigned nr_pages) { pvec->nr =find_get_pages (mapping, start, nr_pages, pvec->pages);return pagevec_count (pvec);
Signature · 1 line
2.12.3
Jan Kara
maintainerPATCH 7/35 mm: Implement find_get_pages_range()
In reply to Jan KaraImplement a variant of find_get_pages() that stops iterating at given index. This may be substantial performance gain if the mapping is sparse. See following commit for details. Furthermore 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() function.
--- include/linux/pagemap.h | 12 ++++++++++-- include/linux/pagevec.h | 13 +++++++++++-- mm/filemap.c | 42 ++++++++++++++++++++++++++++++------------ mm/swap.c | 22 ++++++++++++++-------- 4 files changed, 65 insertions(+), 24 deletions(-)
include/linux/pagemap.h +10 -2
@@ -336,8 +336,16 @@ struct page *find_lock_entry(struct address_space *mapping, pgoff_t offset);unsigned find_get_entries (struct address_space *mapping,pgoff_t start,unsigned int nr_entries,struct page **entries,pgoff_t *indices); -unsigned find_get_pages (struct address_space *mapping,pgoff_t *start, -unsigned int nr_pages,struct page **pages); +unsigned find_get_pages_range (struct address_space *mapping,pgoff_t *start, +pgoff_t end,unsigned int nr_pages, +struct page **pages); +static inline unsigned find_get_pages (struct address_space *mapping, +pgoff_t *start,unsigned int nr_pages, +struct page **pages) +{ +return find_get_pages_range (mapping, start, (pgoff_t)-1 , nr_pages, + pages); +}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,
include/linux/pagevec.h +11 -2
@@ -27,8 +27,17 @@ unsigned pagevec_lookup_entries(struct pagevec *pvec, pgoff_t start, unsigned nr_entries, pgoff_t *indices);void pagevec_remove_exceptionals (struct pagevec *pvec); -unsigned pagevec_lookup (struct pagevec *pvec,struct address_space *mapping, -pgoff_t *start,unsigned nr_pages); +unsigned pagevec_lookup_range (struct pagevec *pvec, +struct address_space *mapping, +pgoff_t *start,pgoff_t end,unsigned nr_pages); +static inline unsigned pagevec_lookup (struct pagevec *pvec, +struct address_space *mapping, +pgoff_t *start,unsigned nr_pages) +{ +return pagevec_lookup_range (pvec, mapping, start, (pgoff_t)-1 , + nr_pages); +} +unsigned pagevec_lookup_tag (struct pagevec *pvec,struct address_space *mapping,pgoff_t *index,int tag,unsigned nr_pages);
mm/filemap.c +30 -12
75 lines not on this page · raw message
mm/swap.c +14 -8
@@ -940,29 +940,35 @@ void pagevec_remove_exceptionals(struct pagevec *pvec) }/** -* pagevec_lookup - gang pagecache lookup +* pagevec_lookup_range - gang pagecache lookup * @pvec: Where the resulting pages are placed * @mapping: The address_space to search * @start: The starting page index +* @end: The final page index * @nr_pages: The maximum number of pages * -* pagevec_lookup() will search for and return a group of up to @nr_pages pages -* in the mapping. The pages are placed in @pvec. pagevec_lookup() takes a +* pagevec_lookup_range() will search for and return a group of up to @nr_pages +* pages in the mapping starting from index @start and upto index @end +* (inclusive). The pages are placed in @pvec. pagevec_lookup() takes a * reference against the pages in @pvec. * * The search returns a group of mapping-contiguous pages with ascending * indexes. There may be holes in the indices due to not-present pages. We * also update @start to index the next page for the traversal. * -* pagevec_lookup() returns the number of pages which were found. +* pagevec_lookup_range() returns the number of pages which were found. If this +* number is smaller than @nr_pages, the end of specified range has been +* reached. */ -unsigned pagevec_lookup (struct pagevec *pvec,struct address_space *mapping, -pgoff_t *start,unsigned nr_pages) +unsigned pagevec_lookup_range (struct pagevec *pvec, +struct address_space *mapping,pgoff_t *start,pgoff_t end, +unsigned nr_pages) { - pvec->nr =find_get_pages (mapping, start, nr_pages, pvec->pages); + pvec->nr =find_get_pages_range (mapping, start, end, nr_pages, + pvec->pages);return pagevec_count (pvec); } -EXPORT_SYMBOL (pagevec_lookup); +EXPORT_SYMBOL (pagevec_lookup_range);unsigned pagevec_lookup_tag (struct pagevec *pvec,struct address_space *mapping,pgoff_t *index,int tag,unsigned nr_pages)
Signature · 1 line
2.12.3
Jan Kara
maintainerPATCH 8/35 fs: Fix performance regression in clean_bdev_aliases()
In reply to Jan KaraCommit e64855c6cfaa "fs: Add helper to clean bdev aliases under a bh and use it" added a wrapper for clean_bdev_aliases() that invalidates bdev aliases underlying a single buffer head. However this has caused a performance regression for bonnie++ benchmark on ext4 filesystem when delayed allocation is turned off (ext3 mode) - average of 3 runs:
Hmean SeqOut Char 164787.55 ( 0.00%) 107189.06 (-34.95%) Hmean SeqOut Block 219883.89 ( 0.00%) 168870.32 (-23.20%)
The reason for this regression is that clean_bdev_aliases() is slower when called for a single block because pagevec_lookup() it uses will end up iterating through the radix tree until it finds a page (which may take a while) but we are only interested whether there's a page at a particular index.
Fix the problem by using pagevec_lookup_range() instead which avoids the needless iteration.
--- fs/buffer.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)
fs/buffer.c +8 -6
@@ -1632,19 +1632,18 @@ void clean_bdev_aliases(struct block_device *bdev, sector_t block, sector_t len)struct pagevec pvec;pgoff_t index = block >> (PAGE_SHIFT - bd_inode->i_blkbits);pgoff_t end; -int i; +int i, count;struct buffer_head *bh;struct buffer_head *head; end = (block + len -1 ) >> (PAGE_SHIFT - bd_inode->i_blkbits);pagevec_init (&pvec,0 ); -while (index <= end &&pagevec_lookup (&pvec, bd_mapping, &index, -min (end - index, (pgoff_t )PAGEVEC_SIZE -1 ) +1 )) { -for (i =0 ; i <pagevec_count (&pvec); i++) { +while (pagevec_lookup_range (&pvec, bd_mapping, &index, end, +PAGEVEC_SIZE )) { + count =pagevec_count (&pvec); +for (i =0 ; i < count; i++) {struct page *page = pvec.pages[i]; -if (page->index > end) -break ;if (!page_has_buffers (page))continue ;/*
@@ -1674,6 +1673,9 @@ void clean_bdev_aliases(struct block_device *bdev, sector_t block, sector_t len) }pagevec_release (&pvec);cond_resched (); +/* End of range already reached? */ +if (index > end || !index) +break ; } }EXPORT_SYMBOL (clean_bdev_aliases);
Signature · 1 line
2.12.3
Jan Kara
maintainerPATCH 9/35 ext4: Use pagevec_lookup_range() in ext4_find_unwritten_pgoff()
In reply to Jan KaraUse pagevec_lookup_range() in ext4_find_unwritten_pgoff() since we are interested only in pages in the given range. Simplify the logic as a result of not getting pages out of range and index getting automatically advanced.
--- fs/ext4/file.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-)
fs/ext4/file.c +4 -10
@@ -478,12 +478,11 @@ static int ext4_find_unwritten_pgoff(struct inode *inode,pagevec_init (&pvec,0 ); do { - int i, num; + int i; unsigned long nr_pages; - num = min_t(pgoff_t, end - index, PAGEVEC_SIZE); - nr_pages = pagevec_lookup(&pvec, inode->i_mapping, &index, - (pgoff_t)num); + nr_pages = pagevec_lookup_range(&pvec, inode->i_mapping, + &index, end, PAGEVEC_SIZE); if (nr_pages == 0) break;
@@ -502,9 +501,6 @@ static int ext4_find_unwritten_pgoff(struct inode *inode, goto out; } -if (page->index > end) - goto out; -lock_page (page);if (unlikely (page->mapping != inode->i_mapping)) {
@@ -544,12 +540,10 @@ static int ext4_find_unwritten_pgoff(struct inode *inode,unlock_page (page); } -/* The no. of pages is less than our desired, we are done. */ -if (nr_pages < num) -break ;pagevec_release (&pvec); }while (index <= end); +/* There are no pages upto endoff - that would be a hole in there. */ if (whence ==SEEK_HOLE && lastoff < endoff) { found =1 ; *offset = lastoff;
Signature · 6 lines
2.12.3 ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot
Jan Kara
maintainerPATCH 10/35 ext4: Use pagevec_lookup_range() in writeback code
In reply to Jan KaraBoth occurences of pagevec_lookup() actually want only pages from a given range. Use pagevec_lookup_range() for the lookup.
--- fs/ext4/inode.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-)
fs/ext4/inode.c +5 -7
@@ -1670,13 +1670,13 @@ static void mpage_release_unused_pages(struct mpage_da_data *mpd,pagevec_init (&pvec,0 );while (index <= end) { - nr_pages =pagevec_lookup (&pvec, mapping, &index,PAGEVEC_SIZE ); + nr_pages =pagevec_lookup_range (&pvec, mapping, &index, end, +PAGEVEC_SIZE );if (nr_pages ==0 )break ;for (i =0 ; i < nr_pages; i++) {struct page *page = pvec.pages[i]; -if (page->index > end) -break ; +BUG_ON (!PageLocked (page));BUG_ON (PageWriteback (page));if (invalidate) {
@@ -2283,15 +2283,13 @@ static int mpage_map_and_submit_buffers(struct mpage_da_data *mpd)pagevec_init (&pvec,0 );while (start <= end) { - nr_pages =pagevec_lookup (&pvec, inode->i_mapping, &start, -PAGEVEC_SIZE ); + nr_pages =pagevec_lookup_range (&pvec, inode->i_mapping, + &start, end,PAGEVEC_SIZE );if (nr_pages ==0 )break ;for (i =0 ; i < nr_pages; i++) {struct page *page = pvec.pages[i]; -if (page->index > end) -break ; bh = head =page_buffers (page); do { if (lblk < mpd->map.m_lblk)
Signature · 1 line
2.12.3
Jan Kara
maintainerPATCH 11/35 hugetlbfs: Use pagevec_lookup_range() in remove_inode_hugepages()
In reply to Jan KaraWe want only pages from given range in remove_inode_hugepages(). Use pagevec_lookup_range() instead of pagevec_lookup().
--- fs/hugetlbfs/inode.c | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-)
fs/hugetlbfs/inode.c +2 -16
@@ -403,7 +403,6 @@ static void remove_inode_hugepages(struct inode *inode, loff_t lstart,struct pagevec pvec;pgoff_t next, index;int i, freed =0 ; -long lookup_nr =PAGEVEC_SIZE ;bool truncate_op = (lend ==LLONG_MAX );memset (&pseudo_vma,0 ,sizeof (struct vm_area_struct ));
@@ -412,30 +411,17 @@ static void remove_inode_hugepages(struct inode *inode, loff_t lstart, next = start;while (next < end) {/* -* Don't grab more pages than the number left in the range. -*/ -if (end - next < lookup_nr) - lookup_nr = end - next; - -/* * When no more pages are found, we are done. */ -if (!pagevec_lookup (&pvec, mapping, &next, lookup_nr)) +if (!pagevec_lookup_range (&pvec, mapping, &next, end -1 , +PAGEVEC_SIZE ))break ;for (i =0 ; i <pagevec_count (&pvec); ++i) {struct page *page = pvec.pages[i];u32 hash; -/* -* The page (index) could be beyond end. This is -* only possible in the punch hole case as end is -* max page offset in the truncate case. -*/ index = page->index; -if (index >= end) -break ; - hash =hugetlb_fault_mutex_hash (h, current->mm, &pseudo_vma, mapping, index,0 );
Signature · 6 lines
2.12.3 ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot
Jan Kara
maintainerPATCH 12/35 xfs: Use pagevec_lookup_range() in xfs_find_get_desired_pgoff()
In reply to Jan KaraWe want only pages from given range in xfs_find_get_desired_pgoff(). Use pagevec_lookup_range() instead of pagevec_lookup() and remove unnecessary code. Note that the check for getting less pages than desired can be removed because index gets updated by pagevec_lookup_range().
--- fs/xfs/xfs_file.c | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-)
fs/xfs/xfs_file.c +2 -14
@@ -1045,13 +1045,11 @@ xfs_find_get_desired_pgoff( endoff =XFS_FSB_TO_B (mp, map->br_startoff + map->br_blockcount); end = (endoff -1 ) >>PAGE_SHIFT ; do { - int want; unsigned nr_pages; unsigned int i; - want = min_t(pgoff_t, end - index, PAGEVEC_SIZE - 1) + 1; - nr_pages = pagevec_lookup(&pvec, inode->i_mapping, &index, - want); + nr_pages = pagevec_lookup_range(&pvec, inode->i_mapping, + &index, end, PAGEVEC_SIZE); if (nr_pages == 0) break;
@@ -1075,9 +1073,6 @@ xfs_find_get_desired_pgoff( *offset = lastoff; goto out; } -/* Searching done if the page index is out of range. */ -if (page->index > end) - goto out;lock_page (page);/*
@@ -1117,13 +1112,6 @@ xfs_find_get_desired_pgoff(unlock_page (page); } -/* -* The number of returned pages less than our desired, search -* done. -*/ -if (nr_pages < want) -break ; -pagevec_release (&pvec); }while (index <= end);
Signature · 1 line
2.12.3
Jan Kara
maintainerPATCH 13/35 mm: Remove nr_pages argument from pagevec_lookup{,_range}()
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/buffer.c | 3 +-- fs/ext4/file.c | 2 +- fs/ext4/inode.c | 5 ++--- fs/fscache/page.c | 2 +- fs/hugetlbfs/inode.c | 3 +-- fs/nilfs2/page.c | 2 +- fs/xfs/xfs_file.c | 2 +- include/linux/pagevec.h | 7 +++---- mm/swap.c | 5 ++--- 9 files changed, 13 insertions(+), 18 deletions(-)
fs/buffer.c +1 -2
@@ -1638,8 +1638,7 @@ void clean_bdev_aliases(struct block_device *bdev, sector_t block, sector_t len) end = (block + len -1 ) >> (PAGE_SHIFT - bd_inode->i_blkbits);pagevec_init (&pvec,0 ); -while (pagevec_lookup_range (&pvec, bd_mapping, &index, end, -PAGEVEC_SIZE )) { +while (pagevec_lookup_range (&pvec, bd_mapping, &index, end)) { count =pagevec_count (&pvec);for (i =0 ; i < count; i++) {struct page *page = pvec.pages[i];
fs/ext4/file.c +1 -1
@@ -482,7 +482,7 @@ static int ext4_find_unwritten_pgoff(struct inode *inode,unsigned long nr_pages; nr_pages =pagevec_lookup_range (&pvec, inode->i_mapping, - &index, end,PAGEVEC_SIZE ); + &index, end);if (nr_pages ==0 )break ;
fs/ext4/inode.c +2 -3
@@ -1670,8 +1670,7 @@ static void mpage_release_unused_pages(struct mpage_da_data *mpd,pagevec_init (&pvec,0 );while (index <= end) { - nr_pages =pagevec_lookup_range (&pvec, mapping, &index, end, -PAGEVEC_SIZE ); + nr_pages =pagevec_lookup_range (&pvec, mapping, &index, end);if (nr_pages ==0 )break ;for (i =0 ; i < nr_pages; i++) {
@@ -2284,7 +2283,7 @@ static int mpage_map_and_submit_buffers(struct mpage_da_data *mpd)pagevec_init (&pvec,0 );while (start <= end) { nr_pages =pagevec_lookup_range (&pvec, inode->i_mapping, - &start, end,PAGEVEC_SIZE ); + &start, end);if (nr_pages ==0 )break ;for (i =0 ; i < nr_pages; i++) {
fs/fscache/page.c +1 -1
@@ -1178,7 +1178,7 @@ void __fscache_uncache_all_inode_pages(struct fscache_cookie *cookie,pagevec_init (&pvec,0 ); next =0 ; do { - if (!pagevec_lookup(&pvec, mapping, &next, PAGEVEC_SIZE)) + if (!pagevec_lookup(&pvec, mapping, &next)) break; for (i = 0; i < pagevec_count(&pvec); i++) { struct page *page = pvec.pages[i];
fs/hugetlbfs/inode.c +1 -2
@@ -413,8 +413,7 @@ static void remove_inode_hugepages(struct inode *inode, loff_t lstart,/* * When no more pages are found, we are done. */ -if (!pagevec_lookup_range (&pvec, mapping, &next, end -1 , -PAGEVEC_SIZE )) +if (!pagevec_lookup_range (&pvec, mapping, &next, end -1 ))break ;for (i =0 ; i <pagevec_count (&pvec); ++i) {
fs/nilfs2/page.c +1 -1
@@ -312,7 +312,7 @@ void nilfs_copy_back_pages(struct address_space *dmap,pagevec_init (&pvec,0 ); repeat: - n =pagevec_lookup (&pvec, smap, &index,PAGEVEC_SIZE ); + n =pagevec_lookup (&pvec, smap, &index);if (!n)return ;
fs/xfs/xfs_file.c +1 -1
@@ -1049,7 +1049,7 @@ xfs_find_get_desired_pgoff(unsigned int i; nr_pages =pagevec_lookup_range (&pvec, inode->i_mapping, - &index, end,PAGEVEC_SIZE ); + &index, end);if (nr_pages ==0 )break ;
include/linux/pagevec.h +3 -4
@@ -29,13 +29,12 @@ unsigned pagevec_lookup_entries(struct pagevec *pvec,void pagevec_remove_exceptionals (struct pagevec *pvec);unsigned pagevec_lookup_range (struct pagevec *pvec,struct address_space *mapping, -pgoff_t *start,pgoff_t end,unsigned nr_pages); +pgoff_t *start,pgoff_t end);static inline unsigned pagevec_lookup (struct pagevec *pvec,struct address_space *mapping, -pgoff_t *start,unsigned nr_pages) +pgoff_t *start) { -return pagevec_lookup_range (pvec, mapping, start, (pgoff_t)-1 , - nr_pages); +return pagevec_lookup_range (pvec, mapping, start, (pgoff_t)-1 ); } unsigned pagevec_lookup_tag(struct pagevec *pvec,
mm/swap.c +2 -3
@@ -961,10 +961,9 @@ void pagevec_remove_exceptionals(struct pagevec *pvec)* reached. */ unsigned pagevec_lookup_range (struct pagevec *pvec, -struct address_space *mapping,pgoff_t *start,pgoff_t end, -unsigned nr_pages) +struct address_space *mapping,pgoff_t *start,pgoff_t end) { - pvec->nr =find_get_pages_range (mapping, start, end, nr_pages, + pvec->nr =find_get_pages_range (mapping, start, end,PAGEVEC_SIZE , pvec->pages);return pagevec_count (pvec); }
Signature · 1 line
2.12.3
Jan Kara
maintainerPATCH 14/35 mm: Implement find_get_pages_range_tag()
In reply to Jan KaraImplement 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
@@ -348,8 +348,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
@@ -1612,9 +1612,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
@@ -1622,8 +1623,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;
@@ -1636,6 +1638,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))
@@ -1677,18 +1682,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
@@ -969,14 +969,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 · 1 line
2.12.3
Jan Kara
maintainerPATCH 15/35 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
@@ -3837,8 +3837,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 ;
@@ -3848,11 +3848,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);
@@ -3984,8 +3979,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 ;
@@ -4010,12 +4005,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 · 1 line
2.12.3
Jan Kara
maintainerPATCH 16/35 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, 4 insertions(+), 15 deletions(-)
fs/ceph/addr.c +4 -15
@@ -841,21 +841,16 @@ static int ceph_writepages_start(struct address_space *mapping,struct page **pages =NULL , **data_pages;mempool_t *pool =NULL ;/* Becomes non-null if mempool used */ struct page *page; -int want;u64 offset =0 , len =0 ; max_pages = max_pages_ever; get_more_pages: first =-1 ; - want =min (end - index, -min ((pgoff_t )PAGEVEC_SIZE , - max_pages - (pgoff_t )locked_pages) -1 ) - +1 ; - pvec_pages =pagevec_lookup_tag (&pvec, mapping, &index, -PAGECACHE_TAG_DIRTY , - want); -dout ("pagevec_lookup_tag got %d\n" , pvec_pages); + pvec_pages =pagevec_lookup_range_tag (&pvec, mapping, &index, + end,PAGECACHE_TAG_DIRTY , +PAGEVEC_SIZE ); +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++) {
@@ -873,12 +868,6 @@ static int ceph_writepages_start(struct address_space *mapping,unlock_page (page);break ; } -if (!wbc->range_cyclic && page->index > end) { -dout ("end of range %p\n" , page); - done =1 ; -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 · 1 line
2.12.3
Jan Kara
maintainerPATCH 17/35 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
@@ -2555,8 +2555,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;
@@ -2564,16 +2564,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 · 1 line
2.12.3
Jan Kara
maintainerPATCH 18/35 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
@@ -1603,8 +1603,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 ;
@@ -1612,11 +1612,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;lock_page (page);
Signature · 1 line
2.12.3
Jan Kara
maintainerPATCH 19/35 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
@@ -296,9 +296,10 @@ long sync_meta_pages(struct f2fs_sb_info *sbi, enum page_type type, long nr_to_write) {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 , };
@@ -308,13 +309,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 · 6 lines
2.12.3 ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot
kbuild test robot
build botRe: [PATCH 19/35] f2fs: Simplify page iteration loops
url: https://github.com/0day-ci/linux/commits/Jan-Kara/pagevec-API-cleanups/20170601-200653 config: x86_64-randconfig-x019-201722 (attached as .config) compiler: gcc-6 (Debian 6.2.0-3) 6.2.0…
Hi Jan,
[auto build test WARNING on linus/master]
[also build test WARNING on v4.12-rc3]
[cannot apply to next-20170601]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
url: https://github.com/0day-ci/linux/commits/Jan-Kara/pagevec-API-cleanups/20170601-200653
config: x86_64-randconfig-x019-201722 (attached as .config)
compiler: gcc-6 (Debian 6.2.0-3) 6.2.0 20160901 reproduce:
# save the attached .config to linux build tree
make ARCH=x86_64 All warnings (new ones prefixed by >>):
fs//f2fs/checkpoint.c: In function 'sync_meta_pages':
>> fs//f2fs/checkpoint.c:313:5: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
PAGECACHE_TAG_DIRTY, PAGEVEC_SIZE)) {
^~~~~~~~~~~~~~~~~~~
--
fs//f2fs/node.c: In function 'last_fsync_dnode':
>> fs//f2fs/node.c:1271:5: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
PAGECACHE_TAG_DIRTY, PAGEVEC_SIZE)) {
^~~~~~~~~~~~~~~~~~~
fs//f2fs/node.c: In function 'fsync_node_pages':
fs//f2fs/node.c:1421:5: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
PAGECACHE_TAG_DIRTY, PAGEVEC_SIZE)) {
^~~~~~~~~~~~~~~~~~~
fs//f2fs/node.c: In function 'sync_node_pages':
fs//f2fs/node.c:1533:5: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
PAGECACHE_TAG_DIRTY, PAGEVEC_SIZE)) {
^~~~~~~~~~~~~~~~~~~
fs//f2fs/node.c: In function 'wait_on_node_pages_writeback':
fs//f2fs/node.c:1630:5: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
PAGECACHE_TAG_WRITEBACK, PAGEVEC_SIZE)) {
^~~~~~~~~~~~~~~~~~~~~~~vim +313 fs//f2fs/checkpoint.c
297 {
298 struct address_space *mapping = META_MAPPING(sbi);
299 pgoff_t index = 0, prev = ULONG_MAX;
300 struct pagevec pvec;
301 long nwritten = 0;
302 int nr_pages;
303 struct writeback_control wbc = {
304 .for_reclaim = 0,
305 };
306 struct blk_plug plug;
307
308 pagevec_init(&pvec, 0);
309
310 blk_start_plug(&plug);
311
312 while (nr_pages = pagevec_lookup_tag(&pvec, mapping, &index,
> 313 PAGECACHE_TAG_DIRTY, PAGEVEC_SIZE)) { 314 int i;
315
316 for (i = 0; i < nr_pages; i++) {
317 struct page *page = pvec.pages[i];
318
319 if (prev == ULONG_MAX)
320 prev = page->index - 1;
321 if (nr_to_write != LONG_MAX && page->index != prev + 1) {
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
Jan Kara
maintainerPATCH 20/35 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
@@ -286,18 +286,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 · 1 line
2.12.3
Jan Kara
maintainerPATCH 21/35 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
@@ -268,22 +268,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);
@@ -401,8 +385,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 22/35 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 · 1 line
2.12.3
Jan Kara
maintainerPATCH 23/35 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 | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-)
mm/filemap.c +2 -7
@@ -390,18 +390,13 @@ static int __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);if (TestClearPageError (page)) ret = -EIO ;
Signature · 1 line
2.12.3
Jan Kara
maintainerPATCH 24/35 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 · 1 line
2.12.3
Jan Kara
maintainerPATCH 25/35 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
@@ -3838,7 +3838,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 ;
@@ -3979,8 +3979,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
@@ -848,8 +848,7 @@ static int ceph_writepages_start(struct address_space *mapping, get_more_pages: first =-1 ; pvec_pages =pagevec_lookup_range_tag (&pvec, mapping, &index, - end,PAGECACHE_TAG_DIRTY , -PAGEVEC_SIZE ); + end,PAGECACHE_TAG_DIRTY );dout ("pagevec_lookup_range_tag got %d\n" , pvec_pages);if (!pvec_pages && !locked_pages)break ;
fs/ext4/inode.c +1 -1
@@ -2556,7 +2556,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
@@ -310,7 +310,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
@@ -1604,7 +1604,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
@@ -1268,7 +1268,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++) {
@@ -1418,7 +1418,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++) {
@@ -1530,7 +1530,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++) {
@@ -1627,7 +1627,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
@@ -386,7 +386,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,13 +39,11 @@ 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);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
@@ -391,7 +391,7 @@ static int __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++) {
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
@@ -971,10 +971,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 26/35 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 · 1 line
2.12.3
Jan Kara
maintainerPATCH 27/35 shmem: Use pagevec_lookup() in shmem_unlock_mapping()
In reply to Jan KaraThe comment about find_get_pages() returning if it finds a row of swap entries seems to be stale. Use pagevec_lookup() in shmem_unlock_mapping() to simplify the code.
--- mm/shmem.c | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-)
mm/shmem.c +2 -12
@@ -729,24 +729,14 @@ unsigned long shmem_swap_usage(struct vm_area_struct *vma)void shmem_unlock_mapping (struct address_space *mapping) {struct pagevec pvec; -pgoff_t indices[PAGEVEC_SIZE ];pgoff_t index =0 ;pagevec_init (&pvec,0 );/* * Minor point, but we might as well stop if someone else SHM_LOCKs it. */ -while (!mapping_unevictable (mapping)) { -/* -* Avoid pagevec_lookup(): find_get_pages() returns 0 as if it -* has finished, if it hits a row of PAGEVEC_SIZE swap entries. -*/ - pvec.nr =find_get_entries (mapping, index, -PAGEVEC_SIZE , pvec.pages, indices); -if (!pvec.nr) -break ; - index = indices[pvec.nr -1 ] +1 ; -pagevec_remove_exceptionals (&pvec); +while (!mapping_unevictable (mapping) && +pagevec_lookup (&pvec, mapping, &index)) {check_move_unevictable_pages (pvec.pages, pvec.nr);pagevec_release (&pvec);cond_resched ();
Signature · 1 line
2.12.3
Jan Kara
maintainerPATCH 28/35 shmem: Use pagevec_lookup_entries()
In reply to Jan KaraCurrently we use find_get_entries() shmem which just opencode what pagevec_lookup_entries() does. Use pagevec_lookup_entries() instead except for one case which plays tricks with number of pages looked up and it won't fit in how we will make pagevec_lookup_entries() work.
--- mm/shmem.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-)
mm/shmem.c +5 -7
@@ -768,10 +768,9 @@ static void shmem_undo_range(struct inode *inode, loff_t lstart, loff_t lend,pagevec_init (&pvec,0 ); index = start;while (index < end) { - pvec.nr =find_get_entries (mapping, index, -min (end - index, (pgoff_t )PAGEVEC_SIZE ), - pvec.pages, indices); -if (!pvec.nr) +if (!pagevec_lookup_entries (&pvec, mapping, index, +min (end - index, (pgoff_t )PAGEVEC_SIZE ), + indices))break ;for (i =0 ; i <pagevec_count (&pvec); i++) {struct page *page = pvec.pages[i];
@@ -859,10 +858,9 @@ static void shmem_undo_range(struct inode *inode, loff_t lstart, loff_t lend,while (index < end) {cond_resched (); - pvec.nr =find_get_entries (mapping, index, +if (!pagevec_lookup_entries (&pvec, mapping, index,min (end - index, (pgoff_t )PAGEVEC_SIZE ), - pvec.pages, indices); -if (!pvec.nr) { + indices)) {/* If all gone or hole-punch or unfalloc, we're done */ if (index == start || end !=-1 )break ;
Signature · 1 line
2.12.3
Jan Kara
maintainerPATCH 29/35 mm: Make pagevec_lookup_entries() update index
In reply to Jan KaraMake pagevec_lookup_entries() (and underlying find_get_entries()) update index to the next page where iteration should continue. This is mostly for consistency with pagevec_lookup() and future pagevec_lookup_entries_range().
--- include/linux/pagemap.h | 2 +- include/linux/pagevec.h | 2 +- mm/filemap.c | 11 ++++++--- mm/shmem.c | 57 +++++++++++++++++++++++-------------------- mm/swap.c | 4 +-- mm/truncate.c | 65 +++++++++++++++++++++++-------------------------- 6 files changed, 72 insertions(+), 69 deletions(-)
include/linux/pagemap.h +1 -1
@@ -333,7 +333,7 @@ static inline struct page *grab_cache_page_nowait(struct address_space *mapping,struct page *find_get_entry (struct address_space *mapping,pgoff_t offset);struct page *find_lock_entry (struct address_space *mapping,pgoff_t offset); -unsigned find_get_entries (struct address_space *mapping,pgoff_t start, +unsigned find_get_entries (struct address_space *mapping,pgoff_t *start,unsigned int nr_entries,struct page **entries,pgoff_t *indices); unsigned find_get_pages_range(struct address_space *mapping, pgoff_t *start,
include/linux/pagevec.h +1 -1
@@ -24,7 +24,7 @@ void __pagevec_release(struct pagevec *pvec);void __pagevec_lru_add (struct pagevec *pvec);unsigned pagevec_lookup_entries (struct pagevec *pvec,struct address_space *mapping, -pgoff_t start,unsigned nr_entries, +pgoff_t *start,unsigned nr_entries,pgoff_t *indices);void pagevec_remove_exceptionals (struct pagevec *pvec); unsigned pagevec_lookup_range(struct pagevec *pvec,
mm/filemap.c +7 -4
@@ -1373,11 +1373,11 @@ EXPORT_SYMBOL(pagecache_get_page);* Any shadow entries of evicted pages, or swap entries from * shmem/tmpfs, are included in the returned array. * -* find_get_entries() returns the number of pages and shadow entries -* which were found. +* find_get_entries() returns the number of pages and shadow entries which were +* found. It also updates @start to index the next page for the traversal. */ unsigned find_get_entries (struct address_space *mapping, -pgoff_t start,unsigned int nr_entries, +pgoff_t *start,unsigned int nr_entries,struct page **entries,pgoff_t *indices) {void **slot;
@@ -1388,7 +1388,7 @@ unsigned find_get_entries(struct address_space *mapping,return 0 ;rcu_read_lock (); -radix_tree_for_each_slot (slot, &mapping->page_tree, &iter, start) { +radix_tree_for_each_slot (slot, &mapping->page_tree, &iter, *start) {struct page *head, *page; repeat: page =radix_tree_deref_slot (slot);
@@ -1429,6 +1429,9 @@ unsigned find_get_entries(struct address_space *mapping,break ; }rcu_read_unlock (); + +if (ret) + *start = indices[ret -1 ] +1 ;return ret; }
mm/shmem.c +31 -26
177 lines not on this page · raw message
mm/swap.c +2 -2
@@ -906,11 +906,11 @@ EXPORT_SYMBOL(__pagevec_lru_add);* not-present entries. * * pagevec_lookup_entries() returns the number of entries which were -* found. +* found. It also updates @start to index the next page for the traversal. */ unsigned pagevec_lookup_entries (struct pagevec *pvec,struct address_space *mapping, -pgoff_t start,unsigned nr_pages, +pgoff_t *start,unsigned nr_pages,pgoff_t *indices) { pvec->nr = find_get_entries(mapping, start, nr_pages,
mm/truncate.c +30 -35
207 lines not on this page · raw message
Signature · 1 line
2.12.3
Jan Kara
maintainerPATCH 30/35 mm: Implement find_get_entries_range()
In reply to Jan KaraImplement a variant of find_get_entries() that stops iterating at given index. Some callers want this, so let's provide the interface. Also it makes the interface consistent with find_get_pages().
--- include/linux/pagemap.h | 13 ++++++++++--- include/linux/pagevec.h | 12 ++++++++++-- mm/filemap.c | 32 ++++++++++++++++++++++++-------- mm/swap.c | 11 ++++++----- 4 files changed, 50 insertions(+), 18 deletions(-)
include/linux/pagemap.h +10 -3
@@ -333,9 +333,16 @@ static inline struct page *grab_cache_page_nowait(struct address_space *mapping,struct page *find_get_entry (struct address_space *mapping,pgoff_t offset);struct page *find_lock_entry (struct address_space *mapping,pgoff_t offset); -unsigned find_get_entries (struct address_space *mapping,pgoff_t *start, -unsigned int nr_entries,struct page **entries, -pgoff_t *indices); +unsigned find_get_entries_range (struct address_space *mapping,pgoff_t *start, +pgoff_t end,unsigned int nr_entries, +struct page **entries,pgoff_t *indices); +static inline unsigned find_get_entries (struct address_space *mapping, +pgoff_t *start,unsigned int nr_entries, +struct page **entries,pgoff_t *indices) +{ +return find_get_entries_range (mapping, start, (pgoff_t)-1 , nr_entries, + entries, indices); +}unsigned find_get_pages_range (struct address_space *mapping,pgoff_t *start,pgoff_t end,unsigned int nr_pages,struct page **pages);
include/linux/pagevec.h +10 -2
@@ -22,10 +22,18 @@ struct pagevec {void __pagevec_release (struct pagevec *pvec);void __pagevec_lru_add (struct pagevec *pvec); -unsigned pagevec_lookup_entries (struct pagevec *pvec, +unsigned pagevec_lookup_entries_range (struct pagevec *pvec, +struct address_space *mapping, +pgoff_t *start,pgoff_t end, +unsigned nr_entries,pgoff_t *indices); +static inline unsigned pagevec_lookup_entries (struct pagevec *pvec,struct address_space *mapping,pgoff_t *start,unsigned nr_entries, -pgoff_t *indices); +pgoff_t *indices) +{ +return pagevec_lookup_entries_range (pvec, mapping, start, (pgoff_t)-1 , + nr_entries, indices); +}void pagevec_remove_exceptionals (struct pagevec *pvec); unsigned pagevec_lookup_range(struct pagevec *pvec, struct address_space *mapping,
mm/filemap.c +24 -8
@@ -1354,9 +1354,10 @@ struct page *pagecache_get_page(struct address_space *mapping, pgoff_t offset,EXPORT_SYMBOL (pagecache_get_page);/** -* find_get_entries - gang pagecache lookup +* find_get_entries_range - gang pagecache lookup * @mapping: The address_space to search * @start: The starting page cache index +* @end: The final page cache index (inclusive) * @nr_entries: The maximum number of entries * @entries: Where the resulting entries are placed * @indices: The cache indices corresponding to the entries in @entries
@@ -1376,9 +1377,9 @@ EXPORT_SYMBOL(pagecache_get_page);* find_get_entries() returns the number of pages and shadow entries which were * found. It also updates @start to index the next page for the traversal. */ -unsigned find_get_entries (struct address_space *mapping, -pgoff_t *start,unsigned int nr_entries, -struct page **entries,pgoff_t *indices) +unsigned find_get_entries_range (struct address_space *mapping, +pgoff_t *start,pgoff_t end,unsigned int nr_entries, +struct page **entries,pgoff_t *indices) {void **slot;unsigned int ret =0 ;
@@ -1390,6 +1391,9 @@ unsigned find_get_entries(struct address_space *mapping,rcu_read_lock ();radix_tree_for_each_slot (slot, &mapping->page_tree, &iter, *start) {struct page *head, *page; + +if (iter.index > end) +break ; repeat: page =radix_tree_deref_slot (slot);if (unlikely (!page))
@@ -1425,13 +1429,25 @@ unsigned find_get_entries(struct address_space *mapping, export: indices[ret] = iter.index; entries[ret] = page; -if (++ret == nr_entries) -break ; +if (++ret == nr_entries) { + *start = indices[ret -1 ] +1 ; + goto out; + } } + +/* +* We come here when there is no page beyond @end. We take care to not +* overflow the index @start 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 ) + *start = (pgoff_t)-1 ; +else + *start = end +1 ; +out:rcu_read_unlock (); -if (ret) - *start = indices[ret -1 ] +1 ;return ret; }
mm/swap.c +6 -5
@@ -889,10 +889,11 @@ void __pagevec_lru_add(struct pagevec *pvec)EXPORT_SYMBOL (__pagevec_lru_add);/** -* pagevec_lookup_entries - gang pagecache lookup +* pagevec_lookup_entries_range - gang pagecache lookup * @pvec: Where the resulting entries are placed * @mapping: The address_space to search * @start: The starting entry index +* @end: The final entry index (inclusive) * @nr_entries: The maximum number of entries * @indices: The cache indices corresponding to the entries in @pvec *
@@ -908,13 +909,13 @@ EXPORT_SYMBOL(__pagevec_lru_add);* pagevec_lookup_entries() returns the number of entries which were * found. It also updates @start to index the next page for the traversal. */ -unsigned pagevec_lookup_entries (struct pagevec *pvec, +unsigned pagevec_lookup_entries_range (struct pagevec *pvec,struct address_space *mapping, -pgoff_t *start,unsigned nr_pages, +pgoff_t *start,pgoff_t end,unsigned nr_pages,pgoff_t *indices) { - pvec->nr =find_get_entries (mapping, start, nr_pages, - pvec->pages, indices); + pvec->nr =find_get_entries_range (mapping, start, end, nr_pages, + pvec->pages, indices);return pagevec_count (pvec); }
Signature · 1 line
2.12.3
Jan Kara
maintainerPATCH 31/35 shmem: Convert to pagevec_lookup_entries_range()
In reply to Jan KaraConvert radix tree scanners to use pagevec_lookup_entries_range() and find_get_entries_range() since they all want only entries from given range.
--- mm/shmem.c | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-)
mm/shmem.c +7 -16
@@ -768,16 +768,12 @@ static void shmem_undo_range(struct inode *inode, loff_t lstart, loff_t lend,pagevec_init (&pvec,0 ); index = start;while (index < end) { -if (!pagevec_lookup_entries (&pvec, mapping, &index, -min (end - index, (pgoff_t )PAGEVEC_SIZE ), - indices)) +if (!pagevec_lookup_entries_range (&pvec, mapping, &index, + end -1 ,PAGEVEC_SIZE , indices))break ;for (i =0 ; i <pagevec_count (&pvec); i++) {struct page *page = pvec.pages[i]; -if (indices[i] >= end) -break ; -if (radix_tree_exceptional_entry (page)) {if (unfalloc)continue ;
@@ -860,9 +856,8 @@ static void shmem_undo_range(struct inode *inode, loff_t lstart, loff_t lend,cond_resched (); -if (!pagevec_lookup_entries (&pvec, mapping, &index, -min (end - index, (pgoff_t )PAGEVEC_SIZE ), - indices)) { +if (!pagevec_lookup_entries_range (&pvec, mapping, &index, + end -1 ,PAGEVEC_SIZE , indices)) {/* If all gone or hole-punch or unfalloc, we're done */ if (lookup_start == start || end !=-1 )break ;
@@ -873,9 +868,6 @@ static void shmem_undo_range(struct inode *inode, loff_t lstart, loff_t lend,for (i =0 ; i <pagevec_count (&pvec); i++) {struct page *page = pvec.pages[i]; -if (indices[i] >= end) -break ; -if (radix_tree_exceptional_entry (page)) {if (unfalloc)continue ;
@@ -2494,9 +2486,9 @@ static pgoff_t shmem_seek_hole_data(struct address_space *mapping,pagevec_init (&pvec,0 ); pvec.nr =1 ;/* start small: we may be there already */ -while (!done) { +while (!done && index < end) { last = index; - pvec.nr =find_get_entries (mapping, &index, + pvec.nr =find_get_entries_range (mapping, &index, end -1 , pvec.nr, pvec.pages, indices);if (!pvec.nr) {if (whence ==SEEK_DATA )
@@ -2516,8 +2508,7 @@ static pgoff_t shmem_seek_hole_data(struct address_space *mapping,if (!PageUptodate (page)) page =NULL ; } -if (last >= end || - (page && whence ==SEEK_DATA ) || +if ((page && whence ==SEEK_DATA ) || (!page && whence ==SEEK_HOLE )) { done = true;break ;
Signature · 1 line
2.12.3
kbuild test robot
build botRe: [PATCH 31/35] shmem: Convert to pagevec_lookup_entries_range()
url: https://github.com/0day-ci/linux/commits/Jan-Kara/pagevec-API-cleanups/20170601-200653 config: i386-randconfig-x078-06010927 (attached as .config) compiler: gcc-6 (Debian 6.2.0-3) 6.2.0…
Hi Jan,
[auto build test WARNING on linus/master]
[also build test WARNING on v4.12-rc3]
[cannot apply to next-20170601]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
url: https://github.com/0day-ci/linux/commits/Jan-Kara/pagevec-API-cleanups/20170601-200653
config: i386-randconfig-x078-06010927 (attached as .config)
compiler: gcc-6 (Debian 6.2.0-3) 6.2.0 20160901 reproduce:
# save the attached .config to linux build tree
make ARCH=i386 Note: it may well be a FALSE warning. FWIW you are at least aware of it now.
http://gcc.gnu.org/wiki/Better_Uninitialized_Warnings
All warnings (new ones prefixed by >>):
Cyclomatic Complexity 1 include/linux/huge_mm.h:split_huge_page Cyclomatic Complexity 1 include/linux/radix-tree.h:radix_tree_insert Cyclomatic Complexity 10 mm/shmem.c:shmem_add_to_page_cache Cyclomatic Complexity 2 include/linux/highmem.h:clear_highpage Cyclomatic Complexity 1 mm/shmem.c:shmem_confirm_swap Cyclomatic Complexity 2 include/linux/mm.h:put_page Cyclomatic Complexity 7 mm/shmem.c:shmem_write_end
Cyclomatic Complexity 4 mm/shmem.c:shmem_replace_page Cyclomatic Complexity 13 mm/shmem.c:shmem_unused_huge_shrink Cyclomatic Complexity 69 mm/shmem.c:shmem_getpage_gfp Cyclomatic Complexity 2 mm/shmem.c:shmem_unused_huge_scan Cyclomatic Complexity 1 mm/shmem.c:shmem_put_link
Cyclomatic Complexity 11 mm/shmem.c:shmem_fault
Cyclomatic Complexity 1 mm/shmem.c:synchronous_wake_function Cyclomatic Complexity 1 include/linux/sched.h:cond_resched_rcu Cyclomatic Complexity 5 mm/shmem.c:find_swap_entry
Cyclomatic Complexity 2 include/linux/pagemap.h:linear_page_index Cyclomatic Complexity 2 include/linux/pagevec.h:pagevec_release Cyclomatic Complexity 1 include/linux/pagevec.h:pagevec_lookup Cyclomatic Complexity 2 include/linux/pagemap.h:page_to_pgoff Cyclomatic Complexity 2 mm/shmem.c:shmem_free_swap
Cyclomatic Complexity 8 mm/shmem.c:shmem_unuse_inode Cyclomatic Complexity 1 include/linux/fs.h:inode_lock Cyclomatic Complexity 1 include/linux/fs.h:inode_unlock Cyclomatic Complexity 2 include/linux/fs.h:file_accessed Cyclomatic Complexity 7 include/linux/khugepaged.h:khugepaged_enter Cyclomatic Complexity 2 mm/shmem.c:shmem_mmap
Cyclomatic Complexity 12 mm/shmem.c:shmem_seek_hole_data Cyclomatic Complexity 8 mm/shmem.c:shmem_file_llseek Cyclomatic Complexity 2 include/linux/uaccess.h:copy_user_overflow Cyclomatic Complexity 2 include/linux/mm.h:page_mapcount Cyclomatic Complexity 8 mm/shmem.c:shmem_tag_pins
Cyclomatic Complexity 13 mm/shmem.c:shmem_wait_for_pins Cyclomatic Complexity 2 include/linux/xattr.h:simple_xattrs_free Cyclomatic Complexity 1 include/linux/xattr.h:simple_xattrs_init Cyclomatic Complexity 7 mm/shmem.c:shmem_show_options Cyclomatic Complexity 1 include/linux/percpu_counter.h:percpu_counter_sum Cyclomatic Complexity 3 mm/shmem.c:shmem_statfs
Cyclomatic Complexity 2 mm/shmem.c:shmem_destroy_inode Cyclomatic Complexity 2 mm/shmem.c:shmem_destroy_callback Cyclomatic Complexity 2 mm/shmem.c:shmem_alloc_inode Cyclomatic Complexity 3 mm/shmem.c:shmem_fh_to_dentry Cyclomatic Complexity 4 mm/shmem.c:shmem_encode_fh
Cyclomatic Complexity 7 mm/shmem.c:shmem_parse_huge Cyclomatic Complexity 8 mm/shmem.c:shmem_enabled_store Cyclomatic Complexity 94 mm/shmem.c:shmem_parse_options Cyclomatic Complexity 9 mm/shmem.c:shmem_remount_fs Cyclomatic Complexity 6 mm/shmem.c:shmem_get_inode
Cyclomatic Complexity 4 mm/shmem.c:shmem_tmpfile
Cyclomatic Complexity 3 mm/shmem.c:shmem_exchange
Cyclomatic Complexity 3 mm/shmem.c:shmem_unlink
Cyclomatic Complexity 2 mm/shmem.c:shmem_rmdir
Cyclomatic Complexity 2 include/linux/dcache.h:dget Cyclomatic Complexity 4 mm/shmem.c:shmem_mknod
Cyclomatic Complexity 3 mm/shmem.c:shmem_whiteout
Cyclomatic Complexity 9 mm/shmem.c:shmem_rename2
Cyclomatic Complexity 2 mm/shmem.c:shmem_mkdir
Cyclomatic Complexity 1 mm/shmem.c:shmem_create
Cyclomatic Complexity 2 mm/shmem.c:shmem_link
Cyclomatic Complexity 2 mm/shmem.c:shmem_getattr
Cyclomatic Complexity 1 mm/shmem.c:shmem_put_super
Cyclomatic Complexity 7 mm/shmem.c:shmem_fill_super Cyclomatic Complexity 1 mm/shmem.c:shmem_mount
Cyclomatic Complexity 1 mm/shmem.c:shmem_init_inodecache Cyclomatic Complexity 1 mm/shmem.c:shmem_init_inode Cyclomatic Complexity 1 mm/shmem.c:shmem_destroy_inodecache Cyclomatic Complexity 3 mm/shmem.c:shmem_enabled_show Cyclomatic Complexity 8 mm/shmem.c:__shmem_file_setup Cyclomatic Complexity 1 mm/shmem.c:shmem_getpage
Cyclomatic Complexity 5 mm/shmem.c:shmem_write_begin Cyclomatic Complexity 36 mm/shmem.c:shmem_undo_range Cyclomatic Complexity 17 mm/shmem.c:shmem_file_read_iter Cyclomatic Complexity 8 mm/shmem.c:shmem_symlink
Cyclomatic Complexity 5 mm/shmem.c:shmem_get_link
Cyclomatic Complexity 1 mm/shmem.c:vma_is_shmem
Cyclomatic Complexity 4 mm/shmem.c:shmem_charge
Cyclomatic Complexity 2 mm/shmem.c:shmem_uncharge
Cyclomatic Complexity 7 mm/shmem.c:shmem_partial_swap_usage Cyclomatic Complexity 4 mm/shmem.c:shmem_swap_usage Cyclomatic Complexity 3 mm/shmem.c:shmem_unlock_mapping Cyclomatic Complexity 1 mm/shmem.c:shmem_truncate_range Cyclomatic Complexity 19 mm/shmem.c:shmem_fallocate Cyclomatic Complexity 6 mm/shmem.c:shmem_evict_inode Cyclomatic Complexity 16 mm/shmem.c:shmem_setattr
Cyclomatic Complexity 9 mm/shmem.c:shmem_unuse
Cyclomatic Complexity 7 mm/shmem.c:shmem_lock
Cyclomatic Complexity 1 mm/shmem.c:shmem_mapping
Cyclomatic Complexity 16 mm/shmem.c:shmem_mcopy_atomic_pte Cyclomatic Complexity 9 mm/shmem.c:shmem_add_seals
Cyclomatic Complexity 2 mm/shmem.c:shmem_get_seals
Cyclomatic Complexity 3 mm/shmem.c:shmem_fcntl
Cyclomatic Complexity 7 mm/shmem.c:shmem_init
Cyclomatic Complexity 8 mm/shmem.c:shmem_huge_enabled Cyclomatic Complexity 1 mm/shmem.c:shmem_kernel_file_setup Cyclomatic Complexity 1 mm/shmem.c:shmem_file_setup Cyclomatic Complexity 11 mm/shmem.c:SYSC_memfd_create Cyclomatic Complexity 1 mm/shmem.c:SyS_memfd_create Cyclomatic Complexity 4 mm/shmem.c:shmem_zero_setup Cyclomatic Complexity 2 mm/shmem.c:shmem_read_mapping_page_gfp mm/shmem.c: In function 'shmem_seek_hole_data':
>> mm/shmem.c:2522:9: warning: 'last' may be used uninitialized in this function [-Wmaybe-uninitialized]
return last;
^~~~vim +/last +2522 mm/shmem.c
220f2ac9 Hugh Dickins 2012-12-12 2506 page = pvec.pages[i];
220f2ac9 Hugh Dickins 2012-12-12 2507 if (page && !radix_tree_exceptional_entry(page)) {
220f2ac9 Hugh Dickins 2012-12-12 2508 if (!PageUptodate(page))
220f2ac9 Hugh Dickins 2012-12-12 2509 page = NULL;
220f2ac9 Hugh Dickins 2012-12-12 2510 }
eb675e81 Jan Kara 2017-06-01 2511 if ((page && whence == SEEK_DATA) ||
965c8e59 Andrew Morton 2012-12-17 2512 (!page && whence == SEEK_HOLE)) {
220f2ac9 Hugh Dickins 2012-12-12 2513 done = true;
220f2ac9 Hugh Dickins 2012-12-12 2514 break;
220f2ac9 Hugh Dickins 2012-12-12 2515 }
220f2ac9 Hugh Dickins 2012-12-12 2516 }
0cd6144a Johannes Weiner 2014-04-03 2517 pagevec_remove_exceptionals(&pvec);
220f2ac9 Hugh Dickins 2012-12-12 2518 pagevec_release(&pvec);
220f2ac9 Hugh Dickins 2012-12-12 2519 pvec.nr = PAGEVEC_SIZE;
220f2ac9 Hugh Dickins 2012-12-12 2520 cond_resched();
220f2ac9 Hugh Dickins 2012-12-12 2521 }
1d162ad5 Jan Kara 2017-06-01 @2522 return last;
220f2ac9 Hugh Dickins 2012-12-12 2523 }
220f2ac9 Hugh Dickins 2012-12-12 2524
965c8e59 Andrew Morton 2012-12-17 2525 static loff_t shmem_file_llseek(struct file *file, loff_t offset, int whence)
220f2ac9 Hugh Dickins 2012-12-12 2526 {
220f2ac9 Hugh Dickins 2012-12-12 2527 struct address_space *mapping = file->f_mapping;
220f2ac9 Hugh Dickins 2012-12-12 2528 struct inode *inode = mapping->host;
220f2ac9 Hugh Dickins 2012-12-12 2529 pgoff_t start, end;
220f2ac9 Hugh Dickins 2012-12-12 2530 loff_t new_offset;:::::: The code at line 2522 was first introduced by commit
:::::: 1d162ad5252576fa97d38e96e6e09fd9165f5d6b mm: Make pagevec_lookup_entries() update index
:::::: TO: Jan Kara <[email protected]>
:::::: CC: 0day robot <[email protected]>
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
Jan Kara
maintainerPATCH 32/35 mm: Convert truncate code to pagevec_lookup_entries_range()
In reply to Jan KaraAll radix tree scanning code in truncate paths is interested only in pages from given range. Convert them to pagevec_lookup_entries_range().
--- mm/truncate.c | 52 +++++++++------------------------------------------- 1 file changed, 9 insertions(+), 43 deletions(-)
mm/truncate.c +9 -43
@@ -289,16 +289,11 @@ void truncate_inode_pages_range(struct address_space *mapping,pagevec_init (&pvec,0 ); index = start; -while (index < end &&pagevec_lookup_entries (&pvec, mapping, &index, -min (end - index, (pgoff_t )PAGEVEC_SIZE ), - indices)) { +while (index < end &&pagevec_lookup_entries_range (&pvec, mapping, + &index, end -1 ,PAGEVEC_SIZE , indices)) {for (i =0 ; i <pagevec_count (&pvec); i++) {struct page *page = pvec.pages[i]; -/* We rely upon deletion not changing page->index */ -if (indices[i] >= end) -break ; -if (radix_tree_exceptional_entry (page)) {truncate_exceptional_entry (mapping, indices[i], page);
@@ -352,20 +347,14 @@ void truncate_inode_pages_range(struct address_space *mapping,put_page (page); } } -/* -* If the truncation happened within a single page no pages -* will be released, just zeroed, so we can bail out now. -*/ -if (start >= end) - goto out; index = start; -for ( ; ; ) { +while (index < end) {pgoff_t lookup_start = index;cond_resched (); -if (!pagevec_lookup_entries (&pvec, mapping, &index, -min (end - index, (pgoff_t )PAGEVEC_SIZE ), indices)) { +if (!pagevec_lookup_entries_range (&pvec, mapping, &index, + end -1 ,PAGEVEC_SIZE , indices)) {/* If all gone from start onwards, we're done */ if (lookup_start == start)break ;
@@ -373,22 +362,9 @@ void truncate_inode_pages_range(struct address_space *mapping, index = start;continue ; } -if (lookup_start == start && indices[0 ] >= end) { -/* All gone out of hole to be punched, we're done */ -pagevec_remove_exceptionals (&pvec); -pagevec_release (&pvec); -break ; - }for (i =0 ; i <pagevec_count (&pvec); i++) {struct page *page = pvec.pages[i]; -/* We rely upon deletion not changing page->index */ -if (indices[i] >= end) { -/* Restart punch to make sure all gone */ - index = start; -break ; - } -if (radix_tree_exceptional_entry (page)) {truncate_exceptional_entry (mapping, indices[i], page);
@@ -499,16 +475,11 @@ unsigned long invalidate_mapping_pages(struct address_space *mapping,int i;pagevec_init (&pvec,0 ); -while (index <= end &&pagevec_lookup_entries (&pvec, mapping, &index, -min (end - index, (pgoff_t )PAGEVEC_SIZE -1 ) +1 , - indices)) { +while (index <= end &&pagevec_lookup_entries_range (&pvec, mapping, + &index, end,PAGEVEC_SIZE , indices)) {for (i =0 ; i <pagevec_count (&pvec); i++) {struct page *page = pvec.pages[i]; -/* We rely upon deletion not changing page->index */ -if (indices[i] > end) -break ; -if (radix_tree_exceptional_entry (page)) {invalidate_exceptional_entry (mapping, indices[i], page);
@@ -629,16 +600,11 @@ int invalidate_inode_pages2_range(struct address_space *mapping,pagevec_init (&pvec,0 ); index = start; -while (index <= end &&pagevec_lookup_entries (&pvec, mapping, &index, -min (end - index, (pgoff_t )PAGEVEC_SIZE -1 ) +1 , - indices)) { +while (index <= end &&pagevec_lookup_entries_range (&pvec, mapping, + &index, end,PAGEVEC_SIZE , indices)) {for (i =0 ; i <pagevec_count (&pvec); i++) {struct page *page = pvec.pages[i]; -/* We rely upon deletion not changing page->index */ -if (indices[i] > end) -break ; -if (radix_tree_exceptional_entry (page)) {if (!invalidate_exceptional_entry2 (mapping, indices[i], page))
Signature · 1 line
2.12.3
Jan Kara
maintainerPATCH 33/35 mm: Remove nr_entries argument from pagevec_lookup_entries{,_range}()
In reply to Jan KaraAll users pass PAGEVEC_SIZE as the number of entries now. Remove the argument.
--- include/linux/pagevec.h | 7 +++---- mm/shmem.c | 4 ++-- mm/swap.c | 6 ++---- mm/truncate.c | 8 ++++---- 4 files changed, 11 insertions(+), 14 deletions(-)
include/linux/pagevec.h +3 -4
@@ -25,14 +25,13 @@ void __pagevec_lru_add(struct pagevec *pvec);unsigned pagevec_lookup_entries_range (struct pagevec *pvec,struct address_space *mapping,pgoff_t *start,pgoff_t end, -unsigned nr_entries,pgoff_t *indices); +pgoff_t *indices);static inline unsigned pagevec_lookup_entries (struct pagevec *pvec,struct address_space *mapping, -pgoff_t *start,unsigned nr_entries, -pgoff_t *indices) +pgoff_t *start,pgoff_t *indices) {return pagevec_lookup_entries_range (pvec, mapping, start, (pgoff_t)-1 , - nr_entries, indices); + indices); }void pagevec_remove_exceptionals (struct pagevec *pvec); unsigned pagevec_lookup_range(struct pagevec *pvec,
mm/shmem.c +2 -2
@@ -769,7 +769,7 @@ static void shmem_undo_range(struct inode *inode, loff_t lstart, loff_t lend, index = start;while (index < end) {if (!pagevec_lookup_entries_range (&pvec, mapping, &index, - end -1 ,PAGEVEC_SIZE , indices)) + end -1 , indices))break ;for (i =0 ; i <pagevec_count (&pvec); i++) {struct page *page = pvec.pages[i];
@@ -857,7 +857,7 @@ static void shmem_undo_range(struct inode *inode, loff_t lstart, loff_t lend,cond_resched ();if (!pagevec_lookup_entries_range (&pvec, mapping, &index, - end -1 ,PAGEVEC_SIZE , indices)) { + end -1 , indices)) {/* If all gone or hole-punch or unfalloc, we're done */ if (lookup_start == start || end !=-1 )break ;
mm/swap.c +2 -4
@@ -894,7 +894,6 @@ EXPORT_SYMBOL(__pagevec_lru_add);* @mapping: The address_space to search * @start: The starting entry index * @end: The final entry index (inclusive) -* @nr_entries: The maximum number of entries * @indices: The cache indices corresponding to the entries in @pvec * * pagevec_lookup_entries() will search for and return a group of up
@@ -911,10 +910,9 @@ EXPORT_SYMBOL(__pagevec_lru_add);*/ unsigned pagevec_lookup_entries_range (struct pagevec *pvec,struct address_space *mapping, -pgoff_t *start,pgoff_t end,unsigned nr_pages, -pgoff_t *indices) +pgoff_t *start,pgoff_t end,pgoff_t *indices) { - pvec->nr =find_get_entries_range (mapping, start, end, nr_pages, + pvec->nr =find_get_entries_range (mapping, start, end,PAGEVEC_SIZE , pvec->pages, indices);return pagevec_count (pvec); }
mm/truncate.c +4 -4
@@ -290,7 +290,7 @@ void truncate_inode_pages_range(struct address_space *mapping,pagevec_init (&pvec,0 ); index = start;while (index < end &&pagevec_lookup_entries_range (&pvec, mapping, - &index, end -1 ,PAGEVEC_SIZE , indices)) { + &index, end -1 , indices)) {for (i =0 ; i <pagevec_count (&pvec); i++) {struct page *page = pvec.pages[i];
@@ -354,7 +354,7 @@ void truncate_inode_pages_range(struct address_space *mapping,cond_resched ();if (!pagevec_lookup_entries_range (&pvec, mapping, &index, - end -1 ,PAGEVEC_SIZE , indices)) { + end -1 , indices)) {/* If all gone from start onwards, we're done */ if (lookup_start == start)break ;
@@ -476,7 +476,7 @@ unsigned long invalidate_mapping_pages(struct address_space *mapping,pagevec_init (&pvec,0 );while (index <= end &&pagevec_lookup_entries_range (&pvec, mapping, - &index, end,PAGEVEC_SIZE , indices)) { + &index, end, indices)) {for (i =0 ; i <pagevec_count (&pvec); i++) {struct page *page = pvec.pages[i];
@@ -601,7 +601,7 @@ int invalidate_inode_pages2_range(struct address_space *mapping,pagevec_init (&pvec,0 ); index = start;while (index <= end &&pagevec_lookup_entries_range (&pvec, mapping, - &index, end,PAGEVEC_SIZE , indices)) { + &index, end, indices)) {for (i =0 ; i <pagevec_count (&pvec); i++) {struct page *page = pvec.pages[i];
Signature · 1 line
2.12.3
Jan Kara
maintainerPATCH 34/35 mm: Make find_get_entries_tag() update index
In reply to Jan KaraMake find_get_entries_tag() update 'start' to index the next page for iteration.
--- fs/dax.c | 3 +-- include/linux/pagemap.h | 2 +- mm/filemap.c | 8 ++++++-- 3 files changed, 8 insertions(+), 5 deletions(-)
fs/dax.c +1 -2
@@ -841,7 +841,7 @@ int dax_writeback_mapping_range(struct address_space *mapping,pagevec_init (&pvec,0 );while (!done) { - pvec.nr =find_get_entries_tag (mapping, start_index, + pvec.nr =find_get_entries_tag (mapping, &start_index,PAGECACHE_TAG_TOWRITE ,PAGEVEC_SIZE , pvec.pages, indices);
@@ -859,7 +859,6 @@ int dax_writeback_mapping_range(struct address_space *mapping,if (ret <0 ) goto out; } - start_index = indices[pvec.nr -1 ] +1 ; } out:put_dax (dax_dev);
include/linux/pagemap.h +1 -1
@@ -365,7 +365,7 @@ static inline unsigned find_get_pages_tag(struct address_space *mapping,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, +unsigned find_get_entries_tag (struct address_space *mapping,pgoff_t *start,int tag,unsigned int nr_entries,struct page **entries,pgoff_t *indices);
mm/filemap.c +6 -2
@@ -1731,7 +1731,7 @@ EXPORT_SYMBOL(find_get_pages_range_tag);* Like find_get_entries, except we only return entries which are tagged with * @tag. */ -unsigned find_get_entries_tag (struct address_space *mapping,pgoff_t start, +unsigned find_get_entries_tag (struct address_space *mapping,pgoff_t *start,int tag,unsigned int nr_entries,struct page **entries,pgoff_t *indices) {
@@ -1744,7 +1744,7 @@ unsigned find_get_entries_tag(struct address_space *mapping, pgoff_t start,rcu_read_lock ();radix_tree_for_each_tagged (slot, &mapping->page_tree, - &iter, start, tag) { + &iter, *start, tag) {struct page *head, *page; repeat: page =radix_tree_deref_slot (slot);
@@ -1786,6 +1786,10 @@ unsigned find_get_entries_tag(struct address_space *mapping, pgoff_t start,break ; }rcu_read_unlock (); + +if (ret) + *start = indices[ret -1 ] +1 ; +return ret; }EXPORT_SYMBOL (find_get_entries_tag);
Signature · 6 lines
2.12.3 ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot
Jan Kara
maintainerPATCH 35/35 mm: Implement find_get_entries_range_tag()
In reply to Jan KaraImplement find_get_entries_range_tag() (actually convert find_get_entries_tag() tag to it as the only user of find_get_entries_tag() needs a ranged lookup) and use it in DAX which is the only user of this interface. This is mostly for consistency with other page/entry iteration interfaces.
--- fs/dax.c | 12 +++--------- include/linux/pagemap.h | 3 ++- mm/filemap.c | 36 ++++++++++++++++++++++++++---------- 3 files changed, 31 insertions(+), 20 deletions(-)
fs/dax.c +3 -9
@@ -819,7 +819,6 @@ int dax_writeback_mapping_range(struct address_space *mapping,pgoff_t indices[PAGEVEC_SIZE ];struct dax_device *dax_dev;struct pagevec pvec; -bool done = false;int i, ret =0 ;if (WARN_ON_ONCE (inode->i_blkbits !=PAGE_SHIFT ))
@@ -840,20 +839,15 @@ int dax_writeback_mapping_range(struct address_space *mapping,tag_pages_for_writeback (mapping, start_index, end_index);pagevec_init (&pvec,0 ); -while (!done) { - pvec.nr =find_get_entries_tag (mapping, &start_index, -PAGECACHE_TAG_TOWRITE ,PAGEVEC_SIZE , +while (start_index <= end_index) { + pvec.nr =find_get_entries_range_tag (mapping, &start_index, + end_index,PAGECACHE_TAG_TOWRITE ,PAGEVEC_SIZE , pvec.pages, indices);if (pvec.nr ==0 )break ;for (i =0 ; i < pvec.nr; i++) { -if (indices[i] > end_index) { - done = true; -break ; - } - ret =dax_writeback_one (bdev, dax_dev, mapping, indices[i], pvec.pages[i]);if (ret <0 )
include/linux/pagemap.h +2 -1
@@ -365,7 +365,8 @@ static inline unsigned find_get_pages_tag(struct address_space *mapping,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, +unsigned find_get_entries_range_tag (struct address_space *mapping, +pgoff_t *start,pgoff_t end,int tag,unsigned int nr_entries,struct page **entries,pgoff_t *indices);
mm/filemap.c +26 -10
@@ -1720,9 +1720,10 @@ unsigned find_get_pages_range_tag(struct address_space *mapping, pgoff_t *index,EXPORT_SYMBOL (find_get_pages_range_tag);/** -* find_get_entries_tag - find and return entries that match @tag +* find_get_entries_range_tag - find and return entries that match @tag * @mapping: the address_space to search * @start: the starting page cache index +* @end: the final page cache index (inclusive) * @tag: the tag index * @nr_entries: the maximum number of entries * @entries: where the resulting entries are placed
@@ -1731,9 +1732,10 @@ EXPORT_SYMBOL(find_get_pages_range_tag);* Like find_get_entries, except we only return entries which are tagged with * @tag. */ -unsigned find_get_entries_tag (struct address_space *mapping,pgoff_t *start, -int tag,unsigned int nr_entries, -struct page **entries,pgoff_t *indices) +unsigned find_get_entries_range_tag (struct address_space *mapping, +pgoff_t *start,pgoff_t end,int tag, +unsigned int nr_entries,struct page **entries, +pgoff_t *indices) {void **slot;unsigned int ret =0 ;
@@ -1746,6 +1748,9 @@ unsigned find_get_entries_tag(struct address_space *mapping, pgoff_t *start,radix_tree_for_each_tagged (slot, &mapping->page_tree, &iter, *start, tag) {struct page *head, *page; + +if (iter.index > end) +break ; repeat: page =radix_tree_deref_slot (slot);if (unlikely (!page))
@@ -1782,17 +1787,28 @@ unsigned find_get_entries_tag(struct address_space *mapping, pgoff_t *start, export: indices[ret] = iter.index; entries[ret] = page; -if (++ret == nr_entries) -break ; +if (++ret == nr_entries) { + *start = indices[ret -1 ] +1 ; + goto out; + } } -rcu_read_unlock (); -if (ret) - *start = indices[ret -1 ] +1 ; +/* +* 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 ) + *start = (pgoff_t)-1 ; +else + *start = end +1 ; +out: +rcu_read_unlock ();return ret; } -EXPORT_SYMBOL (find_get_entries_tag); +EXPORT_SYMBOL (find_get_entries_range_tag);/* * CD/DVDs are error prone. When a medium error occurs, the driver may fail
Signature · 1 line
2.12.3
Quoted 3 lines · Jan Kara
* Implement ranged variants for
pagevec_lookupandfind_get_functions. Lot of callers actually want a ranged lookup and we unnecessarily opencode this in lot of them.
How does this compare to Kents page cache iterators:
http://www.spinics.net/lists/linux-mm/msg104737.html
--
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
maintainerQuoted 8 lines · Christoph Hellwig
Quoted 3 lines · Jan Kara
* Implement ranged variants for
pagevec_lookupandfind_get_functions. Lot of callers actually want a ranged lookup and we unnecessarily opencode this in lot of them.How does this compare to Kents page cache iterators:
Interesting. I didn't know about that work. I guess the tradeoff is pretty obvious - my patches are more conservative (changing less) and as a result the API is not as neat as Kent's one. That being said I was also thinking about something similar to what Kent did but what I didn't like about such iterator is that you still need to specially handle the cases where you break out of the loop (you need to do that with pagevecs too but there it is kind of obvious from the API).
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR