Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp1988pxb; Wed, 29 Sep 2021 19:19:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxe9vigNvtU5xnk4m/QjosrwzOEmMqFn9rdehol8lezEb0h1IE9eKqx2qXnxa7jIT/XkUTq X-Received: by 2002:a17:906:5384:: with SMTP id g4mr3762199ejo.27.1632968360369; Wed, 29 Sep 2021 19:19:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632968360; cv=none; d=google.com; s=arc-20160816; b=PYIDQPugdx7QigRvPmsVVWoTPIrPFtamnhhW7AsDZQYb4K94H2ob4vECPr8Gq1uhg8 n43bIk8p1GZUUObPtTWaXRA01tPZYxYWBcRxPztXGnYKgrGfdaSOtmgiMxIMPDre/fYR /wo55DxckLpzYNGJMDBR0gKDBzkBLwzb2n3O3ZtHxOtGJVITdIWNxEE6gFFBDgG1T7nP LHViHgFIFtQTJ0tJ6K5BJ6nITyosGjsHf+y0EGsIOk/99ereoYj6uU08j5Wm8qGZrnC9 BbtVnolvD+y0aONDH83obNPqkvbaSt15rWriHJEWewD9AVLeEuOxxeXqyP0a4x7gbPY6 y7KQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id; bh=7ozvuSdB+T4j4qJO29CX9QkQbkuP+/xQsvtq6SF7fGE=; b=0X2V1h4pDsya1mq7bcSgGUXzenthmpPPchgIA78VURuWY62F9l1SQnSrFHl+Pw2u5u XDUBlU7UL87avC3D3Uriewan26UyUngZBq0MK1ONViUV93AfQ0U6nPY7xhIBNokHWfQN +B7gMxhxItiBhJb7bR4mjBgxAJ6fSHe0dnlpvYxf3HeOfiUKQ8uOohXo4xaVGxlyRMaP iUgIT8TjRlTBhBqe9tUjN/posvSXwzMLQItPdAyhTpjkc3XCNKiKQiRzkhGRwlR/3zhs WEL2/SuwvXqdWsh+jhj/8UWsa1kTqwDtEU5VESXT4PfhC+TqaXPKyoQnZ10nSa8Gzs+3 7LWA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id hh20si1977472ejb.10.2021.09.29.19.18.56; Wed, 29 Sep 2021 19:19:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347596AbhI3CQP (ORCPT + 99 others); Wed, 29 Sep 2021 22:16:15 -0400 Received: from out30-45.freemail.mail.aliyun.com ([115.124.30.45]:51706 "EHLO out30-45.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232383AbhI3CQL (ORCPT ); Wed, 29 Sep 2021 22:16:11 -0400 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R131e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e01424;MF=rongwei.wang@linux.alibaba.com;NM=1;PH=DS;RN=7;SR=0;TI=SMTPD_---0Uq4fOIK_1632968067; Received: from 30.240.97.26(mailfrom:rongwei.wang@linux.alibaba.com fp:SMTPD_---0Uq4fOIK_1632968067) by smtp.aliyun-inc.com(127.0.0.1); Thu, 30 Sep 2021 10:14:28 +0800 Message-ID: Date: Thu, 30 Sep 2021 10:14:26 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:93.0) Gecko/20100101 Thunderbird/93.0 Subject: Re: [PATCH v2 1/2] mm, thp: check page mapping when truncating page cache Content-Language: en-US To: Song Liu , Matthew Wilcox Cc: Andrew Morton , Linux MM , Linux Kernel Mailing List , William Kucharski , Hugh Dickins References: <20210923194343.ca0f29e1c4d361170343a6f2@linux-foundation.org> <9e41661d-9919-d556-8c49-610dae157553@linux.alibaba.com> <68737431-01d2-e6e3-5131-7d7c731e49ae@linux.alibaba.com> From: Rongwei Wang In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 9/30/21 8:41 AM, Song Liu wrote: > On Wed, Sep 29, 2021 at 5:02 PM Matthew Wilcox wrote: >> >> On Wed, Sep 29, 2021 at 04:41:48PM -0700, Song Liu wrote: >>> The issue is NOT caused by concurrent khugepaged:collapse_file() and >>> truncate_pagecache(inode, 0). With some printks, we can see a clear >>> time gap (>2 second ) between collapse_file() finishes, and >>> truncate_pagecache() (which crashes soon). Therefore, my earlier >>> suggestion that adds deny_write_access() to collapse_file() does NOT >>> work. >>> >>> The crash is actually caused by concurrent truncate_pagecache(inode, 0). >>> If I change the number of write thread in stress_madvise_dso.c to one, >>> (IOW, one thread_read and one thread_write), I cannot reproduce the >>> crash anymore. >>> >>> I think this means we cannot fix this issue in collapse_file(), because it >>> finishes long before the crash. >> >> Ah! So are we missing one or more of these locks: >> >> inode_lock(inode); >> filemap_invalidate_lock(mapping); >> >> in the open path? > > The following fixes the crash in my test. But I am not sure whether this is the > best fix. > > Rongwei, could you please run more tests on it? Yes, I'd like to. > > Thanks, > Song > > > diff --git i/fs/open.c w/fs/open.c > index daa324606a41f..d13c4668b2e53 100644 > --- i/fs/open.c > +++ w/fs/open.c > @@ -856,8 +856,11 @@ static int do_dentry_open(struct file *f, > * of THPs into the page cache will fail. > */ > smp_mb(); > - if (filemap_nr_thps(inode->i_mapping)) > + if (filemap_nr_thps(inode->i_mapping)) { > + filemap_invalidate_lock(inode->i_mapping); Learned something, Thanks! But, the race between collapse_file and truncate_pagecache, I am not sure whether it exists or not. If exists, whether this patch only can fix truncate_pagecache concurrent? Anyway, I will run more tests on it at first. Thanks! > truncate_pagecache(inode, 0); > + filemap_invalidate_unlock(inode->i_mapping); > + } > } > > return 0; >