From: Jeff Layton <jlayton@kernel.org>
To: Matthew Wilcox <willy@infradead.org>,
Andrew Morton <akpm@linux-foundation.org>
Cc: Matthew Wilcox <mawilcox@microsoft.com>,
linux-kernel@vger.kernel.org, linux-mm@kvack.org,
linux-fsdevel@vger.kernel.org
Subject: Re: [PATCH v7 08/61] xarray: Add the xa_lock to the radix_tree_root
Date: Sat, 03 Mar 2018 09:55:22 -0500 [thread overview]
Message-ID: <1520088922.4280.47.camel@kernel.org> (raw)
In-Reply-To: <20180219194556.6575-9-willy@infradead.org>
On Mon, 2018-02-19 at 11:45 -0800, Matthew Wilcox wrote:
> From: Matthew Wilcox <mawilcox@microsoft.com>
>
> This results in no change in structure size on 64-bit x86 as it fits in
> the padding between the gfp_t and the void *.
>
While the patch itself looks fine, we should take note that this will
likely increase the size of radix_tree_root on 32-bit arches.
I don't think that's necessarily a deal breaker, but there are a lot of
users of radix_tree_root. Many of those users have their own spinlock
for radix tree accesses, and could be trivially changed to use the
xa_lock. That would need to be done piecemeal though.
A less disruptive idea might be to just create some new struct that's a
spinlock + radix_tree_root, and then use that going forward in the
xarray conversion. That might be better anyway if you're considering a
more phased approach for getting this merged.
> Initialising the spinlock requires a name for the benefit of lockdep,
> so RADIX_TREE_INIT() now needs to know the name of the radix tree it's
> initialising, and so do IDR_INIT() and IDA_INIT().
>
> Also add the xa_lock() and xa_unlock() family of wrappers to make it
> easier to use the lock. If we could rely on -fplan9-extensions in
> the compiler, we could avoid all of this syntactic sugar, but that
> wasn't added until gcc 4.6.
>
> Signed-off-by: Matthew Wilcox <mawilcox@microsoft.com>
> ---
> fs/f2fs/gc.c | 2 +-
> include/linux/idr.h | 19 ++++++++++---------
> include/linux/radix-tree.h | 7 +++++--
> include/linux/xarray.h | 24 ++++++++++++++++++++++++
> kernel/pid.c | 2 +-
> tools/include/linux/spinlock.h | 1 +
> 6 files changed, 42 insertions(+), 13 deletions(-)
> create mode 100644 include/linux/xarray.h
>
> diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c
> index aa720cc44509..7aa15134180e 100644
> --- a/fs/f2fs/gc.c
> +++ b/fs/f2fs/gc.c
> @@ -1006,7 +1006,7 @@ int f2fs_gc(struct f2fs_sb_info *sbi, bool sync,
> unsigned int init_segno = segno;
> struct gc_inode_list gc_list = {
> .ilist = LIST_HEAD_INIT(gc_list.ilist),
> - .iroot = RADIX_TREE_INIT(GFP_NOFS),
> + .iroot = RADIX_TREE_INIT(gc_list.iroot, GFP_NOFS),
> };
>
> trace_f2fs_gc_begin(sbi->sb, sync, background,
> diff --git a/include/linux/idr.h b/include/linux/idr.h
> index 913c335054f0..e856f4e0ab35 100644
> --- a/include/linux/idr.h
> +++ b/include/linux/idr.h
> @@ -32,27 +32,28 @@ struct idr {
> #define IDR_RT_MARKER (ROOT_IS_IDR | (__force gfp_t) \
> (1 << (ROOT_TAG_SHIFT + IDR_FREE)))
>
> -#define IDR_INIT_BASE(base) { \
> - .idr_rt = RADIX_TREE_INIT(IDR_RT_MARKER), \
> +#define IDR_INIT_BASE(name, base) { \
> + .idr_rt = RADIX_TREE_INIT(name, IDR_RT_MARKER), \
> .idr_base = (base), \
> .idr_next = 0, \
> }
>
> /**
> * IDR_INIT() - Initialise an IDR.
> + * @name: Name of IDR.
> *
> * A freshly-initialised IDR contains no IDs.
> */
> -#define IDR_INIT IDR_INIT_BASE(0)
> +#define IDR_INIT(name) IDR_INIT_BASE(name, 0)
>
> /**
> - * DEFINE_IDR() - Define a statically-allocated IDR
> - * @name: Name of IDR
> + * DEFINE_IDR() - Define a statically-allocated IDR.
> + * @name: Name of IDR.
> *
> * An IDR defined using this macro is ready for use with no additional
> * initialisation required. It contains no IDs.
> */
> -#define DEFINE_IDR(name) struct idr name = IDR_INIT
> +#define DEFINE_IDR(name) struct idr name = IDR_INIT(name)
>
> /**
> * idr_get_cursor - Return the current position of the cyclic allocator
> @@ -219,10 +220,10 @@ struct ida {
> struct radix_tree_root ida_rt;
> };
>
> -#define IDA_INIT { \
> - .ida_rt = RADIX_TREE_INIT(IDR_RT_MARKER | GFP_NOWAIT), \
> +#define IDA_INIT(name) { \
> + .ida_rt = RADIX_TREE_INIT(name, IDR_RT_MARKER | GFP_NOWAIT), \
> }
> -#define DEFINE_IDA(name) struct ida name = IDA_INIT
> +#define DEFINE_IDA(name) struct ida name = IDA_INIT(name)
>
> int ida_pre_get(struct ida *ida, gfp_t gfp_mask);
> int ida_get_new_above(struct ida *ida, int starting_id, int *p_id);
> diff --git a/include/linux/radix-tree.h b/include/linux/radix-tree.h
> index 6c4e2e716dac..34149e8b5f73 100644
> --- a/include/linux/radix-tree.h
> +++ b/include/linux/radix-tree.h
> @@ -110,20 +110,23 @@ struct radix_tree_node {
> #define ROOT_TAG_SHIFT (__GFP_BITS_SHIFT)
>
> struct radix_tree_root {
> + spinlock_t xa_lock;
> gfp_t gfp_mask;
> struct radix_tree_node __rcu *rnode;
> };
>
> -#define RADIX_TREE_INIT(mask) { \
> +#define RADIX_TREE_INIT(name, mask) { \
> + .xa_lock = __SPIN_LOCK_UNLOCKED(name.xa_lock), \
> .gfp_mask = (mask), \
> .rnode = NULL, \
> }
>
> #define RADIX_TREE(name, mask) \
> - struct radix_tree_root name = RADIX_TREE_INIT(mask)
> + struct radix_tree_root name = RADIX_TREE_INIT(name, mask)
>
> #define INIT_RADIX_TREE(root, mask) \
> do { \
> + spin_lock_init(&(root)->xa_lock); \
> (root)->gfp_mask = (mask); \
> (root)->rnode = NULL; \
> } while (0)
> diff --git a/include/linux/xarray.h b/include/linux/xarray.h
> new file mode 100644
> index 000000000000..2dfc8006fe64
> --- /dev/null
> +++ b/include/linux/xarray.h
> @@ -0,0 +1,24 @@
> +/* SPDX-License-Identifier: GPL-2.0+ */
> +#ifndef _LINUX_XARRAY_H
> +#define _LINUX_XARRAY_H
> +/*
> + * eXtensible Arrays
> + * Copyright (c) 2017 Microsoft Corporation
> + * Author: Matthew Wilcox <mawilcox@microsoft.com>
> + */
> +
> +#include <linux/spinlock.h>
> +
> +#define xa_trylock(xa) spin_trylock(&(xa)->xa_lock)
> +#define xa_lock(xa) spin_lock(&(xa)->xa_lock)
> +#define xa_unlock(xa) spin_unlock(&(xa)->xa_lock)
> +#define xa_lock_bh(xa) spin_lock_bh(&(xa)->xa_lock)
> +#define xa_unlock_bh(xa) spin_unlock_bh(&(xa)->xa_lock)
> +#define xa_lock_irq(xa) spin_lock_irq(&(xa)->xa_lock)
> +#define xa_unlock_irq(xa) spin_unlock_irq(&(xa)->xa_lock)
> +#define xa_lock_irqsave(xa, flags) \
> + spin_lock_irqsave(&(xa)->xa_lock, flags)
> +#define xa_unlock_irqrestore(xa, flags) \
> + spin_unlock_irqrestore(&(xa)->xa_lock, flags)
> +
> +#endif /* _LINUX_XARRAY_H */
> diff --git a/kernel/pid.c b/kernel/pid.c
> index ed6c343fe50d..157fe4b19971 100644
> --- a/kernel/pid.c
> +++ b/kernel/pid.c
> @@ -70,7 +70,7 @@ int pid_max_max = PID_MAX_LIMIT;
> */
> struct pid_namespace init_pid_ns = {
> .kref = KREF_INIT(2),
> - .idr = IDR_INIT,
> + .idr = IDR_INIT(init_pid_ns.idr),
> .pid_allocated = PIDNS_ADDING,
> .level = 0,
> .child_reaper = &init_task,
> diff --git a/tools/include/linux/spinlock.h b/tools/include/linux/spinlock.h
> index 4ed569fcb139..b21b586b9854 100644
> --- a/tools/include/linux/spinlock.h
> +++ b/tools/include/linux/spinlock.h
> @@ -7,6 +7,7 @@
>
> #define spinlock_t pthread_mutex_t
> #define DEFINE_SPINLOCK(x) pthread_mutex_t x = PTHREAD_MUTEX_INITIALIZER;
> +#define __SPIN_LOCK_UNLOCKED(x) (pthread_mutex_t)PTHREAD_MUTEX_INITIALIZER
>
> #define spin_lock_irqsave(x, f) (void)f, pthread_mutex_lock(x)
> #define spin_unlock_irqrestore(x, f) (void)f, pthread_mutex_unlock(x)
--
Jeff Layton <jlayton@kernel.org>
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next prev parent reply other threads:[~2018-03-03 14:55 UTC|newest]
Thread overview: 72+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-02-19 19:44 [PATCH v7 00/61] XArray version 7 -- for merging Matthew Wilcox
2018-02-19 19:44 ` [PATCH v7 01/61] radix tree test suite: Check reclaim bit Matthew Wilcox
2018-02-19 19:44 ` [PATCH v7 02/61] radix tree: Use bottom four bits of gfp_t for flags Matthew Wilcox
2018-03-03 12:44 ` Jeff Layton
2018-03-03 17:09 ` Matthew Wilcox
2018-02-19 19:44 ` [PATCH v7 03/61] arm64: Turn flush_dcache_mmap_lock into a no-op Matthew Wilcox
2018-02-19 19:44 ` [PATCH v7 04/61] unicore32: " Matthew Wilcox
2018-02-19 19:45 ` [PATCH v7 05/61] Export __set_page_dirty Matthew Wilcox
2018-03-03 13:56 ` Jeff Layton
2018-02-19 19:45 ` [PATCH v7 06/61] xfs: Rename xa_ elements to ail_ Matthew Wilcox
2018-02-19 19:45 ` [PATCH v7 07/61] fscache: Use appropriate radix tree accessors Matthew Wilcox
2018-03-03 13:57 ` Jeff Layton
2018-02-19 19:45 ` [PATCH v7 08/61] xarray: Add the xa_lock to the radix_tree_root Matthew Wilcox
2018-03-03 14:19 ` Jeff Layton
2018-03-03 14:55 ` Jeff Layton [this message]
2018-03-03 16:57 ` Matthew Wilcox
2018-02-19 19:45 ` [PATCH v7 09/61] page cache: Use xa_lock Matthew Wilcox
2018-03-03 14:27 ` Jeff Layton
2018-02-19 19:45 ` [PATCH v7 10/61] xarray: Replace exceptional entries Matthew Wilcox
2018-02-19 19:45 ` [PATCH v7 11/61] xarray: Change definition of sibling entries Matthew Wilcox
2018-02-19 19:45 ` [PATCH v7 12/61] xarray: Add definition of struct xarray Matthew Wilcox
2018-02-19 19:45 ` [PATCH v7 13/61] xarray: Define struct xa_node Matthew Wilcox
2018-02-19 19:45 ` [PATCH v7 14/61] xarray: Add documentation Matthew Wilcox
2018-02-19 19:45 ` [PATCH v7 15/61] xarray: Add xa_load Matthew Wilcox
2018-02-20 7:34 ` Philippe Ombredanne
2018-02-20 12:47 ` Matthew Wilcox
2018-02-19 19:45 ` [PATCH v7 16/61] xarray: Add xa_get_tag, xa_set_tag and xa_clear_tag Matthew Wilcox
2018-02-19 19:45 ` [PATCH v7 17/61] xarray: Add xa_store Matthew Wilcox
2018-02-19 19:45 ` [PATCH v7 18/61] xarray: Add xa_cmpxchg and xa_insert Matthew Wilcox
2018-02-19 19:45 ` [PATCH v7 19/61] xarray: Add xa_for_each Matthew Wilcox
2018-02-19 19:45 ` [PATCH v7 20/61] xarray: Add xa_extract Matthew Wilcox
2018-02-19 19:45 ` [PATCH v7 21/61] xarray: Add xa_destroy Matthew Wilcox
2018-02-19 19:45 ` [PATCH v7 22/61] xarray: Add xas_next and xas_prev Matthew Wilcox
2018-02-19 19:45 ` [PATCH v7 23/61] xarray: Add xas_create_range Matthew Wilcox
2018-02-19 19:45 ` [PATCH v7 24/61] xarray: Add MAINTAINERS entry Matthew Wilcox
2018-02-19 19:45 ` [PATCH v7 25/61] page cache: Convert hole search to XArray Matthew Wilcox
2018-02-19 19:45 ` [PATCH v7 26/61] page cache: Add page_cache_range_empty function Matthew Wilcox
2018-02-19 19:45 ` [PATCH v7 27/61] page cache: Add and replace pages using the XArray Matthew Wilcox
2018-02-19 19:45 ` [PATCH v7 28/61] page cache: Convert page deletion to XArray Matthew Wilcox
2018-02-19 19:45 ` [PATCH v7 29/61] page cache: Convert page cache lookups " Matthew Wilcox
2018-02-19 19:45 ` [PATCH v7 30/61] page cache: Convert delete_batch " Matthew Wilcox
2018-02-19 19:45 ` [PATCH v7 31/61] page cache: Remove stray radix comment Matthew Wilcox
2018-02-19 19:45 ` [PATCH v7 32/61] page cache: Convert filemap_range_has_page to XArray Matthew Wilcox
2018-02-19 19:45 ` [PATCH v7 33/61] mm: Convert page-writeback " Matthew Wilcox
2018-02-19 19:45 ` [PATCH v7 34/61] mm: Convert workingset " Matthew Wilcox
2018-02-19 19:45 ` [PATCH v7 35/61] mm: Convert truncate " Matthew Wilcox
2018-02-19 19:45 ` [PATCH v7 36/61] mm: Convert add_to_swap_cache " Matthew Wilcox
2018-02-19 19:45 ` [PATCH v7 37/61] mm: Convert delete_from_swap_cache " Matthew Wilcox
2018-02-19 19:45 ` [PATCH v7 38/61] mm: Convert __do_page_cache_readahead " Matthew Wilcox
2018-02-19 19:45 ` [PATCH v7 39/61] mm: Convert page migration " Matthew Wilcox
2018-02-19 19:45 ` [PATCH v7 40/61] mm: Convert huge_memory " Matthew Wilcox
2018-02-19 19:45 ` [PATCH v7 41/61] mm: Convert collapse_shmem " Matthew Wilcox
2018-02-19 19:45 ` [PATCH v7 42/61] mm: Convert khugepaged_scan_shmem " Matthew Wilcox
2018-02-19 19:45 ` [PATCH v7 43/61] pagevec: Use xa_tag_t Matthew Wilcox
2018-02-19 19:45 ` [PATCH v7 44/61] shmem: Convert replace to XArray Matthew Wilcox
2018-02-19 19:45 ` [PATCH v7 45/61] shmem: Convert shmem_confirm_swap " Matthew Wilcox
2018-02-19 19:45 ` [PATCH v7 46/61] shmem: Convert find_swap_entry " Matthew Wilcox
2018-02-19 19:45 ` [PATCH v7 47/61] shmem: Convert shmem_tag_pins " Matthew Wilcox
2018-02-19 19:45 ` [PATCH v7 48/61] shmem: Convert shmem_wait_for_pins " Matthew Wilcox
2018-02-19 19:45 ` [PATCH v7 49/61] shmem: Convert shmem_add_to_page_cache " Matthew Wilcox
2018-02-19 19:45 ` [PATCH v7 50/61] shmem: Convert shmem_alloc_hugepage " Matthew Wilcox
2018-02-19 19:45 ` [PATCH v7 51/61] shmem: Convert shmem_free_swap " Matthew Wilcox
2018-02-19 19:45 ` [PATCH v7 52/61] shmem: Convert shmem_partial_swap_usage " Matthew Wilcox
2018-02-19 19:45 ` [PATCH v7 53/61] shmem: Comment fixups Matthew Wilcox
2018-02-19 19:45 ` [PATCH v7 54/61] btrfs: Convert page cache to XArray Matthew Wilcox
2018-02-19 19:45 ` [PATCH v7 55/61] fs: Convert buffer " Matthew Wilcox
2018-02-19 19:45 ` [PATCH v7 56/61] fs: Convert writeback " Matthew Wilcox
2018-02-19 19:45 ` [PATCH v7 57/61] nilfs2: Convert " Matthew Wilcox
2018-02-19 19:45 ` [PATCH v7 58/61] f2fs: " Matthew Wilcox
2018-02-19 19:45 ` [PATCH v7 59/61] lustre: " Matthew Wilcox
2018-02-19 19:45 ` [PATCH v7 60/61] dax: " Matthew Wilcox
2018-02-19 19:45 ` [PATCH v7 61/61] page cache: Finish XArray conversion Matthew Wilcox
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1520088922.4280.47.camel@kernel.org \
--to=jlayton@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mawilcox@microsoft.com \
--cc=willy@infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).