Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp284715ybl; Thu, 5 Dec 2019 20:09:28 -0800 (PST) X-Google-Smtp-Source: APXvYqzG1QJl8fSyGbz3e7sy0rz8Po5kp7XXOICDstEtX7sQq+GQ20pRsrRO+BB9vjT7aq6Cc49P X-Received: by 2002:aca:481:: with SMTP id 123mr344548oie.110.1575605368436; Thu, 05 Dec 2019 20:09:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1575605368; cv=none; d=google.com; s=arc-20160816; b=G+4ImpyPw8dZCGSYqcoJLwBw5LexuIQ0BtYr14TjfGvaxL8vOVzsqS18EVb/CP94Gb WQ2uA6XVHxj8c9izUR0sxtH1zLpaG6KQk5K/aJ7THbEngSLu/1n2WrznNV2OUlv0QwWg JeZSKe7opxdeoJpZIRE0YVvwH3zDucd+G3aWN682hXkzDBuITGE1cKCZ4P6w68Uf5wTA a5yrptA7tmeRnMtNL+4smQIua3hzP7ffwSSleScw/5SrwMQ+D9EMGCdt0mzV/8JWdT4R BMa5TNeD2Ppw+S2MFGncdwUlw+loqr52WTRR2C9gqoGl3aRlJBp08N6BEJLlBcCX+3b5 SEng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=Nj3xns2x/AlA74QkXu0IUlkm6jU1rHGT51/KYm8MWvE=; b=e0f+dvoILrMIRX7R3tnl9GrTMKVoE+L1upnzon7IWUnlGq9bt6pA2V7i3zld4iQwKC Ypg4Fg6EAJXk6xLSyr0CFV3PCB9793ppbyf3+vx9hIfw/vDnGuxA6tlm5x7oWQUQtm66 X5+x1JiMjWYWiPBn2WEGUIc7278CWnB+TwTxUjpHYr+HgiV153GCur+YBYWfGZEhcaDX 982wt2TOR5JHoTFecDpRN/gujgJyaASKl21LtqGyDdV13NfrreCQFYLtitx3XVcMHFcM 85HaUzCcWWAW8VruMNXtBA4IEupD/0PapimFn23YA2h85txyVoxWi9pT8vLowG+3ceWR ZfoA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=GGiMLRPF; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i78si6424073oib.1.2019.12.05.20.09.15; Thu, 05 Dec 2019 20:09:28 -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; dkim=pass header.i=@kernel.org header.s=default header.b=GGiMLRPF; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726287AbfLFEIZ (ORCPT + 99 others); Thu, 5 Dec 2019 23:08:25 -0500 Received: from mail.kernel.org ([198.145.29.99]:44480 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726076AbfLFEIZ (ORCPT ); Thu, 5 Dec 2019 23:08:25 -0500 Received: from localhost (unknown [104.132.0.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 95F1621823; Fri, 6 Dec 2019 04:08:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1575605304; bh=j7VIs/pP2Li7ttXFZelak/7oq+uT2fUP9Er5lq8WUk4=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=GGiMLRPFljplVbwHEJ4djhtj0Keydq/B2UZcK8qlSb7S0+JXXTO0pN4NsR/d+5xZO 9u06KvCL6artBVKWPAvj9zPBC9PCtiXrNyTFStTagz1Rb3YhVkMvdmad3a1fQQmeBl L8dru2gtvpk005BznlEd0JOLFWqG6WmsdkMZDnqA= Date: Thu, 5 Dec 2019 20:08:23 -0800 From: Jaegeuk Kim To: Chao Yu Cc: linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, chao@kernel.org Subject: Re: [PATCH] f2fs: fix to relocate f2fs_balance_fs() in mkwrite() Message-ID: <20191206040823.GA33758@jaegeuk-macbookpro.roam.corp.google.com> References: <20191206033100.36345-1-yuchao0@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20191206033100.36345-1-yuchao0@huawei.com> User-Agent: Mutt/1.8.2 (2017-04-18) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Chao, I was testing this. https://github.com/jaegeuk/f2fs/commit/76be33b9f1fce70dd2d3f04f66d0f78b418fe3f5 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