Re: [PATCH 27/33] readahead: laptop mode

Andrew Morton
2006-05-26T17:39:09Z

Wu Fengguang <wfg@mail.ustc.edu.cn> wrote:
>
> /*
> + * Set a new look-ahead mark at @new_index.
> + * Return 0 if the new mark is successfully set.
> + */
> +static inline int renew_lookahead(struct address_space *mapping,
> + struct file_ra_state *ra,
> + pgoff_t index, pgoff_t new_index)
> +{
> + struct page *page;
> +
> + if (index == ra->lookahead_index &&
> + new_index >= ra->readahead_index)
> + return 1;
> +
> + page = find_page(mapping, new_index);
> + if (!page)
> + return 1;
> +
> + __SetPageReadahead(page);
> + if (ra->lookahead_index == index)
> + ra->lookahead_index = new_index;
> +
> + return 0;
> +}
> +

This is a pagecache page and other CPUs can look it up and play with it.
The __SetPageReadahead() is quite wrong here.

And we don't have a reference on this page, so this code appears to be racy.

You could fix that by taking and dropping a ref on the page, but it'd be
quicker to take tree_lock and do the SetPageReadahead() while holding it.

This function is too large to inline.