Skip to content

Commit 12af660

Browse files
joelagnelpaulmckrcu
authored andcommitted
rcuperf: Measure memory footprint during kfree_rcu() test
During changes to kfree_rcu() code, we often check the amount of free memory. As an alternative to checking this manually, this commit adds a measurement in the test itself. It measures four times during the test for available memory, digitally filters these measurements to produce a running average with a weight of 0.5, and compares this digitally filtered value with the amount of available memory at the beginning of the test. Something like the following is printed at the end of the run: Total time taken by all kfree'ers: 6369738407 ns, loops: 10000, batches: 764, memory footprint: 216MB Signed-off-by: Joel Fernandes (Google) <[email protected]> Signed-off-by: Paul E. McKenney <[email protected]>
1 parent 5396d31 commit 12af660

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

kernel/rcu/rcuperf.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <linux/types.h>
1313
#include <linux/kernel.h>
1414
#include <linux/init.h>
15+
#include <linux/mm.h>
1516
#include <linux/module.h>
1617
#include <linux/kthread.h>
1718
#include <linux/err.h>
@@ -611,6 +612,7 @@ kfree_perf_thread(void *arg)
611612
long me = (long)arg;
612613
struct kfree_obj *alloc_ptr;
613614
u64 start_time, end_time;
615+
long long mem_begin, mem_during = 0;
614616

615617
VERBOSE_PERFOUT_STRING("kfree_perf_thread task started");
616618
set_cpus_allowed_ptr(current, cpumask_of(me % nr_cpu_ids));
@@ -626,6 +628,12 @@ kfree_perf_thread(void *arg)
626628
}
627629

628630
do {
631+
if (!mem_during) {
632+
mem_during = mem_begin = si_mem_available();
633+
} else if (loop % (kfree_loops / 4) == 0) {
634+
mem_during = (mem_during + si_mem_available()) / 2;
635+
}
636+
629637
for (i = 0; i < kfree_alloc_num; i++) {
630638
alloc_ptr = kmalloc(sizeof(struct kfree_obj), GFP_KERNEL);
631639
if (!alloc_ptr)
@@ -645,9 +653,11 @@ kfree_perf_thread(void *arg)
645653
else
646654
b_rcu_gp_test_finished = cur_ops->get_gp_seq();
647655

648-
pr_alert("Total time taken by all kfree'ers: %llu ns, loops: %d, batches: %ld\n",
656+
pr_alert("Total time taken by all kfree'ers: %llu ns, loops: %d, batches: %ld, memory footprint: %lldMB\n",
649657
(unsigned long long)(end_time - start_time), kfree_loops,
650-
rcuperf_seq_diff(b_rcu_gp_test_finished, b_rcu_gp_test_started));
658+
rcuperf_seq_diff(b_rcu_gp_test_finished, b_rcu_gp_test_started),
659+
(mem_begin - mem_during) >> (20 - PAGE_SHIFT));
660+
651661
if (shutdown) {
652662
smp_mb(); /* Assign before wake. */
653663
wake_up(&shutdown_wq);

0 commit comments

Comments
 (0)