当前位置:网站首页>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
边栏推荐
- 从数字化到智能运维:有哪些价值,又有哪些挑战?
- 在华为昇腾Ascend910上复现swin_transformer
- 首页门户分类查询
- [OBS] Reprint: what about the serious delay of OBS live broadcast and Caton?
- From digitalization to intelligent operation and maintenance: what are the values and challenges?
- Go language series: where does go come from and where will go?
- 中国芯片自给率大幅提升,导致外国芯片库存高企而损失惨重,美国芯片可谓捧起石头砸自己的脚...
- 3D 语义分割——Scribble-Supervised LiDAR Semantic Segmentation
- Rosen's QT journey 100 QML four standard dialog boxes (color, font, file, promotion)
- Unity is better to use the hot scheme Wolong
猜你喜欢

Automatic reply of wechat official account development message

2022年最新北京建筑施工焊工(建筑特种作业)模拟题库及答案解析

2D 语义分割——DeepLabV3plus 复现

复旦大学EMBA同学同行专题:始终将消费者的价值放在最重要的位置

The gas is exhausted! After 23 years of operation, the former "largest e-commerce website in China" has become yellow...

复旦大学EMBA2022毕业季丨毕业不忘初心 荣耀再上征程

Don't believe these "rumors" in the process of preparing for the exam!

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

Exception handling mechanism topic 1

MySQL之联表查询、常用函数、聚合函数
随机推荐
EasyUI modification and DataGrid dialog form control use
【小5聊】公众号排查<该公众号提供的服务出现故障,请稍后>
IAAs infrastructure cloud cloud network
What is chain game system development? How to make chain game system development
Go language series: where does go come from and where will go?
免费的低代码开发平台有哪些?
Redis cluster deployment based on redis6.2.4
Unity is better to use the hot scheme Wolong
虚拟内存管理
Talk about how to use redis to realize distributed locks?
Frustrated Internet people desperately knock on the door of Web3
The gas is exhausted! After 23 years of operation, the former "largest e-commerce website in China" has become yellow...
复旦大学EMBA同学同行专题:始终将消费者的价值放在最重要的位置
How to deploy applications on IPFs using 4everland cli
mindoc制作思维导图
Jenkins' role based authorization strategy installation configuration
【云驻共创】探秘GaussDB如何助力工商银行打造金融核心数据
ReBudget:通过运行时重新分配预算的方法,在基于市场的多核资源分配中权衡效率与公平性
[target detection] yolov5 Runtong voc2007 dataset (repair version)
Chapter 4: operators