Switch_mm () is used to switch the user space. Specifically, the address translation table (PGD) is switched. Because PGD includes the process system space (0xc000 0000 ~ 0 xFFFF FFFF) and user space (0x0000 0000 ~ 0 xbfff FFFF) Address ing, but because all processes have the same system space address ing. Therefore, switching between user spaces is essentially performed.
- Each process has its own page Directory table PGD
- The reader may ask: the process itself has not been switched, but the page Directory pointer of the storage management mechanism has been switched to S3. will this not cause a problem? No, because the CPU runs in the system space at this time, and the Directory items corresponding to the system space in the page directory of all processes point to the same page table, no matter which process you switch to, the page Directory tables are the same, only the user space is affected, and the system space ing remains unchanged.
Static inline void switch_mm (struct mm_struct * Prev,
Struct mm_struct * next,
Struct task_struct * TSK)
...{
Int CPU = smp_processor_id ();
If (likely (prev! = NEXT ))...{
Cpu_clear (CPU, Prev-> cpu_vm_mask );
# Ifdef config_smp
Per_cpu (cpu_tlbstate, CPU). State = tlbstate_ OK;
Per_cpu (cpu_tlbstate, CPU). active_mm = next;
# Endif
Cpu_set (CPU, next-> cpu_vm_mask );
Load_convention (next-> PGD );
If (unlikely (prev-> context. LDT! = Next-> context. LDT ))
Load_ldt_nolock (& next-> context, CPU );
}
# Ifdef config_smp
Else ...{
Per_cpu (cpu_tlbstate, CPU). State = tlbstate_ OK;
Bug_on (per_cpu (cpu_tlbstate, CPU). active_mm! = NEXT );
If (! Cpu_test_and_set (CPU, next-> cpu_vm_mask ))...{
Load_convention (next-> PGD );
Load_ldt_nolock (& next-> context, CPU );
}
}
# Endif
}
LDT is only used in vm86 mode, so it is not a concern.
Convert the first address next-> PGD of the page Directory table of the Process next to the physical address, and write it into the register % 303. # define load_375 (pgdir)
ASM volatile ("movl % 0, % Convention": "R" (_ Pa (pgdir )))
- When the kernel writes the physical address of the page Directory table of the new process to the control register, the local TLB table item of the old page table is automatically refreshed.