From patchwork Tue May 7 06:20:05 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wang Shilong X-Patchwork-Id: 2532111 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id 85B04DF215 for ; Tue, 7 May 2013 06:27:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756634Ab3EGG1z (ORCPT ); Tue, 7 May 2013 02:27:55 -0400 Received: from cn.fujitsu.com ([222.73.24.84]:1039 "EHLO song.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1755999Ab3EGG1y (ORCPT ); Tue, 7 May 2013 02:27:54 -0400 X-IronPort-AV: E=Sophos;i="4.87,627,1363104000"; d="scan'208";a="7204203" Received: from unknown (HELO tang.cn.fujitsu.com) ([10.167.250.3]) by song.cn.fujitsu.com with ESMTP; 07 May 2013 14:25:04 +0800 Received: from fnstmail02.fnst.cn.fujitsu.com (tang.cn.fujitsu.com [127.0.0.1]) by tang.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id r476Esqw020496; Tue, 7 May 2013 14:14:54 +0800 Received: from [127.0.0.1] ([10.167.233.203]) by fnstmail02.fnst.cn.fujitsu.com (Lotus Domino Release 8.5.3) with ESMTP id 2013050714140035-1043893 ; Tue, 7 May 2013 14:14:00 +0800 Message-ID: <51889D15.9050308@cn.fujitsu.com> Date: Tue, 07 May 2013 14:20:05 +0800 From: Wang Shilong User-Agent: Thunderbird 2.0.0.9 (Windows/20071031) MIME-Version: 1.0 To: Linux Btrfs CC: Jan Schmidt Subject: [PATCH] Btrfs: fix passing wrong arg gfp_t to decide the correct allocation mode X-MIMETrack: Itemize by SMTP Server on mailserver/fnst(Release 8.5.3|September 15, 2011) at 2013/05/07 14:14:00, Serialize by Router on mailserver/fnst(Release 8.5.3|September 15, 2011) at 2013/05/07 14:14:01, Serialize complete at 2013/05/07 14:14:01 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org If you look the code carefully, you will see all the tree_mod_alloc() has to use GFP_ATOMIC. However, the original code pass the wrong arg gfp_t in some places, this dosen't cause any problems, because in the tree_mod_alloc(), it ignores arg gfp_t and just use GFP_ATOMIC directly, this is not good. However, i think we should try best not to allocate with GFP_ATOMIC, so i keep the gfp_t there in the hope we can change allocation mode in the future. Signed-off-by: Wang Shilong --- fs/btrfs/ctree.c | 37 ++++++++++++++++++------------------- 1 files changed, 18 insertions(+), 19 deletions(-) diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c index de6de8e..33c9061 100644 --- a/fs/btrfs/ctree.c +++ b/fs/btrfs/ctree.c @@ -553,7 +553,7 @@ static inline int tree_mod_alloc(struct btrfs_fs_info *fs_info, gfp_t flags, * once we switch from spin locks to something different, we should * honor the flags parameter here. */ - tm = *tm_ret = kzalloc(sizeof(*tm), GFP_ATOMIC); + tm = *tm_ret = kzalloc(sizeof(*tm), flags); if (!tm) return -ENOMEM; @@ -591,14 +591,14 @@ __tree_mod_log_insert_key(struct btrfs_fs_info *fs_info, static noinline int tree_mod_log_insert_key_mask(struct btrfs_fs_info *fs_info, struct extent_buffer *eb, int slot, - enum mod_log_op op, gfp_t flags) + enum mod_log_op op) { int ret; if (tree_mod_dont_log(fs_info, eb)) return 0; - ret = __tree_mod_log_insert_key(fs_info, eb, slot, op, flags); + ret = __tree_mod_log_insert_key(fs_info, eb, slot, op, GFP_ATOMIC); tree_mod_log_write_unlock(fs_info); return ret; @@ -608,7 +608,7 @@ static noinline int tree_mod_log_insert_key(struct btrfs_fs_info *fs_info, struct extent_buffer *eb, int slot, enum mod_log_op op) { - return tree_mod_log_insert_key_mask(fs_info, eb, slot, op, GFP_NOFS); + return tree_mod_log_insert_key_mask(fs_info, eb, slot, op); } static noinline int @@ -616,13 +616,13 @@ tree_mod_log_insert_key_locked(struct btrfs_fs_info *fs_info, struct extent_buffer *eb, int slot, enum mod_log_op op) { - return __tree_mod_log_insert_key(fs_info, eb, slot, op, GFP_NOFS); + return __tree_mod_log_insert_key(fs_info, eb, slot, op, GFP_ATOMIC); } static noinline int tree_mod_log_insert_move(struct btrfs_fs_info *fs_info, struct extent_buffer *eb, int dst_slot, int src_slot, - int nr_items, gfp_t flags) + int nr_items) { struct tree_mod_elem *tm; int ret; @@ -642,7 +642,7 @@ tree_mod_log_insert_move(struct btrfs_fs_info *fs_info, BUG_ON(ret < 0); } - ret = tree_mod_alloc(fs_info, flags, &tm); + ret = tree_mod_alloc(fs_info, GFP_ATOMIC, &tm); if (ret < 0) goto out; @@ -679,7 +679,7 @@ __tree_mod_log_free_eb(struct btrfs_fs_info *fs_info, struct extent_buffer *eb) static noinline int tree_mod_log_insert_root(struct btrfs_fs_info *fs_info, struct extent_buffer *old_root, - struct extent_buffer *new_root, gfp_t flags, + struct extent_buffer *new_root, int log_removal) { struct tree_mod_elem *tm; @@ -691,7 +691,7 @@ tree_mod_log_insert_root(struct btrfs_fs_info *fs_info, if (log_removal) __tree_mod_log_free_eb(fs_info, old_root); - ret = tree_mod_alloc(fs_info, flags, &tm); + ret = tree_mod_alloc(fs_info, GFP_ATOMIC, &tm); if (ret < 0) goto out; @@ -809,19 +809,18 @@ tree_mod_log_eb_move(struct btrfs_fs_info *fs_info, struct extent_buffer *dst, { int ret; ret = tree_mod_log_insert_move(fs_info, dst, dst_offset, src_offset, - nr_items, GFP_NOFS); + nr_items); BUG_ON(ret < 0); } static noinline void tree_mod_log_set_node_key(struct btrfs_fs_info *fs_info, - struct extent_buffer *eb, int slot, int atomic) + struct extent_buffer *eb, int slot) { int ret; ret = tree_mod_log_insert_key_mask(fs_info, eb, slot, - MOD_LOG_KEY_REPLACE, - atomic ? GFP_ATOMIC : GFP_NOFS); + MOD_LOG_KEY_REPLACE); BUG_ON(ret < 0); } @@ -843,7 +842,7 @@ tree_mod_log_set_root_pointer(struct btrfs_root *root, { int ret; ret = tree_mod_log_insert_root(root->fs_info, root->node, - new_root_node, GFP_NOFS, log_removal); + new_root_node, log_removal); BUG_ON(ret < 0); } @@ -1886,7 +1885,7 @@ static noinline int balance_level(struct btrfs_trans_handle *trans, struct btrfs_disk_key right_key; btrfs_node_key(right, &right_key, 0); tree_mod_log_set_node_key(root->fs_info, parent, - pslot + 1, 0); + pslot + 1); btrfs_set_node_key(parent, &right_key, pslot + 1); btrfs_mark_buffer_dirty(parent); } @@ -1931,7 +1930,7 @@ static noinline int balance_level(struct btrfs_trans_handle *trans, struct btrfs_disk_key mid_key; btrfs_node_key(mid, &mid_key, 0); tree_mod_log_set_node_key(root->fs_info, parent, - pslot, 0); + pslot); btrfs_set_node_key(parent, &mid_key, pslot); btrfs_mark_buffer_dirty(parent); } @@ -2030,7 +2029,7 @@ static noinline int push_nodes_for_insert(struct btrfs_trans_handle *trans, orig_slot += left_nr; btrfs_node_key(mid, &disk_key, 0); tree_mod_log_set_node_key(root->fs_info, parent, - pslot, 0); + pslot); btrfs_set_node_key(parent, &disk_key, pslot); btrfs_mark_buffer_dirty(parent); if (btrfs_header_nritems(left) > orig_slot) { @@ -2083,7 +2082,7 @@ static noinline int push_nodes_for_insert(struct btrfs_trans_handle *trans, btrfs_node_key(right, &disk_key, 0); tree_mod_log_set_node_key(root->fs_info, parent, - pslot + 1, 0); + pslot + 1); btrfs_set_node_key(parent, &disk_key, pslot + 1); btrfs_mark_buffer_dirty(parent); @@ -2963,7 +2962,7 @@ static void fixup_low_keys(struct btrfs_root *root, struct btrfs_path *path, if (!path->nodes[i]) break; t = path->nodes[i]; - tree_mod_log_set_node_key(root->fs_info, t, tslot, 1); + tree_mod_log_set_node_key(root->fs_info, t, tslot); btrfs_set_node_key(t, key, tslot); btrfs_mark_buffer_dirty(path->nodes[i]); if (tslot != 0)