linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Glauber Costa <glommer@parallels.com>
To: Christoph Lameter <cl@linux.com>
Cc: Pekka Enberg <penberg@kernel.org>, Joonsoo Kim <js1304@gmail.com>,
	linux-mm@kvack.org, David Rientjes <rientjes@google.com>,
	elezegarcia@gmail.com
Subject: Re: CK2 [07/15] Common kmalloc slab index determination
Date: Mon, 22 Oct 2012 13:45:24 +0400	[thread overview]
Message-ID: <508515B4.1090303@parallels.com> (raw)
In-Reply-To: <0000013a798237ec-faa35541-43fa-4257-b7dc-da955393004f-000000@email.amazonses.com>

On 10/19/2012 06:51 PM, Christoph Lameter wrote:
> Extract the function to determine the index of the slab within
> the array of kmalloc caches as well as a function to determine
> maximum object size from the nr of the kmalloc slab.
> 
> This is used here only to simplify slub bootstrap but will
> be used later also for SLAB.
> 
> Signed-off-by: Christoph Lameter <cl@linux.com> 
> 

> +static __always_inline int kmalloc_index(size_t size)
> +{
> +	if (!size)
> +		return 0;
> +
> +	if (size <= KMALLOC_MIN_SIZE)
> +		return KMALLOC_SHIFT_LOW;
> +
> +	if (KMALLOC_MIN_SIZE <= 32 && size > 64 && size <= 96)
> +		return 1;
> +	if (KMALLOC_MIN_SIZE <= 64 && size > 128 && size <= 192)
> +		return 2;
> +	if (size <=          8) return 3;
> +	if (size <=         16) return 4;
> +	if (size <=         32) return 5;
> +	if (size <=         64) return 6;
> +	if (size <=        128) return 7;
> +	if (size <=        256) return 8;
> +	if (size <=        512) return 9;
> +	if (size <=       1024) return 10;
> +	if (size <=   2 * 1024) return 11;
> +	if (size <=   4 * 1024) return 12;
> +	if (size <=   8 * 1024) return 13;
> +	if (size <=  16 * 1024) return 14;
> +	if (size <=  32 * 1024) return 15;
> +	if (size <=  64 * 1024) return 16;
> +	if (size <= 128 * 1024) return 17;
> +	if (size <= 256 * 1024) return 18;
> +	if (size <= 512 * 1024) return 19;
> +	if (size <= 1024 * 1024) return 20;
> +	if (size <=  2 * 1024 * 1024) return 21;
> +	if (size <=  4 * 1024 * 1024) return 22;
> +	if (size <=  8 * 1024 * 1024) return 23;
> +	if (size <=  16 * 1024 * 1024) return 24;
> +	if (size <=  32 * 1024 * 1024) return 25;
> +	if (size <=  64 * 1024 * 1024) return 26;
> +	BUG();
> +
> +	/* Will never be reached. Needed because the compiler may complain */
> +	return -1;
> +}
> +

It is still unclear to me if the above is really better than
ilog2(size -1) + 1

For that case, gcc seems to generate dec + brs + inc which at some point
will be faster than walking a jump table. At least for dynamically-sized
allocations. The code size is definitely smaller, and this is always
inline... Anyway, this is totally separate.

The patch also seem to have some churn for the slob for no reason: you
have a patch just to move the kmalloc definitions, would maybe be better
to do it in there to decrease the # of changes in this one, which is
more complicated.

The change itself looks fine.


--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

  reply	other threads:[~2012-10-22  9:45 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20121019142254.724806786@linux.com>
2012-10-19 14:25 ` CK2 [01/15] slab: Simplify bootstrap Christoph Lameter
2012-10-22  7:57   ` Glauber Costa
2012-10-23 20:45     ` Christoph Lameter
2012-10-19 14:25 ` CK2 [02/15] create common functions for boot slab creation Christoph Lameter
2012-10-20 15:57   ` JoonSoo Kim
2012-10-19 14:32 ` CK2 [14/15] stat: Use size_t for sizes instead of unsigned Christoph Lameter
2012-10-22  8:42   ` Glauber Costa
2012-10-19 14:32 ` CK2 [05/15] Common alignment code Christoph Lameter
2012-10-19 14:32 ` CK2 [12/15] Common definition for the array of kmalloc caches Christoph Lameter
2012-10-19 14:42 ` CK2 [13/15] Common function to create the kmalloc array Christoph Lameter
2012-10-22  9:51   ` Glauber Costa
2012-10-19 14:42 ` CK2 [15/15] Common Kmalloc cache determination Christoph Lameter
2012-10-20 16:20   ` JoonSoo Kim
2012-10-23 20:40     ` Christoph Lameter
2012-10-19 14:42 ` CK2 [04/15] slab: Use the new create_boot_cache function to simplify bootstrap Christoph Lameter
2012-10-20 16:01   ` JoonSoo Kim
2012-10-22  8:09   ` Glauber Costa
2012-10-23 21:40     ` Christoph Lameter
2012-10-19 14:45 ` CK2 [08/15] slab: Use common kmalloc_index/kmalloc_size functions Christoph Lameter
2012-10-20 16:12   ` JoonSoo Kim
2012-10-23 20:39     ` Christoph Lameter
2012-10-24 17:47       ` JoonSoo Kim
2012-10-19 14:49 ` CK2 [09/15] slab: Common name for the per node structures Christoph Lameter
2012-10-20 16:14   ` JoonSoo Kim
2012-10-23 20:39     ` Christoph Lameter
2012-10-22  8:32   ` Glauber Costa
2012-10-19 14:51 ` CK2 [07/15] Common kmalloc slab index determination Christoph Lameter
2012-10-22  9:45   ` Glauber Costa [this message]
2012-10-23 20:48     ` Christoph Lameter
2012-10-19 14:51 ` CK2 [03/15] slub: Use a statically allocated kmem_cache boot structure for bootstrap Christoph Lameter
2012-10-19 14:51 ` CK2 [06/15] Move kmalloc related function defs Christoph Lameter
2012-10-22  8:11   ` Glauber Costa
2012-10-19 14:51 ` CK2 [10/15] slab: rename nodelists to node Christoph Lameter
2012-10-22  8:34   ` Glauber Costa
2012-10-19 14:58 ` CK2 [11/15] Common constants for kmalloc boundaries Christoph Lameter

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=508515B4.1090303@parallels.com \
    --to=glommer@parallels.com \
    --cc=cl@linux.com \
    --cc=elezegarcia@gmail.com \
    --cc=js1304@gmail.com \
    --cc=linux-mm@kvack.org \
    --cc=penberg@kernel.org \
    --cc=rientjes@google.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