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

NewThinker_wei 2014-12-22 01:29:14
VMA(vm_area_struct) 的 nopage/fault 操作是在缺页异常中被调用,如果请求的页面不在主存中而在磁盘上,就需要从磁盘上读取内容到主存中,这时就会有文件IO操作(意味着会睡眠),但如果 nopage/fault 可以睡眠,那它就不能运行在缺页异常(中断上下文)中。
如何缺页异常中需要IO操作了,内核是怎么做的?跟了一下缺页异常的代码,有些复杂,目前还没头绪。难道是当需要IO操作时就先将当前进程挂起,然后再启动一个内核线程,当缺页异常退出后再由这个内核线程完成被推后的 IO 操作并唤醒被挂起的进程?(只是猜测,在内核源码中还没找到有这样的代码)
...全文
707 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完成了之后再弄回来。
通过本课程学习您可以学习到Dart语言如下知识:第1章 Dart语言概述:Dart语言简介、Dart语言支持平台开发、Flutter为什么选择Dart语言。第2章 开发环境搭建:下载Dart SDK、Windows下安装Dart SDK、macOS下安装Dart SDK、Visual Studio Code开发工具、IntelliJ IDEA开发工具。第3章 完成个Dart程序:动动手写一个HelloWorld、Dart源代码文件组织结构、Visual Studio Code调试Dart代码、IntelliJ IDEA调试Dart代码。第4章 Dart语法基础:标识符、关键字、变量、常量、注释、库。第5章 Dart数据类型:数值类型、字符串、数据类型相互转换、布尔类型和枚举类型第6章 运算符:算术运算符、算术赋值运算符、关系运算符、逻辑运算符、位运算符、条件运算符、类型检查运算符。第7章 控制语句:分支语句、循环语句、跳转语句。第8章 函数:函数声明、可选参数、头等函数(first-class function)、匿名函数。第9章 类:类声明、getter和setter访问器、构造函数、静态变量和静态方法、级联符号。第10章 继承与多态:Dart的继承实现、调用父类构造函数、成员变量的覆盖(Override)、方法的覆盖(Override)、多态、混入(Mixins)。第11章 抽象类与接口:抽象类、接口、Dart隐式接口、实现接口。第12章 数据容器:List容器、Set容器、Map容器、泛型。第13章 异常处理:捕获异常、try-on捕获异常、try-catch捕获异常、try-on-catch捕获异常、使用finally代码块、手动抛出异常、自定义异常类。第14章 异步编程:Dart异步处理机制、案例:同步函数实现读取文件、案例:异步函数实现读取文件、Future对象。  

4,436

社区成员

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

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