From patchwork Thu May 14 21:14:11 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jaegeuk Kim X-Patchwork-Id: 6409901 Return-Path: X-Original-To: patchwork-linux-fsdevel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 82D159F32B for ; Thu, 14 May 2015 21:14:27 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 93DEB20498 for ; Thu, 14 May 2015 21:14:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8C82A20494 for ; Thu, 14 May 2015 21:14:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1161126AbbENVOU (ORCPT ); Thu, 14 May 2015 17:14:20 -0400 Received: from mail.kernel.org ([198.145.29.136]:35525 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1161118AbbENVOS (ORCPT ); Thu, 14 May 2015 17:14:18 -0400 Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 8E47120498; Thu, 14 May 2015 21:14:16 +0000 (UTC) Received: from localhost (unknown [166.177.249.80]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 795F920494; Thu, 14 May 2015 21:14:15 +0000 (UTC) Date: Thu, 14 May 2015 14:14:11 -0700 From: Jaegeuk Kim To: hujianyang Cc: "linux-fsdevel@vger.kernel.org" , linux-f2fs-devel@lists.sourceforge.net Subject: Re: [f2fs-dev] Space leak in f2fs Message-ID: <20150514211250.GA76424@jaegeuk-mac02.mot.com> References: <5552FA7D.7000704@huawei.com> <20150513174417.GA56247@jaegeuk-mac02.mot.com> <20150514002417.GC68412@jaegeuk-mac02> <5553FD09.9030508@huawei.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <5553FD09.9030508@huawei.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Hi Hu, I've been rethinking about whole this issue differently. And, now I'm starting to test with the below patch instead of previous one. Thanks, Signed-off-by: Jaegeuk Kim --- fs/f2fs/checkpoint.c | 19 +++++++++++++++++++ fs/f2fs/data.c | 4 ++++ fs/f2fs/f2fs.h | 1 + fs/f2fs/super.c | 15 --------------- 4 files changed, 24 insertions(+), 15 deletions(-) diff --git a/fs/f2fs/checkpoint.c b/fs/f2fs/checkpoint.c index 7b7a9d8..74875fb 100644 --- a/fs/f2fs/checkpoint.c +++ b/fs/f2fs/checkpoint.c @@ -378,6 +378,20 @@ static void __remove_ino_entry(struct f2fs_sb_info *sbi, nid_t ino, int type) spin_unlock(&im->ino_lock); } +static bool __exist_ino_entry(struct f2fs_sb_info *sbi, nid_t ino, int type) +{ + struct inode_management *im = &sbi->im[type]; + struct ino_entry *e; + bool exist = false; + + spin_lock(&im->ino_lock); + e = radix_tree_lookup(&im->ino_root, ino); + if (e) + exist = true; + spin_unlock(&im->ino_lock); + return exist; +} + void add_dirty_inode(struct f2fs_sb_info *sbi, nid_t ino, int type) { /* add new dirty ino entry into list */ @@ -458,6 +472,11 @@ void remove_orphan_inode(struct f2fs_sb_info *sbi, nid_t ino) __remove_ino_entry(sbi, ino, ORPHAN_INO); } +bool is_orphan_inode(struct f2fs_sb_info *sbi, nid_t ino) +{ + return __exist_ino_entry(sbi, ino, ORPHAN_INO); +} + static void recover_orphan_inode(struct f2fs_sb_info *sbi, nid_t ino) { struct inode *inode = f2fs_iget(sbi->sb, ino); diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c index b0cc2aa..1988f5f 100644 --- a/fs/f2fs/data.c +++ b/fs/f2fs/data.c @@ -1749,6 +1749,10 @@ write: goto out; } + /* if orphan inode, we don't need to write its data */ + if (is_orphan_inode(sbi, inode->i_ino)) + goto out; + if (!wbc->for_reclaim) need_balance_fs = true; else if (has_not_enough_free_secs(sbi, 0)) diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index 8f1f21a..697346a 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -1726,6 +1726,7 @@ int acquire_orphan_inode(struct f2fs_sb_info *); void release_orphan_inode(struct f2fs_sb_info *); void add_orphan_inode(struct f2fs_sb_info *, nid_t); void remove_orphan_inode(struct f2fs_sb_info *, nid_t); +bool is_orphan_inode(struct f2fs_sb_info *, nid_t); void recover_orphan_inodes(struct f2fs_sb_info *); int get_valid_checkpoint(struct f2fs_sb_info *); void update_dirty_page(struct inode *, struct page *); diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index 19438f2..1d0973a 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -422,20 +422,6 @@ static struct inode *f2fs_alloc_inode(struct super_block *sb) return &fi->vfs_inode; } -static int f2fs_drop_inode(struct inode *inode) -{ - /* - * This is to avoid a deadlock condition like below. - * writeback_single_inode(inode) - * - f2fs_write_data_page - * - f2fs_gc -> iput -> evict - * - inode_wait_for_writeback(inode) - */ - if (!inode_unhashed(inode) && inode->i_state & I_SYNC) - return 0; - return generic_drop_inode(inode); -} - /* * f2fs_dirty_inode() is called from __mark_inode_dirty() * @@ -759,7 +745,6 @@ restore_opts: static struct super_operations f2fs_sops = { .alloc_inode = f2fs_alloc_inode, - .drop_inode = f2fs_drop_inode, .destroy_inode = f2fs_destroy_inode, .write_inode = f2fs_write_inode, .dirty_inode = f2fs_dirty_inode,