mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
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 v6 6/6] locking/lockdep: Reuse freed chain_hlocks entries
Date: Thu, 6 Feb 2020 17:16:40 +0100	[thread overview]
Message-ID: <20200206161640.GW14914@hirez.programming.kicks-ass.net> (raw)
In-Reply-To: <20200206152408.24165-7-longman@redhat.com>

On Thu, Feb 06, 2020 at 10:24:08AM -0500, Waiman Long wrote:
> +static int alloc_chain_hlocks(int req)
> +{
> +	int bucket, curr, size;
> +
> +	/*
> +	 * We rely on the MSB to act as an escape bit to denote freelist
> +	 * pointers. Make sure this bit isn't set in 'normal' class_idx usage.
> +	 */
> +	BUILD_BUG_ON((MAX_LOCKDEP_KEYS-1) & CHAIN_BLK_FLAG);
> +
> +	init_data_structures_once();
> +
> +	if (nr_free_chain_hlocks < req)
> +		return -1;
> +
> +	/*
> +	 * We require a minimum of 2 (u16) entries to encode a freelist
> +	 * 'pointer'.
> +	 */
> +	req = max(req, 2);
> +	bucket = size_to_bucket(req);
> +	curr = chain_block_buckets[bucket];
> +
> +	if (bucket && (curr >= 0)) {
> +		del_chain_block(bucket, req, chain_block_next(curr));
> +		return curr;
> +	} else if (bucket) {
> +		/* Try bucket 0 */
> +		curr = chain_block_buckets[0];
> +	}

	if (bucket) {
		if (curr >= 0) {
			del_chain_block(bucket, req, chain_block_next(curr));
			return curr;
		}
		/* Try bucket 0 */
		curr = chain_block_bucket[0];
	}

reads much easier IMO.

> +	/*
> +	 * The variable sized freelist is sorted by size; the first entry is
> +	 * the largest. Use it if it fits.
> +	 */
> +	if (curr >= 0) {
> +		size = chain_block_size(curr);
> +		if (likely(size >= req)) {
> +			del_chain_block(0, size, chain_block_next(curr));
> +			add_chain_block(curr + req, size - req);
> +			return curr;
> +		}
> +	}
> +
> +	/*
> +	 * Last resort, split a block in a larger sized bucket.
> +	 */
> +	for (size = MAX_CHAIN_BUCKETS; size > req; size--) {
> +		bucket = size_to_bucket(size);
> +		curr = chain_block_buckets[bucket];
> +		if (curr < 0)
> +			continue;
> +
> +		del_chain_block(bucket, size, chain_block_next(curr));
> +		add_chain_block(curr + req, size - req);
> +		return curr;
> +	}
> +
> +	return -1;
> +}

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

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-06 15:24 [PATCH v6 0/6] locking/lockdep: Reuse zapped " Waiman Long
2020-02-06 15:24 ` [PATCH v6 1/6] locking/lockdep: Decrement irq context counters when removing lock chain Waiman Long
2020-02-11 12:48   ` [tip: locking/core] locking/lockdep: Decrement IRQ " tip-bot2 for Waiman Long
2020-02-06 15:24 ` [PATCH v6 2/6] locking/lockdep: Display irq_context names in /proc/lockdep_chains Waiman Long
2020-02-11 12:48   ` [tip: locking/core] " tip-bot2 for Waiman Long
2020-02-06 15:24 ` [PATCH v6 3/6] locking/lockdep: Track number of zapped classes Waiman Long
2020-02-11 12:48   ` [tip: locking/core] " tip-bot2 for Waiman Long
2020-02-06 15:24 ` [PATCH v6 4/6] locking/lockdep: Throw away all lock chains with zapped class Waiman Long
2020-02-11 12:48   ` [tip: locking/core] " tip-bot2 for Waiman Long
2020-02-06 15:24 ` [PATCH v6 5/6] locking/lockdep: Track number of zapped lock chains Waiman Long
2020-02-11 12:48   ` [tip: locking/core] " tip-bot2 for Waiman Long
2020-02-06 15:24 ` [PATCH v6 6/6] locking/lockdep: Reuse freed chain_hlocks entries Waiman Long
2020-02-06 16:03   ` Peter Zijlstra
2020-02-06 17:06     ` Waiman Long
2020-02-06 16:16   ` Peter Zijlstra [this message]
2020-02-06 17:08     ` Waiman Long
2020-02-06 17:31       ` Peter Zijlstra
2020-02-11 12:48   ` [tip: locking/core] " tip-bot2 for 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=20200206161640.GW14914@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

all inboxes | Powered by JetHome®