- 论坛徽章:
- 0
|
原帖由 gvim 于 2006-3-13 10:41 发表
你说的是虚拟地址的布局 和分配还是有些许区别地。
嗯,一个是进程可访问的虚拟地址空间的“范围”,一个是进程可访问的虚拟内存的“大小”。这是两个问题。
原帖由 gvim 于 2006-3-13 10:41 发表
对物理内存限定我可以理解,可是我不是很理解这个地方为什么要对虚拟内存做限定。...
这里不能说是“对物理内存限定”,而应该说是对虚拟地址空间的访问范围进行限定。至于对进程可访问的虚拟内存的大小进行限定的问题,我的理解是这样的:
一个进程对于内存的访问都是通过虚拟内存系统进行的,它的虚拟地址空间中映射的每一个“逻辑页”都要落实到一个“物理页”上,一旦物理页用完,就要从内存里面选择若干active的页交换出去,然后再来满足进程对“物理页”的映射需求。系统需要为这些操作预留一些最低资源,否则,物理页和交换区完全有可能被用完。这时,如果进程再请求物理页,系统既无法直接满足这个需求,也无法通过把现有物理页调整到交换区来满足这个需求,出现死锁。此时,内核就只有向进程发送kill信号了。
另外,初步看了一下,觉得实现上述功能的代码在这个地方:
- _______________________________________________________________________________
- 426 /*
- 427 * Implement fork's actions on an address space.
- 428 * Here we arrange for the address space to be copied or referenced,
- 429 * allocate a user struct (pcb and kernel stack), then call the
- 430 * machine-dependent layer to fill those in and make the new process
- 431 * ready to run. The new process is set up so that it returns directly
- 432 * to user mode to avoid stack copying and relocation problems.
- 433 */
- 434 void
- 435 vm_forkproc(td, p2, td2, flags)
- 436 struct thread *td;
- 437 struct proc *p2;
- 438 struct thread *td2;
- 439 int flags;
- 440 {
- ...
- 463 while (vm_page_count_severe()) {
- 464 VM_WAIT;
- 465 }
- ...
- ______________________________________________________/usr/src/sys/vm/vm_glue.c
复制代码
其中,vm_page_count_severe()的定义如下:
- _______________________________________________________________________________
- 118 /*
- 119 * Return TRUE if we are under our severe low-free-pages threshold
- 120 *
- 121 * This routine is typically used at the user<->system interface to determine
- 122 * whether we need to block in order to avoid a low memory deadlock.
- 123 */
- 124
- 125 static __inline
- 126 int
- 127 vm_page_count_severe(void)
- 128 {
- 129 return (cnt.v_free_severe > (cnt.v_free_count + cnt.v_cache_count));
- 130 }
- _____________________________________________________/usr/src/sys/sys/vmmeter.h
复制代码
[ 本帖最后由 雨丝风片 于 2006-3-13 13:14 编辑 ] |
|