#include #include #include #include #include #include #include #include #include #include #include #include #include static uint nr_structs = 2000; module_param(nr_structs, uint, 0644); static struct task_struct * kthread = NULL; static unsigned int my_get_order(unsigned int value) { unsigned int shifts = 0; if (!value) return 0; if (!(value & (value - 1))) value--; while (value > 0) { value >>= 1; shifts++; } return shifts; } static int thread_fn(void * data) { printk("Hello from thread %s. nr_structs=%u\n", current->comm, nr_structs); while (!kthread_should_stop()) { schedule(); } return 0; } static int kernel_memory_init(void) { printk(KERN_INFO "Loaded kernel_memory module\n"); kthread = kthread_create(thread_fn, NULL, "k_memory"); if (IS_ERR(kthread)) { printk(KERN_ERR "Failed to create kernel thread\n"); return PTR_ERR(kthread); } wake_up_process(kthread); return 0; } static void kernel_memory_exit(void) { kthread_stop(kthread); printk(KERN_INFO "Unloaded kernel_memory module\n"); } module_init(kernel_memory_init); module_exit(kernel_memory_exit); MODULE_LICENSE ("GPL");