Skip to content
This repository has been archived by the owner on Jan 12, 2021. It is now read-only.

Commit

Permalink
kmod: run usermodehelpers only on cpus allowed for kthreadd V2
Browse files Browse the repository at this point in the history
usermodehelper() threads can currently run on all processors.  This is an
issue for low latency cores.  Spawnig a new thread causes cpu holdoffs in
the range of hundreds of microseconds to a few milliseconds.  Not good for
cores on which processes run that need to react as fast as possible.

kthreadd threads can be restricted using taskset to a limited set of
processors.  Then the kernel thread pool will not fork processes on those
anymore thereby protecting those processors from additional latencies.

Make usermodehelper() threads obey the limitations that kthreadd is
restricted to.  Kthreadd is not the parent of usermodehelper threads so we
need to explicitly get the allowed processors for kthreadd.

Before this patch there is no way to limit the cpus that usermodehelper
can run on since the affinity is set when the thread is spawned to all
processors.

Signed-off-by: Christoph Lameter <cl@linux.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Mike Galbraith <bitbucket@online.de>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Gilad Ben-Yossef <gilad@benyossef.com>
Cc: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
Cc: Mike Frysinger <vapier@gentoo.org>
Cc: Tejun Heo <tj@kernel.org>
Cc: Rusty Russell <rusty@rustcorp.com.au>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
  • Loading branch information
Christoph Lameter authored and sfrothwell committed Feb 13, 2014
1 parent a82211b commit f680378
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
1 change: 1 addition & 0 deletions include/linux/kthread.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ void kthread_parkme(void);
int kthreadd(void *unused);
extern struct task_struct *kthreadd_task;
extern int tsk_fork_get_node(struct task_struct *tsk);
void set_kthreadd_affinity(void);

/*
* Simple work processor based on kthread.
Expand Down
10 changes: 8 additions & 2 deletions kernel/kmod.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include <linux/ptrace.h>
#include <linux/async.h>
#include <asm/uaccess.h>
#include <linux/kthread.h>

#include <trace/events/module.h>

Expand Down Expand Up @@ -209,8 +210,13 @@ static int ____call_usermodehelper(void *data)
flush_signal_handlers(current, 1);
spin_unlock_irq(&current->sighand->siglock);

/* We can run anywhere, unlike our parent keventd(). */
set_cpus_allowed_ptr(current, cpu_all_mask);
/*
* Kthreadd can be restricted to a set of processors if the user wants to
* protect other processors from OS latencies. If that has happened then
* we do not want to disturb the other processors here either so we start
* the usermode helper threads only on the processors allowed for kthreadd.
*/
set_kthreadd_affinity();

/*
* Our parent is keventd, which runs with elevated scheduling priority.
Expand Down
9 changes: 9 additions & 0 deletions kernel/kthread.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,15 @@ void *kthread_data(struct task_struct *task)
return to_kthread(task)->data;
}

/*
* Set the affinity of the calling task to be the same
* as the kthreadd affinities.
*/
void set_kthreadd_affinity(void)
{
set_cpus_allowed(current, kthreadd_task->cpus_allowed);
}

/**
* probe_kthread_data - speculative version of kthread_data()
* @task: possible kthread task in question
Expand Down

0 comments on commit f680378

Please sign in to comment.