title: How to print the current thread stack trace inside the Linux kernel?
body: <p>I would like to be able to print the stack trace of a thread in the Linux kernel.</p>
  <p>In details: I want to add code to specific functions (e.g. <code>swap_writepage()</code> ) that will print the complete stack trace of the thread where this function is being called. Something like this:</p>
  <pre><code>int swap_writepage(struct page *page, struct writeback_control *wbc)
  {
  
      /* code goes here to print stack trace */
  
      int ret = 0;
  
      if (try_to_free_swap(page)) {
          unlock_page(page);
          goto out;
      }
      if (frontswap_store(page) == 0) {
          set_page_writeback(page);
          unlock_page(page);
          end_page_writeback(page);
          goto out;
      }
      ret = __swap_writepage(page, wbc, end_swap_bio_write);
  out:
      return ret;
  }
  </code></pre>