Skip to content

Commit 504f52b

Browse files
Eric Dumazettorvalds
authored andcommitted
mm: NUMA aware alloc_task_struct_node()
All kthreads being created from a single helper task, they all use memory from a single node for their kernel stack and task struct. This patch suite creates kthread_create_on_cpu(), adding a 'cpu' parameter to parameters already used by kthread_create(). This parameter serves in allocating memory for the new kthread on its memory node if available. Users of this new function are : ksoftirqd, kworker, migration, pktgend... This patch: Add a node parameter to alloc_task_struct(), and change its name to alloc_task_struct_node() This change is needed to allow NUMA aware kthread_create_on_cpu() Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com> Acked-by: David S. Miller <davem@davemloft.net> Reviewed-by: Andi Kleen <ak@linux.intel.com> Acked-by: Rusty Russell <rusty@rustcorp.com.au> Cc: Tejun Heo <tj@kernel.org> Cc: Tony Luck <tony.luck@intel.com> Cc: Fenghua Yu <fenghua.yu@intel.com> Cc: David Howells <dhowells@redhat.com> Cc: <linux-arch@vger.kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 9d502c1 commit 504f52b

5 files changed

Lines changed: 19 additions & 9 deletions

File tree

‎arch/frv/include/asm/processor.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ unsigned long get_wchan(struct task_struct *p);
137137
#define KSTK_ESP(tsk) ((tsk)->thread.frame0->sp)
138138

139139
/* Allocation and freeing of basic task resources. */
140-
extern struct task_struct *alloc_task_struct(void);
140+
extern struct task_struct *alloc_task_struct_node(int node);
141141
extern void free_task_struct(struct task_struct *p);
142142

143143
#define cpu_relax() barrier()

‎arch/frv/kernel/process.c‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,10 @@ asmlinkage void ret_from_fork(void);
4444
void (*pm_power_off)(void);
4545
EXPORT_SYMBOL(pm_power_off);
4646

47-
struct task_struct *alloc_task_struct(void)
47+
struct task_struct *alloc_task_struct_node(int node)
4848
{
49-
struct task_struct *p = kmalloc(THREAD_SIZE, GFP_KERNEL);
49+
struct task_struct *p = kmalloc_node(THREAD_SIZE, GFP_KERNEL, node);
50+
5051
if (p)
5152
atomic_set((atomic_t *)(p+1), 1);
5253
return p;

‎arch/ia64/include/asm/thread_info.h‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,14 @@ struct thread_info {
8484
#define end_of_stack(p) (unsigned long *)((void *)(p) + IA64_RBS_OFFSET)
8585

8686
#define __HAVE_ARCH_TASK_STRUCT_ALLOCATOR
87-
#define alloc_task_struct() ((struct task_struct *)__get_free_pages(GFP_KERNEL | __GFP_COMP, KERNEL_STACK_SIZE_ORDER))
87+
#define alloc_task_struct_node(node) \
88+
({ \
89+
struct page *page = alloc_pages_node(node, GFP_KERNEL | __GFP_COMP, \
90+
KERNEL_STACK_SIZE_ORDER); \
91+
struct task_struct *ret = page ? page_address(page) : NULL; \
92+
\
93+
ret;
94+
})
8895
#define free_task_struct(tsk) free_pages((unsigned long) (tsk), KERNEL_STACK_SIZE_ORDER)
8996

9097
#endif /* !__ASSEMBLY */

‎arch/um/include/asm/processor-generic.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ struct thread_struct {
6666
.request = { 0 } \
6767
}
6868

69-
extern struct task_struct *alloc_task_struct(void);
69+
extern struct task_struct *alloc_task_struct_node(int node);
7070

7171
static inline void release_thread(struct task_struct *task)
7272
{

‎kernel/fork.c‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,10 @@ int nr_processes(void)
109109
}
110110

111111
#ifndef __HAVE_ARCH_TASK_STRUCT_ALLOCATOR
112-
# define alloc_task_struct() kmem_cache_alloc(task_struct_cachep, GFP_KERNEL)
113-
# define free_task_struct(tsk) kmem_cache_free(task_struct_cachep, (tsk))
112+
# define alloc_task_struct_node(node) \
113+
kmem_cache_alloc_node(task_struct_cachep, GFP_KERNEL, node)
114+
# define free_task_struct(tsk) \
115+
kmem_cache_free(task_struct_cachep, (tsk))
114116
static struct kmem_cache *task_struct_cachep;
115117
#endif
116118

@@ -249,12 +251,12 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
249251
struct task_struct *tsk;
250252
struct thread_info *ti;
251253
unsigned long *stackend;
252-
254+
int node = numa_node_id();
253255
int err;
254256

255257
prepare_to_copy(orig);
256258

257-
tsk = alloc_task_struct();
259+
tsk = alloc_task_struct_node(node);
258260
if (!tsk)
259261
return NULL;
260262

0 commit comments

Comments
 (0)