From patchwork Wed Jan 17 20:21:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 10170859 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 6F76360386 for ; Wed, 17 Jan 2018 20:27:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 61F2620163 for ; Wed, 17 Jan 2018 20:27:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 56538207A7; Wed, 17 Jan 2018 20:27:20 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C7A472074F for ; Wed, 17 Jan 2018 20:27:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754429AbeAQU0z (ORCPT ); Wed, 17 Jan 2018 15:26:55 -0500 Received: from bombadil.infradead.org ([65.50.211.133]:59931 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754011AbeAQUXF (ORCPT ); Wed, 17 Jan 2018 15:23:05 -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=7NlhZLzEe862nsjjn+PzkATmLIpT8jJP4lXQ6PTbYLg=; b=tNpBishKcVY2TJvh04kJ6iLEe wuI80h9QimCuAUMH5JwxTqo74bjKHkzu4SDLyqQeRR1TW3HWbqfdD97P8/RF8QlSI84VvyvWq3RHZ IY5opuVMnXjquNJ/EOmcyXF0G18dTmJVtzyDQoGzf06Oe04rQpBpu8tCgMQiIz06Ls6nEzMN5HvEc mu/kE616fg93M3ST1sO9u8ThokoAaYjRFqWxO9wL7E9Uzc98vTkC1VmGCGjsF3zkq7WFAlTP2AhHv 9ta2u2rjPWI3fiH1c5vcJRJOo/JtUdQMQIaB9ZfvWKgJvyHeUhEQmIerd/7YHT3w8NM74djGpICDG Rzt/9sReQ==; Received: from willy by bombadil.infradead.org with local (Exim 4.89 #1 (Red Hat Linux)) id 1ebuEi-0006Kk-K4; 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 93/99] f2fs: Convert ino_root to XArray Date: Wed, 17 Jan 2018 12:21:57 -0800 Message-Id: <20180117202203.19756-94-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-sh-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sh@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Matthew Wilcox I did a fairly major rewrite of __add_ino_entry(); please check carefully. Also, we can remove ino_list unless it's important to write out orphan inodes in the order they were orphaned. It may also make more sense to combine the array of inode_management structures into a single XArray with tags, but that would be a job for someone who understands this filesystem better than I do. Signed-off-by: Matthew Wilcox --- fs/f2fs/checkpoint.c | 85 +++++++++++++++++++++++----------------------------- fs/f2fs/f2fs.h | 3 +- 2 files changed, 38 insertions(+), 50 deletions(-) diff --git a/fs/f2fs/checkpoint.c b/fs/f2fs/checkpoint.c index 4aa69bc1c70a..04d69679da13 100644 --- a/fs/f2fs/checkpoint.c +++ b/fs/f2fs/checkpoint.c @@ -403,33 +403,30 @@ static void __add_ino_entry(struct f2fs_sb_info *sbi, nid_t ino, struct inode_management *im = &sbi->im[type]; struct ino_entry *e, *tmp; - tmp = f2fs_kmem_cache_alloc(ino_entry_slab, GFP_NOFS); - - radix_tree_preload(GFP_NOFS | __GFP_NOFAIL); - - spin_lock(&im->ino_lock); - e = radix_tree_lookup(&im->ino_root, ino); - if (!e) { - e = tmp; - if (unlikely(radix_tree_insert(&im->ino_root, ino, e))) - f2fs_bug_on(sbi, 1); - - memset(e, 0, sizeof(struct ino_entry)); - e->ino = ino; - - list_add_tail(&e->list, &im->ino_list); - if (type != ORPHAN_INO) - im->ino_num++; + xa_lock(&im->ino_root); + e = xa_load(&im->ino_root, ino); + if (e) + goto found; + xa_unlock(&im->ino_root); + + tmp = f2fs_kmem_cache_alloc(ino_entry_slab, GFP_NOFS | __GFP_ZERO); + xa_lock(&im->ino_root); + e = __xa_cmpxchg(&im->ino_root, ino, NULL, tmp, + GFP_NOFS | __GFP_NOFAIL); + if (e) { + kmem_cache_free(ino_entry_slab, tmp); + goto found; } + e = tmp; + e->ino = ino; + list_add_tail(&e->list, &im->ino_list); + if (type != ORPHAN_INO) + im->ino_num++; +found: if (type == FLUSH_INO) f2fs_set_bit(devidx, (char *)&e->dirty_device); - - spin_unlock(&im->ino_lock); - radix_tree_preload_end(); - - if (e != tmp) - kmem_cache_free(ino_entry_slab, tmp); + xa_unlock(&im->ino_root); } static void __remove_ino_entry(struct f2fs_sb_info *sbi, nid_t ino, int type) @@ -437,17 +434,14 @@ static void __remove_ino_entry(struct f2fs_sb_info *sbi, nid_t ino, int type) struct inode_management *im = &sbi->im[type]; struct ino_entry *e; - spin_lock(&im->ino_lock); - e = radix_tree_lookup(&im->ino_root, ino); + xa_lock(&im->ino_root); + e = __xa_erase(&im->ino_root, ino); if (e) { list_del(&e->list); - radix_tree_delete(&im->ino_root, ino); im->ino_num--; - spin_unlock(&im->ino_lock); kmem_cache_free(ino_entry_slab, e); - return; } - spin_unlock(&im->ino_lock); + xa_unlock(&im->ino_root); } void add_ino_entry(struct f2fs_sb_info *sbi, nid_t ino, int type) @@ -466,12 +460,8 @@ void remove_ino_entry(struct f2fs_sb_info *sbi, nid_t ino, int type) bool exist_written_data(struct f2fs_sb_info *sbi, nid_t ino, int mode) { struct inode_management *im = &sbi->im[mode]; - struct ino_entry *e; - spin_lock(&im->ino_lock); - e = radix_tree_lookup(&im->ino_root, ino); - spin_unlock(&im->ino_lock); - return e ? true : false; + return xa_load(&im->ino_root, ino) ? true : false; } void release_ino_entry(struct f2fs_sb_info *sbi, bool all) @@ -482,14 +472,14 @@ void release_ino_entry(struct f2fs_sb_info *sbi, bool all) for (i = all ? ORPHAN_INO : APPEND_INO; i < MAX_INO_ENTRY; i++) { struct inode_management *im = &sbi->im[i]; - spin_lock(&im->ino_lock); + xa_lock(&im->ino_root); list_for_each_entry_safe(e, tmp, &im->ino_list, list) { list_del(&e->list); - radix_tree_delete(&im->ino_root, e->ino); + __xa_erase(&im->ino_root, e->ino); kmem_cache_free(ino_entry_slab, e); im->ino_num--; } - spin_unlock(&im->ino_lock); + xa_unlock(&im->ino_root); } } @@ -506,11 +496,11 @@ bool is_dirty_device(struct f2fs_sb_info *sbi, nid_t ino, struct ino_entry *e; bool is_dirty = false; - spin_lock(&im->ino_lock); - e = radix_tree_lookup(&im->ino_root, ino); + xa_lock(&im->ino_root); + e = xa_load(&im->ino_root, ino); if (e && f2fs_test_bit(devidx, (char *)&e->dirty_device)) is_dirty = true; - spin_unlock(&im->ino_lock); + xa_unlock(&im->ino_root); return is_dirty; } @@ -519,11 +509,11 @@ int acquire_orphan_inode(struct f2fs_sb_info *sbi) struct inode_management *im = &sbi->im[ORPHAN_INO]; int err = 0; - spin_lock(&im->ino_lock); + xa_lock(&im->ino_root); #ifdef CONFIG_F2FS_FAULT_INJECTION if (time_to_inject(sbi, FAULT_ORPHAN)) { - spin_unlock(&im->ino_lock); + xa_unlock(&im->ino_root); f2fs_show_injection_info(FAULT_ORPHAN); return -ENOSPC; } @@ -532,7 +522,7 @@ int acquire_orphan_inode(struct f2fs_sb_info *sbi) err = -ENOSPC; else im->ino_num++; - spin_unlock(&im->ino_lock); + xa_unlock(&im->ino_root); return err; } @@ -541,10 +531,10 @@ void release_orphan_inode(struct f2fs_sb_info *sbi) { struct inode_management *im = &sbi->im[ORPHAN_INO]; - spin_lock(&im->ino_lock); + xa_lock(&im->ino_root); f2fs_bug_on(sbi, im->ino_num == 0); im->ino_num--; - spin_unlock(&im->ino_lock); + xa_unlock(&im->ino_root); } void add_orphan_inode(struct inode *inode) @@ -677,7 +667,7 @@ static void write_orphan_inodes(struct f2fs_sb_info *sbi, block_t start_blk) orphan_blocks = GET_ORPHAN_BLOCKS(im->ino_num); /* - * we don't need to do spin_lock(&im->ino_lock) here, since all the + * we don't need to lock the ino_root here, since all the * orphan inode operations are covered under f2fs_lock_op(). * And, spin_lock should be avoided due to page operations below. */ @@ -1433,8 +1423,7 @@ void init_ino_entry_info(struct f2fs_sb_info *sbi) for (i = 0; i < MAX_INO_ENTRY; i++) { struct inode_management *im = &sbi->im[i]; - INIT_RADIX_TREE(&im->ino_root, GFP_ATOMIC); - spin_lock_init(&im->ino_lock); + xa_init(&im->ino_root); INIT_LIST_HEAD(&im->ino_list); im->ino_num = 0; } diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index 6abf26c31d01..b3ee784b49bc 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -994,8 +994,7 @@ enum inode_type { /* for inner inode cache management */ struct inode_management { - struct radix_tree_root ino_root; /* ino entry array */ - spinlock_t ino_lock; /* for ino entry lock */ + struct xarray ino_root; /* ino entry array */ struct list_head ino_list; /* inode list head */ unsigned long ino_num; /* number of entries */ };