Re: [RFC] iomap: fix race between readahead and direct write

From: Gao Xiang
Date: Sat Jan 18 2020 - 22:02:22 EST


On Sun, Jan 19, 2020 at 10:51:37AM +0800, yukuai (C) wrote:
>
>
> Then, there might be a problem in your implementation.
> if 'use_list' is set to true here:
> + bool use_list = mapping->a_ops->readpages;
>
> Your code do not call add_to_page_cache_lru for the page.

IMO, if use_list == true, it will call read_pages -> .readpages
and go just like the current implementation.

->.readahead is just alloc_page and then add_to_page_cache_lru
right after in time and in principle it saves some extra page
allocation.

Thanks,
Gao Xiang

> + if (use_list) {
> + page->index = page_offset;
> + list_add(&page->lru, &page_pool);
> + } else if (!add_to_page_cache_lru(page, mapping, page_offset,
> + gfp_mask)) {
> + if (nr_pages)
> + read_pages(mapping, filp, &page_pool,
> + page_offset - nr_pages,
> + nr_pages);
> + nr_pages = 0;
> + continue;
> + }
>