Commit 76a0294e authored by Matthew Wilcox (Oracle)'s avatar Matthew Wilcox (Oracle) Committed by Linus Torvalds

fuse: convert from readpages to readahead

Implement the new readahead operation in fuse by using __readahead_batch()
to fill the array of pages in fuse_args_pages directly.  This lets us
inline fuse_readpages_fill() into fuse_readahead().

[willy@infradead.org: build fix]
  Link: http://lkml.kernel.org/r/20200415025938.GB5820@bombadil.infradead.orgSigned-off-by: default avatarMatthew Wilcox (Oracle) <willy@infradead.org>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Reviewed-by: default avatarDave Chinner <dchinner@redhat.com>
Reviewed-by: default avatarWilliam Kucharski <william.kucharski@oracle.com>
Acked-by: default avatarMiklos Szeredi <mszeredi@redhat.com>
Cc: Chao Yu <yuchao0@huawei.com>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Cong Wang <xiyou.wangcong@gmail.com>
Cc: Darrick J. Wong <darrick.wong@oracle.com>
Cc: Eric Biggers <ebiggers@google.com>
Cc: Gao Xiang <gaoxiang25@huawei.com>
Cc: Jaegeuk Kim <jaegeuk@kernel.org>
Cc: John Hubbard <jhubbard@nvidia.com>
Cc: Joseph Qi <joseph.qi@linux.alibaba.com>
Cc: Junxiao Bi <junxiao.bi@oracle.com>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Zi Yan <ziy@nvidia.com>
Cc: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Link: http://lkml.kernel.org/r/20200414150233.24495-25-willy@infradead.orgSigned-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent e20a7693
...@@ -915,84 +915,40 @@ static void fuse_send_readpages(struct fuse_io_args *ia, struct file *file) ...@@ -915,84 +915,40 @@ static void fuse_send_readpages(struct fuse_io_args *ia, struct file *file)
fuse_readpages_end(fc, &ap->args, err); fuse_readpages_end(fc, &ap->args, err);
} }
struct fuse_fill_data { static void fuse_readahead(struct readahead_control *rac)
struct fuse_io_args *ia;
struct file *file;
struct inode *inode;
unsigned int nr_pages;
unsigned int max_pages;
};
static int fuse_readpages_fill(void *_data, struct page *page)
{ {
struct fuse_fill_data *data = _data; struct inode *inode = rac->mapping->host;
struct fuse_io_args *ia = data->ia;
struct fuse_args_pages *ap = &ia->ap;
struct inode *inode = data->inode;
struct fuse_conn *fc = get_fuse_conn(inode); struct fuse_conn *fc = get_fuse_conn(inode);
unsigned int i, max_pages, nr_pages = 0;
fuse_wait_on_page_writeback(inode, page->index);
if (ap->num_pages &&
(ap->num_pages == fc->max_pages ||
(ap->num_pages + 1) * PAGE_SIZE > fc->max_read ||
ap->pages[ap->num_pages - 1]->index + 1 != page->index)) {
data->max_pages = min_t(unsigned int, data->nr_pages,
fc->max_pages);
fuse_send_readpages(ia, data->file);
data->ia = ia = fuse_io_alloc(NULL, data->max_pages);
if (!ia) {
unlock_page(page);
return -ENOMEM;
}
ap = &ia->ap;
}
if (WARN_ON(ap->num_pages >= data->max_pages)) {
unlock_page(page);
fuse_io_free(ia);
return -EIO;
}
get_page(page);
ap->pages[ap->num_pages] = page;
ap->descs[ap->num_pages].length = PAGE_SIZE;
ap->num_pages++;
data->nr_pages--;
return 0;
}
static int fuse_readpages(struct file *file, struct address_space *mapping,
struct list_head *pages, unsigned nr_pages)
{
struct inode *inode = mapping->host;
struct fuse_conn *fc = get_fuse_conn(inode);
struct fuse_fill_data data;
int err;
err = -EIO;
if (is_bad_inode(inode)) if (is_bad_inode(inode))
goto out; return;
data.file = file; max_pages = min_t(unsigned int, fc->max_pages,
data.inode = inode; fc->max_read / PAGE_SIZE);
data.nr_pages = nr_pages;
data.max_pages = min_t(unsigned int, nr_pages, fc->max_pages);
;
data.ia = fuse_io_alloc(NULL, data.max_pages);
err = -ENOMEM;
if (!data.ia)
goto out;
err = read_cache_pages(mapping, pages, fuse_readpages_fill, &data); for (;;) {
if (!err) { struct fuse_io_args *ia;
if (data.ia->ap.num_pages) struct fuse_args_pages *ap;
fuse_send_readpages(data.ia, file);
else nr_pages = readahead_count(rac) - nr_pages;
fuse_io_free(data.ia); if (nr_pages > max_pages)
nr_pages = max_pages;
if (nr_pages == 0)
break;
ia = fuse_io_alloc(NULL, nr_pages);
if (!ia)
return;
ap = &ia->ap;
nr_pages = __readahead_batch(rac, ap->pages, nr_pages);
for (i = 0; i < nr_pages; i++) {
fuse_wait_on_page_writeback(inode,
readahead_index(rac) + i);
ap->descs[i].length = PAGE_SIZE;
}
ap->num_pages = nr_pages;
fuse_send_readpages(ia, rac->file);
} }
out:
return err;
} }
static ssize_t fuse_cache_read_iter(struct kiocb *iocb, struct iov_iter *to) static ssize_t fuse_cache_read_iter(struct kiocb *iocb, struct iov_iter *to)
...@@ -3373,10 +3329,10 @@ static const struct file_operations fuse_file_operations = { ...@@ -3373,10 +3329,10 @@ static const struct file_operations fuse_file_operations = {
static const struct address_space_operations fuse_file_aops = { static const struct address_space_operations fuse_file_aops = {
.readpage = fuse_readpage, .readpage = fuse_readpage,
.readahead = fuse_readahead,
.writepage = fuse_writepage, .writepage = fuse_writepage,
.writepages = fuse_writepages, .writepages = fuse_writepages,
.launder_page = fuse_launder_page, .launder_page = fuse_launder_page,
.readpages = fuse_readpages,
.set_page_dirty = __set_page_dirty_nobuffers, .set_page_dirty = __set_page_dirty_nobuffers,
.bmap = fuse_bmap, .bmap = fuse_bmap,
.direct_IO = fuse_direct_IO, .direct_IO = fuse_direct_IO,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment