操作系统驱逐受害者页面时,操作系统如何更新适当的页面表? [英] How does the OS update the appropriate page table when it evicts a victim page?

查看:88
本文介绍了操作系统驱逐受害者页面时,操作系统如何更新适当的页面表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用虚拟内存的OS中,每个进程都有一个页表.每个页表将一个进程的虚拟内存页映射到系统的物理内存页,并指示给定的页当前是否有效(加载到内存中).

In an OS that uses virtual memory, each process has a page table. Each page table maps a process's virtual memory pages to the system's physical memory pages and indicates whether a given page is currently valid (loaded in memory) or not.

假设内存快用完了,操作系统需要选择一个页面从物理内存中逐出.为此有不同的算法.例如,FIFO,LRU.一旦操作系统选择了要退出的页面,它将如何使对该页面的任何现有引用无效?

Suppose that memory is running low and the OS needs to choose a page to evict from physical memory. There are different algorithms for this. For example, FIFO, LRU. Once the OS chooses a page to evict, how does it invalidate any existing references to the page?

如果活动进程当前正在使用受害者页面,则OS必须使当前进程的页面表中的映射无效.如果受害者页面当前被另一个进程使用,则操作系统必须使另一个进程的页面表中的映射无效.无论如何,操作系统如何确定要更新的页表(如果有),以及如何在不进行线性搜索的情况下知道映射在该页表中的位置?

If the victim page is currently used by the active process, then the OS must invalidate the mapping in the current process's page table. If the victim page is currently used by another process, the OS must invalidate the mapping in the other process's page table. In any case, how does the OS determine which page table to update (if any), and how does it know where the mapping lives in that page table without doing a linear search?

从此演示文稿的幻灯片22开始有x86页表结构的详细描述:

There is a detailed description of x86 page table structure beginning at slide 22 of this presentation:

http://www.scs.stanford.edu/12au -cs140/notes/l8.pdf

我还发现了一些有用的虚拟内存概述:

I also found some helpful overviews of virtual memory:

http://www.cs.uic.edu/〜jbell/CourseNotes/OperatingSystems/9_VirtualMemory.html http://www.cs.umd.edu/class/sum2003/cmsc311/Notes/Memory/virtual.html

类似的堆栈溢出问题,没有答案:

Similar Stack Overflow question without an answer:

在上下文切换后linux如何更新页表

推荐答案

实际上,您要问的事情称为反向映射.例如,在Linux中,您可以找到有用的函数 try_to_unmap_anon 在页面描述符中有一个称为映射的字段.该字段是 anon_vma 匿名页面.如您所见,这不仅是普通的struct,而且是列表条目.一页可能有多个anon_vmas(请参阅try_to_unmap_anon):

Actually, the thing you are asking about called reverse mapping. For example, in Linux, you can find usefull function try_to_unmap_anon Inside page descriptor there is a field called mapping. This field is anon_vma for annonymous pages. As you can see this is not just ordinary struct, but also a list entry. There might be several anon_vmas for one page (see try_to_unmap_anon):

list_for_each_entry(vma, &anon_vma->head, anon_vma_node)

每页映射恰好一个.所有这些vmas链接到列表中.这就是内核知道正在运行哪些进程(及其页表)的方式. 现在,关于内核如何确定虚拟地址……再次可以在这里找到答案:

exactly one per page mapping. All this vmas linked into list. That is how kernel knows which processes (and their page tables) are in play. Now about how kernel determines the virtual address ... again the answer could be found here: vma_address

233         pgoff_t pgoff = page->index << (PAGE_CACHE_SHIFT - PAGE_SHIFT);
234         unsigned long address;
235 
236         address = vma->vm_start + ((pgoff - vma->vm_pgoff) << PAGE_SHIFT);

所以我们现在可以立即回答您的问题:为了不进行页表扫描,内核将其需要的所有内容(用于快速获取)存储在页描述符(结构页)中.

So we can answer your question shortly now: in order not to do the page tables scan, kernel stores everything it needs (for quick fetch) in page descriptor (struct page).

这篇关于操作系统驱逐受害者页面时,操作系统如何更新适当的页面表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆