Skip to content

Commit

Permalink
sched/numa: Call task_numa_free() from do_execve()
Browse files Browse the repository at this point in the history
It is possible for a task in a numa group to call exec, and
have the new (unrelated) executable inherit the numa group
association from its former self.

This has the potential to break numa grouping, and is trivial
to fix.

Signed-off-by: Rik van Riel <riel@redhat.com>
Signed-off-by: Mel Gorman <mgorman@suse.de>
Cc: Andrea Arcangeli <aarcange@redhat.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Srikar Dronamraju <srikar@linux.vnet.ibm.com>
Signed-off-by: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/1381141781-10992-51-git-send-email-mgorman@suse.de
Signed-off-by: Ingo Molnar <mingo@kernel.org>
  • Loading branch information
Rik van Riel authored and Ingo Molnar committed Oct 9, 2013
1 parent 83e1d2c commit 8272701
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
1 change: 1 addition & 0 deletions fs/exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -1547,6 +1547,7 @@ static int do_execve_common(const char *filename,
current->fs->in_exec = 0;
current->in_execve = 0;
acct_update_integrals(current);
task_numa_free(current);
free_bprm(bprm);
if (displaced)
put_files_struct(displaced);
Expand Down
4 changes: 4 additions & 0 deletions include/linux/sched.h
Original file line number Diff line number Diff line change
Expand Up @@ -1458,6 +1458,7 @@ struct task_struct {
extern void task_numa_fault(int last_node, int node, int pages, int flags);
extern pid_t task_numa_group_id(struct task_struct *p);
extern void set_numabalancing_state(bool enabled);
extern void task_numa_free(struct task_struct *p);
#else
static inline void task_numa_fault(int last_node, int node, int pages,
int flags)
Expand All @@ -1470,6 +1471,9 @@ static inline pid_t task_numa_group_id(struct task_struct *p)
static inline void set_numabalancing_state(bool enabled)
{
}
static inline void task_numa_free(struct task_struct *p)
{
}
#endif

static inline struct pid *task_pid(struct task_struct *task)
Expand Down
9 changes: 8 additions & 1 deletion kernel/sched/fair.c
Original file line number Diff line number Diff line change
Expand Up @@ -1418,6 +1418,7 @@ void task_numa_free(struct task_struct *p)
{
struct numa_group *grp = p->numa_group;
int i;
void *numa_faults = p->numa_faults;

if (grp) {
for (i = 0; i < 2*nr_node_ids; i++)
Expand All @@ -1433,7 +1434,9 @@ void task_numa_free(struct task_struct *p)
put_numa_group(grp);
}

kfree(p->numa_faults);
p->numa_faults = NULL;
p->numa_faults_buffer = NULL;
kfree(numa_faults);
}

/*
Expand All @@ -1452,6 +1455,10 @@ void task_numa_fault(int last_cpupid, int node, int pages, int flags)
if (!p->mm)
return;

/* Do not worry about placement if exiting */
if (p->state == TASK_DEAD)
return;

/* Allocate buffer to track faults on a per-node basis */
if (unlikely(!p->numa_faults)) {
int size = sizeof(*p->numa_faults) * 2 * nr_node_ids;
Expand Down
5 changes: 0 additions & 5 deletions kernel/sched/sched.h
Original file line number Diff line number Diff line change
Expand Up @@ -559,11 +559,6 @@ static inline u64 rq_clock_task(struct rq *rq)
#ifdef CONFIG_NUMA_BALANCING
extern int migrate_task_to(struct task_struct *p, int cpu);
extern int migrate_swap(struct task_struct *, struct task_struct *);
extern void task_numa_free(struct task_struct *p);
#else /* CONFIG_NUMA_BALANCING */
static inline void task_numa_free(struct task_struct *p)
{
}
#endif /* CONFIG_NUMA_BALANCING */

#ifdef CONFIG_SMP
Expand Down

0 comments on commit 8272701

Please sign in to comment.