当前位置:网站首页>Page table cache of Linux kernel source code analysis
Page table cache of Linux kernel source code analysis
2022-07-25 17:04:00 【To maintain world peace_】
Memory unit of processor (MMU) Responsible for converting virtual addresses into physical addresses . In order to improve the conversion speed from virtual address to physical address , introduce TLB The cache of . Namely page table cache
The page table cache is used to cache recently used page table entries , Some processors use a two-level page table cache : first stage TLB Divided into instructions TLB And data TLB, Level second TLB It's unity TLB, That is, instructions and data are common TLB
TLB management
If the kernel modifies the cache in TLB Data in , Then the old data must be abolished , How does the kernel ensure consistency ?
| function | |
| flush_tlb_all | Make all TLB invalid |
| flush_tlb_mm | Make all of the specified user address space TLB invalid |
| flush_tlb_range | Make the specified address space range TLB invalid |
| flush_tlb_page | Make the specified virtual address page in the specified user address space TLB The entry is invalid |
| flush_tlb_kernel_range | Make the kernel virtual address range TLB The entry is invalid |
| update_mmu_cache | After modifying the page table entry, set the page table entry to the page table cache , The processor that manages the page table cache by software must implement this function . |
| tlb_migrate_finish | After the kernel migrates processes from one processor to another , Call this function to update the page table cache or context specific information . |
When TLB When you miss ,ARM64 The memory management unit of the processor automatically traverses the page table in memory , Copy page entries to TLB, There is no need for software to write the page table TLB, therefore ARM64 The schema does not provide write TLB Instructions .
#define isb() asm volatile("isb" : : : "memory")
#define dmb(opt) asm volatile("dmb " #opt : : : "memory")
#define dsb(opt) asm volatile("dsb " #opt : : : "memory")
#define __TLBI_1(op, arg) asm ("tlbi " #op ", %0\n" \
ALTERNATIVE("nop\n nop", \
"dsb ish\n tlbi " #op ", %0", \
ARM64_WORKAROUND_REPEAT_TLBI, \
CONFIG_ARM64_WORKAROUND_REPEAT_TLBI) \
: : "r" (arg))
#define __TLBI_N(op, arg, n, ...) __TLBI_##n(op, arg)
#define __tlbi(op, ...) __TLBI_N(op, ##__VA_ARGS__, 1, 0)static inline void flush_tlb_all(void)
{
dsb(ishst);
__tlbi(vmalle1is);
dsb(ish);
isb();
}
The expanded procedure is
static inline void flush_tlb_all(void)
{
// Ensure that the stored instructions in front of the barrier are executed ,dsb It's data synchronization ,ish Indicates that the shared domain is an internal share ,st Indicates storage
asm volatile("dsb ishst" : : : "memory");
// Make all cores match the current VMID, Stage 1 And exception level 1 All of the TLB The entry is invalid
asm ("tlbi vmallelis" : :);
// Make sure TLB The previous instructions have been executed
asm volatile("dsb ish" : : : "memory");
// Command synchronization barrier , Instructions wash the pipeline of the processor , Reread all instructions following the barrier instruction
asm volatile("isb" : : : "memory")
}
local_flush_tlb_all Used to make all of the current core TLB The entry is invalid
static inline void local_flush_tlb_all(void)
{
dsb(nshst);
__tlbi(vmalle1);
dsb(nsh);
isb();
}
And the function flush_tlb_all The difference is as follows
1) Instructions dsb Medium ish Instead of nsh,nsh Yes no share , Indicates that the data synchronization barrier instruction only works in the current core
2) Instructions tlbi Not carrying is, Means to make only the current core TLB The entry is invalid .
Address space identifier
To reduce the need to empty the page table cache during process switching ,ARM64 The processor's page table cache uses non global bits to distinguish between kernel and process page table entries . Use an address space identifier ASID(Address Space Identifier) Distinguish the page table entries of different processes .
Virtual machine identifier
The virtual address of the guest operating system running in the virtual machine is changed into the physical address in two stages : The first 1 Stage virtual Address conversion to intermediate physical address , The first 2 Phase converts intermediate physical addresses into physical addresses . The first 1 The phase transition is operated by the customer Memory control of the system , The conversion process is the same as that of non virtualization . The first 2 Phase transitions are controlled by the virtual machine monitor , Virtual machine monitor The controller maintains a conversion table for each virtual machine , Assign a virtual machine identifier (Virtual Machine Identifier,VMID), register VTTBR_EL2( Virtualization conversion table reference register ,Virtualization Translation Table Base Register) The stage where the current virtual machine is stored 2 Translate the physical address of the table .
Reference link
https://course.0voice.com/v1/course/intro?courseId=2&agentId=0
边栏推荐
- Roson的Qt之旅#99 QML表格控件-TableView
- [target detection] yolov5 Runtong voc2007 dataset (repair version)
- easyui修改以及datagrid dialog form控件使用
- Chapter III data types and variables
- Homepage portal classification query
- EasyUI DataGrid control uses
- 虚拟内存管理
- What is the monthly salary of 10000 in China? The answer reveals the cruel truth of income
- 2D semantic segmentation -- deeplabv3plus reproduction
- Using rank to discuss the solution of linear equations / the positional relationship of three planes
猜你喜欢

Replicate swin on Huawei ascend910_ transformer

第三章、数据类型和变量

多租户软件开发架构

Mindoc makes mind map

Rebudget汇报PPT

博云容器云、DevOps平台斩获可信云“技术最佳实践奖”

Enterprise live broadcast: witness focused products, praise and embrace ecology
Go language series: where does go come from and where will go?

QT listview list display component notes

【南京航空航天大学】考研初试复试资料分享
随机推荐
Technical difficulties and applications of large humanoid robots
柏睿数据加入阿里云PolarDB开源数据库社区
7. Dependency injection
[MySQL] takes you to the database
Dynamic planning topic record
Chapter III data types and variables
【知识图谱】实践篇——基于医疗知识图谱的问答系统实践(Part4):结合问题分类的问题解析与检索语句生成
QT ListView 列表显示组件笔记
Exception handling mechanism topic 1
Is the online account opening of Founder futures reliable and safe?
Hcip notes 11 days
方正期货网上开户靠谱吗,开户安全吗?
Roson的Qt之旅#100 QML四种标准对话框(颜色、字体、文件、提升)
China's chip self-sufficiency rate has increased significantly, resulting in high foreign chip inventories and heavy losses. American chips can be said to have thrown themselves in the foot
Talk about how to use redis to realize distributed locks?
Go language series: where does go come from and where will go?
Fudan University EMBA peer topic: always put the value of consumers in the most important position
【知识图谱】实践篇——基于医疗知识图谱的问答系统实践(Part3):基于规则的问题分类
[knowledge atlas] practice -- Practice of question answering system based on medical knowledge atlas (Part4): problem analysis and retrieval sentence generation combined with problem classification
【南京航空航天大学】考研初试复试资料分享