0

On a Linux kernel 3.11.0-13-generic i can't set affinity for kernel threads as in the following example:

>ps -p 828
  PID TTY          TIME CMD
  828 ?        00:00:00 nfsiod
>sudo taskset -pc 7 828
pid 828's current affinity list: 0-11
taskset: failed to set pid 828's affinity: Invalid argument
>sudo taskset -pc 7 17551
pid 17551's current affinity list: 7
pid 17551's new affinity list: 7
>

17551 is a user process, and nfsiod is a kernel thread. How can I change the affinity for the nfsiod deamon running as a kernel thread ?

Manuel Selva
  • 18,554
  • 22
  • 89
  • 134

1 Answers1

2

Many kernel threads set the flag PF_NO_SETAFFINITY:

#define PF_NO_SETAFFINITY 0x04000000 /* Userland is not allowed to meddle with cpus_allowed */

To change the affinity, you would have to change the kernel.

CL.
  • 173,858
  • 17
  • 217
  • 259
  • Thanks for the answer. Does the boot parameter isolcpus override this restriction ? – Manuel Selva Aug 18 '14 at 09:50
  • `isolcpus` just adds another restriction. – CL. Aug 18 '14 at 10:16
  • what do you mean by it adds another restriction ? Does for example isolcpus=1,2,3 ensures that a kernel thread seting its affinity for example to 0,1,2,3 (on a four core processor, able to run anywhere) will only run on cpu 0 ? – Manuel Selva Aug 18 '14 at 11:14
  • The `isolcpus` restriction is *independent* from the `PF_NO_SETAFFINITY` check. (And it affects the entire system, so it has no relation to this question.) – CL. Aug 18 '14 at 11:17
  • Accepted your answer. Nevertheless I am wondering if the isolcpus parameter will override affinity defined by kernel thread creation code. Do you think I have to ask another question for that ? – Manuel Selva Aug 18 '14 at 11:32
  • 1
    Why don't you just try it out? – CL. Aug 18 '14 at 12:22
  • I just tried, and the answer is no. So I conclude that as you suggested the only way to change the affinity for these threads is to change kernel. – Manuel Selva Aug 20 '14 at 11:16