Ranged pagevec lookup
Subsystems (12)
Jan Kara
maintainerv2 cover Ranged pagevec lookup
Hello,
This patch series was split out of the larger series to clean up pagevec APIs and provide ranged lookups. In this series I make pagevec_lookup() update the index (to be consistent with pagevec_lookup_tag() and also as a preparation for ranged lookups), provide ranged variant of pagevec_lookup() and use it in places where it makes sense. This not only removes some common code but is also a measurable performance win for some use cases (see patch 4/10) where radix tree is sparse and searching & grabing of a page after the end of the range has measurable overhead.
Andrew, can you please consider merging this series?
Full series including dependencies can be also obtained from my git tree:
git://git.kernel.org/pub/scm/linux/kernel/git/jack/linux-fs.git find_get_pages_range
Opinions and review welcome!
Honza
--
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 v2 1/10 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
@@ -194,36 +194,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 ,
@@ -231,7 +201,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 · 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 v2 2/10 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 | 10 ++++------ 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 +- include/linux/pagemap.h | 2 +- include/linux/pagevec.h | 2 +- mm/filemap.c | 11 ++++++++--- mm/swap.c | 5 +++-- 11 files changed, 32 insertions(+), 37 deletions(-)
fs/buffer.c +4 -6
@@ -1633,13 +1633,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 ;
@@ -1670,7 +1669,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);
@@ -3552,7 +3550,8 @@ page_cache_seek_hole_data(struct inode *inode, loff_t offset, loff_t length,unsigned want, nr_pages, i; want =min_t (unsigned, end - index,PAGEVEC_SIZE ); - nr_pages =pagevec_lookup (&pvec, inode->i_mapping, index, want); + nr_pages =pagevec_lookup (&pvec, inode->i_mapping, &index, + want);if (nr_pages ==0 )break ;
@@ -3594,7 +3593,6 @@ page_cache_seek_hole_data(struct inode *inode, loff_t offset, loff_t length,if (nr_pages < want)break ; - index = pvec.pages[i -1 ]->index +1 ;pagevec_release (&pvec); }while (index < end);
fs/ext4/file.c +1 -3
@@ -498,7 +498,7 @@ static int ext4_find_unwritten_pgoff(struct inode *inode,unsigned long nr_pages; num =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, (pgoff_t )num);if (nr_pages ==0 )break ;
@@ -563,8 +563,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
@@ -1676,7 +1676,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++) {
@@ -1693,7 +1693,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); } }
@@ -2304,7 +2303,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 ;
@@ -2313,8 +2312,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)
@@ -2359,7 +2356,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 */
include/linux/pagemap.h +1 -1
@@ -355,7 +355,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 +8 -3
@@ -412,7 +412,7 @@ bool filemap_range_has_page(struct address_space *mapping,return false;pagevec_init (&pvec,0 ); -if (!pagevec_lookup (&pvec, mapping, index,1 )) +if (!pagevec_lookup (&pvec, mapping, &index,1 ))return false; ret = (pvec.pages[0 ]->index <= end);pagevec_release (&pvec);
@@ -1576,10 +1576,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;
@@ -1590,7 +1591,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);
@@ -1632,6 +1633,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
@@ -957,12 +957,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 · 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 v2 3/10 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
@@ -355,8 +355,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
@@ -946,29 +946,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 · 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 v2 4/10 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
@@ -1627,19 +1627,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 ;/*
@@ -1669,6 +1668,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 · 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 v2 5/10 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 +3 -6
@@ -494,12 +494,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 - 1) + 1; - 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;
@@ -518,9 +517,6 @@ static int ext4_find_unwritten_pgoff(struct inode *inode, goto out; } -if (page->index > end) - goto out;
Jan Kara
maintainerPATCH v2 6/10 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
@@ -1676,13 +1676,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) {
@@ -2303,15 +2303,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 v2 7/10 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 · 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>
Re: [PATCH 07/10] hugetlbfs: Use pagevec_lookup_range() in remove_inode_hugepages()
Quoted 5 lines · Jan Kara
We want only pages from given range in
remove_inode_hugepages(). Usepagevec_lookup_range()instead ofpagevec_lookup().CC Nadia Yvette Chambers <[email protected]>Signed-off-by Jan Kara <[email protected]>
Nice. I like the new interface.
Quoted 40 lines
--- fs/hugetlbfs/inode.c | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-)fs/hugetlbfs/inode.c +2
-10@@ -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
fs/hugetlbfs/inode.c static void remove_inode_hugepages(struct inode *inode, loff_t lstart, · line 427
Quoted 10 lines
fs/hugetlbfs/inode.c +0
-6-* 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 );
--
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 v2 8/10 fs: Use pagevec_lookup_range() in page_cache_seek_hole_data()
In reply to Jan KaraWe want only pages from given range in page_cache_seek_hole_data(). 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/buffer.c | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-)
fs/buffer.c +3 -13
@@ -3549,11 +3549,10 @@ page_cache_seek_hole_data(struct inode *inode, loff_t offset, loff_t length,pagevec_init (&pvec,0 ); do { - unsigned want, nr_pages, i; + unsigned nr_pages, i; - want = min_t(unsigned, end - index, PAGEVEC_SIZE); - nr_pages = pagevec_lookup(&pvec, inode->i_mapping, &index, - want); + nr_pages = pagevec_lookup_range(&pvec, inode->i_mapping, &index, + end - 1, PAGEVEC_SIZE); if (nr_pages == 0) break;
@@ -3574,10 +3573,6 @@ page_cache_seek_hole_data(struct inode *inode, loff_t offset, loff_t length, lastoff < page_offset(page)) goto check_range; -/* Searching done if the page index is out of range. */ -if (page->index >= end) - goto not_found; -lock_page (page);if (likely (page->mapping == inode->i_mapping) &&page_has_buffers (page)) {
@@ -3590,11 +3585,6 @@ page_cache_seek_hole_data(struct inode *inode, loff_t offset, loff_t length,unlock_page (page); lastoff =page_offset (page) +PAGE_SIZE ; } - -/* Searching done if fewer pages returned than wanted. */ -if (nr_pages < want) -break ; -pagevec_release (&pvec); }while (index < end);
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 v2 9/10 mm: Use find_get_pages_range() in filemap_range_has_page()
In reply to Jan KaraWe want only pages from given range in filemap_range_has_page(), furthermore we want at most a single page. So use find_get_pages_range() instead of pagevec_lookup() and remove unnecessary code.
--- mm/filemap.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-)
mm/filemap.c +4 -7
@@ -402,8 +402,7 @@ bool filemap_range_has_page(struct address_space *mapping, {pgoff_t index = start_byte >>PAGE_SHIFT ;pgoff_t end = end_byte >>PAGE_SHIFT ; -struct pagevec pvec; -bool ret; +struct page *page;if (end_byte < start_byte)return false;
@@ -411,12 +410,10 @@ bool filemap_range_has_page(struct address_space *mapping,if (mapping->nrpages ==0 )return false; -pagevec_init (&pvec,0 ); -if (!pagevec_lookup (&pvec, mapping, &index,1 )) +if (!find_get_pages_range (mapping, &index, end,1 , &page))return false; - ret = (pvec.pages[0 ]->index <= end); -pagevec_release (&pvec); -return ret; +put_page (page); +return true; }EXPORT_SYMBOL (filemap_range_has_page);
Signature · 7 lines
2.12.3 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Jan Kara
maintainerPATCH v2 10/10 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 | 5 ++--- 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 +- include/linux/pagevec.h | 7 +++---- mm/swap.c | 5 ++--- 8 files changed, 13 insertions(+), 18 deletions(-)
fs/buffer.c +2 -3
@@ -1633,8 +1633,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];
@@ -3552,7 +3551,7 @@ page_cache_seek_hole_data(struct inode *inode, loff_t offset, loff_t length,unsigned nr_pages, i; nr_pages =pagevec_lookup_range (&pvec, inode->i_mapping, &index, - end -1 ,PAGEVEC_SIZE ); + end -1 );if (nr_pages ==0 )break ;
fs/ext4/file.c +1 -1
@@ -498,7 +498,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
@@ -1676,8 +1676,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++) {
@@ -2304,7 +2303,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 ;
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
@@ -967,10 +967,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 · 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>