From: Peter Zijlstra <peterz@infradead.org>
To: Waiman Long <longman@redhat.com>
Cc: Ingo Molnar <mingo@redhat.com>, Will Deacon <will.deacon@arm.com>,
linux-kernel@vger.kernel.org,
Bart Van Assche <bvanassche@acm.org>
Subject: Re: [PATCH v2 4/6] locking/lockdep: Reuse freed chain_hlocks entries
Date: Mon, 13 Jan 2020 16:58:23 +0100 [thread overview]
Message-ID: <20200113155823.GY2844@hirez.programming.kicks-ass.net> (raw)
In-Reply-To: <20191216151517.7060-5-longman@redhat.com>
On Mon, Dec 16, 2019 at 10:15:15AM -0500, Waiman Long wrote:
> +/*
> + * Return offset of a chain block of the right size or -1 if not found.
> + */
> +static inline int alloc_chain_hlocks_from_buckets(int size)
> +{
> + int prev, curr, next;
> +
> + if (!nr_free_chain_hlocks)
> + return -1;
> +
> + if (size <= MAX_CHAIN_BUCKETS) {
> + curr = chain_block_buckets[size - 1];
> + if (curr < 0)
> + return -1;
> +
> + chain_block_buckets[size - 1] = next_chain_block(curr);
> + nr_free_chain_hlocks -= size;
> + return curr;
> + }
> +
> + /*
> + * Look for a free chain block of the given size
> + *
> + * It is rare to have a lock chain with depth > MAX_CHAIN_BUCKETS.
> + * It is also more expensive as we may iterate the whole list
> + * without finding one.
> + */
> + prev = -1;
> + curr = chain_block_buckets[0];
> + while (curr >= 0) {
> + next = next_chain_block(curr);
> + if (chain_block_size(curr) == size) {
> + set_chain_block(prev, 0, next);
> + nr_free_chain_hlocks -= size;
> + nr_large_chain_blocks--;
> + return curr;
> + }
> + prev = curr;
> + curr = next;
> + }
> + return -1;
> +}
> +/*
> + * The graph lock must be held before calling this function.
> + *
> + * Return: an offset to chain_hlocks if successful, or
> + * -1 with graph lock released
> + */
> +static int alloc_chain_hlocks(int size)
> +{
> + int curr;
> +
> + if (size < 2)
> + size = 2;
> +
> + curr = alloc_chain_hlocks_from_buckets(size);
> + if (curr >= 0)
> + return curr;
> +
> + BUILD_BUG_ON((1UL << 24) <= ARRAY_SIZE(chain_hlocks));
> + BUILD_BUG_ON((1UL << 6) <= ARRAY_SIZE(current->held_locks));
> + BUILD_BUG_ON((1UL << 8*sizeof(chain_hlocks[0])) <=
> + ARRAY_SIZE(lock_classes));
> +
> + /*
> + * Allocate directly from chain_hlocks.
> + */
> + if (likely(nr_chain_hlocks + size <= MAX_LOCKDEP_CHAIN_HLOCKS)) {
> + curr = nr_chain_hlocks;
> + nr_chain_hlocks += size;
> + return curr;
> + }
> + if (!debug_locks_off_graph_unlock())
> + return -1;
> +
> + print_lockdep_off("BUG: MAX_LOCKDEP_CHAIN_HLOCKS too low!");
> + dump_stack();
> + return -1;
> +}
*groan*....
That's _two_ allocators :/ And it can trivially fail, even if there's
plenty space available.
Consider nr_chain_hlocks is exhaused, and @size is empty, but size+1
still has blocks.
I'm guessing you didn't make it a single allocator because you didn't
want to implement block splitting? why?
next prev parent reply other threads:[~2020-01-13 15:58 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-12-16 15:15 [PATCH v2 0/6] locking/lockdep: Reuse zapped chain_hlocks entries Waiman Long
2019-12-16 15:15 ` [PATCH v2 1/6] locking/lockdep: Track number of zapped classes Waiman Long
2020-01-13 14:55 ` Peter Zijlstra
2020-01-13 14:58 ` Waiman Long
2020-01-13 16:02 ` Bart Van Assche
2019-12-16 15:15 ` [PATCH v2 2/6] locking/lockdep: Throw away all lock chains with zapped class Waiman Long
2020-01-13 15:18 ` Peter Zijlstra
2020-01-13 15:44 ` Waiman Long
2020-01-13 16:05 ` Bart Van Assche
2020-01-13 16:15 ` Waiman Long
2019-12-16 15:15 ` [PATCH v2 3/6] locking/lockdep: Track number of zapped lock chains Waiman Long
2019-12-16 15:15 ` [PATCH v2 4/6] locking/lockdep: Reuse freed chain_hlocks entries Waiman Long
2020-01-13 15:51 ` Peter Zijlstra
2020-01-13 16:04 ` Waiman Long
2020-01-13 15:58 ` Peter Zijlstra [this message]
2020-01-13 16:24 ` Waiman Long
2020-01-14 9:46 ` Peter Zijlstra
2020-01-14 19:16 ` Waiman Long
2020-01-15 10:44 ` Peter Zijlstra
2020-01-15 19:26 ` Waiman Long
2020-01-13 15:59 ` Peter Zijlstra
2020-01-13 16:03 ` Waiman Long
2019-12-16 15:15 ` [PATCH v2 5/6] locking/lockdep: Decrement irq context counters when removing lock chain Waiman Long
2020-01-14 9:53 ` Peter Zijlstra
2020-01-14 15:04 ` Waiman Long
2019-12-16 15:15 ` [PATCH v2 6/6] locking/lockdep: Display irq_context names in /proc/lockdep_chains Waiman Long
2020-01-06 15:54 ` [PATCH v2 0/6] locking/lockdep: Reuse zapped chain_hlocks entries Waiman Long
2020-01-06 16:50 ` Peter Zijlstra
2020-01-06 16:52 ` 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=20200113155823.GY2844@hirez.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=bvanassche@acm.org \
--cc=linux-kernel@vger.kernel.org \
--cc=longman@redhat.com \
--cc=mingo@redhat.com \
--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).