Skip to content

Commit

Permalink
mm: NUMA aware alloc_task_struct_node()
Browse files Browse the repository at this point in the history
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 <[email protected]>
Acked-by: David S. Miller <[email protected]>
Reviewed-by: Andi Kleen <[email protected]>
Acked-by: Rusty Russell <[email protected]>
Cc: Tejun Heo <[email protected]>
Cc: Tony Luck <[email protected]>
Cc: Fenghua Yu <[email protected]>
Cc: David Howells <[email protected]>
Cc: <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Eric Dumazet authored and torvalds committed Mar 23, 2011
1 parent 9d502c1 commit 504f52b
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 9 deletions.
2 changes: 1 addition & 1 deletion arch/frv/include/asm/processor.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ unsigned long get_wchan(struct task_struct *p);
#define KSTK_ESP(tsk) ((tsk)->thread.frame0->sp)

/* Allocation and freeing of basic task resources. */
extern struct task_struct *alloc_task_struct(void);
extern struct task_struct *alloc_task_struct_node(int node);
extern void free_task_struct(struct task_struct *p);

#define cpu_relax() barrier()
Expand Down
5 changes: 3 additions & 2 deletions arch/frv/kernel/process.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,10 @@ asmlinkage void ret_from_fork(void);
void (*pm_power_off)(void);
EXPORT_SYMBOL(pm_power_off);

struct task_struct *alloc_task_struct(void)
struct task_struct *alloc_task_struct_node(int node)
{
struct task_struct *p = kmalloc(THREAD_SIZE, GFP_KERNEL);
struct task_struct *p = kmalloc_node(THREAD_SIZE, GFP_KERNEL, node);

if (p)
atomic_set((atomic_t *)(p+1), 1);
return p;
Expand Down
9 changes: 8 additions & 1 deletion arch/ia64/include/asm/thread_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,14 @@ struct thread_info {
#define end_of_stack(p) (unsigned long *)((void *)(p) + IA64_RBS_OFFSET)

#define __HAVE_ARCH_TASK_STRUCT_ALLOCATOR
#define alloc_task_struct() ((struct task_struct *)__get_free_pages(GFP_KERNEL | __GFP_COMP, KERNEL_STACK_SIZE_ORDER))
#define alloc_task_struct_node(node) \
({ \
struct page *page = alloc_pages_node(node, GFP_KERNEL | __GFP_COMP, \
KERNEL_STACK_SIZE_ORDER); \
struct task_struct *ret = page ? page_address(page) : NULL; \
\
ret;
})
#define free_task_struct(tsk) free_pages((unsigned long) (tsk), KERNEL_STACK_SIZE_ORDER)

#endif /* !__ASSEMBLY */
Expand Down
2 changes: 1 addition & 1 deletion arch/um/include/asm/processor-generic.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ struct thread_struct {
.request = { 0 } \
}

extern struct task_struct *alloc_task_struct(void);
extern struct task_struct *alloc_task_struct_node(int node);

static inline void release_thread(struct task_struct *task)
{
Expand Down
10 changes: 6 additions & 4 deletions kernel/fork.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,10 @@ int nr_processes(void)
}

#ifndef __HAVE_ARCH_TASK_STRUCT_ALLOCATOR
# define alloc_task_struct() kmem_cache_alloc(task_struct_cachep, GFP_KERNEL)
# define free_task_struct(tsk) kmem_cache_free(task_struct_cachep, (tsk))
# define alloc_task_struct_node(node) \
kmem_cache_alloc_node(task_struct_cachep, GFP_KERNEL, node)
# define free_task_struct(tsk) \
kmem_cache_free(task_struct_cachep, (tsk))
static struct kmem_cache *task_struct_cachep;
#endif

Expand Down Expand Up @@ -249,12 +251,12 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
struct task_struct *tsk;
struct thread_info *ti;
unsigned long *stackend;

int node = numa_node_id();
int err;

prepare_to_copy(orig);

tsk = alloc_task_struct();
tsk = alloc_task_struct_node(node);
if (!tsk)
return NULL;

Expand Down

0 comments on commit 504f52b

Please sign in to comment.