Readahead fixes / improvements
Subsystems (2)
cover Readahead fixes / improvements
From: Raghavendra D Prabhu <[email protected]>
Following are some of the fixes / improvements to the page cache readahead:
first four are minor fixes along the readahead path, the last one is an improvement to use find_get_pages in __do_page_cache_readahead.
Raghavendra D Prabhu (5):
mm/readahead: Check return value of read_pages mm/readahead: Change the condition for SetPageReadahead Remove file_ra_state from arguments of count_history_pages. Move the check for ra_pages after VM_SequentialReadHint() mm/readahead: Use find_get_pages instead of radix_tree_lookup.
mm/filemap.c | 5 +++-- mm/readahead.c | 50 ++++++++++++++++++++++++++++++++++---------------- 2 files changed, 37 insertions(+), 18 deletions(-)
Signature · 7 lines
1.7.12.1 -- 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>
PATCH 1/5 mm/readahead: Check return value of read_pages
From: Raghavendra D Prabhu <[email protected]>
Return value of a_ops->readpage will be propagated to return value of read_pages and __do_page_cache_readahead.
--- mm/readahead.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
mm/readahead.c +7 -5
@@ -113,7 +113,7 @@ static int read_pages(struct address_space *mapping, struct file *filp, {struct blk_plug plug;unsigned page_idx; -int ret; +int ret =0 ;blk_start_plug (&plug);
@@ -129,11 +129,12 @@ static int read_pages(struct address_space *mapping, struct file *filp,list_del (&page->lru);if (!add_to_page_cache_lru (page, mapping, page->index,GFP_KERNEL )) { - mapping->a_ops->readpage (filp, page); + ret = mapping->a_ops->readpage (filp, page); +if (ret <0 ) +break ; }page_cache_release (page); } - ret =0 ; out:blk_finish_plug (&plug);
@@ -160,6 +161,7 @@ __do_page_cache_readahead(struct address_space *mapping, struct file *filp,LIST_HEAD (page_pool);int page_idx;int ret =0 ; +int ret_read =0 ;loff_t isize =i_size_read (inode);if (isize ==0 )
@@ -198,10 +200,10 @@ __do_page_cache_readahead(struct address_space *mapping, struct file *filp,* will then handle the error. */ if (ret) -read_pages (mapping, filp, &page_pool, ret); + ret_read =read_pages (mapping, filp, &page_pool, ret);BUG_ON (!list_empty (&page_pool)); out: -return ret; +return (ret_read <0 ? ret_read : ret); }/*
Signature · 7 lines
1.7.12.1 -- 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>
PATCH 2/5 mm/readahead: Change the condition for SetPageReadahead
In reply to [email protected]From: Raghavendra D Prabhu <[email protected]>
If page lookup from radix_tree_lookup is successful and its index page_idx == nr_to_read - lookahead_size, then SetPageReadahead never gets called, so this fixes that.
--- mm/readahead.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
mm/readahead.c +3 -1
@@ -189,8 +189,10 @@ __do_page_cache_readahead(struct address_space *mapping, struct file *filp,break ; page->index = page_offset;list_add (&page->lru, &page_pool); -if (page_idx == nr_to_read - lookahead_size) +if (page_idx >= nr_to_read - lookahead_size) {SetPageReadahead (page); + lookahead_size =0 ; + } ret++; }
Signature · 7 lines
1.7.12.1 -- 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>
PATCH 3/5 Remove file_ra_state from arguments of count_history_pages.
In reply to [email protected]From: Raghavendra D Prabhu <[email protected]>
count_history_pages doesn't require readahead state to calculate the offset from history.
--- mm/readahead.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
mm/readahead.c +1 -2
@@ -349,7 +349,6 @@ static unsigned long get_next_ra_size(struct file_ra_state *ra,* - thrashing threshold in memory tight systems */ static pgoff_t count_history_pages (struct address_space *mapping, -struct file_ra_state *ra,pgoff_t offset,unsigned long max) {pgoff_t head;
@@ -372,7 +371,7 @@ static int try_context_readahead(struct address_space *mapping, {pgoff_t size; - size =count_history_pages (mapping, ra, offset, max); + size =count_history_pages (mapping, offset, max);/* * no history pages:
Signature · 7 lines
1.7.12.1 -- 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>
PATCH 4/5 Move the check for ra_pages after VM_SequentialReadHint()
In reply to [email protected]From: Raghavendra D Prabhu <[email protected]>
page_cache_sync_readahead checks for ra->ra_pages again, so moving the check after VM_SequentialReadHint.
--- mm/filemap.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
mm/filemap.c +3 -2
@@ -1523,8 +1523,6 @@ static void do_sync_mmap_readahead(struct vm_area_struct *vma,/* If we don't want any read-ahead, don't bother */ if (VM_RandomReadHint (vma))return ; -if (!ra->ra_pages) -return ;if (VM_SequentialReadHint (vma)) { page_cache_sync_readahead(mapping, ra, file, offset,
@@ -1532,6 +1530,9 @@ static void do_sync_mmap_readahead(struct vm_area_struct *vma,return ; } +if (!ra->ra_pages) +return ; +/* Avoid banging the cache line if not needed */ if (ra->mmap_miss <MMAP_LOTSAMISS *10 ) ra->mmap_miss++;
Signature · 7 lines
1.7.12.1 -- 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>
PATCH 5/5 mm/readahead: Use find_get_pages instead of radix_tree_lookup.
In reply to [email protected]From: Raghavendra D Prabhu <[email protected]>
Instead of running radix_tree_lookup in a loop and lock/unlocking in the process, find_get_pages is called once, which returns a page_list, some of which are not NULL and are in core.
Also, since find_get_pages returns number of pages, if all pages are already cached, it can return early.
This will be mostly helpful when a higher proportion of nr_to_read pages are already in the cache, which will mean less locking for page cache hits.
--- mm/readahead.c | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-)
mm/readahead.c +23 -8
@@ -157,35 +157,42 @@ __do_page_cache_readahead(struct address_space *mapping, struct file *filp, {struct inode *inode = mapping->host;struct page *page; +struct page **page_list =NULL ;unsigned long end_index;/* The last page we want to read */ LIST_HEAD (page_pool);int page_idx;int ret =0 ;int ret_read =0 ; +unsigned long num; +pgoff_t page_offset;loff_t isize =i_size_read (inode);if (isize ==0 ) goto out; + page_list =kzalloc (nr_to_read *sizeof (struct page *),GFP_KERNEL ); +if (!page_list) + goto out; + end_index = ((isize -1 ) >>PAGE_CACHE_SHIFT ); + num =find_get_pages (mapping, offset, nr_to_read, page_list);/* * Preallocate as many pages as we will need. */ for (page_idx =0 ; page_idx < nr_to_read; page_idx++) { -pgoff_t page_offset = offset + page_idx; +if (page_list[page_idx]) { +page_cache_release (page_list[page_idx]); +continue ; + } + + page_offset = offset + page_idx;if (page_offset > end_index)break ; -rcu_read_lock (); - page =radix_tree_lookup (&mapping->page_tree, page_offset); -rcu_read_unlock (); -if (page) -continue ; - page =page_cache_alloc_readahead (mapping); -if (!page) +if (unlikely (!page))break ; page->index = page_offset;list_add (&page->lru, &page_pool);
@@ -194,6 +201,13 @@ __do_page_cache_readahead(struct address_space *mapping, struct file *filp, lookahead_size =0 ; } ret++; + +/* +* Since num pages are already returned, bail out after +* nr_to_read - num pages are allocated and added. +*/ +if (ret == nr_to_read - num) +break ; }/*
@@ -205,6 +219,7 @@ __do_page_cache_readahead(struct address_space *mapping, struct file *filp, ret_read =read_pages (mapping, filp, &page_pool, ret);BUG_ON (!list_empty (&page_pool)); out: +kfree (page_list);return (ret_read <0 ? ret_read : ret); }
Signature · 7 lines
1.7.12.1 -- 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 3/5] Remove file_ra_state from arguments of count_history_pages.
In reply to [email protected]Quoted 5 lines · On Sat, Sep 22, 2012 at 04:03:12PM +0530, [email protected] wrote:
From: Raghavendra D Prabhu <[email protected]>
count_history_pagesdoesn't require readahead state to calculate the offset from history.Signed-off-by Raghavendra D Prabhu <[email protected]>
--
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 4/5] Move the check for ra_pages after VM_SequentialReadHint()
In reply to [email protected]Quoted 4 lines · On Sat, Sep 22, 2012 at 04:03:13PM +0530, [email protected] wrote:
From: Raghavendra D Prabhu <[email protected]>
page_cache_sync_readaheadchecks forra->ra_pagesagain, so moving the check afterVM_SequentialReadHint.
Well it depends on what case you are optimizing for. I suspect there are much more tmpfs users than VM_SequentialReadHint users. So this change is actually not desirable wrt the more widely used cases.
Thanks,
Fengguang
Quoted 36 lines
Signed-off-by Raghavendra D Prabhu <[email protected]>--- mm/filemap.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)mm/filemap.c +3
-2@@ -1523,8 +1523,6 @@ static void do_sync_mmap_readahead(struct vm_area_struct *vma,/* If we don't want any read-ahead, don't bother */ if (VM_RandomReadHint (vma))return ; -if (!ra->ra_pages) -return ;if (VM_SequentialReadHint (vma)) { page_cache_sync_readahead(mapping, ra, file, offset,@@ -1532,6 +1530,9 @@ static void do_sync_mmap_readahead(struct vm_area_struct *vma,return ; } +if (!ra->ra_pages) +return ; +/* Avoid banging the cache line if not needed */ if (ra->mmap_miss <MMAP_LOTSAMISS *10 ) ra->mmap_miss++;Signature · 7 lines
1.7.12.1 -- 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>
--
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 1/5] mm/readahead: Check return value of read_pages
In reply to [email protected]Quoted 4 lines · On Sat, Sep 22, 2012 at 04:03:10PM +0530, [email protected] wrote:
From: Raghavendra D Prabhu <[email protected]>
Return value of
a_ops->readpagewill be propagated to return value ofread_pagesand__do_page_cache_readahead.
That does not explain the intention and benefit of this patch..
Thanks,
Fengguang
Quoted 56 lines
Signed-off-by Raghavendra D Prabhu <[email protected]>--- mm/readahead.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)mm/readahead.c +7
-5@@ -113,7 +113,7 @@ static int read_pages(struct address_space *mapping, struct file *filp, {struct blk_plug plug;unsigned page_idx; -int ret; +int ret =0 ;blk_start_plug (&plug);@@ -129,11 +129,12 @@ static int read_pages(struct address_space *mapping, struct file *filp,list_del (&page->lru);if (!add_to_page_cache_lru (page, mapping, page->index,GFP_KERNEL )) { - mapping->a_ops->readpage (filp, page); + ret = mapping->a_ops->readpage (filp, page); +if (ret <0 ) +break ; }page_cache_release (page); } - ret =0 ; out:blk_finish_plug (&plug);@@ -160,6 +161,7 @@ __do_page_cache_readahead(struct address_space *mapping, struct file *filp,LIST_HEAD (page_pool);int page_idx;int ret =0 ; +int ret_read =0 ;loff_t isize =i_size_read (inode);if (isize ==0 )@@ -198,10 +200,10 @@ __do_page_cache_readahead(struct address_space *mapping, struct file *filp,* will then handle the error. */ if (ret) -read_pages (mapping, filp, &page_pool, ret); + ret_read =read_pages (mapping, filp, &page_pool, ret);BUG_ON (!list_empty (&page_pool)); out: -return ret; +return (ret_read <0 ? ret_read : ret); }/* Signature · 1 line
1.7.12.1
--
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 2/5] mm/readahead: Change the condition for SetPageReadahead
In reply to [email protected]Quoted 5 lines · On Sat, Sep 22, 2012 at 04:03:11PM +0530, [email protected] wrote:
From: Raghavendra D Prabhu <[email protected]>
If page lookup from
radix_tree_lookupis successful and its indexpage_idx==nr_to_read-lookahead_size, then SetPageReadahead never gets called, so this fixes that.
NAK. Sorry. It's actually an intentional behavior, so that for the common cases of many cached files that are accessed frequently, no PG_readahead will be set at all to pointlessly trap into the readahead routines once and again.
Perhaps we need a patch for commenting that case. :)
Thanks,
Fengguang
Quoted 23 lines
Signed-off-by Raghavendra D Prabhu <[email protected]>--- mm/readahead.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)mm/readahead.c +3
-1@@ -189,8 +189,10 @@ __do_page_cache_readahead(struct address_space *mapping, struct file *filp,break ; page->index = page_offset;list_add (&page->lru, &page_pool); -if (page_idx == nr_to_read - lookahead_size) +if (page_idx >= nr_to_read - lookahead_size) {SetPageReadahead (page); + lookahead_size =0 ; + } ret++; }Signature · 1 line
1.7.12.1
--
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 5/5] mm/readahead: Use find_get_pages instead of radix_tree_lookup.
In reply to [email protected]Quoted 11 lines · On Sat, Sep 22, 2012 at 04:03:14PM +0530, [email protected] wrote:
From: Raghavendra D Prabhu <[email protected]>
Instead of running
radix_tree_lookupin a loop and lock/unlocking in the process,find_get_pagesis called once, which returns apage_list, some of which are not NULL and are in core.Also, since
find_get_pagesreturns number of pages, if all pages are already cached, it can return early.This will be mostly helpful when a higher proportion of
nr_to_readpages are already in the cache, which will mean less locking for page cache hits.
Do you mean the rcu_read_lock()? But it's a no-op for most archs. So the benefit of this patch is questionable. Will need real performance numbers to support it.
Quoted 19 lines
Signed-off-by Raghavendra D Prabhu <[email protected]>--- mm/readahead.c | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-)mm/readahead.c +1
-0@@ -157,35 +157,42 @@ __do_page_cache_readahead(struct address_space *mapping, struct file *filp, {struct inode *inode = mapping->host;struct page *page; +struct page **page_list =NULL ;unsigned long end_index;/* The last page we want to read */ LIST_HEAD (page_pool);int page_idx;int ret =0 ;int ret_read =0 ;
mm/readahead.c __do_page_cache_readahead(struct address_space *mapping, struct file *filp, · line 175
Quoted 10 lines
mm/readahead.c +5
-0+unsigned long num; +pgoff_t page_offset;loff_t isize =i_size_read (inode);if (isize ==0 ) goto out; + page_list =kzalloc (nr_to_read *sizeof (struct page *),GFP_KERNEL ); +if (!page_list) + goto out;
That cost one more memory allocation and added code to maintain the page list. The original code also don't have the cost of grabbing the page count, which eliminate the trouble of page release.
mm/readahead.c __do_page_cache_readahead(struct address_space *mapping, struct file *filp, · line 178
Quoted 2 lines
mm/readahead.c +1
-0end_index = ((isize -1 ) >>PAGE_CACHE_SHIFT ); + num =find_get_pages (mapping, offset, nr_to_read, page_list);
Assume we want to readahead pages for indexes [0, 100] and the cached pages are in [1000, 1100]. find_get_pages() will return the latter. Which is probably not the your expected results.
Quoted 15 lines
mm/readahead.c +6
-1/* * Preallocate as many pages as we will need. */ for (page_idx =0 ; page_idx < nr_to_read; page_idx++) { -pgoff_t page_offset = offset + page_idx; +if (page_list[page_idx]) { +page_cache_release (page_list[page_idx]); +continue ; + } + + page_offset = offset + page_idx;if (page_offset > end_index)break ;
mm/readahead.c __do_page_cache_readahead(struct address_space *mapping, struct file *filp, · line 196
Quoted 10 lines
mm/readahead.c +1
-7-rcu_read_lock (); - page =radix_tree_lookup (&mapping->page_tree, page_offset); -rcu_read_unlock (); -if (page) -continue ; - page =page_cache_alloc_readahead (mapping); -if (!page) +if (unlikely (!page))break ;
That break will leave the remaining pages' page_count lifted and lead to memory leak.
mm/readahead.c __do_page_cache_readahead(struct address_space *mapping, struct file *filp, · line 210
Quoted 13 lines
mm/readahead.c +7
-0page->index = page_offset;list_add (&page->lru, &page_pool);@@ -194,6 +201,13 @@ __do_page_cache_readahead(struct address_space *mapping, struct file *filp, lookahead_size =0 ; } ret++; + +/* +* Since num pages are already returned, bail out after +* nr_to_read - num pages are allocated and added. +*/ +if (ret == nr_to_read - num) +break ;
Confused. That break seems unnecessary?
Thanks,
Fengguang
Quoted 19 lines
mm/readahead.c +1
-0}/* @@ -205,6 +219,7 @@ __do_page_cache_readahead(struct address_space *mapping, struct file *filp, ret_read =read_pages (mapping, filp, &page_pool, ret);BUG_ON (!list_empty (&page_pool)); out: +kfree (page_list);return (ret_read <0 ? ret_read : ret); }Signature · 7 lines
1.7.12.1 -- 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>
--
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: Re: [PATCH 1/5] mm/readahead: Check return value of read_pages
In reply to Fengguang WuHi,
Quoted 7 lines · * On Sat, Sep 22, 2012 at 08:43:37PM +0800, Fengguang Wu…
Quoted 4 lines · On Sat, Sep 22, 2012 at 04:03:10PM +0530, [email protected] wrote:
From: Raghavendra D Prabhu <[email protected]>
Return value of
a_ops->readpagewill be propagated to return value ofread_pagesand__do_page_cache_readahead.That does not explain the intention and benefit of this patch..
I noticed that force_page_cache_readahead checks return value of __do_page_cache_readahead but the actual error if any is never propagated.
Also, I made a slight change there:
+ int alloc = 1;
blk_start_plug(&plug);
@@ -127,13 +128,18 @@ static int read_pages(struct address_space *mapping, struct file *filp,
for (page_idx = 0; page_idx < nr_pages; page_idx++) {
struct page *page = list_to_page(pages);
list_del(&page->lru);
- if (!add_to_page_cache_lru(page, mapping,
+ if (alloc && !add_to_page_cache_lru(page, mapping,
page->index, GFP_KERNEL)) {
- mapping->a_ops->readpage(filp, page);
+ ret = mapping->a_ops->readpage(filp, page);
+ /* + * If readpage fails, don't proceed with further
+ * readpage
+ * */
+ if (ret < 0)
+ alloc = 0;
Before, this the page_cache_release was not happening for the rest of the pages.
I will send it in separate patch if this is fine.
Quoted 57 lines
Thanks,
FengguangQuoted 53 lines
Signed-off-by Raghavendra D Prabhu <[email protected]>--- mm/readahead.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)mm/readahead.c +7
-5@@ -113,7 +113,7 @@ static int read_pages(struct address_space *mapping, struct file *filp, {struct blk_plug plug;unsigned page_idx; -int ret; +int ret =0 ;blk_start_plug (&plug);@@ -129,11 +129,12 @@ static int read_pages(struct address_space *mapping, struct file *filp,list_del (&page->lru);if (!add_to_page_cache_lru (page, mapping, page->index,GFP_KERNEL )) { - mapping->a_ops->readpage (filp, page); + ret = mapping->a_ops->readpage (filp, page); +if (ret <0 ) +break ; }page_cache_release (page); } - ret =0 ; out:blk_finish_plug (&plug);@@ -160,6 +161,7 @@ __do_page_cache_readahead(struct address_space *mapping, struct file *filp,LIST_HEAD (page_pool);int page_idx;int ret =0 ; +int ret_read =0 ;loff_t isize =i_size_read (inode);if (isize ==0 )@@ -198,10 +200,10 @@ __do_page_cache_readahead(struct address_space *mapping, struct file *filp,* will then handle the error. */ if (ret) -read_pages (mapping, filp, &page_pool, ret); + ret_read =read_pages (mapping, filp, &page_pool, ret);BUG_ON (!list_empty (&page_pool)); out: -return ret; +return (ret_read <0 ? ret_read : ret); }
Quoted 4 lines
Quoted 3 lines
mm/readahead.c +0
-1/* -- 1.7.12.1
Regards,
Signature · 4 lines
Raghavendra Prabhu GPG Id : 0xD72BE977 Fingerprint: B93F EBCB 8E05 7039 CD3C A4B8 A616 DCA1 D72B E977 www: wnohang.net
Re: Re: [PATCH 2/5] mm/readahead: Change the condition for SetPageReadahead
In reply to Fengguang WuHi,
Quoted 11 lines · * On Sat, Sep 22, 2012 at 08:49:20PM +0800, Fengguang Wu…
Quoted 5 lines · On Sat, Sep 22, 2012 at 04:03:11PM +0530, [email protected] wrote:
From: Raghavendra D Prabhu <[email protected]>
If page lookup from
radix_tree_lookupis successful and its indexpage_idx==nr_to_read-lookahead_size, then SetPageReadahead never gets called, so this fixes that.NAK. Sorry. It's actually an intentional behavior, so that for the common cases of many cached files that are accessed frequently, no
PG_readaheadwill be set at all to pointlessly trap into the readahead routines once and again.
ACK, thanks for explaining that. However, regarding this, I would like to know if the implications of the patch 51daa88ebd8e0d437289f589af29d4b39379ea76 will still apply if PG_readahead is not set.
Quoted 27 lines
Perhaps we need a patch for commenting that case. :)
Thanks,
FengguangQuoted 21 lines
Signed-off-by Raghavendra D Prabhu <[email protected]>--- mm/readahead.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)mm/readahead.c +3
-1@@ -189,8 +189,10 @@ __do_page_cache_readahead(struct address_space *mapping, struct file *filp,break ; page->index = page_offset;list_add (&page->lru, &page_pool); -if (page_idx == nr_to_read - lookahead_size) +if (page_idx >= nr_to_read - lookahead_size) {SetPageReadahead (page); + lookahead_size =0 ; + } ret++; }
Quoted 3 lines
Quoted 2 lines
--
1.7.12.1
Regards,
Signature · 4 lines
Raghavendra Prabhu GPG Id : 0xD72BE977 Fingerprint: B93F EBCB 8E05 7039 CD3C A4B8 A616 DCA1 D72B E977 www: wnohang.net
Re: Re: [PATCH 4/5] Move the check for ra_pages after VM_SequentialReadHint()
In reply to Fengguang WuHi,
Quoted 9 lines · * On Sat, Sep 22, 2012 at 08:42:50PM +0800, Fengguang Wu…
Quoted 4 lines · On Sat, Sep 22, 2012 at 04:03:13PM +0530, [email protected] wrote:
From: Raghavendra D Prabhu <[email protected]>
page_cache_sync_readaheadchecks forra->ra_pagesagain, so moving the check afterVM_SequentialReadHint.Well it depends on what case you are optimizing for. I suspect there are much more tmpfs users than
VM_SequentialReadHintusers. So this change is actually not desirable wrt the more widely used cases.
Yes, that is true. However, it was meant to eliminate duplicate checking of the same condition in two places. But you are right, it may impose overhead for majority of the cases (assuming POSIX_FADVISE is used less than tmpfs).
Quoted 35 lines
Thanks,
FengguangQuoted 31 lines
Signed-off-by Raghavendra D Prabhu <[email protected]>--- mm/filemap.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)mm/filemap.c +3
-3@@ -1523,8 +1523,6 @@ static void do_sync_mmap_readahead(struct vm_area_struct *vma,/* If we don't want any read-ahead, don't bother */ if (VM_RandomReadHint (vma))return ; -if (!ra->ra_pages) -return ;if (VM_SequentialReadHint (vma)) { page_cache_sync_readahead(mapping, ra, file, offset,@@ -1532,6 +1530,9 @@ static void do_sync_mmap_readahead(struct vm_area_struct *vma,return ; } +if (!ra->ra_pages) +return ; +/* Avoid banging the cache line if not needed */ if (ra->mmap_miss <MMAP_LOTSAMISS *10 ) ra->mmap_miss++; --1.7.12.1
Quoted 6 lines
Quoted 5 lines
--
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>
Regards,
Signature · 4 lines
Raghavendra Prabhu GPG Id : 0xD72BE977 Fingerprint: B93F EBCB 8E05 7039 CD3C A4B8 A616 DCA1 D72B E977 www: wnohang.net
Re: Re: [PATCH 5/5] mm/readahead: Use find_get_pages instead of radix_tree_lookup.
In reply to Fengguang WuHi,
Quoted 10 lines · * On Sat, Sep 22, 2012 at 09:15:07PM +0800, Fengguang Wu…
Quoted 9 lines · On Sat, Sep 22, 2012 at 04:03:14PM +0530, [email protected] wrote:
From: Raghavendra D Prabhu <[email protected]>
Instead of running
radix_tree_lookupin a loop and lock/unlocking in the process,find_get_pagesis called once, which returns apage_list, some of which are not NULL and are in core.Also, since
find_get_pagesreturns number of pages, if all pages are already cached, it can return early.
Quoted 6 lines
Quoted 2 lines
This will be mostly helpful when a higher proportion of
nr_to_readpages are already in the cache, which will mean less locking for page cache hits.Do you mean the
rcu_read_lock()? But it's a no-op for most archs. So the benefit of this patch is questionable. Will need real performance numbers to support it.
Aside from the rcu lock/unlock, isn't it better to not make separate calls to radix_tree_lookup and merge them into one call? Similar approach is used with pagevec_lookup which is usually used when one needs to deal with a set of pages.
Quoted 35 lines
Quoted 20 lines
Signed-off-by Raghavendra D Prabhu <[email protected]>--- mm/readahead.c | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-)mm/readahead.c +1
-0@@ -157,35 +157,42 @@ __do_page_cache_readahead(struct address_space *mapping, struct file *filp, {struct inode *inode = mapping->host;struct page *page; +struct page **page_list =NULL ;unsigned long end_index;/* The last page we want to read */ LIST_HEAD (page_pool);int page_idx;int ret =0 ;int ret_read =0 ;mm/readahead.c __do_page_cache_readahead(struct address_space *mapping, struct file *filp, · line 175
Quoted 10 lines
mm/readahead.c +5
-0+unsigned long num; +pgoff_t page_offset;loff_t isize =i_size_read (inode);if (isize ==0 ) goto out; + page_list =kzalloc (nr_to_read *sizeof (struct page *),GFP_KERNEL ); +if (!page_list) + goto out;That cost one more memory allocation and added code to maintain the page list. The original code also don't have the cost of grabbing the page count, which eliminate the trouble of page release.
Quoted 6 lines
mm/readahead.c __do_page_cache_readahead(struct address_space *mapping, struct file *filp, · line 178
Quoted 2 lines
mm/readahead.c +1
-0end_index = ((isize -1 ) >>PAGE_CACHE_SHIFT ); + num =find_get_pages (mapping, offset, nr_to_read, page_list);Assume we want to readahead pages for indexes [0, 100] and the cached pages are in [1000, 1100].
find_get_pages()will return the latter. Which is probably not the your expected results.
I thought if I ask for pages in the range [0,100] it will return a sparse array [0,100] but with holes (NULL) for pages not in cache and references to pages in cache. Isn't that the expected behavior?
Quoted 16 lines
Quoted 16 lines
mm/readahead.c +6
-1/* * Preallocate as many pages as we will need. */ for (page_idx =0 ; page_idx < nr_to_read; page_idx++) { -pgoff_t page_offset = offset + page_idx; +if (page_list[page_idx]) { +page_cache_release (page_list[page_idx]); +continue ; + } + + page_offset = offset + page_idx;if (page_offset > end_index)break ;
Quoted 13 lines
mm/readahead.c __do_page_cache_readahead(struct address_space *mapping, struct file *filp, · line 196
Quoted 10 lines
mm/readahead.c +1
-7-rcu_read_lock (); - page =radix_tree_lookup (&mapping->page_tree, page_offset); -rcu_read_unlock (); -if (page) -continue ; - page =page_cache_alloc_readahead (mapping); -if (!page) +if (unlikely (!page))break ;That break will leave the remaining pages'
page_countlifted and lead to memory leak.
Thanks. Yes, I realized that now.
Quoted 16 lines
Quoted 4 lines
mm/readahead.c +0
-0page->index = page_offset;list_add (&page->lru, &page_pool);mm/readahead.c __do_page_cache_readahead(struct address_space *mapping, struct file *filp, · line 210
Quoted 10 lines
mm/readahead.c +7
-0@@ -194,6 +201,13 @@ __do_page_cache_readahead(struct address_space *mapping, struct file *filp, lookahead_size =0 ; } ret++; + +/* +* Since num pages are already returned, bail out after +* nr_to_read - num pages are allocated and added. +*/ +if (ret == nr_to_read - num) +break ;Confused. That break seems unnecessary?
I fixed that:
- pgoff_t page_offset = offset + page_idx;
-
- if (page_offset > end_index)
- break;
-
- rcu_read_lock();
- page = radix_tree_lookup(&mapping->page_tree, page_offset);
- rcu_read_unlock();
- if (page)
+ if (page_list[page_idx]) {
+ page_cache_release(page_list[page_idx]);
+ num--;
continue;
+ }
+
+ page_offset = offset + page_idx;
+
+ /*
+ * Break only if all the previous
+ * references have been released
+ */ + if (page_offset > end_index) {
+ if (!num)
+ break;
+ else
+ continue;
+ }
page = page_cache_alloc_readahead(mapping);
- if (!page)
- break;
+ if (unlikely(!page))
+ continue;
Quoted 15 lines
Thanks,
FengguangQuoted 11 lines
mm/readahead.c +1
-0}/* @@ -205,6 +219,7 @@ __do_page_cache_readahead(struct address_space *mapping, struct file *filp, ret_read =read_pages (mapping, filp, &page_pool, ret);BUG_ON (!list_empty (&page_pool)); out: +kfree (page_list);return (ret_read <0 ? ret_read : ret); }
Quoted 9 lines
Quoted 8 lines
--
1.7.12.1--
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>
Regards,
Signature · 4 lines
Raghavendra Prabhu GPG Id : 0xD72BE977 Fingerprint: B93F EBCB 8E05 7039 CD3C A4B8 A616 DCA1 D72B E977 www: wnohang.net
Re: Re: [PATCH 1/5] mm/readahead: Check return value of read_pages
In reply to Raghavendra D PrabhuQuoted 8 lines · Raghavendra D Prabhu
Hi,
Quoted 3 lines · * On Sat, Sep 22, 2012 at 08:43:37PM +0800, Fengguang Wu…
Quoted 2 lines · On Sat, Sep 22, 2012 at 04:03:10PM +0530, [email protected] wrote:
From: Raghavendra D Prabhu <[email protected]>
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
Return value of
a_ops->readpagewill be propagated to return value ofread_pagesand__do_page_cache_readahead.That does not explain the intention and benefit of this patch..
I noticed that
force_page_cache_readaheadchecks return value of__do_page_cache_readaheadbut the actual error if any is never propagated.
force_page_cache_readahead()'s return value, in turn, is never used by its callers.. Nor does the other __do_page_cache_readahead() callers care about the error state. So until we find an actual user of the error code, I'd recommend to avoid changing the current code.
Thanks,
Fengguang
--
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: Re: [PATCH 2/5] mm/readahead: Change the condition for SetPageReadahead
In reply to Raghavendra D PrabhuQuoted 16 lines · Raghavendra D Prabhu
Hi,
Quoted 11 lines · * On Sat, Sep 22, 2012 at 08:49:20PM +0800, Fengguang Wu…
Quoted 5 lines · On Sat, Sep 22, 2012 at 04:03:11PM +0530, [email protected] wrote:
From: Raghavendra D Prabhu <[email protected]>
If page lookup from
radix_tree_lookupis successful and its indexpage_idx==nr_to_read-lookahead_size, then SetPageReadahead never gets called, so this fixes that.NAK. Sorry. It's actually an intentional behavior, so that for the common cases of many cached files that are accessed frequently, no
PG_readaheadwill be set at all to pointlessly trap into the readahead routines once and again.
Quoted 4 lines
ACK, thanks for explaining that. However, regarding this, I would like to know if the implications of the patch
51daa88ebd8e0d437289f589af29d4b39379ea76will still apply ifPG_readaheadis not set.
Would you elaborate the implication and the possible problematic case?
Thanks,
Fengguang
--
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: Re: [PATCH 5/5] mm/readahead: Use find_get_pages instead of radix_tree_lookup.
In reply to Raghavendra D PrabhuQuoted 17 lines · Raghavendra D Prabhu
Hi,
Quoted 13 lines · * On Sat, Sep 22, 2012 at 09:15:07PM +0800, Fengguang Wu…
Quoted 11 lines · On Sat, Sep 22, 2012 at 04:03:14PM +0530, [email protected] wrote:
From: Raghavendra D Prabhu <[email protected]>
Instead of running
radix_tree_lookupin a loop and lock/unlocking in the process,find_get_pagesis called once, which returns apage_list, some of which are not NULL and are in core.Also, since
find_get_pagesreturns number of pages, if all pages are already cached, it can return early.This will be mostly helpful when a higher proportion of
nr_to_readpages are already in the cache, which will mean less locking for page cache hits.
Quoted 8 lines
Quoted 3 lines
Do you mean the
rcu_read_lock()? But it's a no-op for most archs. So the benefit of this patch is questionable. Will need real performance numbers to support it.Aside from the rcu lock/unlock, isn't it better to not make separate calls to
radix_tree_lookupand merge them into one call? Similar approach is used withpagevec_lookupwhich is usually used when one needs to deal with a set of pages.
Yeah, batching is generally good, however find_get_pages() is not the right tool. It costs:
- get/release page counts
- likely a lot more searches in the address space, because it does not limit the end index of the search.
radix_tree_next_hole() will be the right tool, and I have a patch to make it actually smarter than the current dumb loop.
Quoted 41 lines
Quoted 34 lines
Quoted 19 lines
Signed-off-by Raghavendra D Prabhu <[email protected]>---
mm/readahead.c| 31 +++++++++++++++++++++++--------1 file changed, 23 insertions(+), 8 deletions(-)mm/readahead.c +1
-0@@ -157,35 +157,42 @@ __do_page_cache_readahead(struct address_space *mapping, struct file *filp, {struct inode *inode = mapping->host;struct page *page; +struct page **page_list =NULL ;unsigned long end_index;/* The last page we want to read */ LIST_HEAD (page_pool);int page_idx;int ret =0 ;int ret_read =0 ;mm/readahead.c __do_page_cache_readahead(struct address_space *mapping, struct file *filp, · line 175
Quoted 10 lines
mm/readahead.c +5
-0+unsigned long num; +pgoff_t page_offset;loff_t isize =i_size_read (inode);if (isize ==0 ) goto out; + page_list =kzalloc (nr_to_read *sizeof (struct page *),GFP_KERNEL ); +if (!page_list) + goto out;That cost one more memory allocation and added code to maintain the page list. The original code also don't have the cost of grabbing the page count, which eliminate the trouble of page release.
Quoted 6 lines
mm/readahead.c __do_page_cache_readahead(struct address_space *mapping, struct file *filp, · line 178
Quoted 2 lines
mm/readahead.c +1
-0end_index = ((isize -1 ) >>PAGE_CACHE_SHIFT ); + num =find_get_pages (mapping, offset, nr_to_read, page_list);Assume we want to readahead pages for indexes [0, 100] and the cached pages are in [1000, 1100].
find_get_pages()will return the latter. Which is probably not the your expected results.
Quoted 3 lines
I thought if I ask for pages in the range [0,100] it will return a sparse array [0,100] but with holes (NULL) for pages not in cache and references to pages in cache. Isn't that the expected behavior?
Nope. The comments above find_get_pages() made it clear, that it's limited by the number of pages rather than the end page index.
Quoted 56 lines
Quoted 16 lines
Quoted 16 lines
mm/readahead.c +6
-1/* * Preallocate as many pages as we will need. */ for (page_idx =0 ; page_idx < nr_to_read; page_idx++) { -pgoff_t page_offset = offset + page_idx; +if (page_list[page_idx]) { +page_cache_release (page_list[page_idx]); +continue ; + } + + page_offset = offset + page_idx;if (page_offset > end_index)break ;Quoted 13 lines
mm/readahead.c __do_page_cache_readahead(struct address_space *mapping, struct file *filp, · line 196
Quoted 10 lines
mm/readahead.c +1
-7-rcu_read_lock (); - page =radix_tree_lookup (&mapping->page_tree, page_offset); -rcu_read_unlock (); -if (page) -continue ; - page =page_cache_alloc_readahead (mapping); -if (!page) +if (unlikely (!page))break ;That break will leave the remaining pages'
page_countlifted and lead to memory leak.Thanks. Yes, I realized that now.
Quoted 16 lines
Quoted 4 lines
mm/readahead.c +0
-0page->index = page_offset;list_add (&page->lru, &page_pool);mm/readahead.c __do_page_cache_readahead(struct address_space *mapping, struct file *filp, · line 210
Quoted 10 lines
mm/readahead.c +7
-0@@ -194,6 +201,13 @@ __do_page_cache_readahead(struct address_space *mapping, struct file *filp, lookahead_size =0 ; } ret++; + +/* +* Since num pages are already returned, bail out after +* nr_to_read - num pages are allocated and added. +*/ +if (ret == nr_to_read - num) +break ;Confused. That break seems unnecessary?
I fixed that:
-
pgoff_tpage_offset= offset +page_idx;
-
- if (page_offset>end_index)
- break;
-
Quoted 7 lines
- rcu_read_lock(); - page = radix_tree_lookup(&mapping->page_tree, page_offset); - rcu_read_unlock(); - if (page)+ if (page_list[page_idx]) {
+page_cache_release(page_list[page_idx]);
No, you cannot expect:
page_list[page_idx]->index == page_idx
Thanks,
Fengguang
Quoted 51 lines
+ num--; continue; + } + + page_offset = offset + page_idx; + + /* + * Break only if all the previous + * references have been released + */+ if (
page_offset>end_index) {
+ if (!num)
+ break;
+ else
+ continue;
+ }page = page_cache_alloc_readahead(mapping);- if (!page)
- break;
+ if (unlikely(!page))
+ continue;Quoted 15 lines
Thanks,
FengguangQuoted 11 lines
mm/readahead.c +0
-0}/* @@ -205,6 +219,7 @@ __do_page_cache_readahead(struct address_space *mapping, struct file *filp, ret_read =read_pages (mapping, filp, &page_pool, ret);BUG_ON (!list_empty (&page_pool));out:
mm/readahead.c +1
-0+kfree (page_list);return (ret_read < 0 ? ret_read : ret); }Quoted 9 lines
Quoted 8 lines
--
1.7.12.1--
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>
Quoted 6 lines
Regards,
Signature · 4 lines
Raghavendra Prabhu GPG Id : 0xD72BE977 Fingerprint: B93F EBCB 8E05 7039 CD3C A4B8 A616 DCA1 D72B E977 www: wnohang.net
--
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: Re: Re: [PATCH 5/5] mm/readahead: Use find_get_pages instead of radix_tree_lookup.
Hi,
Quoted 27 lines · * On Fri, Sep 28, 2012 at 08:18:50PM +0800, Fengguang Wu…
Quoted 17 lines · Raghavendra D Prabhu
Hi,
Quoted 13 lines · * On Sat, Sep 22, 2012 at 09:15:07PM +0800, Fengguang Wu…
Quoted 11 lines · On Sat, Sep 22, 2012 at 04:03:14PM +0530, [email protected] wrote:
From: Raghavendra D Prabhu <[email protected]>
Instead of running
radix_tree_lookupin a loop and lock/unlocking in the process,find_get_pagesis called once, which returns apage_list, some of which are not NULL and are in core.Also, since
find_get_pagesreturns number of pages, if all pages are already cached, it can return early.This will be mostly helpful when a higher proportion of
nr_to_readpages are already in the cache, which will mean less locking for page cache hits.Quoted 8 lines
Quoted 3 lines
Do you mean the
rcu_read_lock()? But it's a no-op for most archs. So the benefit of this patch is questionable. Will need real performance numbers to support it.Aside from the rcu lock/unlock, isn't it better to not make separate calls to
radix_tree_lookupand merge them into one call? Similar approach is used withpagevec_lookupwhich is usually used when one needs to deal with a set of pages.
Quoted 8 lines
Yeah, batching is generally good, however
find_get_pages()is not the right tool. It costs:
- get/release page counts
- likely a lot more searches in the address space, because it does not limit the end index of the search.
radix_tree_next_hole()will be the right tool, and I have a patch to make it actually smarter than the current dumb loop.
Good to know.
Quoted 42 lines
Quoted 42 lines
Quoted 41 lines
Quoted 20 lines
Signed-off-by Raghavendra D Prabhu <[email protected]>---
mm/readahead.c| 31 +++++++++++++++++++++++--------1 file changed, 23 insertions(+), 8 deletions(-)mm/readahead.c +1
-0@@ -157,35 +157,42 @@ __do_page_cache_readahead(struct address_space *mapping, struct file *filp, {struct inode *inode = mapping->host;struct page *page; +struct page **page_list =NULL ;unsigned long end_index;/* The last page we want to read */ LIST_HEAD (page_pool);int page_idx;int ret =0 ;int ret_read =0 ;mm/readahead.c __do_page_cache_readahead(struct address_space *mapping, struct file *filp, · line 175
Quoted 10 lines
mm/readahead.c +5
-0+unsigned long num; +pgoff_t page_offset;loff_t isize =i_size_read (inode);if (isize ==0 ) goto out; + page_list =kzalloc (nr_to_read *sizeof (struct page *),GFP_KERNEL ); +if (!page_list) + goto out;That cost one more memory allocation and added code to maintain the page list. The original code also don't have the cost of grabbing the page count, which eliminate the trouble of page release.
mm/readahead.c __do_page_cache_readahead(struct address_space *mapping, struct file *filp, · line 178
Quoted 2 lines
mm/readahead.c +1
-0end_index = ((isize -1 ) >>PAGE_CACHE_SHIFT ); + num =find_get_pages (mapping, offset, nr_to_read, page_list);Assume we want to readahead pages for indexes [0, 100] and the cached pages are in [1000, 1100].
find_get_pages()will return the latter. Which is probably not the your expected results.
Quoted 6 lines
Quoted 3 lines
I thought if I ask for pages in the range [0,100] it will return a sparse array [0,100] but with holes (NULL) for pages not in cache and references to pages in cache. Isn't that the expected behavior?
Nope. The comments above
find_get_pages()made it clear, that it's limited by the number of pages rather than the end page index.
Yes, I noticed that, however since nr_to_read in this case is equal to nr_pages.
However, I think I understand what you are saying -- ie. if offset + nr_pages exceeds the end_index then it will return pages not belonging to the file, is that right?
In that case, won't capping nr_pages do, ie. check if offset + nr_pages > end_index and if that is true, then reduce nr_to_read by end_index. Won't that work?
Quoted 65 lines
Quoted 57 lines
Quoted 17 lines
Quoted 17 lines
mm/readahead.c +6
-1/* * Preallocate as many pages as we will need. */ for (page_idx =0 ; page_idx < nr_to_read; page_idx++) { -pgoff_t page_offset = offset + page_idx; +if (page_list[page_idx]) { +page_cache_release (page_list[page_idx]); +continue ; + } + + page_offset = offset + page_idx;if (page_offset > end_index)break ;Quoted 13 lines
mm/readahead.c __do_page_cache_readahead(struct address_space *mapping, struct file *filp, · line 196
Quoted 10 lines
mm/readahead.c +1
-7-rcu_read_lock (); - page =radix_tree_lookup (&mapping->page_tree, page_offset); -rcu_read_unlock (); -if (page) -continue ; - page =page_cache_alloc_readahead (mapping); -if (!page) +if (unlikely (!page))break ;That break will leave the remaining pages'
page_countlifted and lead to memory leak.Thanks. Yes, I realized that now.
Quoted 16 lines
Quoted 4 lines
mm/readahead.c +0
-0page->index = page_offset;list_add (&page->lru, &page_pool);mm/readahead.c __do_page_cache_readahead(struct address_space *mapping, struct file *filp, · line 210
Quoted 10 lines
mm/readahead.c +7
-0@@ -194,6 +201,13 @@ __do_page_cache_readahead(struct address_space *mapping, struct file *filp, lookahead_size =0 ; } ret++; + +/* +* Since num pages are already returned, bail out after +* nr_to_read - num pages are allocated and added. +*/ +if (ret == nr_to_read - num) +break ;Confused. That break seems unnecessary?
I fixed that:
-
pgoff_tpage_offset= offset +page_idx;
-
- if (page_offset>end_index)
- break;
-Quoted 7 lines
- rcu_read_lock(); - page = radix_tree_lookup(&mapping->page_tree, page_offset); - rcu_read_unlock(); - if (page)+ if (page_list[page_idx]) {
+page_cache_release(page_list[page_idx]);
Quoted 67 lines
No, you cannot expect:
page_list[page_idx]->index == page_idxThanks,
FengguangQuoted 57 lines
+ num--; continue; + } + + page_offset = offset + page_idx; + + /* + * Break only if all the previous + * references have been released + */+ if (
page_offset>end_index) {
+ if (!num)
+ break;
+ else
+ continue;
+ }page = page_cache_alloc_readahead(mapping);- if (!page)
- break;
+ if (unlikely(!page))
+ continue;Quoted 15 lines
Thanks,
FengguangQuoted 11 lines
mm/readahead.c +0
-0}/* @@ -205,6 +219,7 @@ __do_page_cache_readahead(struct address_space *mapping, struct file *filp, ret_read =read_pages (mapping, filp, &page_pool, ret);BUG_ON (!list_empty (&page_pool));out:
mm/readahead.c +1
-0+kfree (page_list);return (ret_read < 0 ? ret_read : ret); }Quoted 9 lines
Quoted 8 lines
--
1.7.12.1--
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>Regards,
--
Raghavendra Prabhu
GPG Id :0xD72BE977
Fingerprint: B93F EBCB 8E05 7039 CD3C A4B8 A616 DCA1 D72B E977
www: wnohang.net
Regards,
Signature · 4 lines
Raghavendra Prabhu GPG Id : 0xD72BE977 Fingerprint: B93F EBCB 8E05 7039 CD3C A4B8 A616 DCA1 D72B E977 www: wnohang.net
Re: Re: Re: [PATCH 2/5] mm/readahead: Change the condition for SetPageReadahead
In reply to Fengguang WuHi,
Quoted 17 lines · * On Fri, Sep 28, 2012 at 07:56:23PM +0800, Fengguang Wu…
Quoted 16 lines · Raghavendra D Prabhu
Hi,
Quoted 11 lines · * On Sat, Sep 22, 2012 at 08:49:20PM +0800, Fengguang Wu…
Quoted 5 lines · On Sat, Sep 22, 2012 at 04:03:11PM +0530, [email protected] wrote:
From: Raghavendra D Prabhu <[email protected]>
If page lookup from
radix_tree_lookupis successful and its indexpage_idx==nr_to_read-lookahead_size, then SetPageReadahead never gets called, so this fixes that.NAK. Sorry. It's actually an intentional behavior, so that for the common cases of many cached files that are accessed frequently, no
PG_readaheadwill be set at all to pointlessly trap into the readahead routines once and again.
Quoted 6 lines
Quoted 4 lines
ACK, thanks for explaining that. However, regarding this, I would like to know if the implications of the patch
51daa88ebd8e0d437289f589af29d4b39379ea76will still apply ifPG_readaheadis not set.Would you elaborate the implication and the possible problematic case?
Certainly.
An implication of 51daa88ebd8e0d437289f589af29d4b39379ea76 is that, a redundant check for PageReadahead(page) is avoided since async is piggy-backed into the synchronous readahead itself.
So, in case of
page = find_get_page()
if(!page)
page_cache_sync_readahead()
else if (PageReadahead(page))
page_cache_async_readahead();
isnt' there a possibility that PG_readahead won't be set at all if page is not in cache (causing page_cache_sync_readahead) but page at index (nr_to_read - lookahead_size) is already in the cache? (due to if (page) continue; in the code)?
Hence, I changed the condition from equality to >= for setting SetPageReadahead(page) (and added a variable so that it is done only once).
Quoted 4 lines
Thanks,
Fengguang
Regards,
Signature · 4 lines
Raghavendra Prabhu GPG Id : 0xD72BE977 Fingerprint: B93F EBCB 8E05 7039 CD3C A4B8 A616 DCA1 D72B E977 www: wnohang.net
Re: Re: Re: [PATCH 1/5] mm/readahead: Check return value of read_pages
In reply to Fengguang WuHi,
Quoted 12 lines · * On Fri, Sep 28, 2012 at 07:54:05PM +0800, Fengguang Wu…
Quoted 11 lines · Raghavendra D Prabhu
Hi,
Quoted 6 lines · * On Sat, Sep 22, 2012 at 08:43:37PM +0800, Fengguang Wu…
Quoted 4 lines · On Sat, Sep 22, 2012 at 04:03:10PM +0530, [email protected] wrote:
From: Raghavendra D Prabhu <[email protected]>
Return value of
a_ops->readpagewill be propagated to return value ofread_pagesand__do_page_cache_readahead.
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
That does not explain the intention and benefit of this patch..
I noticed that
force_page_cache_readaheadchecks return value of__do_page_cache_readaheadbut the actual error if any is never propagated.force_page_cache_readahead()'s return value, in turn, is never used by its callers..
Yes, it is not called by its callers, however, since it is called in a loop, shouldn't we bail out if force_page_cache_readahead fails once? Without the appropriate return value, it will continue and in
force_page_cache_readahead
if (err < 0) {
ret = err;
break;
}
is never hit.Nor does the other __do_page_cache_readahead() callers
Quoted 6 lines
care about the error state. So until we find an actual user of the error code, I'd recommend to avoid changing the current code.
Thanks,
Fengguang
Regards,
Signature · 4 lines
Raghavendra Prabhu GPG Id : 0xD72BE977 Fingerprint: B93F EBCB 8E05 7039 CD3C A4B8 A616 DCA1 D72B E977 www: wnohang.net
Re: Re: [PATCH 4/5] Move the check for ra_pages after VM_SequentialReadHint()
In reply to Fengguang WuHi,
Quoted 5 lines · * On Sat, Sep 22, 2012 at 08:42:50PM +0800, Fengguang Wu…
[email protected]>
User-Agent: Mutt/1.5.21 (2010-09-15)
X-Date: Sat Sep 22 18:12:50 IST 2012On Sat, Sep 22, 2012 at 04:03:13PM +0530, [email protected] wrote:
Quoted 8 lines
Quoted 4 lines
From: Raghavendra D Prabhu <[email protected]>
page_cache_sync_readaheadchecks forra->ra_pagesagain, so moving the check afterVM_SequentialReadHint.Well it depends on what case you are optimizing for. I suspect there are much more tmpfs users than
VM_SequentialReadHintusers. So this change is actually not desirable wrt the more widely used cases.
shm/tmpfs doesn't use this function for fault. They have shmem_fault for that. So, that shouldn't matter here. Agree?
Quoted 35 lines
Thanks,
FengguangQuoted 31 lines
Signed-off-by Raghavendra D Prabhu <[email protected]>--- mm/filemap.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)mm/filemap.c +3
-3@@ -1523,8 +1523,6 @@ static void do_sync_mmap_readahead(struct vm_area_struct *vma,/* If we don't want any read-ahead, don't bother */ if (VM_RandomReadHint (vma))return ; -if (!ra->ra_pages) -return ;if (VM_SequentialReadHint (vma)) { page_cache_sync_readahead(mapping, ra, file, offset,@@ -1532,6 +1530,9 @@ static void do_sync_mmap_readahead(struct vm_area_struct *vma,return ; } +if (!ra->ra_pages) +return ; +/* Avoid banging the cache line if not needed */ if (ra->mmap_miss <MMAP_LOTSAMISS *10 ) ra->mmap_miss++; --1.7.12.1
Quoted 4 lines
Quoted 4 lines
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see
Regards,
Signature · 4 lines
Raghavendra Prabhu GPG Id : 0xD72BE977 Fingerprint: B93F EBCB 8E05 7039 CD3C A4B8 A616 DCA1 D72B E977 www: wnohang.net
Re: Re: [PATCH 3/5] Remove file_ra_state from arguments of count_history_pages.
In reply to Fengguang WuHi,
Quoted 9 lines · * On Sat, Sep 22, 2012 at 08:40:28PM +0800, Fengguang Wu…
Quoted 5 lines · On Sat, Sep 22, 2012 at 04:03:12PM +0530, [email protected] wrote:
From: Raghavendra D Prabhu <[email protected]>
count_history_pagesdoesn't require readahead state to calculate the offset from history.Signed-off-by Raghavendra D Prabhu <[email protected]>Acked-by Fengguang Wu <[email protected]>
Good. Do I need do anything else to get this into mm-tree? Few months back, I had sent and few were acked, but they didn't end up anywhere.
Regards,
Signature · 4 lines
Raghavendra Prabhu GPG Id : 0xD72BE977 Fingerprint: B93F EBCB 8E05 7039 CD3C A4B8 A616 DCA1 D72B E977 www: wnohang.net
Re: Re: Re: [PATCH 5/5] mm/readahead: Use find_get_pages instead of radix_tree_lookup.
In reply to Raghavendra D PrabhuQuoted 88 lines · Raghavendra D Prabhu
Hi,
Quoted 27 lines · * On Fri, Sep 28, 2012 at 08:18:50PM +0800, Fengguang Wu…
Quoted 17 lines · Raghavendra D Prabhu
Hi,
Quoted 13 lines · * On Sat, Sep 22, 2012 at 09:15:07PM +0800, Fengguang Wu…
Quoted 11 lines · On Sat, Sep 22, 2012 at 04:03:14PM +0530, [email protected] wrote:
From: Raghavendra D Prabhu <[email protected]>
Instead of running
radix_tree_lookupin a loop and lock/unlocking in the process,find_get_pagesis called once, which returns apage_list, some of which are not NULL and are in core.Also, since
find_get_pagesreturns number of pages, if all pages are already cached, it can return early.This will be mostly helpful when a higher proportion of
nr_to_readpages are already in the cache, which will mean less locking for page cache hits.Quoted 8 lines
Quoted 3 lines
Do you mean the
rcu_read_lock()? But it's a no-op for most archs. So the benefit of this patch is questionable. Will need real performance numbers to support it.Aside from the rcu lock/unlock, isn't it better to not make separate calls to
radix_tree_lookupand merge them into one call? Similar approach is used withpagevec_lookupwhich is usually used when one needs to deal with a set of pages.Quoted 8 lines
Yeah, batching is generally good, however
find_get_pages()is not the right tool. It costs:
- get/release page counts
- likely a lot more searches in the address space, because it does not limit the end index of the search.
radix_tree_next_hole()will be the right tool, and I have a patch to make it actually smarter than the current dumb loop.Good to know.
Quoted 46 lines
Quoted 45 lines
Quoted 35 lines
Quoted 20 lines
Signed-off-by Raghavendra D Prabhu <[email protected]>---
mm/readahead.c| 31 +++++++++++++++++++++++--------1 file changed, 23 insertions(+), 8 deletions(-)mm/readahead.c +1
-0@@ -157,35 +157,42 @@ __do_page_cache_readahead(struct address_space *mapping, struct file *filp, {struct inode *inode = mapping->host;struct page *page; +struct page **page_list =NULL ;unsigned long end_index;/* The last page we want to read */ LIST_HEAD (page_pool);int page_idx;int ret =0 ;int ret_read =0 ;mm/readahead.c __do_page_cache_readahead(struct address_space *mapping, struct file *filp, · line 175
Quoted 10 lines
mm/readahead.c +5
-0+unsigned long num; +pgoff_t page_offset;loff_t isize =i_size_read (inode);if (isize ==0 ) goto out; + page_list =kzalloc (nr_to_read *sizeof (struct page *),GFP_KERNEL ); +if (!page_list) + goto out;That cost one more memory allocation and added code to maintain the page list. The original code also don't have the cost of grabbing the page count, which eliminate the trouble of page release.
Quoted 6 lines
mm/readahead.c __do_page_cache_readahead(struct address_space *mapping, struct file *filp, · line 178
Quoted 2 lines
mm/readahead.c +1
-0end_index = ((isize -1 ) >>PAGE_CACHE_SHIFT ); + num =find_get_pages (mapping, offset, nr_to_read, page_list);Assume we want to readahead pages for indexes [0, 100] and the cached pages are in [1000, 1100].
find_get_pages()will return the latter. Which is probably not the your expected results.I thought if I ask for pages in the range [0,100] it will return a sparse array [0,100] but with holes (NULL) for pages not in cache and references to pages in cache. Isn't that the expected behavior?
Quoted 7 lines
Quoted 2 lines
Nope. The comments above
find_get_pages()made it clear, that it's limited by the number of pages rather than the end page index.Yes, I noticed that, however since
nr_to_readin this case is equal tonr_pages.However, I think I understand what you are saying -- ie. if offset +
You seem to still don't understand it after all the explanations..
Quoted 2 lines
nr_pagesexceeds theend_indexthen it will return pages not belonging to the file, is that right?
Nope.
Quoted 3 lines
In that case, won't capping
nr_pagesdo, ie. check if offset +nr_pages>end_indexand if that is true, then reducenr_to_readbyend_index. Won't that work?
Either you or me are get lost in the discussion. Please research the code and emails and show me working code (that's actually tested) that can serve as the new base for our discussions.
Thanks,
Fengguang
Quoted 134 lines
Quoted 63 lines
Quoted 52 lines
Quoted 15 lines
Quoted 15 lines
mm/readahead.c +6
-1/* * Preallocate as many pages as we will need. */ for (page_idx =0 ; page_idx < nr_to_read; page_idx++) { -pgoff_t page_offset = offset + page_idx; +if (page_list[page_idx]) { +page_cache_release (page_list[page_idx]); +continue ; + } + + page_offset = offset + page_idx;if (page_offset > end_index)break ;Quoted 13 lines
mm/readahead.c __do_page_cache_readahead(struct address_space *mapping, struct file *filp, · line 196
Quoted 10 lines
mm/readahead.c +1
-7-rcu_read_lock (); - page =radix_tree_lookup (&mapping->page_tree, page_offset); -rcu_read_unlock (); -if (page) -continue ; - page =page_cache_alloc_readahead (mapping); -if (!page) +if (unlikely (!page))break ;That break will leave the remaining pages'
page_countlifted and lead to memory leak.Thanks. Yes, I realized that now.
Quoted 16 lines
Quoted 4 lines
mm/readahead.c +0
-0page->index = page_offset;list_add (&page->lru, &page_pool);mm/readahead.c __do_page_cache_readahead(struct address_space *mapping, struct file *filp, · line 210
Quoted 10 lines
mm/readahead.c +7
-0@@ -194,6 +201,13 @@ __do_page_cache_readahead(struct address_space *mapping, struct file *filp, lookahead_size =0 ; } ret++; + +/* +* Since num pages are already returned, bail out after +* nr_to_read - num pages are allocated and added. +*/ +if (ret == nr_to_read - num) +break ;Confused. That break seems unnecessary?
I fixed that:
(quoted diff) +0
-2- pgoff_t page_offset = offset + page_idx; -Review
Quoted 10 lines
(quoted diff) +2
-7- if (page_offset > end_index) - break; - - rcu_read_lock(); - page = radix_tree_lookup(&mapping->page_tree, page_offset); - rcu_read_unlock(); - if (page) + if (page_list[page_idx]) { + page_cache_release(page_list[page_idx]);Quoted 67 lines
No, you cannot expect:
page_list[page_idx]->index == page_idxThanks,
FengguangQuoted 57 lines
(quoted diff) +17
-2+ num--; continue; + } + + page_offset = offset + page_idx; + + /* + * Break only if all the previous + * references have been released + */ + if (page_offset > end_index) { + if (!num) + break; + else + continue; + } page = page_cache_alloc_readahead(mapping); - if (!page) - break; + if (unlikely(!page)) + continue;Quoted 16 lines
Thanks,
FengguangQuoted 11 lines
mm/readahead.c +0
-0}/* @@ -205,6 +219,7 @@ __do_page_cache_readahead(struct address_space *mapping, struct file *filp, ret_read =read_pages (mapping, filp, &page_pool, ret);BUG_ON (!list_empty (&page_pool));out:
mm/readahead.c +1
-0+kfree (page_list);return (ret_read < 0 ? ret_read : ret); }Quoted 9 lines
Quoted 8 lines
--
1.7.12.1--
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>Regards,
--
Raghavendra Prabhu
GPG Id :0xD72BE977
Fingerprint: B93F EBCB 8E05 7039 CD3C A4B8 A616 DCA1 D72B E977
www: wnohang.net
Quoted 6 lines
Regards,
Signature · 4 lines
Raghavendra Prabhu GPG Id : 0xD72BE977 Fingerprint: B93F EBCB 8E05 7039 CD3C A4B8 A616 DCA1 D72B E977 www: wnohang.net
--
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: Re: Re: [PATCH 2/5] mm/readahead: Change the condition for SetPageReadahead
In reply to Raghavendra D PrabhuHi Raghavendra,
Quoted 3 lines
An implication of
51daa88ebd8e0d437289f589af29d4b39379ea76is that, a redundant check for PageReadahead(page) is avoided since async is piggy-backed into the synchronous readahead itself.
That's right.
Quoted 8 lines
So, in case of
page =
find_get_page()
if(!page)
page_cache_sync_readahead()
else if (PageReadahead(page))
page_cache_async_readahead();
Quoted 4 lines
isnt' there a possibility that
PG_readaheadwon't be set at all if page is not in cache (causingpage_cache_sync_readahead) but page at index (nr_to_read-lookahead_size) is already in the cache? (due to if (page) continue; in the code)?
Yes, and I'm fully aware of that. It's left alone because it's assumed to be a rare case. The nature of readahead is, there are all kinds of less common cases that we deliberately ignore in order to keep the code simple and maintainable.
Quoted 3 lines
Hence, I changed the condition from equality to >= for setting SetPageReadahead(page) (and added a variable so that it is done only once).
It's excellent that you noticed that case. And sorry that I come to realize that your change
- if (page_idx == nr_to_read - lookahead_size)
+ if (page_idx >= nr_to_read - lookahead_size) {
SetPageReadahead(page);+ lookahead_size = 0;
+ }
won't negatively impact cache hot reads. So I have no strong feelings about the patch now.
Thanks,
Fengguang
--
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: Re: Re: [PATCH 1/5] mm/readahead: Check return value of read_pages
In reply to Raghavendra D PrabhuQuoted 32 lines · Raghavendra D Prabhu
Hi,
Quoted 12 lines · * On Fri, Sep 28, 2012 at 07:54:05PM +0800, Fengguang Wu…
Quoted 11 lines · Raghavendra D Prabhu
Hi,
Quoted 6 lines · * On Sat, Sep 22, 2012 at 08:43:37PM +0800, Fengguang Wu…
Quoted 4 lines · On Sat, Sep 22, 2012 at 04:03:10PM +0530, [email protected] wrote:
From: Raghavendra D Prabhu <[email protected]>
Return value of
a_ops->readpagewill be propagated to return value ofread_pagesand__do_page_cache_readahead.Quoted 8 lines
Quoted 5 lines
Quoted 1 line
That does not explain the intention and benefit of this patch..
I noticed that
force_page_cache_readaheadchecks return value of__do_page_cache_readaheadbut the actual error if any is never propagated.force_page_cache_readahead()'s return value, in turn, is never used by its callers..
Yes, it is not called by its callers, however, since it is called in a loop, shouldn't we bail out if
force_page_cache_readaheadfails once? Without the appropriate return value, it will continue and in
force_page_cache_readahead
Quoted 7 lines
if (err < 0) { ret = err; break; } is never hit.Nor does the other
__do_page_cache_readahead()callers
That sounds all reasonable, but please don't change the meaning of __do_page_cache_readahead()'s return value. It should always return the number of new pages put to IO, which will be used by some readahead tracing/accounting feature. So it will need another parameter for passing the error code from ->readpages(). However since the major filesystems always return 0 in ->readpages(), I'm not sure it worth the efforts.
Thanks,
Fengguang
Quoted 6 lines
Quoted 6 lines
care about the error state. So until we find an actual user of the error code, I'd recommend to avoid changing the current code.
Thanks,
Fengguang
--
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: Re: [PATCH 4/5] Move the check for ra_pages after VM_SequentialReadHint()
In reply to Raghavendra D PrabhuQuoted 14 lines · Raghavendra D Prabhu
Hi,
Quoted 10 lines · * On Sat, Sep 22, 2012 at 08:42:50PM +0800, Fengguang Wu…
[email protected]>
User-Agent: Mutt/1.5.21 (2010-09-15)
X-Date: Sat Sep 22 18:12:50 IST 2012Quoted 4 lines · On Sat, Sep 22, 2012 at 04:03:13PM +0530, [email protected] wrote:
From: Raghavendra D Prabhu <[email protected]>
page_cache_sync_readaheadchecks forra->ra_pagesagain, so moving the check afterVM_SequentialReadHint.
Quoted 6 lines
Quoted 3 lines
Well it depends on what case you are optimizing for. I suspect there are much more tmpfs users than
VM_SequentialReadHintusers. So this change is actually not desirable wrt the more widely used cases.shm/tmpfs doesn't use this function for fault. They have
shmem_faultfor that. So, that shouldn't matter here. Agree?
That's true for the regular tmpfs and it still calls filemap_fault() in the !CONFIG_SHMEM case and squashfs/cramfs etc. They together should still overweight the VM_SequentialReadHint users?
Thanks,
Fengguang
--
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: Re: [PATCH 3/5] Remove file_ra_state from arguments of count_history_pages.
In reply to Raghavendra D PrabhuQuoted 9 lines · Raghavendra D Prabhu
Hi,
Quoted 5 lines · * On Sat, Sep 22, 2012 at 08:40:28PM +0800, Fengguang Wu…
Quoted 4 lines · On Sat, Sep 22, 2012 at 04:03:12PM +0530, [email protected] wrote:
From: Raghavendra D Prabhu <[email protected]>
count_history_pagesdoesn't require readahead state to calculate the offset from history.
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
Signed-off-by Raghavendra D Prabhu <[email protected]>Acked-by Fengguang Wu <[email protected]>Good. Do I need do anything else to get this into mm-tree? Few months back, I had sent and few were acked, but they didn't end up anywhere.
Raghavendra, you may repost a revised patchset to the lists to move things forward.
Thanks,
Fengguang
--
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>