readahead: split ondemand readahead interface into two functions
Split ondemand readahead interface into two functions. I think this makes it a little clearer for non-readahead experts (like Rusty). Internally they both call ondemand_readahead(), but the page argument is changed to an obvious boolean flag. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> Signed-off-by: Fengguang Wu <wfg@mail.ustc.edu.cn> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
parent
fe3cba17c4
commit
cf914a7d65
|
@ -139,10 +139,10 @@ static int ext3_readdir(struct file * filp,
|
||||||
pgoff_t index = map_bh.b_blocknr >>
|
pgoff_t index = map_bh.b_blocknr >>
|
||||||
(PAGE_CACHE_SHIFT - inode->i_blkbits);
|
(PAGE_CACHE_SHIFT - inode->i_blkbits);
|
||||||
if (!ra_has_index(&filp->f_ra, index))
|
if (!ra_has_index(&filp->f_ra, index))
|
||||||
page_cache_readahead_ondemand(
|
page_cache_sync_readahead(
|
||||||
sb->s_bdev->bd_inode->i_mapping,
|
sb->s_bdev->bd_inode->i_mapping,
|
||||||
&filp->f_ra, filp,
|
&filp->f_ra, filp,
|
||||||
NULL, index, 1);
|
index, 1);
|
||||||
filp->f_ra.prev_index = index;
|
filp->f_ra.prev_index = index;
|
||||||
bh = ext3_bread(NULL, inode, blk, 0, &err);
|
bh = ext3_bread(NULL, inode, blk, 0, &err);
|
||||||
}
|
}
|
||||||
|
|
|
@ -138,10 +138,10 @@ static int ext4_readdir(struct file * filp,
|
||||||
pgoff_t index = map_bh.b_blocknr >>
|
pgoff_t index = map_bh.b_blocknr >>
|
||||||
(PAGE_CACHE_SHIFT - inode->i_blkbits);
|
(PAGE_CACHE_SHIFT - inode->i_blkbits);
|
||||||
if (!ra_has_index(&filp->f_ra, index))
|
if (!ra_has_index(&filp->f_ra, index))
|
||||||
page_cache_readahead_ondemand(
|
page_cache_sync_readahead(
|
||||||
sb->s_bdev->bd_inode->i_mapping,
|
sb->s_bdev->bd_inode->i_mapping,
|
||||||
&filp->f_ra, filp,
|
&filp->f_ra, filp,
|
||||||
NULL, index, 1);
|
index, 1);
|
||||||
filp->f_ra.prev_index = index;
|
filp->f_ra.prev_index = index;
|
||||||
bh = ext4_bread(NULL, inode, blk, 0, &err);
|
bh = ext4_bread(NULL, inode, blk, 0, &err);
|
||||||
}
|
}
|
||||||
|
|
|
@ -295,8 +295,8 @@ __generic_file_splice_read(struct file *in, loff_t *ppos,
|
||||||
* readahead/allocate the rest and fill in the holes.
|
* readahead/allocate the rest and fill in the holes.
|
||||||
*/
|
*/
|
||||||
if (spd.nr_pages < nr_pages)
|
if (spd.nr_pages < nr_pages)
|
||||||
page_cache_readahead_ondemand(mapping, &in->f_ra, in,
|
page_cache_sync_readahead(mapping, &in->f_ra, in,
|
||||||
NULL, index, req_pages - spd.nr_pages);
|
index, req_pages - spd.nr_pages);
|
||||||
|
|
||||||
error = 0;
|
error = 0;
|
||||||
while (spd.nr_pages < nr_pages) {
|
while (spd.nr_pages < nr_pages) {
|
||||||
|
@ -352,7 +352,7 @@ __generic_file_splice_read(struct file *in, loff_t *ppos,
|
||||||
page = pages[page_nr];
|
page = pages[page_nr];
|
||||||
|
|
||||||
if (PageReadahead(page))
|
if (PageReadahead(page))
|
||||||
page_cache_readahead_ondemand(mapping, &in->f_ra, in,
|
page_cache_async_readahead(mapping, &in->f_ra, in,
|
||||||
page, index, req_pages - page_nr);
|
page, index, req_pages - page_nr);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -1138,12 +1138,20 @@ int do_page_cache_readahead(struct address_space *mapping, struct file *filp,
|
||||||
pgoff_t offset, unsigned long nr_to_read);
|
pgoff_t offset, unsigned long nr_to_read);
|
||||||
int force_page_cache_readahead(struct address_space *mapping, struct file *filp,
|
int force_page_cache_readahead(struct address_space *mapping, struct file *filp,
|
||||||
pgoff_t offset, unsigned long nr_to_read);
|
pgoff_t offset, unsigned long nr_to_read);
|
||||||
unsigned long page_cache_readahead_ondemand(struct address_space *mapping,
|
|
||||||
struct file_ra_state *ra,
|
void page_cache_sync_readahead(struct address_space *mapping,
|
||||||
struct file *filp,
|
struct file_ra_state *ra,
|
||||||
struct page *page,
|
struct file *filp,
|
||||||
pgoff_t offset,
|
pgoff_t offset,
|
||||||
unsigned long size);
|
unsigned long size);
|
||||||
|
|
||||||
|
void page_cache_async_readahead(struct address_space *mapping,
|
||||||
|
struct file_ra_state *ra,
|
||||||
|
struct file *filp,
|
||||||
|
struct page *pg,
|
||||||
|
pgoff_t offset,
|
||||||
|
unsigned long size);
|
||||||
|
|
||||||
unsigned long max_sane_readahead(unsigned long nr);
|
unsigned long max_sane_readahead(unsigned long nr);
|
||||||
|
|
||||||
/* Do stack extension */
|
/* Do stack extension */
|
||||||
|
|
10
mm/filemap.c
10
mm/filemap.c
|
@ -894,15 +894,15 @@ void do_generic_mapping_read(struct address_space *mapping,
|
||||||
find_page:
|
find_page:
|
||||||
page = find_get_page(mapping, index);
|
page = find_get_page(mapping, index);
|
||||||
if (!page) {
|
if (!page) {
|
||||||
page_cache_readahead_ondemand(mapping,
|
page_cache_sync_readahead(mapping,
|
||||||
&ra, filp, page,
|
&ra, filp,
|
||||||
index, last_index - index);
|
index, last_index - index);
|
||||||
page = find_get_page(mapping, index);
|
page = find_get_page(mapping, index);
|
||||||
if (unlikely(page == NULL))
|
if (unlikely(page == NULL))
|
||||||
goto no_cached_page;
|
goto no_cached_page;
|
||||||
}
|
}
|
||||||
if (PageReadahead(page)) {
|
if (PageReadahead(page)) {
|
||||||
page_cache_readahead_ondemand(mapping,
|
page_cache_async_readahead(mapping,
|
||||||
&ra, filp, page,
|
&ra, filp, page,
|
||||||
index, last_index - index);
|
index, last_index - index);
|
||||||
}
|
}
|
||||||
|
@ -1348,14 +1348,14 @@ retry_find:
|
||||||
*/
|
*/
|
||||||
if (VM_SequentialReadHint(vma)) {
|
if (VM_SequentialReadHint(vma)) {
|
||||||
if (!page) {
|
if (!page) {
|
||||||
page_cache_readahead_ondemand(mapping, ra, file, page,
|
page_cache_sync_readahead(mapping, ra, file,
|
||||||
vmf->pgoff, 1);
|
vmf->pgoff, 1);
|
||||||
page = find_lock_page(mapping, vmf->pgoff);
|
page = find_lock_page(mapping, vmf->pgoff);
|
||||||
if (!page)
|
if (!page)
|
||||||
goto no_cached_page;
|
goto no_cached_page;
|
||||||
}
|
}
|
||||||
if (PageReadahead(page)) {
|
if (PageReadahead(page)) {
|
||||||
page_cache_readahead_ondemand(mapping, ra, file, page,
|
page_cache_async_readahead(mapping, ra, file, page,
|
||||||
vmf->pgoff, 1);
|
vmf->pgoff, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -359,7 +359,7 @@ static unsigned long get_next_ra_size(struct file_ra_state *ra,
|
||||||
static unsigned long
|
static unsigned long
|
||||||
ondemand_readahead(struct address_space *mapping,
|
ondemand_readahead(struct address_space *mapping,
|
||||||
struct file_ra_state *ra, struct file *filp,
|
struct file_ra_state *ra, struct file *filp,
|
||||||
struct page *page, pgoff_t offset,
|
bool hit_readahead_marker, pgoff_t offset,
|
||||||
unsigned long req_size)
|
unsigned long req_size)
|
||||||
{
|
{
|
||||||
unsigned long max; /* max readahead pages */
|
unsigned long max; /* max readahead pages */
|
||||||
|
@ -387,7 +387,7 @@ ondemand_readahead(struct address_space *mapping,
|
||||||
* Standalone, small read.
|
* Standalone, small read.
|
||||||
* Read as is, and do not pollute the readahead state.
|
* Read as is, and do not pollute the readahead state.
|
||||||
*/
|
*/
|
||||||
if (!page && !sequential) {
|
if (!hit_readahead_marker && !sequential) {
|
||||||
return __do_page_cache_readahead(mapping, filp,
|
return __do_page_cache_readahead(mapping, filp,
|
||||||
offset, req_size, 0);
|
offset, req_size, 0);
|
||||||
}
|
}
|
||||||
|
@ -408,7 +408,7 @@ ondemand_readahead(struct address_space *mapping,
|
||||||
* E.g. interleaved reads.
|
* E.g. interleaved reads.
|
||||||
* Not knowing its readahead pos/size, bet on the minimal possible one.
|
* Not knowing its readahead pos/size, bet on the minimal possible one.
|
||||||
*/
|
*/
|
||||||
if (page) {
|
if (hit_readahead_marker) {
|
||||||
ra_index++;
|
ra_index++;
|
||||||
ra_size = min(4 * ra_size, max);
|
ra_size = min(4 * ra_size, max);
|
||||||
}
|
}
|
||||||
|
@ -421,50 +421,71 @@ fill_ra:
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* page_cache_readahead_ondemand - generic file readahead
|
* page_cache_sync_readahead - generic file readahead
|
||||||
* @mapping: address_space which holds the pagecache and I/O vectors
|
* @mapping: address_space which holds the pagecache and I/O vectors
|
||||||
* @ra: file_ra_state which holds the readahead state
|
* @ra: file_ra_state which holds the readahead state
|
||||||
* @filp: passed on to ->readpage() and ->readpages()
|
* @filp: passed on to ->readpage() and ->readpages()
|
||||||
* @page: the page at @offset, or NULL if non-present
|
* @offset: start offset into @mapping, in pagecache page-sized units
|
||||||
* @offset: start offset into @mapping, in PAGE_CACHE_SIZE units
|
|
||||||
* @req_size: hint: total size of the read which the caller is performing in
|
* @req_size: hint: total size of the read which the caller is performing in
|
||||||
* PAGE_CACHE_SIZE units
|
* pagecache pages
|
||||||
*
|
*
|
||||||
* page_cache_readahead_ondemand() is the entry point of readahead logic.
|
* page_cache_sync_readahead() should be called when a cache miss happened:
|
||||||
* This function should be called when it is time to perform readahead:
|
* it will submit the read. The readahead logic may decide to piggyback more
|
||||||
* 1) @page == NULL
|
* pages onto the read request if access patterns suggest it will improve
|
||||||
* A cache miss happened, time for synchronous readahead.
|
* performance.
|
||||||
* 2) @page != NULL && PageReadahead(@page)
|
|
||||||
* A look-ahead hit occured, time for asynchronous readahead.
|
|
||||||
*/
|
*/
|
||||||
unsigned long
|
void page_cache_sync_readahead(struct address_space *mapping,
|
||||||
page_cache_readahead_ondemand(struct address_space *mapping,
|
struct file_ra_state *ra, struct file *filp,
|
||||||
struct file_ra_state *ra, struct file *filp,
|
pgoff_t offset, unsigned long req_size)
|
||||||
struct page *page, pgoff_t offset,
|
|
||||||
unsigned long req_size)
|
|
||||||
{
|
{
|
||||||
/* no read-ahead */
|
/* no read-ahead */
|
||||||
if (!ra->ra_pages)
|
if (!ra->ra_pages)
|
||||||
return 0;
|
return;
|
||||||
|
|
||||||
if (page) {
|
|
||||||
/*
|
|
||||||
* It can be PG_reclaim.
|
|
||||||
*/
|
|
||||||
if (PageWriteback(page))
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
ClearPageReadahead(page);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Defer asynchronous read-ahead on IO congestion.
|
|
||||||
*/
|
|
||||||
if (bdi_read_congested(mapping->backing_dev_info))
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* do read-ahead */
|
/* do read-ahead */
|
||||||
return ondemand_readahead(mapping, ra, filp, page,
|
ondemand_readahead(mapping, ra, filp, false, offset, req_size);
|
||||||
offset, req_size);
|
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(page_cache_readahead_ondemand);
|
EXPORT_SYMBOL_GPL(page_cache_sync_readahead);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* page_cache_async_readahead - file readahead for marked pages
|
||||||
|
* @mapping: address_space which holds the pagecache and I/O vectors
|
||||||
|
* @ra: file_ra_state which holds the readahead state
|
||||||
|
* @filp: passed on to ->readpage() and ->readpages()
|
||||||
|
* @page: the page at @offset which has the PG_readahead flag set
|
||||||
|
* @offset: start offset into @mapping, in pagecache page-sized units
|
||||||
|
* @req_size: hint: total size of the read which the caller is performing in
|
||||||
|
* pagecache pages
|
||||||
|
*
|
||||||
|
* page_cache_async_ondemand() should be called when a page is used which
|
||||||
|
* has the PG_readahead flag: this is a marker to suggest that the application
|
||||||
|
* has used up enough of the readahead window that we should start pulling in
|
||||||
|
* more pages. */
|
||||||
|
void
|
||||||
|
page_cache_async_readahead(struct address_space *mapping,
|
||||||
|
struct file_ra_state *ra, struct file *filp,
|
||||||
|
struct page *page, pgoff_t offset,
|
||||||
|
unsigned long req_size)
|
||||||
|
{
|
||||||
|
/* no read-ahead */
|
||||||
|
if (!ra->ra_pages)
|
||||||
|
return;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Same bit is used for PG_readahead and PG_reclaim.
|
||||||
|
*/
|
||||||
|
if (PageWriteback(page))
|
||||||
|
return;
|
||||||
|
|
||||||
|
ClearPageReadahead(page);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Defer asynchronous read-ahead on IO congestion.
|
||||||
|
*/
|
||||||
|
if (bdi_read_congested(mapping->backing_dev_info))
|
||||||
|
return;
|
||||||
|
|
||||||
|
/* do read-ahead */
|
||||||
|
ondemand_readahead(mapping, ra, filp, true, offset, req_size);
|
||||||
|
}
|
||||||
|
EXPORT_SYMBOL_GPL(page_cache_async_readahead);
|
||||||
|
|
Loading…
Reference in New Issue