Received: by 10.223.164.200 with SMTP id h8csp666057wrb; Sun, 5 Nov 2017 18:09:51 -0800 (PST) X-Google-Smtp-Source: ABhQp+R7wkK4NTBR1pH93nktHPbFCGcnOniCbtGm/09D0oqdDvtji86B95J7wbKhg9nbbENfdNmB X-Received: by 10.98.133.10 with SMTP id u10mr14987296pfd.22.1509934191159; Sun, 05 Nov 2017 18:09:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1509934191; cv=none; d=google.com; s=arc-20160816; b=wl99gy4XoJQ3agWEK4nw7x25a56k/o8ZCSfgxUphCFnF4+kkIKI8pVrp54NWa7JAXQ RkRcduW8u3TGipHiC9WErkYtJqeXeW6yJoAIm/5mCUoRA5aPsiSgQ6Xx/BIR5TgHWvuY 7NeDPfNWVX/VxSdk1ulcZENDVKFCq+zulePZMr6Yceb4p/uG1c56LIQRTP66fiFyEEIq pzsZ7RDdx+A4Ss6SHtOUJCvPwzYR5ju2KDej5s5zi4M4fyAf+NwiC4Cq9NcdFfIIEGNx Jpszk7wWFqRd/TfbHo02WaIxMU2Pm79dmO7Ow+kTYwfkrCCyRsLBPCVg5N6flaAOmGcZ TxFA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from:arc-authentication-results; bh=xdln7QKj6md5Tr/2p879AQWb1vD5QJjskdyJaYJ71YY=; b=o0PQKJ+xrcigVeBgQZvwiyn2xBNrY+odAhaKA5ESKtYqXRAMcXsRV2ckOV53W7ATDj xqp/Q797I+gx1hcrPLeln6hO04KtNqetNQHQTgPS4Xz0GZDgv6d+rwFn/0zrjtlgcEPy StYrzjcJCeam4o2YC2QUut4cYo7NrcmN6/X5GFhe0wMFC7Y5BlAdwyPN3mQ2T5HyxlmL N91I4f/K/fUuIjzTkZtLas8/aClsEYbI24S878HQZPaEVm1CJl7Kut4iUoqxuLw5/h5T jwOc4UabzIP8Whi86Gft/wDOHhp9bRcvGk2YyVYgMj5oQYMoN4758yNSPgInGOIpfVCR SZfQ== 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 e12si9389950plj.21.2017.11.05.18.09.29; Sun, 05 Nov 2017 18:09:51 -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 S1751540AbdKFCIh (ORCPT + 96 others); Sun, 5 Nov 2017 21:08:37 -0500 Received: from szxga06-in.huawei.com ([45.249.212.32]:40385 "EHLO huawei.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1750907AbdKFCIg (ORCPT ); Sun, 5 Nov 2017 21:08:36 -0500 Received: from DGGEMS413-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 62ABF9984F239; Mon, 6 Nov 2017 10:08:23 +0800 (CST) Received: from huawei.com (10.107.193.250) by DGGEMS413-HUB.china.huawei.com (10.3.19.213) with Microsoft SMTP Server id 14.3.361.1; Mon, 6 Nov 2017 10:07:56 +0800 From: Yunlong Song To: , , , , CC: , , , , Subject: [PATCH v3] f2fs: fix out-of-free problem caused by atomic write Date: Mon, 6 Nov 2017 10:07:51 +0800 Message-ID: <1509934071-116656-1-git-send-email-yunlong.song@huawei.com> X-Mailer: git-send-email 1.8.5.2 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.107.193.250] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. Signed-off-by: Yunlong Song --- fs/f2fs/f2fs.h | 1 + fs/f2fs/segment.c | 24 +++++++++++++++++++++++- 2 files changed, 24 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..b87ede4 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,6 +418,16 @@ 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); @@ -429,7 +447,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 +455,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 From 1583278665566088564@xxx Mon Nov 06 01:36:39 +0000 2017 X-GM-THRID: 1582330312060990093 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread