linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Peng Zhang <zhangpeng.00@bytedance.com>
To: Liam.Howlett@oracle.com, corbet@lwn.net,
	akpm@linux-foundation.org, willy@infradead.org,
	brauner@kernel.org, surenb@google.com,
	michael.christie@oracle.com, mjguzik@gmail.com,
	mathieu.desnoyers@efficios.com, npiggin@gmail.com,
	peterz@infradead.org, oliver.sang@intel.com
Cc: zhangpeng.00@bytedance.com, maple-tree@lists.infradead.org,
	linux-mm@kvack.org, linux-doc@vger.kernel.org,
	linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org
Subject: [PATCH v3 2/9] maple_tree: Introduce {mtree,mas}_lock_nested()
Date: Mon, 25 Sep 2023 11:56:10 +0800	[thread overview]
Message-ID: <20230925035617.84767-3-zhangpeng.00@bytedance.com> (raw)
In-Reply-To: <20230925035617.84767-1-zhangpeng.00@bytedance.com>

In some cases, nested locks may be needed, so {mtree,mas}_lock_nested is
introduced. For example, when duplicating maple tree, we need to hold
the locks of two trees, in which case nested locks are needed.

At the same time, add the definition of spin_lock_nested() in tools for
testing.

Signed-off-by: Peng Zhang <zhangpeng.00@bytedance.com>
---
 include/linux/maple_tree.h     | 4 ++++
 tools/include/linux/spinlock.h | 1 +
 2 files changed, 5 insertions(+)

diff --git a/include/linux/maple_tree.h b/include/linux/maple_tree.h
index e41c70ac7744..666a3764ed89 100644
--- a/include/linux/maple_tree.h
+++ b/include/linux/maple_tree.h
@@ -256,6 +256,8 @@ struct maple_tree {
 	struct maple_tree name = MTREE_INIT(name, 0)
 
 #define mtree_lock(mt)		spin_lock((&(mt)->ma_lock))
+#define mtree_lock_nested(mas, subclass) \
+		spin_lock_nested((&(mt)->ma_lock), subclass)
 #define mtree_unlock(mt)	spin_unlock((&(mt)->ma_lock))
 
 /*
@@ -406,6 +408,8 @@ struct ma_wr_state {
 };
 
 #define mas_lock(mas)           spin_lock(&((mas)->tree->ma_lock))
+#define mas_lock_nested(mas, subclass) \
+		spin_lock_nested(&((mas)->tree->ma_lock), subclass)
 #define mas_unlock(mas)         spin_unlock(&((mas)->tree->ma_lock))
 
 
diff --git a/tools/include/linux/spinlock.h b/tools/include/linux/spinlock.h
index 622266b197d0..a6cdf25b6b9d 100644
--- a/tools/include/linux/spinlock.h
+++ b/tools/include/linux/spinlock.h
@@ -11,6 +11,7 @@
 #define spin_lock_init(x)	pthread_mutex_init(x, NULL)
 
 #define spin_lock(x)			pthread_mutex_lock(x)
+#define spin_lock_nested(x, subclass)	pthread_mutex_lock(x)
 #define spin_unlock(x)			pthread_mutex_unlock(x)
 #define spin_lock_bh(x)			pthread_mutex_lock(x)
 #define spin_unlock_bh(x)		pthread_mutex_unlock(x)
-- 
2.20.1


  parent reply	other threads:[~2023-09-25  3:58 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-25  3:56 [PATCH v3 0/9] Introduce __mt_dup() to improve the performance of fork() Peng Zhang
2023-09-25  3:56 ` [PATCH v3 1/9] maple_tree: Add mt_free_one() and mt_attr() helpers Peng Zhang
2023-09-25  3:56 ` Peng Zhang [this message]
2023-09-25  3:56 ` [PATCH v3 3/9] maple_tree: Introduce interfaces __mt_dup() and mtree_dup() Peng Zhang
2023-10-03 18:45   ` Liam R. Howlett
2023-10-04  9:09     ` Peng Zhang
2023-10-04 14:25       ` Liam R. Howlett
2023-10-05 15:55         ` Peng Zhang
2023-10-05 19:09           ` Liam R. Howlett
2023-09-25  3:56 ` [PATCH v3 4/9] maple_tree: Add test for mtree_dup() Peng Zhang
2023-09-25  3:56 ` [PATCH v3 5/9] maple_tree: Update the documentation of maple tree Peng Zhang
2023-10-03 18:46   ` Liam R. Howlett
2023-10-04  9:09     ` Peng Zhang
2023-09-25  3:56 ` [PATCH v3 6/9] maple_tree: Skip other tests when BENCH is enabled Peng Zhang
2023-09-25  3:56 ` [PATCH v3 7/9] maple_tree: Update check_forking() and bench_forking() Peng Zhang
2023-09-25  3:56 ` [PATCH v3 8/9] maple_tree: Preserve the tree attributes when destroying maple tree Peng Zhang
2023-09-25  3:56 ` [PATCH v3 9/9] fork: Use __mt_dup() to duplicate maple tree in dup_mmap() Peng Zhang
2023-10-03 18:46   ` Liam R. Howlett
2023-10-04  9:10     ` Peng Zhang
2023-10-04 19:53       ` Liam R. Howlett
2023-10-05 15:56         ` Peng Zhang
2023-10-07  1:11           ` Liam R. Howlett
2023-10-07  1:32             ` Liam R. Howlett
2023-10-07  4:25               ` Peng Zhang
2023-10-08  7:54               ` Peng Zhang

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=20230925035617.84767-3-zhangpeng.00@bytedance.com \
    --to=zhangpeng.00@bytedance.com \
    --cc=Liam.Howlett@oracle.com \
    --cc=akpm@linux-foundation.org \
    --cc=brauner@kernel.org \
    --cc=corbet@lwn.net \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=maple-tree@lists.infradead.org \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=michael.christie@oracle.com \
    --cc=mjguzik@gmail.com \
    --cc=npiggin@gmail.com \
    --cc=oliver.sang@intel.com \
    --cc=peterz@infradead.org \
    --cc=surenb@google.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).