Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp4992050ybe; Mon, 9 Sep 2019 18:49:04 -0700 (PDT) X-Google-Smtp-Source: APXvYqwevMBxmQ68mKb/JzYAf7hamDYikseLi2vDR1XS7g8q19GwIEAsa3XyhWikYRWa3t+ePd5c X-Received: by 2002:a05:6402:1854:: with SMTP id v20mr27676141edy.43.1568080143935; Mon, 09 Sep 2019 18:49:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568080143; cv=none; d=google.com; s=arc-20160816; b=GoagjfJvdZUGBLOoha9bKGeofjOwvd5G5E3SNZ+vOvELg3JfV9zhWnsIHrhcyGO3Q1 iyQuFBogvkYJy9isurWOi8BeYf1z32qcOCucPqxqgcM2ngaKTH6wtAAczEPyxoLpZvUL CbYkZZeon9kMZ+LSdnxP+Gc5tWF2R8qkhZ/mqzgdIAusQGUSn1WyLibuZVdWEecm9cFJ XmO6sgzas5JsGbdMguG6Y/qrgPdtJEF7SrmTGdSw48O3LSF1AZF/KAKGaan5hTsU+rAL LSLMS8FVzgORdHqEBO32Wvho/0+Ov+Phq/4lt2+nPsCehJW5hMpLZuxjACym+bTsxvLO kG7w== 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=YbMgqgvu6UqFMbxsSDMqWIOxYDk0f0S24BmZL/tuwGM=; b=JjRXQC2y/HU/BIVInSc3v5zCOepoVnbhOm53wCdFAi1bxriM38m0sbsWxTgEZjrox1 gwnfeuLCoQzvzQLP1mEyZO7AEwzgUiHOKeWMdyVKeLK5LTi5Ljqzo8UIQcLGHcldtmw5 BWeK1rB8a1yncSM9A+fFgeScYiK0l9BPkJIItAG58PO3YR4lNIcRa4fxzEnM2GN1OvPU FSqdIbbO93rvjccw8yTIXAhSUcxQNEQp3uEGtF7IoNhCBH7z52u8H1eekzspvRogNrFV nDv0wrrkUXK8hfTBdQRbaSrCOCip45/hHW/lh8oUldEHqe8YfQYGOnnTbn+OM2Z5gwBq IlZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=oTrc87a2; 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 c14si8551223ejb.232.2019.09.09.18.48.39; Mon, 09 Sep 2019 18:49:03 -0700 (PDT) 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=oTrc87a2; 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 S2389478AbfIIIpD (ORCPT + 99 others); Mon, 9 Sep 2019 04:45:03 -0400 Received: from mail.kernel.org ([198.145.29.99]:43820 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726121AbfIIIpD (ORCPT ); Mon, 9 Sep 2019 04:45:03 -0400 Received: from localhost (unknown [148.69.85.38]) (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 26B56218DE; Mon, 9 Sep 2019 08:45:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1568018701; bh=SfOVF0UVj2/iqk0P+Dqr6jBUTLzBE5GoykPWadjNIXk=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=oTrc87a2UvuQf1FVQDO3tPM9Yg5s20LfGJLz6DJUvrOYAOmlr+YVaKiCpiJx8vBE3 s9HvF77EEnwZBcisA68SJ3ktfQ0x2ni7n0C8tV4gKLtqnkBXBtNTbViPkU7RQIk+rv 8qf4Oe96b8JHTPVNx5sfHPjgn3CE3474vv3fxPZE= Date: Mon, 9 Sep 2019 09:44:58 +0100 From: Jaegeuk Kim To: Chao Yu Cc: linux-f2fs-devel@lists.sourceforge.net, g@jaegeuk-macbookpro.roam.corp.google.com, linux-kernel@vger.kernel.org Subject: Re: [f2fs-dev] [PATCH 2/2] f2fs: avoid infinite GC loop due to stale atomic files Message-ID: <20190909084458.GA26885@jaegeuk-macbookpro.roam.corp.google.com> References: <20190909012532.20454-1-jaegeuk@kernel.org> <20190909012532.20454-2-jaegeuk@kernel.org> <20190909073011.GA21625@jaegeuk-macbookpro.roam.corp.google.com> <5a473076-14b8-768a-62ac-f686e850d5a6@huawei.com> <20190909080108.GC21625@jaegeuk-macbookpro.roam.corp.google.com> <20190909082112.GA25724@jaegeuk-macbookpro.roam.corp.google.com> <2f5b844c-f722-6a80-a4ab-61bdd72b8be4@huawei.com> <20190909083844.GC25724@jaegeuk-macbookpro.roam.corp.google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190909083844.GC25724@jaegeuk-macbookpro.roam.corp.google.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 On 09/09, Jaegeuk Kim wrote: > On 09/09, Chao Yu wrote: > > On 2019/9/9 16:21, Jaegeuk Kim wrote: > > > On 09/09, Chao Yu wrote: > > >> On 2019/9/9 16:01, Jaegeuk Kim wrote: > > >>> On 09/09, Chao Yu wrote: > > >>>> On 2019/9/9 15:30, Jaegeuk Kim wrote: > > >>>>> On 09/09, Chao Yu wrote: > > >>>>>> On 2019/9/9 9:25, Jaegeuk Kim wrote: > > >>>>>>> If committing atomic pages is failed when doing f2fs_do_sync_file(), we can > > >>>>>>> get commited pages but atomic_file being still set like: > > >>>>>>> > > >>>>>>> - inmem: 0, atomic IO: 4 (Max. 10), volatile IO: 0 (Max. 0) > > >>>>>>> > > >>>>>>> If GC selects this block, we can get an infinite loop like this: > > >>>>>>> > > >>>>>>> f2fs_submit_page_bio: dev = (253,7), ino = 2, page_index = 0x2359a8, oldaddr = 0x2359a8, newaddr = 0x2359a8, rw = READ(), type = COLD_DATA > > >>>>>>> f2fs_submit_read_bio: dev = (253,7)/(253,7), rw = READ(), DATA, sector = 18533696, size = 4096 > > >>>>>>> f2fs_get_victim: dev = (253,7), type = No TYPE, policy = (Foreground GC, LFS-mode, Greedy), victim = 4355, cost = 1, ofs_unit = 1, pre_victim_secno = 4355, prefree = 0, free = 234 > > >>>>>>> f2fs_iget: dev = (253,7), ino = 6247, pino = 5845, i_mode = 0x81b0, i_size = 319488, i_nlink = 1, i_blocks = 624, i_advise = 0x2c > > >>>>>>> f2fs_submit_page_bio: dev = (253,7), ino = 2, page_index = 0x2359a8, oldaddr = 0x2359a8, newaddr = 0x2359a8, rw = READ(), type = COLD_DATA > > >>>>>>> f2fs_submit_read_bio: dev = (253,7)/(253,7), rw = READ(), DATA, sector = 18533696, size = 4096 > > >>>>>>> f2fs_get_victim: dev = (253,7), type = No TYPE, policy = (Foreground GC, LFS-mode, Greedy), victim = 4355, cost = 1, ofs_unit = 1, pre_victim_secno = 4355, prefree = 0, free = 234 > > >>>>>>> f2fs_iget: dev = (253,7), ino = 6247, pino = 5845, i_mode = 0x81b0, i_size = 319488, i_nlink = 1, i_blocks = 624, i_advise = 0x2c > > >>>>>>> > > >>>>>>> In that moment, we can observe: > > >>>>>>> > > >>>>>>> [Before] > > >>>>>>> Try to move 5084219 blocks (BG: 384508) > > >>>>>>> - data blocks : 4962373 (274483) > > >>>>>>> - node blocks : 121846 (110025) > > >>>>>>> Skipped : atomic write 4534686 (10) > > >>>>>>> > > >>>>>>> [After] > > >>>>>>> Try to move 5088973 blocks (BG: 384508) > > >>>>>>> - data blocks : 4967127 (274483) > > >>>>>>> - node blocks : 121846 (110025) > > >>>>>>> Skipped : atomic write 4539440 (10) > > >>>>>>> > > >>>>>>> Signed-off-by: Jaegeuk Kim > > >>>>>>> --- > > >>>>>>> fs/f2fs/file.c | 10 +++++----- > > >>>>>>> 1 file changed, 5 insertions(+), 5 deletions(-) > > >>>>>>> > > >>>>>>> diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c > > >>>>>>> index 7ae2f3bd8c2f..68b6da734e5f 100644 > > >>>>>>> --- a/fs/f2fs/file.c > > >>>>>>> +++ b/fs/f2fs/file.c > > >>>>>>> @@ -1997,11 +1997,11 @@ static int f2fs_ioc_commit_atomic_write(struct file *filp) > > >>>>>>> goto err_out; > > >>>>>>> > > >>>>>>> ret = f2fs_do_sync_file(filp, 0, LLONG_MAX, 0, true); > > >>>>>>> - if (!ret) { > > >>>>>>> - clear_inode_flag(inode, FI_ATOMIC_FILE); > > >>>>>>> - F2FS_I(inode)->i_gc_failures[GC_FAILURE_ATOMIC] = 0; > > >>>>>>> - stat_dec_atomic_write(inode); > > >>>>>>> - } > > >>>>>>> + > > >>>>>>> + /* doesn't need to check error */ > > >>>>>>> + clear_inode_flag(inode, FI_ATOMIC_FILE); > > >>>>>>> + F2FS_I(inode)->i_gc_failures[GC_FAILURE_ATOMIC] = 0; > > >>>>>>> + stat_dec_atomic_write(inode); > > >>>>>> > > >>>>>> If there are still valid atomic write pages linked in .inmem_pages, it may cause > > >>>>>> memory leak when we just clear FI_ATOMIC_FILE flag. > > >>>>> > > >>>>> f2fs_commit_inmem_pages() should have flushed them. > > >>>> > > >>>> Oh, we failed to flush its nodes. > > >>>> > > >>>> However we won't clear such info if we failed to flush inmen pages, it looks > > >>>> inconsistent. > > >>>> > > >>>> Any interface needed to drop inmem pages or clear ATOMIC_FILE flag in that two > > >>>> error path? I'm not very clear how sqlite handle such error. > > >>> > > >>> f2fs_drop_inmem_pages() did that, but not in this case. > > >> > > >> What I mean is, for any error returned from atomic_commit() interface, should > > >> userspace application handle it with consistent way, like trigger > > >> f2fs_drop_inmem_pages(), so we don't need to handle it inside atomic_commit(). > > > > > > f2fs_ioc_abort_volatile_write() will be triggered. > > > > If userspace can do this, we can get rid of this patch, or am I missing sth? > > We don't know when that will come. And, other threads are waiting for GC here. > Actually, we can call this. --- fs/f2fs/file.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index 7ae2f3bd8c2f..98e2f58467d3 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -1997,11 +1997,7 @@ static int f2fs_ioc_commit_atomic_write(struct file *filp) goto err_out; ret = f2fs_do_sync_file(filp, 0, LLONG_MAX, 0, true); - if (!ret) { - clear_inode_flag(inode, FI_ATOMIC_FILE); - F2FS_I(inode)->i_gc_failures[GC_FAILURE_ATOMIC] = 0; - stat_dec_atomic_write(inode); - } + f2fs_drop_inmem_pages(inode); } else { ret = f2fs_do_sync_file(filp, 0, LLONG_MAX, 1, false); } -- 2.19.0.605.g01d371f741-goog