免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12
最近访问板块 发新帖
楼主: 雨丝风片

[FreeBSD] 推荐一篇关于FreeBSD内核如何在保护模式下管理IA32处理器的文章 [复制链接]

论坛徽章:
0
发表于 2006-04-12 08:45 |显示全部楼层
原帖由 ocean390 于 2006-4-10 20:30 发表
我看了内核的代码,没有找到关于进程的页目录的分配,每个进程的页目录应该是不同的吧,因为在进程切换的时候改变了页目录的基址。好像在3G内核空间下面预留了4M的空间,不知道是做什么用的。在locore.s中设置了PTmap,PTD等,这些值就是设置为在4M的空间内,在pmap中有extern pt_entry_t PTmap[];extern pt_entry_t PTD[];在源文件中好像并没有定义。我猜测有可能页表就应该分配在这个4M内,也就是用户空间内,不知道对不对?这是不清楚页目录的地址,如果也在这些地址内的话,进行进程切换的时候并不能保证页目录在内存中。 ...


CR3里面存放的是页目录的物理基地址,进程切换的时候操作的也正是这个基地址。你说的“好像在3G内核空间”是否应该是用户空间?我还没有看到你所说的4M的地方,但从目前的资料来看,一个进程的页目录和页表应该是在用户空间的,在进程切换的时候确保其页目录和页表驻留在内存中,并将基地址写入CR3。

进行进程切换的时候新进程的页目录确实可能不在内存中,【IA-32 Intel Architecture Software Developer's Manual】第三卷的3.7.4节是这样说的:
The page directory may be not present (paged out of physical memory) while its associated task is suspended, but the operating system must ensure that the page directory indicated by the PDBR image in a task's TSS is present in physical memory before the task is dispatched.

论坛徽章:
2
亥猪
日期:2014-03-19 16:36:35午马
日期:2014-11-23 23:48:46
发表于 2006-04-12 09:06 |显示全部楼层
呵呵,先把进程和内存两个支撑部分弄清楚了,以后的分析都可以脱离硬件去考虑,相对简单多了
其实,ocean390的疑问我也有,先放到我的pending list里面去

论坛徽章:
0
发表于 2006-04-12 11:29 |显示全部楼层
原帖由 gvim 于 2006-4-12 09:06 发表
呵呵,先把进程和内存两个支撑部分弄清楚了,以后的分析都可以脱离硬件去考虑,相对简单多了


这两个部分我都是新手。

论坛徽章:
0
发表于 2006-04-12 12:17 |显示全部楼层
先积累一点资料吧:

【FreeBSD操作系统设计与实现】:
There are two strategies that can be used for management of pmap memory resources, such as user-directory or page-table memory. The traditional and easiest approach is for the pmap module to manage its own memory. Under this strategy, the pmap module can grab a fixed amount of wired physical memory at system boot time, map that memory into the kernel's address space, and allocate pieces of the memory as needed for its own data structures.

......

An alternative approach, used by the PC, is to use the higher-level virtual-memory code recursively to manage some pmap resources. Here, the 4-Kbyte directory table for each user process is mapped into the address space of the kernel as part of setting up the process and remains resident until the process exits. While a process is running, its page-table entries are mapped into a virtually contiguous 4-Mbyte array of page-table entries in the kernel's address space.

论坛徽章:
0
发表于 2006-04-12 23:42 |显示全部楼层
内核的页目录是在内核地址空间中分配的,可以在内核地址空间访问到,在pmap中的pm_pdir包含的也是内核空间的地址。在页目录的第767项,也就是包含3068M-3072M地址的项指向了页目录本身所在的页,因此访问3068M开始的4M空间就相当于是访问页表页本身,如果对应页表页本身存在的话,也就可以说进程的页表是在用户空间内,VM_MAXUSER_ADDRESS定义为3068M,栈也是3068M开始的。vm_object中包含了物理页的信息,通过vm_object可以在内存中找到相应的页,如果不在内存中可以通过对应的pager将其换入内存,然后就可以映射了。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP