process.c 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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, SLAB_PANIC, NULL);
  25. }
  26. #else
  27. struct thread_info *alloc_thread_info(struct task_struct *tsk)
  28. {
  29. #ifdef CONFIG_DEBUG_STACK_USAGE
  30. gfp_t mask = GFP_KERNEL | __GFP_ZERO;
  31. #else
  32. gfp_t mask = GFP_KERNEL;
  33. #endif
  34. return (struct thread_info *)__get_free_pages(mask, THREAD_SIZE_ORDER);
  35. }
  36. void free_thread_info(struct thread_info *ti)
  37. {
  38. free_pages((unsigned long)ti, THREAD_SIZE_ORDER);
  39. }
  40. #endif /* THREAD_SHIFT < PAGE_SHIFT */