Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756767AbbBEKC1 (ORCPT ); Thu, 5 Feb 2015 05:02:27 -0500 Received: from mailout4.samsung.com ([203.254.224.34]:32726 "EHLO mailout4.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752612AbbBEKC0 (ORCPT ); Thu, 5 Feb 2015 05:02:26 -0500 X-AuditID: cbfee61b-f79d76d0000024d6-09-54d33fb08ed0 From: Chao Yu To: Jaegeuk Kim , Changman Lee Cc: linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org Subject: [PATCH 1/3] f2fs: support fast lookup in extent cache Date: Thu, 05 Feb 2015 18:01:39 +0800 Message-id: <000801d0412a$d5da9bd0$818fd370$@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: AdA5SRGL7dw4LaN9So6iimAx9Bxrrw== Content-language: zh-cn X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrMLMWRmVeSWpSXmKPExsVy+t9jAd0N9pdDDOaskLC4tq+RyeLJ+lnM FpcWuVtc3jWHzYHFY9OqTjaP3Qs+M3n0bVnF6PF5k1wASxSXTUpqTmZZapG+XQJXxqbvn5kL lohWtE39yNjA+Emgi5GTQ0LARKJz+gQ2CFtM4sK99UA2F4eQwCJGie/b5kM5PxglNrz/xwxS xSagIrG84z8TiC0i4CUxaf8JFhCbWcBDorHjOyuILSxgJ/Hh0x6wGhYBVYkNd1+AxXkFLCX+ zF7ICGELSvyYfA+qV0ti/c7jTBC2vMTmNW+ZIS5SkNhx9jUjxC49iebns6DqxSU2HrnFMoFR YBaSUbOQjJqFZNQsJC0LGFlWMYqmFiQXFCel5xrpFSfmFpfmpesl5+duYgQH9TPpHYyrGiwO MQpwMCrx8FrsuxQixJpYVlyZe4hRgoNZSYRXk+NyiBBvSmJlVWpRfnxRaU5q8SFGaQ4WJXFe Jfu2ECGB9MSS1OzU1ILUIpgsEwenVAPjpCN9fkp/i85fWtsu6Pm+339W4ynXBUGsa9+kGcqG fznya5PWAyPNezWVjAeD5XcYTl8trOxWq3HqSvvrt7WrjCR+2qZVOq20dCp7xG7rnRLzO2i1 dPFUzxk9eTu7lOa7Sn/n0vw9Z/fLE743+97mLomvkvMKXW+1WPjDhyN6nbuvHvxrGZurxFKc kWioxVxUnAgACENkX2YCAAA= Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2884 Lines: 90 This patch adds a fast lookup path for rb-tree extent cache. In this patch we add a recently accessed extent node pointer 'cached_en' in extent tree. In lookup path of extent cache, we will firstly lookup the last accessed extent node which cached_en points, if we do not hit in this node, we will try to lookup extent node in rb-tree. By this way we can avoid unnecessary slow lookup in rb-tree sometimes. Note that, side-effect of this patch is that we will increase memory cost, because we will store a pointer variable in each struct extent tree additionally. Signed-off-by: Chao Yu --- fs/f2fs/data.c | 19 ++++++++++++++++--- fs/f2fs/f2fs.h | 1 + 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c index 4ba1605..112db9c 100644 --- a/fs/f2fs/data.c +++ b/fs/f2fs/data.c @@ -395,6 +395,9 @@ static void __detach_extent_node(struct f2fs_sb_info *sbi, rb_erase(&en->rb_node, &et->root); et->count--; atomic_dec(&sbi->total_ext_node); + + if (et->cached_en == en) + et->cached_en = NULL; } static struct extent_node *__lookup_extent_tree(struct extent_tree *et, @@ -403,15 +406,24 @@ static struct extent_node *__lookup_extent_tree(struct extent_tree *et, struct rb_node *node = et->root.rb_node; struct extent_node *en; + if (et->cached_en) { + struct extent_info *cei = &et->cached_en->ei; + + if (cei->fofs <= fofs && cei->fofs + cei->len > fofs) + return et->cached_en; + } + while (node) { en = rb_entry(node, struct extent_node, rb_node); - if (fofs < en->ei.fofs) + if (fofs < en->ei.fofs) { node = node->rb_left; - else if (fofs >= en->ei.fofs + en->ei.len) + } else if (fofs >= en->ei.fofs + en->ei.len) { node = node->rb_right; - else + } else { + et->cached_en = en; return en; + } } return NULL; } @@ -587,6 +599,7 @@ static void f2fs_update_extent_tree(struct inode *inode, pgoff_t fofs, memset(et, 0, sizeof(struct extent_tree)); et->ino = ino; et->root = RB_ROOT; + et->cached_en = NULL; rwlock_init(&et->lock); atomic_set(&et->refcount, 0); et->count = 0; diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index 9572f7c..47b30de 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -296,6 +296,7 @@ struct extent_node { struct extent_tree { nid_t ino; /* inode number */ struct rb_root root; /* root of extent info rb-tree */ + struct extent_node *cached_en; /* recently accessed extent node */ rwlock_t lock; /* protect extent info rb-tree */ atomic_t refcount; /* reference count of rb-tree */ unsigned int count; /* # of extent node in rb-tree*/ -- 2.2.1 -- 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/