关于缺页异常的疑问: 缺页异常中可能需要读取文件或交换区到主存中,不会引起睡眠吗?在中断上下文睡眠是不允许的

NewThinker_wei 2014-12-22 01:29:14
VMA(vm_area_struct) 的 nopage/fault 操作是在缺页异常中被调用,如果请求的页面不在主存中而在磁盘上,就需要从磁盘上读取内容到主存中,这时就会有文件IO操作(意味着会睡眠),但如果 nopage/fault 可以睡眠,那它就不能运行在缺页异常(中断上下文)中。
如何缺页异常中需要IO操作了,内核是怎么做的?跟了一下缺页异常的代码,有些复杂,目前还没头绪。难道是当需要IO操作时就先将当前进程挂起,然后再启动一个内核线程,当缺页异常退出后再由这个内核线程完成被推后的 IO 操作并唤醒被挂起的进程?(只是猜测,在内核源码中还没找到有这样的代码)
...全文
706 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
abcde1120 2018-10-13
  • 打赏
  • 举报
回复
异常处理应该是可以睡眠的,整个流程中也有几处提示might_sleep()。从代码分析看进入睡眠的地方应该在filemap_fault->lock_page_or_retry()。 中断和异常都保存了进程的上下文,只要中断开着,执行进程切换理论上也是可行的。 至于中断中为什么不能睡眠,看了下面这篇文章,了解个大概: http://www.360doc.com/content/13/0911/15/7377734_313740608.shtml
  • 打赏
  • 举报
回复
I am not a kernel expert and I am trying to explain this as much as I can If this happens because a program in user-mode leads to a "page_fault" the CPU in which it is running receives the interrupt of "page_fault" and the context of the current execution must be saved in the system's stack space so that the control is passed to the handler of "page_fault" ("ENTRY(page_fault)" defined in /kernel/entry.S). In other words, an interrupt occurs When an interrupt occurs, the hardware (usually, CPU supports this) automatically switches a part of the context (at least enough to allow the handler to return to the interrupted code). The handler may save additional context, depending on details of the particular hardware and software designs. Often only a minimal part of the context is changed in order to minimize the amount of time spent handling the interrupt. The kernel does not spawn or schedule a special process to handle interrupts, but instead the handler executes in the (often partial) context established at the beginning of interrupt handling. Once interrupt servicing is complete, the context in effect before the interrupt occurred is restored so that the interrupted process can resume execution in its proper state. as for the "睡眠" you mentioned, IMHO, that is a behavior at least couple levels higher than the implementation of page fault handling and the context switch beneath it.
Heaven_Redsky 2014-12-22
  • 打赏
  • 举报
回复
所谓缺页中断,也仅仅是个中断而已,不会在这个中断里做IO的。应该是把发生缺页的那个任务/进程切换出去,等IO完成了之后再弄回来。

4,436

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 内核源代码研究区
社区管理员
  • 内核源代码研究区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧