Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2339134imu; Fri, 23 Nov 2018 07:49:36 -0800 (PST) X-Google-Smtp-Source: AJdET5f61gRyh582Rn8TshdvMvlRjqYo64ayljtkuVxNI9903Ni1lS5d9KAw0EN60zXap7Zm9g4t X-Received: by 2002:a63:e655:: with SMTP id p21mr14437320pgj.70.1542988176308; Fri, 23 Nov 2018 07:49:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542988176; cv=none; d=google.com; s=arc-20160816; b=A54Zk2iJau+mQ9w6EaQ+lbpKSosvhQxACSDnXvZAazy1rA5NP8Ojza55t+FmXv9R5z /BlI6BhRPJlp4OaUU5fhNK4UYEvVwVUXVN3vHv0CMlIn1CMsiKFQo3i72qSUMv3dCOfG W+Dp/KhR2fF+P91tL9exeTLacUOVvuTFzX7P18ERYVBE2PMNWrzFA8uv68+3zGi8rzM3 Hhsz80M3lSPoUQsv5+KXw7twSMJTdw+qbC7VUleeAUS14JG8c0muT/mqirCFOd/kCwx4 trGXj7BUrWH9P+yEL4gcWCMqpw++cmQ6CT0FRnf4llip9Xs1kVTMCDkAf/kKtzZ5+kjS hKTw== 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:cc:to:subject; bh=juTO/eWhb3DZr+3Y1cB33IG612+y6LkJRE8rP4BPCnQ=; b=ou3wBAEGO6fSZEbH5PPNOiZmblfsH0GStaY40tdgMsjp0KiV9uoddEKEn61ukzblT8 4o2EHLeBECTJ9ycSoGzKEN1tlI0mOdZeXtC4zdQkcnhBTjOtW9oqczf6RKN25RlKWJmq 5Cgh07VSVz2dVW03S8HHtZFtB3146SqxCT5+5+6KB1KSnkc1JMtAnxZDVHqDENDymRod yc3IFSfA06A3/b/7wBNSNKSWQJeAgVM7aqKnhPS2bG0kdJB6hnaHGyxGOXGxHvhH+k7d t95+snQdy3bI94PSY9Ez6jQjH6WJRSUNrVCu4rDQOCMuDkAmMTnJ5M0n494Etpy9wAfy mW8Q== 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 j1si1792506pff.42.2018.11.23.07.49.17; Fri, 23 Nov 2018 07:49:36 -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 S2390885AbeKVWzh (ORCPT + 99 others); Thu, 22 Nov 2018 17:55:37 -0500 Received: from szxga06-in.huawei.com ([45.249.212.32]:46062 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1732390AbeKVWzh (ORCPT ); Thu, 22 Nov 2018 17:55:37 -0500 Received: from DGGEMS403-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 04F1CAACC4862; Thu, 22 Nov 2018 20:16:21 +0800 (CST) Received: from [127.0.0.1] (10.134.22.195) by DGGEMS403-HUB.china.huawei.com (10.3.19.203) with Microsoft SMTP Server id 14.3.408.0; Thu, 22 Nov 2018 20:16:17 +0800 Subject: Re: [PATCH 2/2] f2fs: fix memory leak of quota files extent tree and it's nodes To: Sahitya Tummala , Jaegeuk Kim , CC: References: <1542884360-19470-1-git-send-email-stummala@codeaurora.org> <1542884360-19470-2-git-send-email-stummala@codeaurora.org> From: Chao Yu Message-ID: <47e3b4e7-c1a6-f130-5765-d212ac9de367@huawei.com> Date: Thu, 22 Nov 2018 20:16:15 +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: <1542884360-19470-2-git-send-email-stummala@codeaurora.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 2018/11/22 18:59, Sahitya Tummala wrote: > When there is a failure in f2fs_fill_super() after the quota is > enabled, then f2fs_quota_off_umount() is called in the error handling. > Then sbi is freed up and f2fs_fill_super() retries again. > But f2fs_quota_off_umount() doesn't guarantee that quota file's extent > tree/nodes are removed/freed. It will just add to sbi->zombie_list, > if those files are referenced. In the next retry, quota is enabled > again with the new extent tree and nodes, causing memory leak for the > previously allocated memory. > > Fix this by cleaning up the sbi->zombie_list before freeing sbi and > before the next retry. I guess we can fix this issue with the same way as the comment I add in your previous patch, how do you think? Thanks, > > Signed-off-by: Sahitya Tummala > --- > fs/f2fs/extent_cache.c | 21 +++++++++++++++++++++ > fs/f2fs/f2fs.h | 1 + > fs/f2fs/super.c | 5 +++++ > 3 files changed, 27 insertions(+) > > diff --git a/fs/f2fs/extent_cache.c b/fs/f2fs/extent_cache.c > index 763ba83..c2bcd88 100644 > --- a/fs/f2fs/extent_cache.c > +++ b/fs/f2fs/extent_cache.c > @@ -629,6 +629,27 @@ static void f2fs_update_extent_tree_range(struct inode *inode, > f2fs_mark_inode_dirty_sync(inode, true); > } > > +void f2fs_cleanup_zombie_list(struct f2fs_sb_info *sbi) > +{ > + struct extent_tree *et, *next; > + > + mutex_lock(&sbi->extent_tree_lock); > + list_for_each_entry_safe(et, next, &sbi->zombie_list, list) { > + if (atomic_read(&et->node_cnt)) { > + write_lock(&et->lock); > + __free_extent_tree(sbi, et); > + write_unlock(&et->lock); > + } > + f2fs_bug_on(sbi, atomic_read(&et->node_cnt)); > + list_del_init(&et->list); > + radix_tree_delete(&sbi->extent_tree_root, et->ino); > + kmem_cache_free(extent_tree_slab, et); > + atomic_dec(&sbi->total_ext_tree); > + atomic_dec(&sbi->total_zombie_tree); > + } > + mutex_unlock(&sbi->extent_tree_lock); > +} > + > unsigned int f2fs_shrink_extent_tree(struct f2fs_sb_info *sbi, int nr_shrink) > { > struct extent_tree *et, *next; > diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h > index db8a919..6807815 100644 > --- a/fs/f2fs/f2fs.h > +++ b/fs/f2fs/f2fs.h > @@ -3419,6 +3419,7 @@ void f2fs_update_extent_cache_range(struct dnode_of_data *dn, > void f2fs_init_extent_cache_info(struct f2fs_sb_info *sbi); > int __init f2fs_create_extent_cache(void); > void f2fs_destroy_extent_cache(void); > +void f2fs_cleanup_zombie_list(struct f2fs_sb_info *sbi); > > /* > * sysfs.c > diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c > index f41ac43..521fe3f 100644 > --- a/fs/f2fs/super.c > +++ b/fs/f2fs/super.c > @@ -3023,6 +3023,11 @@ void f2fs_cleanup_extent_cache(struct f2fs_sb_info *sbi) > > list_for_each_entry_safe(inode, next, &sb->s_inodes, i_sb_list) > f2fs_destroy_extent_tree(inode, true); > + > + f2fs_cleanup_zombie_list(sbi); > + > + f2fs_bug_on(sbi, !list_empty(&sbi->zombie_list)); > + f2fs_bug_on(sbi, !list_empty(&sbi->extent_list)); > } > > static int f2fs_fill_super(struct super_block *sb, void *data, int silent) >