CFQ,即Completely Fair Queueing绝对公平调度器,力图为竞争块设备使用权的所有进程分配一个等同的时间片,在调度器分配给进程的时间片内,进程可以将其读写请求发送给底层块设备,当进程的时间片消耗完,进程的请求队列将被挂起,等待调度。相对于Noop和Deadline调度器,CFQ要复杂得多,因此可能要分几次才能将其分析完。

优先级

每个进程都会有一个IO优先级,CFQ调度器将会将其作为考虑的因素之一,来确定该进程的请求队列何时可以获取块设备的使用权。IO优先级从高到低可以分为三大类:RT(real time),BE(best try),IDLE(idle),其中RT和BE又可以再划分为8个子优先级。实际上,我们已经知道CFQ调度器的公平是针对于进程而言的,而只有同步请求(read或syn write)才是针对进程而存在的,他们会放入进程自身的请求队列,而所有同优先级的异步请求,无论来自于哪个进程,都会被放入公共的队列,异步请求的队列总共有8(RT)+8(BE)+1(IDLE)=17个。

调度器的结构

CFQ调度器在整个工作过程中所涉及到的结构比较多,我们可以把这些结构分为两类,一类是用来描述调度器本身相关的结构,由于CFQ将进程作为考虑对象,因此另一类结构就是特定于进程的结构,对于这些结构,我们只选择其内部的重要元素进行分析。和调度器相关的数据结构主要有两个,

一个是描述调度器的struct cfq_data

一个是描述队列的struct cfq_queue。

struct cfq_data {struct request_queue *queue;/** rr list of queues with requests and the count of them*/struct cfq_rb_root service_tree;/** Each priority tree is sorted by next_request position.  These* trees are used when determining if two or more queues are* interleaving requests (see cfq_close_cooperator).*/struct rb_root prio_trees[CFQ_PRIO_LISTS];unsigned int busy_queues;int rq_in_driver[2];int sync_flight;/** queue-depth detection*/int rq_queued;int hw_tag;int hw_tag_samples;int rq_in_driver_peak;/** idle window management*/struct timer_list idle_slice_timer;struct work_struct unplug_work;struct cfq_queue *active_queue;struct cfq_io_context *active_cic;/** async queue for each priority case*/struct cfq_queue *async_cfqq[2][IOPRIO_BE_NR];  struct cfq_queue *async_idle_cfqq;sector_t last_position;/** tunables, see top of file*/unsigned int cfq_quantum;unsigned int cfq_fifo_expire[2];unsigned int cfq_back_penalty;unsigned int cfq_back_max;unsigned int cfq_slice[2];unsigned int cfq_slice_async_rq;unsigned int cfq_slice_idle;unsigned int cfq_latency;struct list_head cic_list;/** Fallback dummy cfqq for extreme OOM conditions*/struct cfq_queue oom_cfqq;unsigned long last_end_sync_rq;
}; queue:指向块设备对应的request_queueservice_tree:所有待调度的队列都被添加进该红黑树,等待调度获取时间片prio_trees[CFQ_PRIO_LISTS]:对应8个优先级的红黑树,所有优先级类别为RT或BE的进程的同步请求队列,都会根据优先级添加至相应的红黑树busy_queues:用于计算service_tree中有多少个队列在等待调度active_queue:指向当前占有块设备的队列async_cfqq[2][IOPRIO_BE_NR]:对应RT和BE优先级类的16个异步请求队列async_idle_cfqq:对应优先级类别为IDLE的异步请求队列cfq_quantum:用于计算在一个队列的时间片内,最多发放多少个请求到底层的块设备cfq_fifo_expire[2]:同步、异步请求的响应期限时间cfq_slice[2]:同步、异步请求队列的时间片长度
struct cfq_queue {/* reference count */atomic_t ref;/* various state flags, see below */unsigned int flags;/* parent cfq_data */struct cfq_data *cfqd;/* service_tree member */struct rb_node rb_node;/* service_tree key */unsigned long rb_key;/* prio tree member */struct rb_node p_node;  /* prio tree root we belong to, if any */struct rb_root *p_root;/* sorted list of pending requests */struct rb_root sort_list; /* if fifo isn't expired, next request to serve */struct request *next_rq;/* requests queued in sort_list */int queued[2];/* currently allocated requests */int allocated[2];/* fifo list of requests in sort_list */struct list_head fifo;     unsigned long slice_end;long slice_resid;unsigned int slice_dispatch;/* pending metadata requests */int meta_pending;/* number of requests that are on the dispatch list or inside driver */int dispatched;/* io prio of this group */unsigned short ioprio, org_ioprio;unsigned short ioprio_class, org_ioprio_class;unsigned int seek_samples;u64 seek_total;sector_t seek_mean;sector_t last_request_pos;unsigned long seeky_start;pid_t pid;struct cfq_queue *new_cfqq;
};cfqd:指向队列所属的cfq_datarb_node:用于将队列插入service_treerb_key:红黑树节点关键值,用于确定队列在service_tree中的位置,该值要综合jiffies,进程的IO优先级等因素进行计算p_node:用于将队列插入对应优先级的prio_treep_root:对应的prio_tree树根sort_list:组织队列内的请求用的红黑树,按请求的起始扇区进行排序fifo:组织队列内的请求用的链表头,按请求的响应期限排序slice_end:指明时间片何时消耗完slice_dispatch:在时间片内发送的请求数ioprio:进程的当前IO优先级

相对于进程的结构有struct io_context和struct cfq_io_context。io_context的核心结构是一个基数树,里面组织了进程所访问的所有块设备所对应的cfq_io_context。cfq_io_context中的核心结构是两个队列,也就是进程在一个CFQ调度器所关系到的队列,一个是同步的,一个是异步的,下面是我根据自己的理解画的一张关系图:

REF

cfq参数: https://www.kernel.org/doc/Documentation/block/cfq-iosched.txt

转载于:https://www.cnblogs.com/muahao/p/9361872.html

block: cfq 学习01相关推荐

  1. block:cfq 学习02

    From: https://blog.csdn.net/vanbreaker/article/details/8308766 前文介绍了CFQ调度器的一些概念和结构之间的关系,这里再结合实际的代码,来 ...

  2. vue快速学习01、环境与常用属性标签

    vue快速学习01.环境与常用属性标签 1.MVVC MVVM 设计模式是由 Model (模型). View (视图)和 ViewModel (视图模型)三部分组成,是 MVC 设计模式的进化版,即 ...

  3. webservice学习01:wsdl文档结构

    webservice学习01:wsdl文档结构 wsdl文档结构 WSDL文档示例 <wsdl:definitions xmlns:xsd="http://www.w3.org/200 ...

  4. MyBatis学习(01)之解决mapper绑定异常

    MyBatis学习(01)之解决mapper绑定异常 参考文章: (1)MyBatis学习(01)之解决mapper绑定异常 (2)https://www.cnblogs.com/limn/p/858 ...

  5. ThinkPhp学习01

    原文:ThinkPhp学习01 一.ThinkPHP的介绍            MVC   M - Model 模型                工作:负责数据的操作   V - View  视图 ...

  6. hadoop2.x学习01

    hadoop2.x学习01 最新的发行版本已经是2.7了,我围绕2.5展开学习. hadoop2.x是在hadoop0.23之后发行的正式版2.2. 本身是来自于lucene和nutch,在ggl的论 ...

  7. 强化学习(Reinforcement Learning)入门学习--01

    强化学习(Reinforcement Learning)入门学习–01 定义 Reinforcement learning (RL) is an area of machine learning in ...

  8. 计算机编码二进制0001,二进制学习01(二进制,进制运算,数据宽度,无符号位有符号位编码规则)...

    二进制学习01 进制 一.二进制简介 1)什么是二进制? 2)二进制的简写形式 二.进制运算 1)八进制运算表 (1) 加法运算表 (2)乘法运算表 (3)八进制简单运算题 三.数据宽度 1)什么是数 ...

  9. Java多线程学习——01

    Java多线程学习--01 1.核心概念 程序:是指令和数据的有序集合,其本身没有任何运行的含义,是一个静态的概念 进程Process:是执行程序的一次执行过程,它是一个动态的概念,是系统资源分配的单 ...

最新文章

  1. 【React系列】状态(State)和生命周期
  2. acdream 1222 Quantization Problem [dp]
  3. java发生fullgc的时机_2021-01-02:java中,MinorGC、MajorGC、FullGC 什么时候发生?
  4. pep3评估报告解读_quot;聚焦慢病、助力医改,检验项目风险评估培训计划“大兴区第四期培训班成功举办...
  5. 力扣450. 删除二叉搜索树中的节点(JavaScript)
  6. Android NDK之JNI陷阱
  7. ubuntu16 下安装freeswitch 1.8.3
  8. 完成基于ICX285和ICX205两种CCD的兼容性电路设计
  9. f452虚拟服务器,中兴f452网关,超级用户的密码如何获得,启动路由功能
  10. Installation for COMSOl(安装COMSOL)
  11. lv官网编码查询_申购比近3:1!这个单价2万的共产房审核结果可查询
  12. 微软skype收购案
  13. python爬取芒果TV《乘风破浪的姐姐》弹幕数据(已完成)
  14. Android 如何让你的App分享给别人
  15. Centos7下areaDetector IOC的编译后记
  16. 关于centOS7在U盘安装时遇到的dracut-initqueue[]:Warning:dracut-inituenue timeout....查找不到文件无法安装系统的问题的解决办法。
  17. 关于软件测试的MySQL基础
  18. IDEA2022版教程下(快键键总结、Debug断点调试总结、22版本idea创建各种工程、关联数据库、常用插件)
  19. 用matlab模拟机械运动
  20. Java栈的使用方法

热门文章

  1. 超详细Windows10 Tomcat 9安装与配置
  2. U盘连接时显示位置不可用无法访问请问怎样才能修复
  3. 设计模式 - 创建型模式_抽象工厂模式
  4. springboot实现用户统一认证、管理(单点登录)
  5. java通过模板匹配html,OpenCV模板匹配
  6. Security Onion安全洋葱2.X-架构概述
  7. 外贸跟客户讲价有什么技巧?
  8. 四年Web渗透,六月跳槽爆斩腾讯offer,回馈面试之路
  9. 毕业设计-基于SSM实现的民宿网站系统
  10. 女生学计算机 路在何方(完)