linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Waiman Long <longman@redhat.com>
To: Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>, Will Deacon <will.deacon@arm.com>
Cc: linux-kernel@vger.kernel.org,
	Bart Van Assche <bvanassche@acm.org>,
	Waiman Long <longman@redhat.com>
Subject: [PATCH v5 7/7] locking/lockdep: Add a fast path for chain_hlocks allocation
Date: Mon,  3 Feb 2020 11:41:47 -0500	[thread overview]
Message-ID: <20200203164147.17990-8-longman@redhat.com> (raw)
In-Reply-To: <20200203164147.17990-1-longman@redhat.com>

When alloc_chain_hlocks() is called, the most likely scenario is
to allocate from the primordial chain block which holds the whole
chain_hlocks[] array initially. It is the primordial chain block if its
size is bigger than MAX_LOCK_DEPTH. As long as the number of entries left
after splitting is still bigger than MAX_CHAIN_BUCKETS it will remain
in bucket 0. By splitting out a sub-block at the end, we only need to
adjust the size without changing any of the existing linkage information.
This optimized fast path can reduce the latency of allocation requests.

This patch does change the order by which chain_hlocks entries are
allocated. The original code allocates entries from the beginning of
the array. Now it will be allocated from the end of the array backward.

Signed-off-by: Waiman Long <longman@redhat.com>
---
 kernel/locking/lockdep.c | 24 ++++++++++++++++++++----
 1 file changed, 20 insertions(+), 4 deletions(-)

diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
index 70288bb2331d..d05799872882 100644
--- a/kernel/locking/lockdep.c
+++ b/kernel/locking/lockdep.c
@@ -2701,15 +2701,19 @@ static inline int chain_block_size(int offset)
 	return (chain_hlocks[offset + 2] << 16) | chain_hlocks[offset + 3];
 }
 
+static inline void init_chain_block_size(int offset, int size)
+{
+	chain_hlocks[offset + 2] = size >> 16;
+	chain_hlocks[offset + 3] = (u16)size;
+}
+
 static inline void init_chain_block(int offset, int next, int bucket, int size)
 {
 	chain_hlocks[offset] = (next >> 16) | CHAIN_BLK_FLAG;
 	chain_hlocks[offset + 1] = (u16)next;
 
-	if (bucket == 0) {
-		chain_hlocks[offset + 2] = size >> 16;
-		chain_hlocks[offset + 3] = (u16)size;
-	}
+	if (bucket == 0)
+		init_chain_block_size(offset, size);
 }
 
 static inline void add_chain_block(int offset, int size)
@@ -2809,6 +2813,18 @@ static int alloc_chain_hlocks(int req)
 			return curr;
 		}
 
+		/*
+		 * Fast path: splitting out a sub-block at the end of the
+		 * primordial chain block.
+		 */
+		if (likely((size > MAX_LOCK_DEPTH) &&
+			   (size - req > MAX_CHAIN_BUCKETS))) {
+			size -= req;
+			nr_free_chain_hlocks -= req;
+			init_chain_block_size(curr, size);
+			return curr + size;
+		}
+
 		if (size > max_size) {
 			max_prev = prev;
 			max_curr = curr;
-- 
2.18.1


  parent reply	other threads:[~2020-02-03 16:42 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-03 16:41 [PATCH v5 0/7] locking/lockdep: Reuse zapped chain_hlocks entries Waiman Long
2020-02-03 16:41 ` [PATCH v5 1/7] locking/lockdep: Decrement irq context counters when removing lock chain Waiman Long
2020-02-03 16:41 ` [PATCH v5 2/7] locking/lockdep: Display irq_context names in /proc/lockdep_chains Waiman Long
2020-02-03 16:41 ` [PATCH v5 3/7] locking/lockdep: Track number of zapped classes Waiman Long
2020-02-03 16:41 ` [PATCH v5 4/7] locking/lockdep: Throw away all lock chains with zapped class Waiman Long
2020-02-03 16:41 ` [PATCH v5 5/7] locking/lockdep: Track number of zapped lock chains Waiman Long
2020-02-03 16:41 ` [PATCH v5 6/7] locking/lockdep: Reuse freed chain_hlocks entries Waiman Long
2020-02-04 12:36   ` Peter Zijlstra
2020-02-04 14:54     ` Waiman Long
2020-02-04 16:45     ` Waiman Long
2020-02-05  9:41       ` Peter Zijlstra
2020-02-05 13:59         ` Waiman Long
2020-02-04 15:42   ` Peter Zijlstra
2020-02-04 16:12     ` Waiman Long
2020-02-04 16:26       ` Waiman Long
2020-02-04 16:57         ` Waiman Long
2020-02-05  9:48           ` Peter Zijlstra
2020-02-05 14:03             ` Waiman Long
2020-02-03 16:41 ` Waiman Long [this message]
2020-02-04 12:47   ` [PATCH v5 7/7] locking/lockdep: Add a fast path for chain_hlocks allocation Peter Zijlstra
2020-02-04 15:07     ` Waiman Long
2020-02-04 13:18   ` Peter Zijlstra
2020-02-04 13:44     ` Peter Zijlstra
2020-02-04 18:02       ` Waiman Long

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=20200203164147.17990-8-longman@redhat.com \
    --to=longman@redhat.com \
    --cc=bvanassche@acm.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=will.deacon@arm.com \
    /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).