Received: by 10.223.164.221 with SMTP id h29csp2941869wrb; Thu, 2 Nov 2017 21:55:51 -0700 (PDT) X-Google-Smtp-Source: ABhQp+SBHJefUH0xksxK6ldHWWcQyEX/NFZolALseZOKD1WOWtLErBMLGfAi08biK8rbIlvqtk8j X-Received: by 10.99.126.84 with SMTP id o20mr5973169pgn.220.1509684951806; Thu, 02 Nov 2017 21:55:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1509684951; cv=none; d=google.com; s=arc-20160816; b=zHTdD7y4XDI4sgUCloXlZOFkGqLs5+eeln27ixvSTkM7WEY+WdNf1UIXhxs31WSU/L 63917ZbeRKW5rfQHUGbKsur8IE5X3clVvcugm/iw0D9oK2BPbRgSpj4un1nfc4uaR6Io LIEHdpzsjfDG4KrxeWxeVlRgwHNn15uekpMCLwVq1RMQrSnT0FzLMYtc4jvXJ21VXEQY aV3zg6vGLXC3FliKwumO1bJ+Qs+L2ZQPBLBqwKZcUVldxzJn34Lzwzccdtkd4KWbQqxZ B7pJQvV1rhcbo1jgwAmiOOCeHMyj9gwCeea7phR6USQHznai65f9Kjlc9Wh2gI+V0yHj eVwA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:arc-authentication-results; bh=yaW/C8p1T4JU83dV8c4UfXxSz8gs7RnjhSUaJpj0lbs=; b=g1fboYlElAUbeMTzNyJ/rlGbZD1GWYyiUUGph6dB0XHxxtk+lfo2lJyCO9R/RS4JeV GKQ2Zlxl8/HlxGRkw9HHjqqkI2Er0OQfuLJjy0HnKtBHzsUaSjn2SScty7dBVYDjUmXE Wv4qCA4o5Qvs21VikF4SsJ5kSE9Fmvk9TkFw0Mwv39W9VEUbC9QY3fqr/0coXS/ysnpo 7A1zHiyoCL/Y9R2XCBYMiMsAfnn84H+rVArn2nJxJweAtRG0hUvWDo8+Yuhc0GP/xKZp 7Hb8XPBiKFAWQf0GXur3H5i7hPv16RDJh5GsfAA4D5avGbxqRsMSQCV16FuFY+NXkMfr DKdA== 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 68si5181318pfe.145.2017.11.02.21.55.38; Thu, 02 Nov 2017 21:55:51 -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 S1753092AbdKCExk (ORCPT + 97 others); Fri, 3 Nov 2017 00:53:40 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:51919 "EHLO huawei.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1752296AbdKCExi (ORCPT ); Fri, 3 Nov 2017 00:53:38 -0400 Received: from DGGEMS405-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 5B39ED71FB311; Fri, 3 Nov 2017 12:53:25 +0800 (CST) Received: from [127.0.0.1] (10.111.220.140) by DGGEMS405-HUB.china.huawei.com (10.3.19.205) with Microsoft SMTP Server id 14.3.361.1; Fri, 3 Nov 2017 12:52:17 +0800 Subject: Re: [PATCH v2] f2fs: fix out-of-free problem caused by atomic write To: Jaegeuk Kim CC: , , , , , , , References: <1509027715-80477-1-git-send-email-yunlong.song@huawei.com> <1509368658-60355-1-git-send-email-yunlong.song@huawei.com> <20171103034618.GD11335@jaegeuk-macbookpro.roam.corp.google.com> From: Yunlong Song Message-ID: Date: Fri, 3 Nov 2017 12:48:39 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 In-Reply-To: <20171103034618.GD11335@jaegeuk-macbookpro.roam.corp.google.com> Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US X-Originating-IP: [10.111.220.140] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Because I found that it will still lead to out-of-free problem with out that check. I trace and find that it is possible that the committing date pages of the atomic file is bigger than the sbi->user_block_count - valid_user_blocks(sbi), so I add this check. On 2017/11/3 11:46, Jaegeuk Kim wrote: > On 10/30, Yunlong Song wrote: >> f2fs_balance_fs only actives once in the commit_inmem_pages, but there >> are more than one page to commit, so all the other pages will miss the >> check. This will lead to out-of-free problem when commit a very large >> file. However, we cannot do f2fs_balance_fs for each inmem page, since >> this will break atomicity. As a result, we should collect prefree >> segments if needed and stop atomic commit when there are not enough >> available blocks to write atomic pages. >> >> Signed-off-by: Yunlong Song >> --- >> fs/f2fs/f2fs.h | 1 + >> fs/f2fs/segment.c | 29 ++++++++++++++++++++++++++++- >> 2 files changed, 29 insertions(+), 1 deletion(-) >> >> diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h >> index 13a96b8..04ce48f 100644 >> --- a/fs/f2fs/f2fs.h >> +++ b/fs/f2fs/f2fs.h >> @@ -610,6 +610,7 @@ struct f2fs_inode_info { >> struct list_head inmem_pages; /* inmemory pages managed by f2fs */ >> struct task_struct *inmem_task; /* store inmemory task */ >> struct mutex inmem_lock; /* lock for inmemory pages */ >> + unsigned long inmem_blocks; /* inmemory blocks */ >> struct extent_tree *extent_tree; /* cached extent_tree entry */ >> struct rw_semaphore dio_rwsem[2];/* avoid racing between dio and gc */ >> struct rw_semaphore i_mmap_sem; >> diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c >> index 46dfbca..813c110 100644 >> --- a/fs/f2fs/segment.c >> +++ b/fs/f2fs/segment.c >> @@ -210,6 +210,7 @@ void register_inmem_page(struct inode *inode, struct page *page) >> list_add_tail(&fi->inmem_ilist, &sbi->inode_list[ATOMIC_FILE]); >> spin_unlock(&sbi->inode_lock[ATOMIC_FILE]); >> inc_page_count(F2FS_I_SB(inode), F2FS_INMEM_PAGES); >> + fi->inmem_blocks++; >> mutex_unlock(&fi->inmem_lock); >> >> trace_f2fs_register_inmem_page(page, INMEM); >> @@ -221,6 +222,7 @@ static int __revoke_inmem_pages(struct inode *inode, >> struct f2fs_sb_info *sbi = F2FS_I_SB(inode); >> struct inmem_pages *cur, *tmp; >> int err = 0; >> + struct f2fs_inode_info *fi = F2FS_I(inode); >> >> list_for_each_entry_safe(cur, tmp, head, list) { >> struct page *page = cur->page; >> @@ -263,6 +265,7 @@ static int __revoke_inmem_pages(struct inode *inode, >> list_del(&cur->list); >> kmem_cache_free(inmem_entry_slab, cur); >> dec_page_count(F2FS_I_SB(inode), F2FS_INMEM_PAGES); >> + fi->inmem_blocks--; >> } >> return err; >> } >> @@ -302,6 +305,10 @@ void drop_inmem_pages(struct inode *inode) >> if (!list_empty(&fi->inmem_ilist)) >> list_del_init(&fi->inmem_ilist); >> spin_unlock(&sbi->inode_lock[ATOMIC_FILE]); >> + if (fi->inmem_blocks) { >> + f2fs_bug_on(sbi, 1); >> + fi->inmem_blocks = 0; >> + } >> mutex_unlock(&fi->inmem_lock); >> >> clear_inode_flag(inode, FI_ATOMIC_FILE); >> @@ -326,6 +333,7 @@ void drop_inmem_page(struct inode *inode, struct page *page) >> >> f2fs_bug_on(sbi, !cur || cur->page != page); >> list_del(&cur->list); >> + fi->inmem_blocks--; >> mutex_unlock(&fi->inmem_lock); >> >> dec_page_count(sbi, F2FS_INMEM_PAGES); >> @@ -410,11 +418,26 @@ int commit_inmem_pages(struct inode *inode) >> >> INIT_LIST_HEAD(&revoke_list); >> f2fs_balance_fs(sbi, true); >> + if (prefree_segments(sbi) >> + && has_not_enough_free_secs(sbi, 0, >> + fi->inmem_blocks / BLKS_PER_SEC(sbi))) { >> + struct cp_control cpc; >> + >> + cpc.reason = __get_cp_reason(sbi); >> + err = write_checkpoint(sbi, &cpc); >> + if (err) >> + goto drop; >> + } >> f2fs_lock_op(sbi); >> >> set_inode_flag(inode, FI_ATOMIC_COMMIT); >> >> mutex_lock(&fi->inmem_lock); >> + if ((sbi->user_block_count - valid_user_blocks(sbi)) < > What does this mean? We already allocated blocks successfully? > >> + fi->inmem_blocks) { >> + err = -ENOSPC; >> + goto drop; >> + } >> err = __commit_inmem_pages(inode, &revoke_list); >> if (err) { >> int ret; >> @@ -429,7 +452,7 @@ int commit_inmem_pages(struct inode *inode) >> ret = __revoke_inmem_pages(inode, &revoke_list, false, true); >> if (ret) >> err = ret; >> - >> +drop: >> /* drop all uncommitted pages */ >> __revoke_inmem_pages(inode, &fi->inmem_pages, true, false); >> } >> @@ -437,6 +460,10 @@ int commit_inmem_pages(struct inode *inode) >> if (!list_empty(&fi->inmem_ilist)) >> list_del_init(&fi->inmem_ilist); >> spin_unlock(&sbi->inode_lock[ATOMIC_FILE]); >> + if (fi->inmem_blocks) { >> + f2fs_bug_on(sbi, 1); >> + fi->inmem_blocks = 0; >> + } >> mutex_unlock(&fi->inmem_lock); >> >> clear_inode_flag(inode, FI_ATOMIC_COMMIT); >> -- >> 1.8.5.2 > . > -- Thanks, Yunlong Song From 1583015086968499575@xxx Fri Nov 03 03:47:10 +0000 2017 X-GM-THRID: 1582330312060990093 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread