Switch_mm ()

Source: Internet
Author: User
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.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.