Received: by 10.223.148.5 with SMTP id 5csp6342917wrq; Wed, 17 Jan 2018 12:28:26 -0800 (PST) X-Google-Smtp-Source: ACJfBotyGvaF9JSk3BY2yu3MfhC93Ed/dzB7AxS/u2eXPcgbWFi/P8NdBvBdAyQ21sgNhMua1OL1 X-Received: by 10.98.174.8 with SMTP id q8mr20159274pff.109.1516220906732; Wed, 17 Jan 2018 12:28:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516220906; cv=none; d=google.com; s=arc-20160816; b=kvM9g9JgT+H3eazQ4pM7oYNIMXY2Ih3YvXHrm/xPCgnqYimzOrjQXXlCcek2SGi13j Kfhd1KO4OIeqwydDcBFgAhCpRujfk9kuA6XqxTzJm/HXiUdkMuKAIwvi3F6eYa/fxhM7 Rbt9Pz30cClLbPExizoalBg/4sheyRPNYuVirmE3k9XBxey+vCV5xMerlWI9M3vAwxV3 gMNGwgBIlL9AdZhPQ0XVvcacD8+St3IPQ/BHjsbQSzsM1QAmLJyTlAQrQC7dzMpH2/k5 pONBRlSq8CMzGlg9AiTg8yTV90ydQxYpbpIpCPiuvgEzGdWBH7fP6QkHF/PgBywji0g1 dGDg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=/a6OGWRc2ZLVnDjmJc12Mjc/f/sFqqYukAEJhi/KYjo=; b=Draq6eWTgPdWhgjJHxao13L9mbkTEc/AvWg0Lf3d0GxHRIaK2WhO7iQDwPrHZZRLEl Tm/FAEmgOb6nkXpr/p1chJoL7hVRFBxEzxHEtoDZKVjcbOxKiWiKf2HptmFAj2RugOrf N0rnu0M64iuxrEwpiQLeNMdOAJwcTeWKcmlHBqP2QJ/F+9rnelFdIb/sCWIHhDYPmQV6 G8AzygHyRXgo1zeZV4FOTvF9y4GqfAePibqsTooSvhXMWYnR3Z2bFsTdmwH4/U2jvMv4 7Y7vdyi0maW6DTwyHO93F54oirvuRHSpokAitiKXLVRzetV3d4it+HYX9PV9bP76lDXc Uodw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=efn8fvAU; 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 1si5172621plc.205.2018.01.17.12.28.12; Wed, 17 Jan 2018 12:28:26 -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; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=efn8fvAU; 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 S1754209AbeAQU0y (ORCPT + 99 others); Wed, 17 Jan 2018 15:26:54 -0500 Received: from bombadil.infradead.org ([65.50.211.133]:40135 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753128AbeAQUXG (ORCPT ); Wed, 17 Jan 2018 15:23:06 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=References:In-Reply-To:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=/a6OGWRc2ZLVnDjmJc12Mjc/f/sFqqYukAEJhi/KYjo=; b=efn8fvAUACKFKPKaEaureEs4R wnlOJ/seiL1eUALkkSpEbvCrSkDO3G7C0z8h7XDthvsIstRxdcXg2ZHyP5+WHLuZKZVq98hG1hJd0 d5oDYelnr18UzmZqVC7P4kSEL1z1yqcWpQ2cynw/r5QKATpl2WY5YanwelP2acILAOKmGPaSEp8sa 9cLUM8S9sL0OMhwEmK0O0uUNkGgosWyIGQNqkHF7f7LqMTo9D2nppJcO46gPAANzhIbvTrWprcBmS VvDii+dZiqJY0i9c8vnh0lP1EFtWIuWeridDjCMxYiBmwj1qOVw9+B334XD5TqOe/ljTu9P+viKEn WygANlSYQ==; Received: from willy by bombadil.infradead.org with local (Exim 4.89 #1 (Red Hat Linux)) id 1ebuEi-0006LE-VZ; Wed, 17 Jan 2018 20:23:04 +0000 From: Matthew Wilcox To: linux-kernel@vger.kernel.org Cc: Matthew Wilcox , linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, linux-nilfs@vger.kernel.org, linux-btrfs@vger.kernel.org, linux-xfs@vger.kernel.org, linux-usb@vger.kernel.org, Bjorn Andersson , Stefano Stabellini , iommu@lists.linux-foundation.org, linux-remoteproc@vger.kernel.org, linux-s390@vger.kernel.org, intel-gfx@lists.freedesktop.org, cgroups@vger.kernel.org, linux-sh@vger.kernel.org, David Howells Subject: [PATCH v6 94/99] f2fs: Convert extent_tree_root to XArray Date: Wed, 17 Jan 2018 12:21:58 -0800 Message-Id: <20180117202203.19756-95-willy@infradead.org> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180117202203.19756-1-willy@infradead.org> References: <20180117202203.19756-1-willy@infradead.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Matthew Wilcox Rename it to extent_array and use the xa_lock in place of the extent_tree_lock mutex. Signed-off-by: Matthew Wilcox --- fs/f2fs/extent_cache.c | 59 +++++++++++++++++++++++++------------------------- fs/f2fs/f2fs.h | 3 +-- 2 files changed, 30 insertions(+), 32 deletions(-) diff --git a/fs/f2fs/extent_cache.c b/fs/f2fs/extent_cache.c index ff2352a0ed15..da5f3bd1808d 100644 --- a/fs/f2fs/extent_cache.c +++ b/fs/f2fs/extent_cache.c @@ -250,25 +250,25 @@ static struct extent_tree *__grab_extent_tree(struct inode *inode) struct extent_tree *et; nid_t ino = inode->i_ino; - mutex_lock(&sbi->extent_tree_lock); - et = radix_tree_lookup(&sbi->extent_tree_root, ino); - if (!et) { - et = f2fs_kmem_cache_alloc(extent_tree_slab, GFP_NOFS); - f2fs_radix_tree_insert(&sbi->extent_tree_root, ino, et); - memset(et, 0, sizeof(struct extent_tree)); - et->ino = ino; - et->root = RB_ROOT; - et->cached_en = NULL; - rwlock_init(&et->lock); - INIT_LIST_HEAD(&et->list); - atomic_set(&et->node_cnt, 0); - atomic_inc(&sbi->total_ext_tree); - } else { + et = xa_load(&sbi->extent_array, ino); + if (et) { atomic_dec(&sbi->total_zombie_tree); list_del_init(&et->list); + goto out; } - mutex_unlock(&sbi->extent_tree_lock); + et = f2fs_kmem_cache_alloc(extent_tree_slab, GFP_NOFS | __GFP_ZERO); + et->ino = ino; + et->root = RB_ROOT; + et->cached_en = NULL; + rwlock_init(&et->lock); + INIT_LIST_HEAD(&et->list); + atomic_set(&et->node_cnt, 0); + + xa_store(&sbi->extent_array, ino, et, GFP_NOFS); + atomic_inc(&sbi->total_ext_tree); + +out: /* never died until evict_inode */ F2FS_I(inode)->extent_tree = et; @@ -622,7 +622,7 @@ unsigned int f2fs_shrink_extent_tree(struct f2fs_sb_info *sbi, int nr_shrink) if (!atomic_read(&sbi->total_zombie_tree)) goto free_node; - if (!mutex_trylock(&sbi->extent_tree_lock)) + if (!xa_trylock(&sbi->extent_array)) goto out; /* 1. remove unreferenced extent tree */ @@ -634,7 +634,7 @@ unsigned int f2fs_shrink_extent_tree(struct f2fs_sb_info *sbi, int nr_shrink) } f2fs_bug_on(sbi, atomic_read(&et->node_cnt)); list_del_init(&et->list); - radix_tree_delete(&sbi->extent_tree_root, et->ino); + xa_erase(&sbi->extent_array, et->ino); kmem_cache_free(extent_tree_slab, et); atomic_dec(&sbi->total_ext_tree); atomic_dec(&sbi->total_zombie_tree); @@ -642,13 +642,13 @@ unsigned int f2fs_shrink_extent_tree(struct f2fs_sb_info *sbi, int nr_shrink) if (node_cnt + tree_cnt >= nr_shrink) goto unlock_out; - cond_resched(); + cond_resched_lock(&sbi->extent_array.xa_lock); } - mutex_unlock(&sbi->extent_tree_lock); + xa_unlock(&sbi->extent_array); free_node: /* 2. remove LRU extent entries */ - if (!mutex_trylock(&sbi->extent_tree_lock)) + if (!xa_trylock(&sbi->extent_array)) goto out; remained = nr_shrink - (node_cnt + tree_cnt); @@ -678,7 +678,7 @@ unsigned int f2fs_shrink_extent_tree(struct f2fs_sb_info *sbi, int nr_shrink) spin_unlock(&sbi->extent_lock); unlock_out: - mutex_unlock(&sbi->extent_tree_lock); + xa_unlock(&sbi->extent_array); out: trace_f2fs_shrink_extent_tree(sbi, node_cnt, tree_cnt); @@ -725,23 +725,23 @@ void f2fs_destroy_extent_tree(struct inode *inode) if (inode->i_nlink && !is_bad_inode(inode) && atomic_read(&et->node_cnt)) { - mutex_lock(&sbi->extent_tree_lock); + xa_lock(&sbi->extent_array); list_add_tail(&et->list, &sbi->zombie_list); atomic_inc(&sbi->total_zombie_tree); - mutex_unlock(&sbi->extent_tree_lock); + xa_unlock(&sbi->extent_array); return; } /* free all extent info belong to this extent tree */ node_cnt = f2fs_destroy_extent_node(inode); - /* delete extent tree entry in radix tree */ - mutex_lock(&sbi->extent_tree_lock); + /* delete extent from array */ + xa_lock(&sbi->extent_array); f2fs_bug_on(sbi, atomic_read(&et->node_cnt)); - radix_tree_delete(&sbi->extent_tree_root, inode->i_ino); - kmem_cache_free(extent_tree_slab, et); + __xa_erase(&sbi->extent_array, inode->i_ino); atomic_dec(&sbi->total_ext_tree); - mutex_unlock(&sbi->extent_tree_lock); + xa_unlock(&sbi->extent_array); + kmem_cache_free(extent_tree_slab, et); F2FS_I(inode)->extent_tree = NULL; @@ -787,8 +787,7 @@ void f2fs_update_extent_cache_range(struct dnode_of_data *dn, void init_extent_cache_info(struct f2fs_sb_info *sbi) { - INIT_RADIX_TREE(&sbi->extent_tree_root, GFP_NOIO); - mutex_init(&sbi->extent_tree_lock); + xa_init(&sbi->extent_array); INIT_LIST_HEAD(&sbi->extent_list); spin_lock_init(&sbi->extent_lock); atomic_set(&sbi->total_ext_tree, 0); diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index b3ee784b49bc..4eacef9c7274 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -1064,8 +1064,7 @@ struct f2fs_sb_info { spinlock_t inode_lock[NR_INODE_TYPE]; /* for dirty inode list lock */ /* for extent tree cache */ - struct radix_tree_root extent_tree_root;/* cache extent cache entries */ - struct mutex extent_tree_lock; /* locking extent radix tree */ + struct xarray extent_array; /* cache extent cache entries */ struct list_head extent_list; /* lru list for shrinker */ spinlock_t extent_lock; /* locking extent lru list */ atomic_t total_ext_tree; /* extent tree count */ -- 2.15.1