[PATCH] readahead: simplify ra->size testing
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> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Showing
Please register or sign in to comment