#include #include #include #include #include /* Meta Information */ MODULE_LICENSE("GPL"); static unsigned int i = 0; static char ** buffer; static int loop_cnt; static int alloc_size; module_param(loop_cnt, int, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP); module_param(alloc_size, int, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP); static int __init initmodule(void) { int size = sizeof(char); buffer = kmalloc_array(loop_cnt, size, GFP_KERNEL); printk(KERN_DEBUG "Allocating %d times the memory size of %d\n", loop_cnt, alloc_size); unsigned long long totalStart; unsigned long long totalStop; totalStart = rdtsc(); while (i < loop_cnt) { unsigned long long start; unsigned long long stop; start = rdtsc(); buffer[i] = kmalloc(alloc_size, GFP_KERNEL); stop = rdtsc(); printk(KERN_DEBUG "%i: It took %lld ticks to allocate the memory\n", i, stop - start); i++; } totalStop = rdtsc(); printk(KERN_DEBUG "Total: It took %lld ticks to allocate the memory\n", totalStop - totalStart); return 0; } static void __exit moduleExit(void) { while (i > 0) { kfree(buffer[i]); printk(KERN_DEBUG "Cleared\n"); i--; } } module_init(initmodule); module_exit(moduleExit);