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