From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1948496AbcBSKNo (ORCPT ); Fri, 19 Feb 2016 05:13:44 -0500 Received: from mailout2.samsung.com ([203.254.224.25]:56972 "EHLO mailout2.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932824AbcBSKNl (ORCPT ); Fri, 19 Feb 2016 05:13:41 -0500 X-AuditID: cbfee61b-f793c6d00000236c-2d-56c6ead444d9 From: Chao Yu To: Jaegeuk Kim Cc: linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org Subject: [PATCH v2 3/7] f2fs: reorder nat cache lock in cache_nat_entry Date: Fri, 19 Feb 2016 18:12:28 +0800 Message-id: <01d101d16afe$3497b510$9dc71f30$@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: AdFq/bihyCDMcN9RSrCcyg5zSUnUwQ== Content-language: zh-cn X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrFLMWRmVeSWpSXmKPExsVy+t9jAd0rr46FGZzfIGPxZP0sZotLi9wt Lu+aw+bA7LFpVSebx+4Fn5k8Pm+SC2CO4rJJSc3JLEst0rdL4Mq4tGcue8EasYq5V2axNTB2 CXUxcnJICJhI/H/wkxnCFpO4cG89WxcjF4eQwFJGiW2PzrJCOK8YJT4ca2YDqWITUJFY3vGf CcQWAbIPLbrMDmIzC3hINHZ8ZwWxhQXcJY5+6wWLswioSjxZMg1oAwcHr4ClxP+WFJAwr4Cg xI/J91ggWrUkNm9rYoWw5SU2r3kLdZCCxI6zrxlBWkUE9CTaVmdAlIhLbDxyi2UCo8AsJJNm IZk0C8mkWUhaFjCyrGKUSC1ILihOSs81ykst1ytOzC0uzUvXS87P3cQIDuFn0jsYD+9yP8Qo wMGoxMNboXcsTIg1say4MvcQowQHs5IIb+9LoBBvSmJlVWpRfnxRaU5q8SFGaQ4WJXHex//X hQkJpCeWpGanphakFsFkmTg4pRoYA+LYUmIi1713+bZL/cj7x/zG7bWcQkFFLlU9b/senj98 596DttPlzjubBULm/Va4dK6s8bK45Iaas/u3zDJh6PF5VKzOcDJHoDft1apNO5t2StdOdp7q PvHSO5FN03aUcHlZpCWtX+6X6/PAOCv2027j5+17p56/dVhyoUGM3g31iRuO7Go/p8RSnJFo qMVcVJwIAB8nM6ldAgAA Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When lookuping nat entry in cache_nat_entry, if we fail to hit nat cache, we try to load nat entries a) from journal of current segment cache or b) from NAT pages for updating, during the process, write lock of nat_tree_lock will be held to avoid inconsistent condition in between nid cache and nat cache caused by racing among nat entry shrinker, checkpointer, nat entry updater. But this way may cause low efficient when updating nat cache, because it serializes accessing in journal cache or reading NAT pages. Here, we reorder lock and update flow as below to enhance accessing concurrency: - get_node_info - down_read(nat_tree_lock) - lookup nat cache --- hit -> unlock & return - lookup journal cache --- hit -> unlock & goto update - up_read(nat_tree_lock) update: - down_write(nat_tree_lock) - cache_nat_entry - lookup nat cache --- nohit -> update - up_write(nat_tree_lock) Signed-off-by: Chao Yu --- v2: - update commit log for readability and more details. fs/f2fs/node.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c index 94b8016..966176b 100644 --- a/fs/f2fs/node.c +++ b/fs/f2fs/node.c @@ -257,15 +257,20 @@ static struct nat_entry *grab_nat_entry(struct f2fs_nm_info *nm_i, nid_t nid) return new; } -static void cache_nat_entry(struct f2fs_nm_info *nm_i, nid_t nid, +static void cache_nat_entry(struct f2fs_sb_info *sbi, nid_t nid, struct f2fs_nat_entry *ne) { + struct f2fs_nm_info *nm_i = NM_I(sbi); struct nat_entry *e; e = __lookup_nat_cache(nm_i, nid); if (!e) { e = grab_nat_entry(nm_i, nid); node_info_from_raw_nat(&e->ni, ne); + } else { + f2fs_bug_on(sbi, nat_get_ino(e) != ne->ino || + nat_get_blkaddr(e) != ne->block_addr || + nat_get_version(e) != ne->version); } } @@ -371,15 +376,12 @@ void get_node_info(struct f2fs_sb_info *sbi, nid_t nid, struct node_info *ni) ni->ino = nat_get_ino(e); ni->blk_addr = nat_get_blkaddr(e); ni->version = nat_get_version(e); - } - up_read(&nm_i->nat_tree_lock); - if (e) + up_read(&nm_i->nat_tree_lock); return; + } memset(&ne, 0, sizeof(struct f2fs_nat_entry)); - down_write(&nm_i->nat_tree_lock); - /* Check current segment summary */ down_read(&curseg->journal_rwsem); i = lookup_journal_in_cursum(journal, NAT_JOURNAL, nid, 0); @@ -398,8 +400,10 @@ void get_node_info(struct f2fs_sb_info *sbi, nid_t nid, struct node_info *ni) node_info_from_raw_nat(ni, &ne); f2fs_put_page(page, 1); cache: + up_read(&nm_i->nat_tree_lock); /* cache nat entry */ - cache_nat_entry(NM_I(sbi), nid, &ne); + down_write(&nm_i->nat_tree_lock); + cache_nat_entry(sbi, nid, &ne); up_write(&nm_i->nat_tree_lock); } -- 2.7.0