process.c 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #include <linux/mm.h>
  2. #include <linux/kernel.h>
  3. #include <linux/sched.h>
  4. #if THREAD_SHIFT < PAGE_SHIFT
  5. static struct kmem_cache *thread_info_cache;
  6. struct thread_info *alloc_thread_info(struct task_struct *tsk)
  7. {
  8. struct thread_info *ti;
  9. ti = kmem_cache_alloc(thread_info_cache, GFP_KERNEL);
  10. if (unlikely(ti == NULL))
  11. return NULL;
  12. #ifdef CONFIG_DEBUG_STACK_USAGE
  13. memset(ti, 0, THREAD_SIZE);
  14. #endif
  15. return ti;
  16. }
  17. void free_thread_info(struct thread_info *ti)
  18. {
  19. kmem_cache_free(thread_info_cache, ti);
  20. }
  21. void thread_info_cache_init(void)
  22. {
  23. thread_info_cache = kmem_cache_create("thread_info", THREAD_SIZE,
  24. THREAD_SIZE, 0, NULL);
  25. BUG_ON(thread_info_cache == NULL);
  26. }
  27. #else
  28. struct thread_info *alloc_thread_info(struct task_struct *tsk)
  29. {
  30. #ifdef CONFIG_DEBUG_STACK_USAGE
  31. gfp_t mask = GFP_KERNEL | __GFP_ZERO;
  32. #else
  33. gfp_t mask = GFP_KERNEL;
  34. #endif
  35. return (struct thread_info *)__get_free_pages(mask, THREAD_SIZE_ORDER);
  36. }
  37. void free_thread_info(struct thread_info *ti)
  38. {
  39. free_pages((unsigned long)ti, THREAD_SIZE_ORDER);
  40. }
  41. #endif /* THREAD_SHIFT < PAGE_SHIFT */