public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] readahead: simplify ra->size testing
@ 2005-03-02 19:08 Oleg Nesterov
  2005-03-03  1:59 ` Andrew Morton
  0 siblings, 1 reply; 4+ messages in thread
From: Oleg Nesterov @ 2005-03-02 19:08 UTC (permalink / raw)
  To: linux-kernel; +Cc: Ram Pai, Steven Pratt, Andrew Morton

On top of "readahead: cleanup blockable_page_cache_readahead()",
see http://marc.theaimsgroup.com/?l=linux-kernel&m=110927049500942

Currently page_cache_readahead() treats ra->size == 0 (first read)
and ra->size == -1 (ra_off was called) separately, but does exactly
the same in both cases.

With this patch we may assume that the reading starts in 'ra_off()'
state, so we don't need to consider the first read as a special case.

Signed-off-by: Oleg Nesterov <oleg@tv-sign.ru>

--- 2.6.11/mm/readahead.c~	2005-02-04 21:33:40.000000000 +0300
+++ 2.6.11/mm/readahead.c	2005-02-04 21:33:57.000000000 +0300
@@ -55,7 +55,7 @@ static inline void ra_off(struct file_ra
 {
 	ra->start = 0;
 	ra->flags = 0;
-	ra->size = -1;
+	ra->size = 0;
 	ra->ahead_start = 0;
 	ra->ahead_size = 0;
 	return;
@@ -452,7 +452,7 @@ page_cache_readahead(struct address_spac
 	 * perturbing the readahead window expansion logic.
 	 * If size is zero, there is no read ahead window so we need one
 	 */
-	if (offset == ra->prev_page && req_size == 1 && ra->size != 0)
+	if (offset == ra->prev_page && req_size == 1)
 		goto out;
 
 	ra->prev_page = offset;
@@ -471,9 +471,7 @@ page_cache_readahead(struct address_spac
 	 * at start of file, and grow the window fast.  Or detect first
 	 * sequential access
 	 */
-	if ((ra->size == 0 && offset == 0)	/* first io and start of file */
-	    || (ra->size == -1 && sequential)) {
-		/* First sequential */
+	if (sequential && ra->size == 0) {
 		ra->size = get_init_ra_size(newsize, max);
 		ra->start = offset;
 		if (!blockable_page_cache_readahead(mapping, filp, offset,
@@ -499,7 +497,7 @@ page_cache_readahead(struct address_spac
 	 * partial page reads and first access were handled above,
 	 * so this must be the next page otherwise it is random
 	 */
-	if (!sequential || (ra->size == 0)) {
+	if (!sequential) {
 		ra_off(ra);
 		blockable_page_cache_readahead(mapping, filp, offset,
 				 newsize, ra, 1);

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/2] readahead: simplify ra->size testing
  2005-03-02 19:08 [PATCH 1/2] readahead: simplify ra->size testing Oleg Nesterov
@ 2005-03-03  1:59 ` Andrew Morton
  2005-03-03 10:08   ` Oleg Nesterov
  0 siblings, 1 reply; 4+ messages in thread
From: Andrew Morton @ 2005-03-03  1:59 UTC (permalink / raw)
  To: Oleg Nesterov; +Cc: linux-kernel, linuxram, slpratt

Oleg Nesterov <oleg@tv-sign.ru> wrote:
>
> On top of "readahead: cleanup blockable_page_cache_readahead()",
>  see http://marc.theaimsgroup.com/?l=linux-kernel&m=110927049500942
> 
>  Currently page_cache_readahead() treats ra->size == 0 (first read)
>  and ra->size == -1 (ra_off was called) separately, but does exactly
>  the same in both cases.
> 
>  With this patch we may assume that the reading starts in 'ra_off()'
>  state, so we don't need to consider the first read as a special case.

So...  the big "how it all works" comment needs an update..

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/2] readahead: simplify ra->size testing
  2005-03-03 10:08   ` Oleg Nesterov
@ 2005-03-03  9:28     ` Andrew Morton
  0 siblings, 0 replies; 4+ messages in thread
From: Andrew Morton @ 2005-03-03  9:28 UTC (permalink / raw)
  To: Oleg Nesterov; +Cc: linux-kernel, linuxram, slpratt

Oleg Nesterov <oleg@tv-sign.ru> wrote:
>
> Andrew Morton wrote:
>  > 
>  > So...  the big "how it all works" comment needs an update..
> 
>  Same patch, comment updated.

Thanks, is nice.

But I actually meant this comment, from readahead.c:

 *
 * When readahead is in the off state (size == -1UL), readahead is disabled.
 * In this state, prev_page is used to detect the resumption of sequential I/O.
 *


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/2] readahead: simplify ra->size testing
  2005-03-03  1:59 ` Andrew Morton
@ 2005-03-03 10:08   ` Oleg Nesterov
  2005-03-03  9:28     ` Andrew Morton
  0 siblings, 1 reply; 4+ messages in thread
From: Oleg Nesterov @ 2005-03-03 10:08 UTC (permalink / raw)
  To: Andrew Morton; +Cc: linux-kernel, linuxram, slpratt

Andrew Morton wrote:
> 
> So...  the big "how it all works" comment needs an update..

Same patch, comment updated.

Currently page_cache_readahead() treats ra->size == 0 (first read)
and ra->size == -1 (ra_off was called) separately, but does exactly
the same in both cases.

With this patch we may assume that the reading starts in 'ra_off()'
state, so we don't need to consider the first read as a special case.


file_ra_state_init() sets
	ra->prev_page = -1;
	ra->size      =  0;

When the page_cache_readahead() is called for the first time it sets
ra->size to nonzero value either via get_init_ra_size() or ra_off().
So ra->size == 0 implies that ra->prev_page == -1. I am ignoring the
case when readahead is disabled via ra->ra_pages == 0.


page_cache_readahead detects sub-page sized reads:
	if (offset == ra->prev_page && req_size == 1 && ra->size != 0)

But if offset == ra->prev_page, then ra->size == 0 can happen only if
offset == -1, so there is no need to check ra->size here. If application
starts reading 16Tb file from the last page then readahead can't help.


First offset==0 read or first sequential detection:
	if ((ra->size == 0 && offset == 0) || (ra->size == -1 && sequential)
could be changed to:
	if ((ra->size == 0 && sequential) || (ra->size == -1 && sequential)
which means:
	if (sequential && (ra->size == 0 || ra->size == -1))


Random case detection:
	if (!sequential || (ra->size == 0))
But if sequential == 1, then ra->size can't be 0, this case is already handled
before.


Now we have:

	if (offset == ra->prev_page && req_size == 1)
		/* sub-page reads */

	if (sequential && (ra->size == 0 || ra->size == -1))
		/* first offset==0 read or first sequential */

	if (!sequential)
		/* random case */

Now ->size is checked only in one place, so ra_off() can set ra->size = 0,
and we can just test ->size against 0.

Signed-off-by: Oleg Nesterov <oleg@tv-sign.ru>

--- 2.6.11/mm/readahead.c~	2005-02-04 21:33:40.000000000 +0300
+++ 2.6.11/mm/readahead.c	2005-02-04 21:33:57.000000000 +0300
@@ -55,7 +55,7 @@ static inline void ra_off(struct file_ra
 {
 	ra->start = 0;
 	ra->flags = 0;
-	ra->size = -1;
+	ra->size = 0;
 	ra->ahead_start = 0;
 	ra->ahead_size = 0;
 	return;
@@ -452,7 +452,7 @@ page_cache_readahead(struct address_spac
 	 * perturbing the readahead window expansion logic.
 	 * If size is zero, there is no read ahead window so we need one
 	 */
-	if (offset == ra->prev_page && req_size == 1 && ra->size != 0)
+	if (offset == ra->prev_page && req_size == 1)
 		goto out;
 
 	ra->prev_page = offset;
@@ -471,9 +471,7 @@ page_cache_readahead(struct address_spac
 	 * at start of file, and grow the window fast.  Or detect first
 	 * sequential access
 	 */
-	if ((ra->size == 0 && offset == 0)	/* first io and start of file */
-	    || (ra->size == -1 && sequential)) {
-		/* First sequential */
+	if (sequential && ra->size == 0) {
 		ra->size = get_init_ra_size(newsize, max);
 		ra->start = offset;
 		if (!blockable_page_cache_readahead(mapping, filp, offset,
@@ -499,7 +497,7 @@ page_cache_readahead(struct address_spac
 	 * partial page reads and first access were handled above,
 	 * so this must be the next page otherwise it is random
 	 */
-	if (!sequential || (ra->size == 0)) {
+	if (!sequential) {
 		ra_off(ra);
 		blockable_page_cache_readahead(mapping, filp, offset,
 				 newsize, ra, 1);

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2005-03-03  9:30 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-03-02 19:08 [PATCH 1/2] readahead: simplify ra->size testing Oleg Nesterov
2005-03-03  1:59 ` Andrew Morton
2005-03-03 10:08   ` Oleg Nesterov
2005-03-03  9:28     ` Andrew Morton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox