彩色科技|linux内核写时复制机制源代码解读( 三 )
2252行 关联一个anon_vma实例到vma
2255行 到 2259行 判断原来的页表项映射的页是0页 , 就分配高端可移动的页并用0初始化
2261到2265行 如果不是0页 , 分配高端可移动的页 , 然后将原来的页拷贝到新页
2268if (mem_cgroup_try_charge_delay(new_page, mm, GFP_KERNEL,22702271__SetPageUptodate(new_page);22722273mmu_notifier_range_init(2275mmu_notifier_invalidate_range_start(22762277/*2278|* Re-check the pte - we dropped the lock2279|*/2280vmf->pte = pte_offset_map_lock(mm, vmf->pmd, vmf->address,2281if (likely(pte_same(*vmf->pte, vmf->orig_pte))) {2282if (old_page) {2283if (!PageAnon(old_page)) {2284dec_mm_counter_fast(mm,2285mm_counter_file(old_page));2286inc_mm_counter_fast(mm, MM_ANONPAGES);2287}2288} else {2289inc_mm_counter_fast(mm, MM_ANONPAGES);2290}2291flush_cache_page(vma, vmf->address, pte_pfn(vmf->orig_pte));2292entry = mk_pte(new_page, vma->vm_page_prot);2293entry = maybe_mkwrite(pte_mkdirty(entry), vma);2294/*2295|* Clear the pte entry and flush it first, before updating the2296|* pte with the new entry. This will avoid a race condition2297|* seen in the presence of one thread doing SMC and another2298|* thread doing COW.2299|*/2300ptep_clear_flush_notify(vma, vmf->address, vmf->pte);2301page_add_new_anon_rmap(new_page, vma, vmf->address, false);2302mem_cgroup_commit_charge(new_page, memcg, false, false);2303lru_cache_add_active_or_unevictable(new_page, vma);2304/*2305|* We call the notify macro here because, when using secondary2306|* mmu page tables (such as kvm shadow page tables), we want the2307|* new page to be mapped directly into the secondary page table.2308|*/2309set_pte_at_notify(mm, vmf->address, vmf->pte, entry);2310update_mmu_cache(vma, vmf->address, vmf->pte);2311if (old_page) {2312/*2313|* Only after switching the pte to the new page may2314|* we remove the mapcount here. Otherwise another2315|* process may come and find the rmap count decremented2316|* before the pte is switched to the new page, and2317|* "reuse" the old page writing into it while our pte2318|* here still points into it and can be read by other2319|* threads.2320|*2321|* The critical issue is to order this2322|* page_remove_rmap with the ptp_clear_flush above.2323|* Those stores are ordered by (if nothing else,)2324|* the barrier present in the atomic_add_negative2325|* in page_remove_rmap.2326|*2327|* Then the TLB flush in ptep_clear_flush ensures that2328|* no process can access the old page before the2329|* decremented mapcount is visible. And the old page2330|* cannot be reused until after the decremented2331|* mapcount is visible. So transitively, TLBs to2332|* old page will be flushed before it can be reused.2333|*/2334page_remove_rmap(old_page, false);2335}23362337/* Free the old page.. */2338new_page = old_page;2339page_copied = 1;2340} else {2341mem_cgroup_cancel_charge(new_page, memcg, false);2342}2271行 设置新的页标识位为PageUptodate , 表示页中包含有效数据 。
2280行 锁住页表
2281到2339行是发生缺页异常时获得页表项和现在锁住之后获得页表项内容相同的情况
2341 时页表项不同的情况
推荐阅读
- 所持股份|万兴科技:公司控股股东、实际控制人吴太兵质押150万股
- 发布公告|数量过半!博创科技:天通股份累计减持约150万股
- 英雄科技聊数码|蔡崇信有实力买下篮网,那身价3200亿的马云,能买下几支NBA球队
- 科技前沿阵地|涨疯了!海思安防芯片遭哄抬“围剿”
- 月影浓|吴亦凡机械造型走秀 垫肩披风搭银框眼镜科技感足
- 中国历史发展过程|中国历史发展过程.中国的科技史界过去半个多世纪
- 天津|桂发祥:不再持有昆汀科技股份
- 消费|减持!天通股份:减持博创科技约32万股
- 处罚|老周侃股:吉鑫科技大股东应补偿踩雷投资者
- 华中科技大学|杯具!超本科线95分,本科有路不走,却梦幻般碰瓷,撞开专科的门
