1.. include:: ../disclaimer-zh_CN.rst 2 3:Original: Documentation/core-api/cachetlb.rst 4 5:������: 6 7 ��������� Yanteng Si <siyanteng@loongson.cn> 8 ��������� Binbin Zhou <zhoubinbin@loongson.cn> 9 10:������: 11 12 ��������� Wu XiangCheng <bobwxc@email.cn> 13 14.. _cn_core-api_cachetlb: 15 16====================== 17Linux���������������TLB������ 18====================== 19 20:������: David S. Miller <davem@redhat.com> 21 22*���������TLB���Translation Lookaside Buffer���������������/���������������������* 23 24������������������Linux������������������������������������/TLB������������������������������������ 25��������������������������������������������������������������������������������� 26 27��������������������������������������������������������������������������������������������������������� 28���SMP��������������������������������������������������������������������������������������������������� 29������������������������������������������������������������SMP���������/tlb��������������������� 30��������������������������������������������������������������������������������������������������������� 31������������������������������cpu������������������mm_cpumask()������������������������������ 32cpu��������������������������������������� 33 34���������TLB������������������������������������������������Linux������TLB������������cpu 35������������������������������������������->������������������������������������������������������������ 36���������������������������TLB��������������������������������������������������������������������������������� 37������������������������������������������ *���������* ��������������������������������� 38 391) ``void flush_tlb_all(void)`` 40 41 ������������������������������������������������������������������������������������cpu��������� 42 43 ������������������������������������������������������������������������������������������������������ 44 452) ``void flush_tlb_mm(struct mm_struct *mm)`` 46 47 ���������������TLB��������������������������������������������������������������������������� 48 ������������������������mm���������������������������cpu��������������������������������������� 49 ������������TLB���������������mm������������������ 50 51 ������������������������������������������������������������������������fork���exec������ 52 ��������������������� 53 543) ``void flush_tlb_range(struct vm_area_struct *vma, 55 unsigned long start, unsigned long end)`` 56 57 ������������������TLB������������������������������������������������������������������������������ 58 ������������������������������������start���������end-1������������������������������vma->vm_mm��� 59 ������������������������cpu���������������������������������������������������TLB������������ 60 ���mm������������������������start���������end-1������������������������������ 61 62 ���vma������������������������������������������������������munmap()������������������ 63 64 ������������������������������������������������������������������������������TLB������������ 65 ��������������������������������������������������������������������������������������� 66 flush_tlb_page(���������)��� 67 684) ``void flush_tlb_page(struct vm_area_struct *vma, unsigned long addr)`` 69 70 ������������������������TLB���������PAGE_SIZE���������������������vma������Linux��������� 71 ������������mmap���������������������������������������������������vma->vm_mm������������ 72 ���������������������������vma->vm_flags & VM_EXEC��������������������������������� 73 ������������������������split-tlb������������������������������������TLB������������ 74 75 ���������������������������������������������������������������������addr������������������ 76 ���vma->vm_mm���������������������cpu���������������������������������������������������TLB 77 ���������������������������addr���������vma->vm_mm������������������ 78 79 ��������������������������������������� 80 815) ``void update_mmu_cache(struct vm_area_struct *vma, 82 unsigned long address, pte_t *ptep)`` 83 84 ��������������������������������������������������������������������������������������������������� 85 ������������������������������������vma->vm_mm������������������������������������������������ 86 ��������������� 87 88 ��������������������������������������������������������������������������������������������������� 89 ������������������������������TLB������������TLB���������������sparc64��������������������� 90 ������ 91 92������������������������������������������������������������Linux������������������->������������ 93���������������������������������������������������������:: 94 95 1) flush_cache_mm(mm); 96 change_all_page_tables_of(mm); 97 flush_tlb_mm(mm); 98 99 2) flush_cache_range(vma, start, end); 100 change_range_of_page_tables(mm, start, end); 101 flush_tlb_range(vma, start, end); 102 103 3) flush_cache_page(vma, addr, pfn); 104 set_pte(pte_pointer, new_pte_val); 105 flush_tlb_page(vma, addr); 106 107������������������������������������������������������������������������������������������������������ 108���������������������������������������������������������������������������->������������������������������ 109HyperSparc cpu���������������������������������������cpu��� 110 111������������������������������������������������cpu������������������������������������������������ 112���������������������������������cpu���������������cpu������������������������������������->��� 113���������������������������������������������������������������������IA32������������������������ 114��������������������������������������������������������������������������������������������������� 115������������������������������ 116 117������������������������������: 118 1191) ``void flush_cache_mm(struct mm_struct *mm)`` 120 121 ������������������������������������������������������������������������������������������������ 122 ���������������mm������������������������ 123 124 ��������������������������������������������������������������������������������������������� 125 ��������������������� 126 1272) ``void flush_cache_dup_mm(struct mm_struct *mm)`` 128 129 ��������������������������������������������������������������������������������������������� 130 ���������������������mm������������������������ 131 132 ������������������������������������������������������������������������fork��������������� 133 ������������ 134 135 ���������������flush_cache_mm���������������������VIPT��������������������������� 136 1373) ``void flush_cache_range(struct vm_area_struct *vma, 138 unsigned long start, unsigned long end)`` 139 140 ��������������������������������������������������������������������������������������������� 141 ������������start���������end-1���������������������������������vma->vm_mm��������������� 142 ��������������������� 143 144 ���vma���������������������������������������������������������munmap()������������������ 145 146 ������������������������������������������������������������������������������������������ 147 ��������������������������������� ��������������������������������������������������������� 148 ��� flush_cache_page (���������)��� 149 1504) ``void flush_cache_page(struct vm_area_struct *vma, unsigned long addr, unsigned long pfn)`` 151 152 ���������������������������������������������PAGE_SIZE���������������������vma������ 153 Linux���������������������mmap��������������������������������������������������� 154 vma->vm_mm���������������������������������������������vma->vm_flags & 155 VM_EXEC������������������������������������������������������������Harvard������ 156 ������������������������������������������������������������ 157 158 ���pfn������������addr������������������������������������PAGE_SHIFT������������ 159 ��������������������������������������������������������������������������� 160 161 ���������������������������������������addr���������vma->vm_mm������������������������ 162 ���������������������������������������pfn������ 163 164 ��������������������������������������������� 165 1665) ``void flush_cache_kmaps(void)`` 167 168 ��������������������������������������������������������������������������������������������� 169 kmaps������������������������ 170 171 ������������������������������������PKMAP_ADDR(0)���PKMAP_ADDR(LAST_PKMAP) 172 ��������������������������������� 173 174 ���������������������asm/highmem.h������������ 175 1766) ``void flush_cache_vmap(unsigned long start, unsigned long end)`` 177 ``void flush_cache_vunmap(unsigned long start, unsigned long end)`` 178 179 ��������������������������������������������������������������������������������������������� 180 ���������������������������������start���������end-1��������������������������������������� 181 ������������������������������������������ 182 183 ������������������������������������vmap_range()������������������������������������ 184 ���������������vunmap_range()��������������������������������� 185 186������������cpu������������������������������������������������������������������������������ 187��������������������������������������������������������� 188 189.. note:: 190 191 ������������������������������������������������������������������������������ 192 193 ���������alias������������������������������������������������������������������������ 194 ���������������������������������������index���������������������������������������(��� 195 ������������������������������)������������������������������������������������������������ 196 ������������������cacheline������������������������������ 197 198 ������������������������������������������������������������������������������������cpu��� 199 ������������������������������������PIPT���cache������������������������������������������ 200 ���������������������sparc������������������������������������������������������������������ 201 ��������������������������������������������������������� 202 203������������������������������D-cache������������������������������������������D-cache 204������������������������cache������PAGE_SIZE������������������������������������������ 205���������������������cache������������������������������������������������ 206 207������������D-cache������������������������������������asm/shmparam.h SHMLBA��� 208���������������������������������������D-cache��������������������������������������������� 209������������������������������������������������������SYSv IPC��������������������������� 210������������������������������������������������������������ 211 212.. note:: 213 214 ������������������������mmaps���������������������sparc64������������ 215 ��������������������������������������� SPARC_FLAG_MMAPSHARED������ 216 217���������������������������������������������������D-cache��������������������������������� 218������������������������������������������������������������������������������������������������ 219���������������������������������������������PAGE_OFFSET��������������������������������� 220���������������������������������������������������������������������������D-cache��������� 221������������������������������������������������������������������������������������ 222 223 ``void copy_user_page(void *to, void *from, unsigned long addr, struct page *page)`` 224 ``void clear_user_page(void *to, unsigned long addr, struct page *page)`` 225 226 ���������������������������������COW��������������������������������������������������� 227 ������������������������������������D-cache��������������� 228 229 ���������������������������������������������������from���������to������������������������ 230 ���������������������������������������������������������������������������������������/��� 231 ������������������������������������������������������������������������������������������ 232 ���������������������������Sparc64������������������������ 233 234 ���addr������������������������������������������������������������������������page������ 235 ������������������������������������������������������ 236 237 ������D-cache��������������������������������������������������������������� 238 memcpy/memset������������������������ 239 240 ``void flush_dcache_page(struct page *page)`` 241 242 ������������������������������������������������������������������������������������������ 243 ������������������������������������������������������/������������������������������ 244 ������������������������������ 245 246 .. note:: 247 248 ��������������������������������������������������������������������������� 249 ������������������������������������������������������������vfs��������� 250 ������VFS��������������������������������������������� 251 252 ��������������������������������������������������������������������������������������������� 253 ���������������������������������->��������������������������������������������������������� 254 ������������������������D-cache��������������������������������������������������������� 255 ������������������������������������������ 256 257 ������������������������������������������������������������������������+������������������ 258 ������������������������������������������������������������������������������������������ 259 260 ������D-cache��������������������������������������������������������������������������� 261 ���nop��� 262 263 ���page->flags (PG_arch_1)������������������������������������������������������ 264 ��������������������������������������������������������������������������������������������� 265 ������������ 266 267 ��������������������������������������������������������������������������������������������� 268 ������������������������������������������������������������������������������������������ 269 sparc64���flush_dcache_page���update_mmu_cache��������������������� 270 ��������������������� 271 272 ���������������������������flush_dcache_page()������������page->mapping->i_mmap 273 ���������������������������������������������������������������������update_mmu_cache() 274 ��������������������������������������������������������������������������������������������������� 275 276 .. important:: 277 278 ��������������������������������������������������������������������������������� 279 CPU������������������cpu��������������������������������������������������� 280 sparc64������������������������������������������ 281 282 ``void flush_dcache_folio(struct folio *folio)`` 283 284 ���������������������������flush_dcache_page()������������������������������������������ 285 folio��������������������������������������������������� 286 287 ``void copy_to_user_page(struct vm_area_struct *vma, struct page *page, 288 unsigned long user_vaddr, void *dst, void *src, int len)`` 289 ``void copy_from_user_page(struct vm_area_struct *vma, struct page *page, 290 unsigned long user_vaddr, void *dst, void *src, int len)`` 291 292 ������������������������������������������������������������������������ptrace()��������������� 293 ��������������������� 294 295 ��������������������������������������������������������������������������������������������������� 296 ���������������������������������cpu������������������������������������������������ 297 copy_to_user_page()��������������������� 298 299 ``void flush_anon_page(struct vm_area_struct *vma, struct page *page, 300 unsigned long vmaddr)`` 301 302 ������������������������������������������������������������������������������������������ 303 get_user_pages()���������������flush_dcache_page()��������������������������� 304 ������������������������nop������������������������������������������������������������������������ 305 ���������������������������vmaddr��������������������� 306 307 ``void flush_icache_range(unsigned long start, unsigned long end)`` 308 309 ������������������������������������������������������������������������������������������������������ 310 311 ������icache��������������������������������������������������������������������������� 312 313 ``void flush_icache_page(struct vm_area_struct *vma, struct page *page)`` 314 315 flush_icache_page���������������������������flush_dcache_page���update_mmu_cache 316 ��������������������������������������������������������������������� 317 318������������API���������I/O��������������������������������������������������������������������������� 319vmap/vmalloc API������������������������I/O������������������������������I/O��������������������� 320������������������������������������������������������vmap��������������������������������������������������� 321���������vmap������������I/O���������������������������������������������������������I/O������������vmap 322���������������I/O������������������������ 323 324 ``void flush_kernel_vmap_range(void *vaddr, int size)`` 325 326 ������vmap���������������������������������������������������������������������������������vmap������ 327 ��������������������������������������������������������������������������������������������������������� 328 ���I/O������������������API��� *������* ��������������������������������������� 329 330 ``void invalidate_kernel_vmap_range(void *vaddr, int size) invalidates`` 331 332 ���vmap���������������������������������������������������������������������������������������������I/O 333 ���������������������������������������������������������������������������vmap������������������������������ 334