Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp4684952ybe; Mon, 9 Sep 2019 12:57:44 -0700 (PDT) X-Google-Smtp-Source: APXvYqzVZfUY01KxwjDSL/cyakwlkz+HMFHRp9CfPxmcBxjm6/M6xfwbCYEd6qjCZ4JLK9tuGBSv X-Received: by 2002:aa7:d95a:: with SMTP id l26mr26406868eds.297.1568059064515; Mon, 09 Sep 2019 12:57:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568059064; cv=none; d=google.com; s=arc-20160816; b=tSvba2p44KD9Piau6QoXtK5pJlWt8udJHC3UTE3xb4dWHQXFAuuk5hDmln6B0u1/r9 5X1lvK6mgtwoDYqY+M3lpJ+wOOvxpZ4jo1tiMGAnXpjNnuR7McoaHX2Aa+ILYu8CJrKL zRkNJUL8qB0lf0DDYewwr8F+UYDzmfSrzpAtj3e2F6uxdDXP7Tv6iFjh/Gc0Bfra1yHZ MCWaLZY4fOPBo/wQR+5GH2LzghLZ5Bc5n8bFNJLVHjJH3IAP1ewzxqD3JCiJ2mhGXfCW kAbQ7CeZu6PCs92vxVlN5tAoCzQ2TiNi52SeAsyuViGzz766t0TD15nCURQUwDuzxnIq JT9A== 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:to:subject; bh=7HRrmjgqO95tsmURj/9Gf/7JHcb/0f2aVozAMLRKPSI=; b=NhB8rKXpUsx8QvoUbHByXtf0alzMXei+NY3g77+j2fHLFobACVbivgAWKUi+BRocCR Vmr7X3UZE+T950AUjcMzGXsX4p36UU87d6lYoBgwTAWyDBxJoFfJBwL4t2afoMcR5nHj 4OqqvlMZP2k5DmQ26qqA8eHBwYYQd0G9Z//hb3TeGyMbGw1rak7VF8JySiNxaybJkeB6 S6YCVRH09CO/PnRFZHuKLeiX+bTmdgz+mAMiJULpka7ZVQx/i0yjY81Xgt8rjfQXKJ8J XADRN80FNS9ubHTSRqOjnlwM4LsKRB1eCjtk2XinKUW+gLll3pnIrW61wATgq6T1mpNP XOPA== 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 a11si8356802edh.91.2019.09.09.12.57.21; Mon, 09 Sep 2019 12:57:44 -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; 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 S1733255AbfIIDEC (ORCPT + 99 others); Sun, 8 Sep 2019 23:04:02 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:2175 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1731489AbfIIDEB (ORCPT ); Sun, 8 Sep 2019 23:04:01 -0400 Received: from DGGEMS407-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 028B022A813B78DC2CC7; Mon, 9 Sep 2019 11:03:58 +0800 (CST) Received: from [10.134.22.195] (10.134.22.195) by smtp.huawei.com (10.3.19.207) with Microsoft SMTP Server (TLS) id 14.3.439.0; Mon, 9 Sep 2019 11:03:54 +0800 Subject: Re: [f2fs-dev] [PATCH 2/2] f2fs: avoid infinite GC loop due to stale atomic files To: Jaegeuk Kim , , References: <20190909012532.20454-1-jaegeuk@kernel.org> <20190909012532.20454-2-jaegeuk@kernel.org> From: Chao Yu Message-ID: Date: Mon, 9 Sep 2019 11:03:43 +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: <20190909012532.20454-2-jaegeuk@kernel.org> 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 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. So my question is why below logic didn't handle such condition well? f2fs_gc() if (has_not_enough_free_secs(sbi, sec_freed, 0)) { if (skipped_round <= MAX_SKIP_GC_COUNT || skipped_round * 2 < round) { segno = NULL_SEGNO; goto gc_more; } if (first_skipped < last_skipped && (last_skipped - first_skipped) > sbi->skipped_gc_rwsem) { f2fs_drop_inmem_pages_all(sbi, true); segno = NULL_SEGNO; goto gc_more; } if (gc_type == FG_GC && !is_sbi_flag_set(sbi, SBI_CP_DISABLED)) ret = f2fs_write_checkpoint(sbi, &cpc); } > } else { > ret = f2fs_do_sync_file(filp, 0, LLONG_MAX, 1, false); > } >