Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp1104119ybl; Sat, 18 Jan 2020 18:53:54 -0800 (PST) X-Google-Smtp-Source: APXvYqwhEFvcpnEsG7+pcVUDWAiP39IIOc0xeWIDKMHKueKYIeI1ktSF41R02lKZS2z4QcusbeB3 X-Received: by 2002:a9d:3bc4:: with SMTP id k62mr11920261otc.186.1579402433970; Sat, 18 Jan 2020 18:53:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579402433; cv=none; d=google.com; s=arc-20160816; b=Ph7/6QUJgyun7CnOczi/M7lWZ1RhYJI4DQC/0d2AiWCPahkRzo/+bAjdwjNreYwG+P KXpf+MHSBGHZPYR5fH523ZMJ/oFUX+slKeEDcNQileEEgNnkF2x5hm0MrB0Y73I7bTcX +SW9S+fho0mBzTSYVf382BjmOCuT3VUP8Pj4qMb7WEors1L2mbnSoKvrazK0aYcRrBQp Tz4BzkMMVio5gA0MEoDvrIkwn14gif0y+ND+17euKFgUDdyBdBEOIcQ+lkUUdSUZufc2 ii+Ao2npiL66fIIs3zAzFJM1qt1SWvPHjoZx44bHFBYsthv3xnxZCFJHIytme/1sfh7i tcQw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:in-reply-to :mime-version:user-agent:date:message-id:from:references:cc:to :subject; bh=rTNm1m7JcoLtMw7qK7LnjSUcr75z8jlCxd4k8A6M28k=; b=cHLoIQL7hAOG23bnHfojvKqWGU7VSZIstuLMu567P2sxLBfMYmMmUCzeCQXxOxv1u0 FvIJANXZ5/gqrotenNcuHxz34vxtyYd22ibhg2Rnz4fsaPes1wd3W7CqiB4AYaSAMnda VxnNV5qC8exaolWU16anIV5LnsD+5ujTxD0zJusvrVMnWH9ybgxHQu22oBL4QM5vupuy fXsECqSfL6uQJlmuda8w0htOJ9z6IMQdMt9Wxh59ibTm6tTsZCblH0FjLREslpotzfn5 cSf2p+Cfsu5lkOXGD/vuARZbVPcTdC+a1CRV5FRI68Q8ZbaHU8GvpRxb9Ftx3Z7dSj4f hmxQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p21si19202896otk.162.2020.01.18.18.53.28; Sat, 18 Jan 2020 18:53:53 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728709AbgASCvx (ORCPT + 99 others); Sat, 18 Jan 2020 21:51:53 -0500 Received: from szxga06-in.huawei.com ([45.249.212.32]:60552 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727573AbgASCvx (ORCPT ); Sat, 18 Jan 2020 21:51:53 -0500 Received: from DGGEMS403-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 2D13A706A1201A9528AE; Sun, 19 Jan 2020 10:51:48 +0800 (CST) Received: from [127.0.0.1] (10.173.220.96) by DGGEMS403-HUB.china.huawei.com (10.3.19.203) with Microsoft SMTP Server id 14.3.439.0; Sun, 19 Jan 2020 10:51:38 +0800 Subject: Re: [RFC] iomap: fix race between readahead and direct write To: Matthew Wilcox CC: , , , , , , , References: <20200116063601.39201-1-yukuai3@huawei.com> <20200118230826.GA5583@bombadil.infradead.org> <20200119014213.GA16943@bombadil.infradead.org> From: "yukuai (C)" Message-ID: <64d617cc-e7fe-6848-03bb-aab3498c9a07@huawei.com> Date: Sun, 19 Jan 2020 10:51:37 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 In-Reply-To: <20200119014213.GA16943@bombadil.infradead.org> Content-Type: text/plain; charset="gbk"; format=flowed Content-Transfer-Encoding: 7bit X-Originating-IP: [10.173.220.96] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2020/1/19 9:42, Matthew Wilcox wrote: > Did you read my patch series? The current code allocates pages, > but does not put them in the page cache until after iomap is called. > My patch series changes that to put the pages in the page cache as soon > as they're allocated, and before iomap is called. I just read you patch series again. At first, if you try to add all pages to pagecache and lock them before iomap_begin. I thought aboult it before, but I throw away the idea becacuse all other operation that will lock the page will need to wait for readahead to finish. And it might cause problem for performance overhead. And if you try to add each page to page cache and call iomap before adding the next page. Then, we are facing the same CPU overhead issure. 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. + 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; + } And later, you replace 'iomap_next_page' with 'readahead_page' +static inline +struct page *readahead_page(struct address_space *mapping, loff_t pos) +{ + struct page *page = xa_load(&mapping->i_pages, pos / PAGE_SIZE); + VM_BUG_ON_PAGE(!PageLocked(page), page); + + return page; +} + It seems that the page will never add to page cache. Thanks! Yu Kuai