From: Liam Howlett <liam.howlett@oracle.com>
To: "linux-fsdevel@vger.kernel.org" <linux-fsdevel@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
Matthew Wilcox <willy@infradead.org>
Cc: Liam Howlett <liam.howlett@oracle.com>
Subject: [PATCH 4/4] radix tree test suite: Add support for slab bulk APIs
Date: Wed, 12 May 2021 18:48:53 +0000 [thread overview]
Message-ID: <20210512184850.3526677-4-Liam.Howlett@Oracle.com> (raw)
In-Reply-To: <20210512184850.3526677-1-Liam.Howlett@Oracle.com>
Add support for kmem_cache_free_bulk() and kmem_cache_alloc_bulk() to
the radix tree test suite.
Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
---
tools/testing/radix-tree/linux.c | 61 +++++++++++++++++++++++++++
tools/testing/radix-tree/linux/slab.h | 3 ++
2 files changed, 64 insertions(+)
diff --git a/tools/testing/radix-tree/linux.c b/tools/testing/radix-tree/linux.c
index 7225b5c46bb6..726407f934d3 100644
--- a/tools/testing/radix-tree/linux.c
+++ b/tools/testing/radix-tree/linux.c
@@ -93,6 +93,67 @@ void kmem_cache_free(struct kmem_cache *cachep, void *objp)
pthread_mutex_unlock(&cachep->lock);
}
+void kmem_cache_free_bulk(struct kmem_cache *cachep, size_t size, void **list)
+{
+ if (kmalloc_verbose)
+ printk("Bulk free %p[0-%lu]\n", list, size - 1);
+
+ for (int i = 0; i < size; i++)
+ kmem_cache_free(cachep, list[i]);
+}
+
+int kmem_cache_alloc_bulk(struct kmem_cache *cachep, gfp_t gfp, size_t size,
+ void **p)
+{
+ size_t i;
+
+ if (kmalloc_verbose)
+ printk("Bulk alloc %lu\n", size);
+
+ if (!(gfp & __GFP_DIRECT_RECLAIM)) {
+ if (cachep->non_kernel < size)
+ return 0;
+
+ cachep->non_kernel -= size;
+ }
+
+ pthread_mutex_lock(&cachep->lock);
+ if (cachep->nr_objs >= size) {
+ struct radix_tree_node *node = cachep->objs;
+
+ for (i = 0; i < size; i++) {
+ cachep->nr_objs--;
+ cachep->objs = node->parent;
+ p[i] = cachep->objs;
+ }
+ pthread_mutex_unlock(&cachep->lock);
+ node->parent = NULL;
+ } else {
+ pthread_mutex_unlock(&cachep->lock);
+ for (i = 0; i < size; i++) {
+ if (cachep->align) {
+ posix_memalign(&p[i], cachep->align,
+ cachep->size * size);
+ } else {
+ p[i] = malloc(cachep->size * size);
+ }
+ if (cachep->ctor)
+ cachep->ctor(p[i]);
+ else if (gfp & __GFP_ZERO)
+ memset(p[i], 0, cachep->size);
+ }
+ }
+
+ for (i = 0; i < size; i++) {
+ uatomic_inc(&nr_allocated);
+ uatomic_inc(&nr_tallocated);
+ if (kmalloc_verbose)
+ printf("Allocating %p from slab\n", p[i]);
+ }
+
+ return size;
+}
+
void *kmalloc(size_t size, gfp_t gfp)
{
void *ret;
diff --git a/tools/testing/radix-tree/linux/slab.h b/tools/testing/radix-tree/linux/slab.h
index 2958830ce4d7..de3befdf14df 100644
--- a/tools/testing/radix-tree/linux/slab.h
+++ b/tools/testing/radix-tree/linux/slab.h
@@ -24,4 +24,7 @@ struct kmem_cache *kmem_cache_create(const char *name, unsigned int size,
unsigned int align, unsigned int flags,
void (*ctor)(void *));
+void kmem_cache_free_bulk(struct kmem_cache *cachep, size_t, void **);
+int kmem_cache_alloc_bulk(struct kmem_cache *cachep, gfp_t, size_t, void **);
+
#endif /* SLAB_H */
--
2.30.2
prev parent reply other threads:[~2021-05-12 19:49 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-05-12 18:48 [PATCH 1/4] radix tree test suite: Add support for fallthrough attribute Liam Howlett
2021-05-12 18:48 ` [PATCH 2/4] radix tree test suite: Add __must_be_array() support Liam Howlett
2021-05-12 21:46 ` Matthew Wilcox
2021-05-12 22:13 ` Liam Howlett
2021-05-12 18:48 ` [PATCH 3/4] radix tree test suite: Add kmem_cache enhancements and pr_err Liam Howlett
2021-05-12 18:48 ` Liam Howlett [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=20210512184850.3526677-4-Liam.Howlett@Oracle.com \
--to=liam.howlett@oracle.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=willy@infradead.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;
as well as URLs for NNTP newsgroup(s).