Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753555AbbHSLRV (ORCPT ); Wed, 19 Aug 2015 07:17:21 -0400 Received: from mailout3.samsung.com ([203.254.224.33]:36716 "EHLO mailout3.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752171AbbHSLRU (ORCPT ); Wed, 19 Aug 2015 07:17:20 -0400 X-AuditID: cbfee61a-f79a06d000005c6f-de-55d465bfc12b From: Chao Yu To: Jaegeuk Kim Cc: linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org Subject: [PATCH 8/9] f2fs: lookup neighbor extent nodes for merging later Date: Wed, 19 Aug 2015 19:16:09 +0800 Message-id: <017c01d0da70$9d13feb0$d73bfc10$@samsung.com> MIME-version: 1.0 Content-type: text/plain; charset=us-ascii Content-transfer-encoding: 7bit X-Mailer: Microsoft Outlook 14.0 Thread-index: AdDacHL4Zxh7sfUHQdyYYnASnAI8CQ== Content-language: zh-cn X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrFLMWRmVeSWpSXmKPExsVy+t9jAd39qVdCDf584rJ4sn4Ws8WlRe4W l3fNYXNg9ti0qpPNY/eCz0wenzfJBTBHcdmkpOZklqUW6dslcGWcP85dcFGs4uIWnwbGNqEu Rk4OCQETiTVLfrNA2GISF+6tZ+ti5OIQEljKKHFh+hQmCOcVo8SUtbcZQarYBFQklnf8ZwKx RYDsQ4sus4PYzAIeEo0d31lBbGEBT4kn52eDTWURUJU4+qMfrJdXwFLiwK79TBC2oMSPyfdY IHq1JNbvPM4EYctLbF7zlhniIgWJHWdfM0Ls0pM4su4VM0SNuMTGI7dYJjAKzEIyahaSUbOQ jJqFpGUBI8sqRonUguSC4qT0XMO81HK94sTc4tK8dL3k/NxNjOAQfia1g/HgLvdDjAIcjEo8 vDO2XQ4VYk0sK67MPcQowcGsJMJ7K+FKqBBvSmJlVWpRfnxRaU5q8SFGaQ4WJXFe2Q2bQ4UE 0hNLUrNTUwtSi2CyTBycUg2MdYf2WW8ovLgzpMFkmUn5kSWc7suNm9Kk79+W6pTeH//9Led+ a2mD59wOU0qFo8XzGEx/7v60xdP3rfIFY8H3H9aKiLTeuZYk4NSjvz2Yu+7zAkclk9dtCr8L 5ITf7F8bzTmRScUwoDfyZ1lh1MVHa8/ZLd3PbH3fK4pvDfMk//B59y7ubFmpxFKckWioxVxU nAgAAuNGQF0CAAA= Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3045 Lines: 102 In __lookup_extent_tree_ret we will not try to find neighbor nodes if we find the target node, in this condition, we will lost the chance to merge the new mapping with exist extent node later. So our extent cache of inode will be fragmented after overwrite exist file, we can see the number of extent node increases intensively in following test case: dd if=/dev/zero of=/mnt/f2fs/4m bs=4K count=1024 Extent Cache: - Hit Count: L1-1:0 L1-2:0 L2:0 - Hit Ratio: 0% (0 / 3072) - Inner Struct Count: tree: 1, node: 1 dd if=/dev/zero of=/mnt/f2fs/4m bs=4K count=1024 conv=notrunc Extent Cache: - Hit Count: L1-1:2048 L1-2:0 L2:0 - Hit Ratio: 33% (2048 / 6144) - Inner Struct Count: tree: 1, node: 961 This patch fixes to lookup neighbors of target node for further merging. Signed-off-by: Chao Yu --- fs/f2fs/extent_cache.c | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/fs/f2fs/extent_cache.c b/fs/f2fs/extent_cache.c index ab26728..dcfeb43 100644 --- a/fs/f2fs/extent_cache.c +++ b/fs/f2fs/extent_cache.c @@ -254,13 +254,21 @@ static struct extent_node *__lookup_extent_tree_ret(struct extent_tree *et, { struct rb_node **pnode = &et->root.rb_node; struct rb_node *parent = NULL, *tmp_node; - struct extent_node *en; + struct extent_node *en = et->cached_en; - if (et->cached_en) { - struct extent_info *cei = &et->cached_en->ei; + *insert_p = NULL; + *insert_parent = NULL; + *prev_ex = NULL; + *next_ex = NULL; + + if (RB_EMPTY_ROOT(&et->root)) + return NULL; + + if (en) { + struct extent_info *cei = &en->ei; if (cei->fofs <= fofs && cei->fofs + cei->len > fofs) - return et->cached_en; + goto lookup_neighbors; } while (*pnode) { @@ -272,7 +280,7 @@ static struct extent_node *__lookup_extent_tree_ret(struct extent_tree *et, else if (fofs >= en->ei.fofs + en->ei.len) pnode = &(*pnode)->rb_right; else - return en; + goto lookup_neighbors; } *insert_p = pnode; @@ -290,8 +298,22 @@ static struct extent_node *__lookup_extent_tree_ret(struct extent_tree *et, tmp_node = rb_prev(parent); *prev_ex = tmp_node ? rb_entry(tmp_node, struct extent_node, rb_node) : NULL; - return NULL; + +lookup_neighbors: + if (fofs == en->ei.fofs) { + /* lookup prev node for merging backward later */ + tmp_node = rb_prev(&en->rb_node); + *prev_ex = tmp_node ? + rb_entry(tmp_node, struct extent_node, rb_node) : NULL; + } + if (fofs == en->ei.fofs + en->ei.len - 1) { + /* lookup next node for merging frontward later */ + tmp_node = rb_next(&en->rb_node); + *next_ex = tmp_node ? + rb_entry(tmp_node, struct extent_node, rb_node) : NULL; + } + return en; } static struct extent_node *__try_merge_extent_node(struct f2fs_sb_info *sbi, -- 2.4.2 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/