[PATCH] rcuperf: Add support to vary the slab object sizes
From: Joel Fernandes
Date: Tue Jan 14 2020 - 09:59:23 EST
Signed-off-by: Joel Fernandes <joelaf@xxxxxxxxxx>
---
kernel/rcu/rcuperf.c | 43 ++++++++++++++++++++++++++++++++++++-------
1 file changed, 36 insertions(+), 7 deletions(-)
diff --git a/kernel/rcu/rcuperf.c b/kernel/rcu/rcuperf.c
index a4a8d097d84d..216d7c072ca2 100644
--- a/kernel/rcu/rcuperf.c
+++ b/kernel/rcu/rcuperf.c
@@ -600,17 +600,29 @@ static int kfree_nrealthreads;
static atomic_t n_kfree_perf_thread_started;
static atomic_t n_kfree_perf_thread_ended;
-struct kfree_obj {
- char kfree_obj[8];
- struct rcu_head rh;
-};
+/*
+ * Define a kfree_obj with size as the @size parameter + the size of rcu_head
+ * (rcu_head is 16 bytes on 64-bit arch).
+ */
+#define DEFINE_KFREE_OBJ(size) \
+struct kfree_obj_ ## size { \
+ char kfree_obj[size]; \
+ struct rcu_head rh; \
+}
+
+/* This should goto the right sized slabs on both 32-bit and 64-bit arch */
+DEFINE_KFREE_OBJ(16); // goes on kmalloc-32 slab
+DEFINE_KFREE_OBJ(32); // goes on kmalloc-64 slab
+DEFINE_KFREE_OBJ(64); // goes on kmalloc-96 slab
+DEFINE_KFREE_OBJ(96); // goes on kmalloc-128 slab
static int
kfree_perf_thread(void *arg)
{
int i, loop = 0;
long me = (long)arg;
- struct kfree_obj *alloc_ptr;
+ void *alloc_ptr;
+
u64 start_time, end_time;
long long mem_begin, mem_during = 0;
@@ -635,11 +647,28 @@ kfree_perf_thread(void *arg)
}
for (i = 0; i < kfree_alloc_num; i++) {
- alloc_ptr = kmalloc(sizeof(struct kfree_obj), GFP_KERNEL);
+ int kfree_type = i % 4;
+
+ if (kfree_type == 0)
+ alloc_ptr = kmalloc(sizeof(struct kfree_obj_16), GFP_KERNEL);
+ else if (kfree_type == 1)
+ alloc_ptr = kmalloc(sizeof(struct kfree_obj_32), GFP_KERNEL);
+ else if (kfree_type == 2)
+ alloc_ptr = kmalloc(sizeof(struct kfree_obj_64), GFP_KERNEL);
+ else
+ alloc_ptr = kmalloc(sizeof(struct kfree_obj_96), GFP_KERNEL);
+
if (!alloc_ptr)
return -ENOMEM;
- kfree_rcu(alloc_ptr, rh);
+ if (kfree_type == 0)
+ kfree_rcu((struct kfree_obj_16 *)alloc_ptr, rh);
+ else if (kfree_type == 1)
+ kfree_rcu((struct kfree_obj_32 *)alloc_ptr, rh);
+ else if (kfree_type == 2)
+ kfree_rcu((struct kfree_obj_64 *)alloc_ptr, rh);
+ else
+ kfree_rcu((struct kfree_obj_96 *)alloc_ptr, rh);
}
cond_resched();
--
2.25.0.rc1.283.g88dfdc4193-goog