linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: Christoph Lameter <cl@linux.com>
Cc: Jesper Dangaard Brouer <brouer@redhat.com>,
	linux-kernel@vger.kernel.org, linux-mm@kvack.org,
	akpm@linuxfoundation.org, Pekka Enberg <penberg@kernel.org>,
	iamjoonsoo@lge.com
Subject: Re: Slab infrastructure for bulk object allocation and freeing V2
Date: Tue, 31 Mar 2015 14:20:25 -0700	[thread overview]
Message-ID: <20150331142025.63249f2f0189aee231a6e0c8@linux-foundation.org> (raw)
In-Reply-To: <alpine.DEB.2.11.1503300927290.6646@gentwo.org>

On Mon, 30 Mar 2015 09:31:19 -0500 (CDT) Christoph Lameter <cl@linux.com> wrote:

> After all of the earlier discussions I thought it would be better to
> first get agreement on the basic way to allow implementation of the
> bulk alloc in the common slab code. So this is a revision of the initial
> proposal and it just covers the first patch.
> 
> 
> 
> This patch adds the basic infrastructure for alloc / free operations
> on pointer arrays. It includes a generic function in the common
> slab code that is used in this infrastructure patch to
> create the unoptimized functionality for slab bulk operations.
> 
> Allocators can then provide optimized allocation functions
> for situations in which large numbers of objects are needed.
> These optimization may avoid taking locks repeatedly and
> bypass metadata creation if all objects in slab pages
> can be used to provide the objects required.

This patch doesn't really do anything.  I guess nailing down the
interface helps a bit.


> @@ -289,6 +289,8 @@ static __always_inline int kmalloc_index
>  void *__kmalloc(size_t size, gfp_t flags);
>  void *kmem_cache_alloc(struct kmem_cache *, gfp_t flags);
>  void kmem_cache_free(struct kmem_cache *, void *);
> +void kmem_cache_free_array(struct kmem_cache *, size_t, void **);
> +int kmem_cache_alloc_array(struct kmem_cache *, gfp_t, size_t, void **);
> 
>  #ifdef CONFIG_NUMA
>  void *__kmalloc_node(size_t size, gfp_t flags, int node);
> Index: linux/mm/slab_common.c
> ===================================================================
> --- linux.orig/mm/slab_common.c	2015-03-30 08:48:12.923927793 -0500
> +++ linux/mm/slab_common.c	2015-03-30 08:57:41.737572817 -0500
> @@ -105,6 +105,29 @@ static inline int kmem_cache_sanity_chec
>  }
>  #endif
> 
> +int __kmem_cache_alloc_array(struct kmem_cache *s, gfp_t flags, size_t nr,
> +								void **p)
> +{
> +	size_t i;
> +
> +	for (i = 0; i < nr; i++) {
> +		void *x = p[i] = kmem_cache_alloc(s, flags);
> +		if (!x)
> +			return i;
> +	}
> +	return nr;
> +}

Some documentation would be nice.  It's a major new interface, exported
to modules.  And it isn't completely obvious, because the return
semantics are weird.

What's the reason for returning a partial result when ENOMEM?  Some
callers will throw away the partial result and simply fail out.  If a
caller attempts to go ahead and use the partial result then great, but
you can bet that nobody will actually runtime test this situation, so
the interface is an invitation for us to release partially-tested code
into the wild.


Instead of the above, did you consider doing

int __weak kmem_cache_alloc_array(struct kmem_cache *s, gfp_t flags, size_t nr,

?

This way we save a level of function call and all that wrapper code in
the allocators simply disappears.

> --- linux.orig/mm/slab.c	2015-03-30 08:48:12.923927793 -0500
> +++ linux/mm/slab.c	2015-03-30 08:49:08.398137844 -0500
> @@ -3401,6 +3401,17 @@ void *kmem_cache_alloc(struct kmem_cache
>  }
>  EXPORT_SYMBOL(kmem_cache_alloc);
> 
> +void kmem_cache_free_array(struct kmem_cache *s, size_t size, void **p) {
> +	__kmem_cache_free_array(s, size, p);
> +}

Coding style is weird.


--
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>

  parent reply	other threads:[~2015-03-31 21:20 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-30 14:31 Christoph Lameter
2015-03-31  0:17 ` Jesper Dangaard Brouer
2015-03-31 21:20 ` Andrew Morton [this message]
2015-04-02 14:25   ` Christoph Lameter
2015-04-02 20:42     ` Andrew Morton
2015-04-06 18:27       ` 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=20150331142025.63249f2f0189aee231a6e0c8@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=akpm@linuxfoundation.org \
    --cc=brouer@redhat.com \
    --cc=cl@linux.com \
    --cc=iamjoonsoo@lge.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=penberg@kernel.org \
    /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