mm_struct 中的 cpumask 是什么

What is cpumask in mm_struct

我正在阅读 linux 内核中的 TLB shotdown 代码,我看到 shotdown ipi's 仅发送到相应 mm_structcpu_vm_mask_var 中的 cpu 集但我找不到 cpu_vm_mask_var 在哪里更新。

所以问题是:

  1. mm_struct中的cpu_vm_mask_var字段代表什么?
  2. 在哪里更新?

我认为在击落案例中 cpu_vm_mask_var 应该说明有多少 CPU 包含当前进程 TLB 条目,但是 cpu_vm_mask_var 究竟维护了什么?

每个进程的内存描述符都有一个名为 cpu_vm_mask_var 的位掩码,它通常在进程至少在一个处理器上执行时使用。当进程被调度到处理器上的 运行 时,位掩码的相应位被设置。同样,当调度程序决定 运行 处理器上的其他内容时,相应的 but 将被重置。字段cpu_vm_mask_var在三种情况下被修改:

  • 当通过调用switch_mm更改内存描述符时。在这种情况下,与当前处理器对应的位为前一个进程清除并为下一个进程设置。
  • 当一个新的处理器被添加到系统时,clear_tasks_mm_cpumask 函数被调用,它重置对应于新处理器的位。
  • cpu_vm_mask_var用于支持惰性TLB切换机制。如果调度程序决定 运行 一个内核线程,它将通过调用 enter_lazy_tlb. However, in this case, there is no need to invalidate a TLB entry that refers to a user-mode paging structure entry because kernel threads don't access user mode entries. So performance can be improved by disabling TLB shootdowns requests for the processor on which the kernel thread is running and delay the invalidation until switching back to the process that may use the invalidated entries. When a processor that is running a kernel thread receives for the first time an inter-processor interrupt to invalidate one or more TLB entries, the switch_mm_irqs_off 函数来打开惰性 TLB 模式。此函数(在这种特殊情况下)将重置位掩码中对应于当前处理器的位,以便它不再接收任何有关刷新 TLB 用户模式条目的 IPI。当处理器切换到具有不同内存描述符的进程时,对 CR3 的写入将刷新所有非全局 TLB 条目。否则,当处理器切换回同一个进程时,它知道一个或多个已经无效,因此它也会刷新所有非全局 TLB 条目。 cpu_vm_mask_varswitch_mm_irqs_off 中修改。请注意,刷新内核模式 TLB 条目不使用此机制。