linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Kees Cook <keescook@chromium.org>
To: Laura Abbott <labbott@redhat.com>
Cc: Alexander Potapenko <glider@google.com>,
	Christoph Lameter <cl@linux.com>,
	Nick Desaulniers <ndesaulniers@google.com>,
	Kostya Serebryany <kcc@google.com>,
	Dmitry Vyukov <dvyukov@google.com>,
	Sandeep Patil <sspatil@android.com>, Jann Horn <jannh@google.com>,
	Marco Elver <elver@google.com>,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	Andrew Morton <akpm@linux-foundation.org>
Subject: Re: [PATCH] lib/test_meminit.c: Add bulk alloc/free tests
Date: Thu, 7 Nov 2019 13:19:50 -0800	[thread overview]
Message-ID: <201911071318.A2FB7A9@keescook> (raw)
In-Reply-To: <20191107191447.23058-1-labbott@redhat.com>

On Thu, Nov 07, 2019 at 02:14:47PM -0500, Laura Abbott wrote:
> 
> kmem_cache_alloc_bulk/kmem_cache_free_bulk are used to
> make multiple allocations of the same size to avoid the
> overhead of multiple kmalloc/kfree calls. Extend the kmem_cache
> tests to make some calls to these APIs.
> 
> Signed-off-by: Laura Abbott <labbott@redhat.com>

Thanks! Andrew, can you add this to -mm please?

Reviewed-by: Kees Cook <keescook@chromium.org>

-Kees

> ---
>  lib/test_meminit.c | 20 +++++++++++++++++++-
>  1 file changed, 19 insertions(+), 1 deletion(-)
> 
> diff --git a/lib/test_meminit.c b/lib/test_meminit.c
> index 9729f271d150..20f330948b92 100644
> --- a/lib/test_meminit.c
> +++ b/lib/test_meminit.c
> @@ -183,6 +183,9 @@ static bool __init check_buf(void *buf, int size, bool want_ctor,
>  	return fail;
>  }
>  
> +#define BULK_SIZE 100
> +static void *bulk_array[BULK_SIZE];
> +
>  /*
>   * Test kmem_cache with given parameters:
>   *  want_ctor - use a constructor;
> @@ -203,9 +206,24 @@ static int __init do_kmem_cache_size(size_t size, bool want_ctor,
>  			      want_rcu ? SLAB_TYPESAFE_BY_RCU : 0,
>  			      want_ctor ? test_ctor : NULL);
>  	for (iter = 0; iter < 10; iter++) {
> +		/* Do a test of bulk allocations */
> +		if (!want_rcu && !want_ctor) {
> +			int ret;
> +
> +			ret = kmem_cache_alloc_bulk(c, alloc_mask, BULK_SIZE, bulk_array);
> +			if (!ret) {
> +				fail = true;
> +			} else {
> +				int i;
> +				for (i = 0; i < ret; i++)
> +					fail |= check_buf(bulk_array[i], size, want_ctor, want_rcu, want_zero);
> +				kmem_cache_free_bulk(c, ret, bulk_array);
> +			}
> +		}
> +
>  		buf = kmem_cache_alloc(c, alloc_mask);
>  		/* Check that buf is zeroed, if it must be. */
> -		fail = check_buf(buf, size, want_ctor, want_rcu, want_zero);
> +		fail |= check_buf(buf, size, want_ctor, want_rcu, want_zero);
>  		fill_with_garbage_skip(buf, size, want_ctor ? CTOR_BYTES : 0);
>  
>  		if (!want_rcu) {
> -- 
> 2.21.0
> 

-- 
Kees Cook


      reply	other threads:[~2019-11-07 21:19 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-07 19:14 [PATCH] lib/test_meminit.c: Add bulk alloc/free tests Laura Abbott
2019-11-07 21:19 ` Kees Cook [this message]

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=201911071318.A2FB7A9@keescook \
    --to=keescook@chromium.org \
    --cc=akpm@linux-foundation.org \
    --cc=cl@linux.com \
    --cc=dvyukov@google.com \
    --cc=elver@google.com \
    --cc=glider@google.com \
    --cc=jannh@google.com \
    --cc=kcc@google.com \
    --cc=labbott@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=ndesaulniers@google.com \
    --cc=sspatil@android.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).