bcachefs: Convert to readahead
PATCH 1/3 bcachefs: Convert to readahead
Use the new readahead method instead of readpages.
Signed-off-by Matthew Wilcox (Oracle) <[email protected]>
--- fs/bcachefs/fs-io.c | 29 +++++++++++------------------ fs/bcachefs/fs-io.h | 3 +-- fs/bcachefs/fs.c | 2 +- 3 files changed, 13 insertions(+), 21 deletions(-)
fs/bcachefs/fs-io.c +11 -18
@@ -663,26 +663,22 @@ struct readpages_iter { };static int readpages_iter_init (struct readpages_iter *iter, -struct address_space *mapping, -struct list_head *pages,unsigned nr_pages) +struct readahead_control *ractl) { +unsigned i, nr_pages =readahead_count (ractl); +memset (iter,0 ,sizeof (*iter)); - iter->mapping = mapping; - iter->offset = list_last_entry(pages, struct page, lru)->index; + iter->mapping = ractl->mapping; + iter->offset =readahead_index (ractl); iter->pages =kmalloc_array (nr_pages,sizeof (struct page *),GFP_NOFS );if (!iter->pages)return -ENOMEM ; -while (!list_empty (pages)) { - struct page *page = list_last_entry(pages, struct page, lru); - -__bch2_page_state_create (page, __GFP_NOFAIL); - - iter->pages[iter->nr_pages++] = page; -list_del (&page->lru); - } +__readahead_batch (ractl, iter->pages, nr_pages); +for (i =0 ; i < nr_pages; i++) +__bch2_page_state_create (iter->pages[i], __GFP_NOFAIL);return 0 ; }
@@ -889,10 +885,9 @@ static void bchfs_read(struct btree_trans *trans, struct btree_iter *iter,bkey_on_stack_exit (&sk, c); } -int bch2_readpages (struct file *file,struct address_space *mapping, -struct list_head *pages,unsigned nr_pages) +void bch2_readahead (struct readahead_control *ractl) { -struct bch_inode_info *inode =to_bch_ei (mapping->host); +struct bch_inode_info *inode =to_bch_ei (ractl->mapping->host);struct bch_fs *c = inode->v.i_sb->s_fs_info;struct bch_io_opts opts =io_opts (c, &inode->ei_inode);struct btree_trans trans;
@@ -901,7 +896,7 @@ int bch2_readpages(struct file *file, struct address_space *mapping,struct readpages_iter readpages_iter;int ret; - ret =readpages_iter_init (&readpages_iter, mapping, pages, nr_pages); + ret =readpages_iter_init (&readpages_iter, ractl);BUG_ON (ret);bch2_trans_init (&trans, c,0 ,0 );
@@ -936,8 +931,6 @@ int bch2_readpages(struct file *file, struct address_space *mapping,bch2_trans_exit (&trans);kfree (readpages_iter.pages); - -return 0 ; } static void __bchfs_readpage(struct bch_fs *c, struct bch_read_bio *rbio,
fs/bcachefs/fs-io.h +1 -2
@@ -19,8 +19,7 @@ int bch2_writepage(struct page *, struct writeback_control *);int bch2_readpage (struct file *,struct page *);int bch2_writepages (struct address_space *,struct writeback_control *); -int bch2_readpages (struct file *,struct address_space *, -struct list_head *,unsigned ); +void bch2_readahead (struct readahead_control *);int bch2_write_begin (struct file *,struct address_space *,loff_t ,unsigned ,unsigned ,struct page **,void **);
fs/bcachefs/fs.c +1 -1
@@ -1064,7 +1064,7 @@ static const struct address_space_operations bch_address_space_operations = { .writepage = bch2_writepage, .readpage = bch2_readpage, .writepages = bch2_writepages, - .readpages = bch2_readpages, + .readahead = bch2_readahead, .set_page_dirty = __set_page_dirty_nobuffers, .write_begin = bch2_write_begin, .write_end = bch2_write_end,
Signature · 1 line
2.28.0
PATCH 2/3 bcachefs: Remove page_state_init_for_read
This is dead code; delete the function.
Signed-off-by Matthew Wilcox (Oracle) <[email protected]>
--- fs/bcachefs/fs-io.c | 6 ------ 1 file changed, 6 deletions(-)
fs/bcachefs/fs-io.c +0 -6
@@ -647,12 +647,6 @@ static void bch2_readpages_end_io(struct bio *bio)bio_put (bio); } -static inline void page_state_init_for_read (struct page *page) -{ -SetPagePrivate (page); - page->private =0 ; -} -struct readpages_iter {struct address_space *mapping;struct page **pages;
Signature · 1 line
2.28.0
PATCH 3/3 bcachefs: Use attach_page_private and detach_page_private
In reply to Matthew Wilcox (Oracle)These recently added helpers simplify the code.
Signed-off-by Matthew Wilcox (Oracle) <[email protected]>
--- fs/bcachefs/fs-io.c | 39 ++++++--------------------------------- 1 file changed, 6 insertions(+), 33 deletions(-)
fs/bcachefs/fs-io.c +6 -33
@@ -265,28 +265,13 @@ static inline struct bch_page_state *bch2_page_state(struct page *page)/* for newly allocated pages: */ static void __bch2_page_state_release (struct page *page) { -struct bch_page_state *s =__bch2_page_state (page); - -if (!s) -return ; - -ClearPagePrivate (page); -set_page_private (page,0 ); -put_page (page); -kfree (s); +kfree (detach_page_private (page)); }static void bch2_page_state_release (struct page *page) { -struct bch_page_state *s =bch2_page_state (page); - -if (!s) -return ; - -ClearPagePrivate (page); -set_page_private (page,0 ); -put_page (page); -kfree (s); +EBUG_ON (!PageLocked (page)); +__bch2_page_state_release (page); }/* for newly allocated pages: */
@@ -300,13 +285,7 @@ static struct bch_page_state *__bch2_page_state_create(struct page *page,return NULL ;spin_lock_init (&s->lock); -/* -* migrate_page_move_mapping() assumes that pages with private data -* have their count elevated by 1. -*/ -get_page (page); -set_page_private (page, (unsigned long ) s); -SetPagePrivate (page); +attach_page_private (page, s);return s; }
@@ -608,14 +587,8 @@ int bch2_migrate_page(struct address_space *mapping, struct page *newpage,if (ret !=MIGRATEPAGE_SUCCESS )return ret; -if (PagePrivate (page)) { -ClearPagePrivate (page); -get_page (newpage); -set_page_private (newpage,page_private (page)); -set_page_private (page,0 ); -put_page (page); -SetPagePrivate (newpage); - } +if (PagePrivate (page)) +attach_page_private (newpage,detach_page_private (page));if (mode !=MIGRATE_SYNC_NO_COPY )migrate_page_copy (newpage, page);
Signature · 1 line
2.28.0