Commit 6e4af69a authored by David Howells's avatar David Howells Committed by Linus Torvalds

mm/readahead: make ondemand_readahead take a readahead_control

Make ondemand_readahead() take a readahead_control struct in preparation
for making do_sync_mmap_readahead() pass down an RAC struct.
Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
Signed-off-by: default avatarMatthew Wilcox (Oracle) <willy@infradead.org>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Cc: Eric Biggers <ebiggers@google.com>
Link: https://lkml.kernel.org/r/20200903140844.14194-6-willy@infradead.orgSigned-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 8238287e
...@@ -431,15 +431,14 @@ static int try_context_readahead(struct address_space *mapping, ...@@ -431,15 +431,14 @@ static int try_context_readahead(struct address_space *mapping,
/* /*
* A minimal readahead algorithm for trivial sequential/random reads. * A minimal readahead algorithm for trivial sequential/random reads.
*/ */
static void ondemand_readahead(struct address_space *mapping, static void ondemand_readahead(struct readahead_control *ractl,
struct file_ra_state *ra, struct file *file, struct file_ra_state *ra, bool hit_readahead_marker,
bool hit_readahead_marker, pgoff_t index,
unsigned long req_size) unsigned long req_size)
{ {
DEFINE_READAHEAD(ractl, file, mapping, index); struct backing_dev_info *bdi = inode_to_bdi(ractl->mapping->host);
struct backing_dev_info *bdi = inode_to_bdi(mapping->host);
unsigned long max_pages = ra->ra_pages; unsigned long max_pages = ra->ra_pages;
unsigned long add_pages; unsigned long add_pages;
unsigned long index = readahead_index(ractl);
pgoff_t prev_index; pgoff_t prev_index;
/* /*
...@@ -477,7 +476,8 @@ static void ondemand_readahead(struct address_space *mapping, ...@@ -477,7 +476,8 @@ static void ondemand_readahead(struct address_space *mapping,
pgoff_t start; pgoff_t start;
rcu_read_lock(); rcu_read_lock();
start = page_cache_next_miss(mapping, index + 1, max_pages); start = page_cache_next_miss(ractl->mapping, index + 1,
max_pages);
rcu_read_unlock(); rcu_read_unlock();
if (!start || start - index > max_pages) if (!start || start - index > max_pages)
...@@ -510,14 +510,15 @@ static void ondemand_readahead(struct address_space *mapping, ...@@ -510,14 +510,15 @@ static void ondemand_readahead(struct address_space *mapping,
* Query the page cache and look for the traces(cached history pages) * Query the page cache and look for the traces(cached history pages)
* that a sequential stream would leave behind. * that a sequential stream would leave behind.
*/ */
if (try_context_readahead(mapping, ra, index, req_size, max_pages)) if (try_context_readahead(ractl->mapping, ra, index, req_size,
max_pages))
goto readit; goto readit;
/* /*
* standalone, small random read * standalone, small random read
* Read as is, and do not pollute the readahead state. * Read as is, and do not pollute the readahead state.
*/ */
do_page_cache_ra(&ractl, req_size, 0); do_page_cache_ra(ractl, req_size, 0);
return; return;
initial_readahead: initial_readahead:
...@@ -543,8 +544,8 @@ static void ondemand_readahead(struct address_space *mapping, ...@@ -543,8 +544,8 @@ static void ondemand_readahead(struct address_space *mapping,
} }
} }
ractl._index = ra->start; ractl->_index = ra->start;
do_page_cache_ra(&ractl, ra->size, ra->async_size); do_page_cache_ra(ractl, ra->size, ra->async_size);
} }
/** /**
...@@ -564,6 +565,8 @@ void page_cache_sync_readahead(struct address_space *mapping, ...@@ -564,6 +565,8 @@ void page_cache_sync_readahead(struct address_space *mapping,
struct file_ra_state *ra, struct file *filp, struct file_ra_state *ra, struct file *filp,
pgoff_t index, unsigned long req_count) pgoff_t index, unsigned long req_count)
{ {
DEFINE_READAHEAD(ractl, filp, mapping, index);
/* no read-ahead */ /* no read-ahead */
if (!ra->ra_pages) if (!ra->ra_pages)
return; return;
...@@ -578,7 +581,7 @@ void page_cache_sync_readahead(struct address_space *mapping, ...@@ -578,7 +581,7 @@ void page_cache_sync_readahead(struct address_space *mapping,
} }
/* do read-ahead */ /* do read-ahead */
ondemand_readahead(mapping, ra, filp, false, index, req_count); ondemand_readahead(&ractl, ra, false, req_count);
} }
EXPORT_SYMBOL_GPL(page_cache_sync_readahead); EXPORT_SYMBOL_GPL(page_cache_sync_readahead);
...@@ -602,6 +605,8 @@ page_cache_async_readahead(struct address_space *mapping, ...@@ -602,6 +605,8 @@ page_cache_async_readahead(struct address_space *mapping,
struct page *page, pgoff_t index, struct page *page, pgoff_t index,
unsigned long req_count) unsigned long req_count)
{ {
DEFINE_READAHEAD(ractl, filp, mapping, index);
/* no read-ahead */ /* no read-ahead */
if (!ra->ra_pages) if (!ra->ra_pages)
return; return;
...@@ -624,7 +629,7 @@ page_cache_async_readahead(struct address_space *mapping, ...@@ -624,7 +629,7 @@ page_cache_async_readahead(struct address_space *mapping,
return; return;
/* do read-ahead */ /* do read-ahead */
ondemand_readahead(mapping, ra, filp, true, index, req_count); ondemand_readahead(&ractl, ra, true, req_count);
} }
EXPORT_SYMBOL_GPL(page_cache_async_readahead); EXPORT_SYMBOL_GPL(page_cache_async_readahead);
......
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