lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20161027125907.GF3175@twins.programming.kicks-ass.net>
Date:   Thu, 27 Oct 2016 14:59:07 +0200
From:   Peter Zijlstra <peterz@...radead.org>
To:     David Herrmann <dh.herrmann@...il.com>
Cc:     linux-kernel@...r.kernel.org,
        Andy Lutomirski <luto@...capital.net>,
        Jiri Kosina <jikos@...nel.org>, Greg KH <greg@...ah.com>,
        Hannes Reinecke <hare@...e.com>,
        Steven Rostedt <rostedt@...dmis.org>,
        Arnd Bergmann <arnd@...db.de>, Tom Gundersen <teg@...m.no>,
        Josh Triplett <josh@...htriplett.org>,
        Linus Torvalds <torvalds@...ux-foundation.org>,
        Andrew Morton <akpm@...ux-foundation.org>
Subject: Re: [RFC v1 05/14] bus1: util - pool utility library

On Wed, Oct 26, 2016 at 09:18:01PM +0200, David Herrmann wrote:
> +/* insert slice into the free tree */
> +static void bus1_pool_slice_link_free(struct bus1_pool_slice *slice,
> +				      struct bus1_pool *pool)
> +{
> +	struct rb_node **n, *prev = NULL;
> +	struct bus1_pool_slice *ps;
> +
> +	n = &pool->slices_free.rb_node;
> +	while (*n) {
> +		prev = *n;
> +		ps = container_of(prev, struct bus1_pool_slice, rb);
> +		if (slice->size < ps->size)
> +			n = &prev->rb_left;
> +		else
> +			n = &prev->rb_right;
> +	}
> +
> +	rb_link_node(&slice->rb, prev, n);
> +	rb_insert_color(&slice->rb, &pool->slices_free);
> +}

If you only sort free slices by size, how do you merge contiguous free
slices?

> +/* find free slice big enough to hold @size bytes */
> +static struct bus1_pool_slice *
> +bus1_pool_slice_find_by_size(struct bus1_pool *pool, size_t size)
> +{
> +	struct bus1_pool_slice *ps, *closest = NULL;
> +	struct rb_node *n;
> +
> +	n = pool->slices_free.rb_node;
> +	while (n) {
> +		ps = container_of(n, struct bus1_pool_slice, rb);
> +		if (size < ps->size) {
> +			closest = ps;
> +			n = n->rb_left;
> +		} else if (size > ps->size) {
> +			n = n->rb_right;
> +		} else /* if (size == ps->size) */ {
> +			return ps;
> +		}
> +	}
> +
> +	return closest;
> +}
> +
> +/* find used slice with given offset */
> +static struct bus1_pool_slice *
> +bus1_pool_slice_find_by_offset(struct bus1_pool *pool, size_t offset)
> +{
> +	struct bus1_pool_slice *ps;
> +	struct rb_node *n;
> +
> +	n = pool->slices_busy.rb_node;
> +	while (n) {
> +		ps = container_of(n, struct bus1_pool_slice, rb);
> +		if (offset < ps->offset)
> +			n = n->rb_left;
> +		else if (offset > ps->offset)
> +			n = n->rb_right;
> +		else /* if (offset == ps->offset) */
> +			return ps;
> +	}
> +
> +	return NULL;
> +}

I find these two function names misleading. They don't find_by_size or
find_by_offset. They find_free_by_size and find_busy_by_offset. You
could reduce that to find_free and find_busy and have the 'size' and
'offset' in the argument name.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ