title: Linux - Difference between migrations and switches?
body: <p>By looking at the scheduling stats in <code>/proc/&lt;PID&gt;/sched</code>, you can get an output like this:</p>
  
  <pre><code>[horro@system ~]$ cat /proc/1/sched
  systemd (1, #threads: 1)
  -------------------------------------------------------------------
  se.exec_start                                :    2499611106.982616
  se.vruntime                                  :          7952.917943
  se.sum_exec_runtime                          :         58651.279127
  se.nr_migrations                             :                53355
  nr_switches                                  :               169561
  nr_voluntary_switches                        :               168185
  nr_involuntary_switches                      :                 1376
  se.load.weight                               :              1048576
  se.avg.load_sum                              :               343837
  se.avg.util_sum                              :               338827
  se.avg.load_avg                              :                    7
  se.avg.util_avg                              :                    7
  se.avg.last_update_time                      :     2499611106982616
  policy                                       :                    0
  prio                                         :                  120
  clock-delta                                  :                  180
  mm-&gt;numa_scan_seq                            :                    1
  numa_pages_migrated                          :                  296
  numa_preferred_nid                           :                    0
  total_numa_faults                            :                   34
  current_node=0, numa_group_id=0
  numa_faults node=0 task_private=0 task_shared=23 group_private=0 group_shared=0
  numa_faults node=1 task_private=0 task_shared=0 group_private=0 group_shared=0
  numa_faults node=2 task_private=0 task_shared=0 group_private=0 group_shared=0
  numa_faults node=3 task_private=0 task_shared=11 group_private=0 group_shared=0
  numa_faults node=4 task_private=0 task_shared=0 group_private=0 group_shared=0
  numa_faults node=5 task_private=0 task_shared=0 group_private=0 group_shared=0
  numa_faults node=6 task_private=0 task_shared=0 group_private=0 group_shared=0
  numa_faults node=7 task_private=0 task_shared=0 group_private=0 group_shared=0
  </code></pre>
  
  <p>I have been trying to figure out what are the differences between migrations and switches, some responses <a href="http://blog.tanelpoder.com/2013/02/21/peeking-into-linux-kernel-land-using-proc-filesystem-for-quickndirty-troubleshooting/" rel="noreferrer">here</a> and <a href="https://www.linuxquestions.org/questions/linux-newbie-8/can-someone-explain-the-output-of-proc-pid-sched-4175412750/" rel="noreferrer">here</a>. Summarizing these responses:</p>
  
  <ul>
  <li><code>nr_switches</code>: number of context switches.</li>
  <li><code>nr_voluntary_switches</code>: number of voluntary switches, i.e. the thread blocked and hence another thread is picked up.</li>
  <li><code>nr_involuntary_switches</code>: the scheduler kicked the thread out as there is another hungry thread is ready to run.</li>
  </ul>
  
  <p>Therefore, what are the <code>migrations</code>? Are these concepts related or not? Migrations are among cores and switches within a core?</p>