I would like to be able to print the stack trace of a thread in the Linux kernel.
In details: I want to add code to specific functions (e.g. swap_writepage()<
swap_writepage()<
Linux kernel has very well known function called dump_stack() here, which prints the content of the stack. Place it in your function in according to see stack info.
dump_stack()