From patchwork Wed Jan 17 20:21:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 10171119 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 E39F16055D for ; Wed, 17 Jan 2018 20:37:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D4CD3204C4 for ; Wed, 17 Jan 2018 20:37:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C909A223A1; Wed, 17 Jan 2018 20:37:34 +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 1E1C422380 for ; Wed, 17 Jan 2018 20:37:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754601AbeAQUhP (ORCPT ); Wed, 17 Jan 2018 15:37:15 -0500 Received: from bombadil.infradead.org ([65.50.211.133]:58635 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753874AbeAQUW4 (ORCPT ); Wed, 17 Jan 2018 15:22:56 -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=ZIXptT2/KaoL7mEg/+zoKIbgDp6xd9Y5i5jb+4Ns2do=; b=AhZY+mIVjoOXSn+vfWZ3CYEhe qkvnfWz0JifJE96lFqGsPKNlwB6KLiP6NI/DeHbZRb7aTaAfmKe4ExNAwKS5rDTwteNwts8yQI66n o8knvfCGh5GxxvwrgocH880LSf/hT//OnafIWEkASUXShL9oPTiOYHw7C9o5BfngspT3vsOsruU5e kKW73yplcdlvD6KlhNRgAAanBncdUNpHJf1mxPkEJg+mDt9P+/s8yQuKwEC3fSDdk6Qo34ZykRtQl cyH1F9qQVhOY6Ei95KfoXay/9ow4cpMeI4hb0OT/aVINQ0JcLJ5cGKooffejKdUCHbLLkkw1XLVba heMf+vJIg==; Received: from willy by bombadil.infradead.org with local (Exim 4.89 #1 (Red Hat Linux)) id 1ebuEY-00069N-Sr; Wed, 17 Jan 2018 20:22:54 +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 70/99] xfs: Convert m_perag_tree to XArray Date: Wed, 17 Jan 2018 12:21:34 -0800 Message-Id: <20180117202203.19756-71-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 Getting rid of the m_perag_lock lets us also get rid of the call to radix_tree_preload(). This is a relatively naive conversion; we could improve performance over the radix tree implementation by passing around xa_state pointers instead of indices, possibly at the expense of extending rcu_read_lock() periods. Signed-off-by: Matthew Wilcox --- fs/xfs/libxfs/xfs_sb.c | 9 ++++----- fs/xfs/xfs_icache.c | 35 +++++++++-------------------------- fs/xfs/xfs_icache.h | 6 +++--- fs/xfs/xfs_mount.c | 19 ++++--------------- fs/xfs/xfs_mount.h | 3 +-- 5 files changed, 21 insertions(+), 51 deletions(-) diff --git a/fs/xfs/libxfs/xfs_sb.c b/fs/xfs/libxfs/xfs_sb.c index 9b5aae2bcc0b..3b0b65eb8224 100644 --- a/fs/xfs/libxfs/xfs_sb.c +++ b/fs/xfs/libxfs/xfs_sb.c @@ -59,7 +59,7 @@ xfs_perag_get( int ref = 0; rcu_read_lock(); - pag = radix_tree_lookup(&mp->m_perag_tree, agno); + pag = xa_load(&mp->m_perag_xa, agno); if (pag) { ASSERT(atomic_read(&pag->pag_ref) >= 0); ref = atomic_inc_return(&pag->pag_ref); @@ -78,14 +78,13 @@ xfs_perag_get_tag( xfs_agnumber_t first, int tag) { + XA_STATE(xas, &mp->m_perag_xa, first); struct xfs_perag *pag; - int found; int ref; rcu_read_lock(); - found = radix_tree_gang_lookup_tag(&mp->m_perag_tree, - (void **)&pag, first, 1, tag); - if (found <= 0) { + pag = xas_find_tag(&xas, ULONG_MAX, tag); + if (!pag) { rcu_read_unlock(); return NULL; } diff --git a/fs/xfs/xfs_icache.c b/fs/xfs/xfs_icache.c index 3861d61fb265..65a8b91b2e70 100644 --- a/fs/xfs/xfs_icache.c +++ b/fs/xfs/xfs_icache.c @@ -156,13 +156,10 @@ static void xfs_reclaim_work_queue( struct xfs_mount *mp) { - - rcu_read_lock(); - if (radix_tree_tagged(&mp->m_perag_tree, XFS_ICI_RECLAIM_TAG)) { + if (xa_tagged(&mp->m_perag_xa, XFS_ICI_RECLAIM_TAG)) { queue_delayed_work(mp->m_reclaim_workqueue, &mp->m_reclaim_work, msecs_to_jiffies(xfs_syncd_centisecs / 6 * 10)); } - rcu_read_unlock(); } /* @@ -194,10 +191,7 @@ xfs_perag_set_reclaim_tag( return; /* propagate the reclaim tag up into the perag radix tree */ - spin_lock(&mp->m_perag_lock); - radix_tree_tag_set(&mp->m_perag_tree, pag->pag_agno, - XFS_ICI_RECLAIM_TAG); - spin_unlock(&mp->m_perag_lock); + xa_set_tag(&mp->m_perag_xa, pag->pag_agno, XFS_ICI_RECLAIM_TAG); /* schedule periodic background inode reclaim */ xfs_reclaim_work_queue(mp); @@ -216,10 +210,7 @@ xfs_perag_clear_reclaim_tag( return; /* clear the reclaim tag from the perag radix tree */ - spin_lock(&mp->m_perag_lock); - radix_tree_tag_clear(&mp->m_perag_tree, pag->pag_agno, - XFS_ICI_RECLAIM_TAG); - spin_unlock(&mp->m_perag_lock); + xa_clear_tag(&mp->m_perag_xa, pag->pag_agno, XFS_ICI_RECLAIM_TAG); trace_xfs_perag_clear_reclaim(mp, pag->pag_agno, -1, _RET_IP_); } @@ -847,12 +838,10 @@ void xfs_queue_eofblocks( struct xfs_mount *mp) { - rcu_read_lock(); - if (radix_tree_tagged(&mp->m_perag_tree, XFS_ICI_EOFBLOCKS_TAG)) + if (xa_tagged(&mp->m_perag_xa, XFS_ICI_EOFBLOCKS_TAG)) queue_delayed_work(mp->m_eofblocks_workqueue, &mp->m_eofblocks_work, msecs_to_jiffies(xfs_eofb_secs * 1000)); - rcu_read_unlock(); } void @@ -874,12 +863,10 @@ void xfs_queue_cowblocks( struct xfs_mount *mp) { - rcu_read_lock(); - if (radix_tree_tagged(&mp->m_perag_tree, XFS_ICI_COWBLOCKS_TAG)) + if (xa_tagged(&mp->m_perag_xa, XFS_ICI_COWBLOCKS_TAG)) queue_delayed_work(mp->m_eofblocks_workqueue, &mp->m_cowblocks_work, msecs_to_jiffies(xfs_cowb_secs * 1000)); - rcu_read_unlock(); } void @@ -1557,7 +1544,7 @@ __xfs_inode_set_blocks_tag( void (*execute)(struct xfs_mount *mp), void (*set_tp)(struct xfs_mount *mp, xfs_agnumber_t agno, int error, unsigned long caller_ip), - int tag) + xa_tag_t tag) { struct xfs_mount *mp = ip->i_mount; struct xfs_perag *pag; @@ -1581,11 +1568,9 @@ __xfs_inode_set_blocks_tag( XFS_INO_TO_AGINO(ip->i_mount, ip->i_ino), tag); if (!tagged) { /* propagate the eofblocks tag up into the perag radix tree */ - spin_lock(&ip->i_mount->m_perag_lock); - radix_tree_tag_set(&ip->i_mount->m_perag_tree, + xa_set_tag(&ip->i_mount->m_perag_xa, XFS_INO_TO_AGNO(ip->i_mount, ip->i_ino), tag); - spin_unlock(&ip->i_mount->m_perag_lock); /* kick off background trimming */ execute(ip->i_mount); @@ -1612,7 +1597,7 @@ __xfs_inode_clear_blocks_tag( xfs_inode_t *ip, void (*clear_tp)(struct xfs_mount *mp, xfs_agnumber_t agno, int error, unsigned long caller_ip), - int tag) + xa_tag_t tag) { struct xfs_mount *mp = ip->i_mount; struct xfs_perag *pag; @@ -1628,11 +1613,9 @@ __xfs_inode_clear_blocks_tag( XFS_INO_TO_AGINO(ip->i_mount, ip->i_ino), tag); if (!radix_tree_tagged(&pag->pag_ici_root, tag)) { /* clear the eofblocks tag from the perag radix tree */ - spin_lock(&ip->i_mount->m_perag_lock); - radix_tree_tag_clear(&ip->i_mount->m_perag_tree, + xa_clear_tag(&ip->i_mount->m_perag_xa, XFS_INO_TO_AGNO(ip->i_mount, ip->i_ino), tag); - spin_unlock(&ip->i_mount->m_perag_lock); clear_tp(ip->i_mount, pag->pag_agno, -1, _RET_IP_); } diff --git a/fs/xfs/xfs_icache.h b/fs/xfs/xfs_icache.h index d4a77588eca1..dfbf13b530bc 100644 --- a/fs/xfs/xfs_icache.h +++ b/fs/xfs/xfs_icache.h @@ -37,9 +37,9 @@ struct xfs_eofblocks { */ #define XFS_ICI_NO_TAG (-1) /* special flag for an untagged lookup in xfs_inode_ag_iterator */ -#define XFS_ICI_RECLAIM_TAG 0 /* inode is to be reclaimed */ -#define XFS_ICI_EOFBLOCKS_TAG 1 /* inode has blocks beyond EOF */ -#define XFS_ICI_COWBLOCKS_TAG 2 /* inode can have cow blocks to gc */ +#define XFS_ICI_RECLAIM_TAG XA_TAG_0 /* inode is to be reclaimed */ +#define XFS_ICI_EOFBLOCKS_TAG XA_TAG_1 /* inode has blocks beyond EOF */ +#define XFS_ICI_COWBLOCKS_TAG XA_TAG_2 /* inode can have cow blocks to gc */ /* * Flags for xfs_iget() diff --git a/fs/xfs/xfs_mount.c b/fs/xfs/xfs_mount.c index c879b517cc94..0541aeb8449c 100644 --- a/fs/xfs/xfs_mount.c +++ b/fs/xfs/xfs_mount.c @@ -156,9 +156,7 @@ xfs_free_perag( struct xfs_perag *pag; for (agno = 0; agno < mp->m_sb.sb_agcount; agno++) { - spin_lock(&mp->m_perag_lock); - pag = radix_tree_delete(&mp->m_perag_tree, agno); - spin_unlock(&mp->m_perag_lock); + pag = xa_erase(&mp->m_perag_xa, agno); ASSERT(pag); ASSERT(atomic_read(&pag->pag_ref) == 0); xfs_buf_hash_destroy(pag); @@ -219,19 +217,11 @@ xfs_initialize_perag( goto out_free_pag; init_waitqueue_head(&pag->pagb_wait); - if (radix_tree_preload(GFP_NOFS)) - goto out_hash_destroy; - - spin_lock(&mp->m_perag_lock); - if (radix_tree_insert(&mp->m_perag_tree, index, pag)) { + if (xa_store(&mp->m_perag_xa, index, pag, GFP_NOFS)) { BUG(); - spin_unlock(&mp->m_perag_lock); - radix_tree_preload_end(); error = -EEXIST; goto out_hash_destroy; } - spin_unlock(&mp->m_perag_lock); - radix_tree_preload_end(); /* first new pag is fully initialized */ if (first_initialised == NULLAGNUMBER) first_initialised = index; @@ -252,7 +242,7 @@ xfs_initialize_perag( out_unwind_new_pags: /* unwind any prior newly initialized pags */ for (index = first_initialised; index < agcount; index++) { - pag = radix_tree_delete(&mp->m_perag_tree, index); + pag = xa_erase(&mp->m_perag_xa, index); if (!pag) break; xfs_buf_hash_destroy(pag); @@ -816,8 +806,7 @@ xfs_mountfs( /* * Allocate and initialize the per-ag data. */ - spin_lock_init(&mp->m_perag_lock); - INIT_RADIX_TREE(&mp->m_perag_tree, GFP_ATOMIC); + xa_init(&mp->m_perag_xa); error = xfs_initialize_perag(mp, sbp->sb_agcount, &mp->m_maxagi); if (error) { xfs_warn(mp, "Failed per-ag init: %d", error); diff --git a/fs/xfs/xfs_mount.h b/fs/xfs/xfs_mount.h index e0792d036be2..6e5ad7b26f46 100644 --- a/fs/xfs/xfs_mount.h +++ b/fs/xfs/xfs_mount.h @@ -134,8 +134,7 @@ typedef struct xfs_mount { xfs_extlen_t m_ag_prealloc_blocks; /* reserved ag blocks */ uint m_alloc_set_aside; /* space we can't use */ uint m_ag_max_usable; /* max space per AG */ - struct radix_tree_root m_perag_tree; /* per-ag accounting info */ - spinlock_t m_perag_lock; /* lock for m_perag_tree */ + struct xarray m_perag_xa; /* per-ag accounting info */ struct mutex m_growlock; /* growfs mutex */ int m_fixedfsid[2]; /* unchanged for life of FS */ uint m_dmevmask; /* DMI events for this FS */