Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp300200ybl; Thu, 5 Dec 2019 20:33:23 -0800 (PST) X-Google-Smtp-Source: APXvYqzGkQ11QVu/qiHM4SRGrIqF8fLZ56RoCL2LGuHVvfBqhq4roLUmdZpyFOcsSXkqmr8FpiBN X-Received: by 2002:a9d:3e43:: with SMTP id h3mr9291570otg.84.1575606803889; Thu, 05 Dec 2019 20:33:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1575606803; cv=none; d=google.com; s=arc-20160816; b=bSM2GVDbcKNdn02pE0y3Lw/5OYODsgPj5ul81r/cySTJW3PUHdBLGeZJBJO/m4Dh8p Ea7CKI9eM0ThXLxcS2TPXArCYx56WCwZreI6GpbixP3MnIiedYALMME+MmQsB3SHtkIS uqFWRwXDtaOaR6wpoMiiYGKG6zeXyg9srQuayuw8NsSFdJyGksnfthOR1fymKEtZ6URr UqfAAyUl3ecEKSq1clbt1rHkA15cz1A70lGtSBBK9PJxDDxqJwP3G7dHmqMz0sBwyqaI V8hST2mJnDTkSb00jBMnYm335UybX/C3nX8HTqa53YE0K3S+jrxVr7Sx2tDlMalyZIdE 8DBA== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=bU1QMwTZg/xe8tNuljQONTxx1OviPd0HKgXxq7u1qAA=; b=LDbuAtEWME016WzoxrCYxKvpu+2Liw1K8MVJiBUWD7QzPGiuGWN52wM/lPFafG2JtM ocWD026qGh0cLzBbK+JXYGdtzcM3m4EWCX8O7Z58UrWKoAcTwidbOe/yzjp8dFAppY7p IuxYZua5GAeU2VGEP063WAI1eGoIhjzdL0WsO3vxfo6zWunD6BaippoAxwR6CQVDd6nw koJWmp2T2578haVy93ZeR/XwFMiK3BY9JEI5wgNhRxD8UgrhbB0/F/84Xnp2AOOub8X9 MZdi5PLH/kXLzB04t8JE4NG4XKmQZttzRCao5QtqlGTCh1TLhQWrnUNjsuuIAaLKU6KX BVmg== 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 t28si6497367otr.16.2019.12.05.20.33.11; Thu, 05 Dec 2019 20:33:23 -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 S1726413AbfLFEcM (ORCPT + 99 others); Thu, 5 Dec 2019 23:32:12 -0500 Received: from szxga07-in.huawei.com ([45.249.212.35]:47128 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726273AbfLFEcM (ORCPT ); Thu, 5 Dec 2019 23:32:12 -0500 Received: from DGGEMS411-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id F0B0344229A131A50F8E; Fri, 6 Dec 2019 12:32:08 +0800 (CST) Received: from [10.134.22.195] (10.134.22.195) by smtp.huawei.com (10.3.19.211) with Microsoft SMTP Server (TLS) id 14.3.439.0; Fri, 6 Dec 2019 12:32:05 +0800 Subject: Re: [PATCH] f2fs: fix to relocate f2fs_balance_fs() in mkwrite() To: Jaegeuk Kim CC: , , References: <20191206033100.36345-1-yuchao0@huawei.com> <20191206040823.GA33758@jaegeuk-macbookpro.roam.corp.google.com> From: Chao Yu Message-ID: <21133017-e538-83b4-b295-abecbcb329df@huawei.com> Date: Fri, 6 Dec 2019 12:32:05 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <20191206040823.GA33758@jaegeuk-macbookpro.roam.corp.google.com> Content-Type: text/plain; charset="windows-1252" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.134.22.195] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Jaeguek, On 2019/12/6 12:08, Jaegeuk Kim wrote: > Hi Chao, > > I was testing this. > > https://github.com/jaegeuk/f2fs/commit/76be33b9f1fce70dd2d3f04f66d0f78b418fe3f5 The patch looks good. BTW, do you mind adding below call stack into your patch? I guess it describes this ABBA deadlock with more details. :) Thanks, > > On 12/06, Chao Yu wrote: >> As Dinosaur Huang reported, there is a potential deadlock in between >> GC and mkwrite(): >> >> Thread A Thread B >> - do_page_mkwrite >> - f2fs_vm_page_mkwrite >> - lock_page >> - f2fs_balance_fs >> - mutex_lock(gc_mutex) >> - f2fs_gc >> - do_garbage_collect >> - ra_data_block >> - grab_cache_page >> - f2fs_balance_fs >> - mutex_lock(gc_mutex) >> >> In order to fix this, we just move f2fs_balance_fs() out of page lock's >> coverage in f2fs_vm_page_mkwrite(). >> >> Reported-by: Dinosaur Huang >> Signed-off-by: Chao Yu >> --- >> fs/f2fs/file.c | 4 ++-- >> 1 file changed, 2 insertions(+), 2 deletions(-) >> >> diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c >> index c0560d62dbee..ed3290225506 100644 >> --- a/fs/f2fs/file.c >> +++ b/fs/f2fs/file.c >> @@ -67,6 +67,8 @@ static vm_fault_t f2fs_vm_page_mkwrite(struct vm_fault *vmf) >> >> f2fs_bug_on(sbi, f2fs_has_inline_data(inode)); >> >> + f2fs_balance_fs(sbi, true); >> + >> file_update_time(vmf->vma->vm_file); >> down_read(&F2FS_I(inode)->i_mmap_sem); >> lock_page(page); >> @@ -120,8 +122,6 @@ static vm_fault_t f2fs_vm_page_mkwrite(struct vm_fault *vmf) >> out_sem: >> up_read(&F2FS_I(inode)->i_mmap_sem); >> >> - f2fs_balance_fs(sbi, dn.node_changed); >> - >> sb_end_pagefault(inode->i_sb); >> err: >> return block_page_mkwrite_return(err); >> -- >> 2.18.0.rc1 > . >