关于RCU-sched的研究

对于synchronize_rcu原理的研究,在现在的源码中发现:

 * When synchronize_rcu() is invoked on one CPU while other CPUs* are within RCU read-side critical sections, then the* synchronize_rcu() is guaranteed to block until after all the other* CPUs exit their critical sections.  Similarly, if call_rcu() is invoked* on one CPU while other CPUs are within RCU read-side critical* sections, invocation of the corresponding RCU callback is deferred* until after the all the other CPUs exit their critical sections.

也就是说一个CPU的synchronize_rcu需要等待其他所有CPU都脱离RCU read-side临界区!

 * In non-preemptible RCU implementations (pure TREE_RCU and TINY_RCU),* it is illegal to block while in an RCU read-side critical section.* In preemptible RCU implementations (PREEMPT_RCU) in CONFIG_PREEMPTION* kernel builds, RCU read-side critical sections may be preempted,* but explicit blocking is illegal.  Finally, in preemptible RCU* implementations in real-time (with -rt patchset) kernel builds, RCU* read-side critical sections may be preempted and they may also block, but* only when acquiring spinlocks that are subject to priority inheritance.

也就是说其实是有可抢占版的RCU的!

可抢占的RCU

如果config文件定义了CONFIG_TREE_PREEMPT_RCU=y,那么sychronize_rcu将默认使用rcu_preempt_state(sychronize_rcu)。这类rcu的特点就在于read_lock期间是允许其它进程抢占的,因此它判断宽限期度过的方法就不太一样。

从rcu_read_lock和rcu_read_unlock的定义就可以知道,TREE_PREEMPT_RCU并不是以简单的经过抢占为CPU渡过GP的标准,而是有个rcu_read_lock_nesting计数

在lwn文章中详细介绍了不同的内核配置导致RCU的不同:

  • CONFIG_PREEMPT=n and CONFIG_SMP=y implies CONFIG_TREE_RCU, selecting the non-preemptible tree-based RCU implementation that is appropriate for server-class SMP builds. It can accommodate a very large number of CPUs, but scales down sufficiently well for all but the most memory-constrained systems.
  • CONFIG_PREEMPT=y implies CONFIG_TREE_PREEMPT_RCU, selecting the preemptible tree-based RCU implementation that is appropriate for real-time and low-latency SMP builds. It can also accommodate a very large number of CPUs, and also scales down sufficiently well for all but the most memory-constrained systems. The boot parameters for CONFIG_TREE_RCU also apply to CONFIG_TREE_PREEMPT_RCU.
  • CONFIG_PREEMPT=n and CONFIG_SMP=n implies CONFIG_TINY_RCU, selecting the non-preemptible uniprocessor RCU implementation that is appropriate for non-real-time UP builds. It has the smallest memory footprint of any of the current in-kernel RCU implementations. In fact, its memory footprint is so small that it doesn’t even have any kernel boot parameters.

也就是说,CONFIG_PREEMPT=n内核用的是不可抢占RCU,而CONFIG_PREEMPT=y implies CONFIG_TREE_PREEMPT_RCU,所以CONFIG_PREEMPT=y用的是可抢占的RCU。查了下我自己的电脑,是CONFIG_PREEMPT_VOLUNTARY=y,因此用的是不可抢占内核!对于不可抢占的RCU来说,RCU和RCU-Sched是一样的,因为反正都是不可抢占。而对于可抢占的RCU来说,RCU是可以抢占的,而RCU-Sched是不可抢占!官方文档中介绍了Sched-Favor的RCU:
“Note well that in CONFIG_PREEMPT=y kernels, rcu_read_lock_sched() and rcu_read_unlock_sched() disable and re-enable preemption, respectively.” 也就是说,RCU-sched在CONFIG_PREEMPT=y的情况下,rcu_read_lock_sched()是关抢占的!

因此,在RCU中_sched API后缀的意义仅仅体现在当CONFIG_PREEMPT=y也就是将内核配置为可抢占的情况!在CONFIG_PREEMPT=y情况下,RCU read-side临界区是可抢占的,而RCU-sched read-side是不可抢占的!

在lwn文章中还讨论的一个RCU和RCU-Sched混用的问题:

Quick Quiz 3: What happens if you mix and match RCU and RCU-Sched?

假如我们把RCU和RCU-Sched混合使用了怎么办?

Answer: In a CONFIG_TREE_RCU or a CONFIG_TINY_RCU kernel, mixing these two works “by accident” because in those kernel builds, RCU and RCU-Sched map to the same implementation.

对于CONFIG_TREE_RCU or a CONFIG_TINY_RCU=y的内核来说,混用两者无所谓,因为在这种内核里RCU和RCU-Sched的实现是相同的

However, this mixture is fatal in CONFIG_TREE_PREEMPT_RCU builds, due to the fact that RCU’s read-side critical sections can then be preempted, which would permit synchronize_sched() to return before the RCU read-side critical section reached its rcu_read_unlock() call.

但是对于CONFIG_TREE_PREEMPT_RCU=y的内核来说,其RCU read-side是可以被抢占的,那么假如读端用的rcu_read_lock/unlock在写端使用synchronize_sched,读端的临界区发生抢占就会提前结束其宽限期(其实并没有)

This could, in turn, result in a data structure being freed before the read-side critical section was finished with it, which could, in turn, greatly increase the actuarial risk experienced by your kernel.

这可能会导致读者还没读完,写者就free掉了其读的内存,导致风险!

Even in CONFIG_TREE_RCU and CONFIG_TINY_RCU builds, such mixing and matching is of course very strongly discouraged. Mixing and matching other flavors of RCU is even worse: it can result in hard-to-debug bad-pointer bugs.

关于RCU-sched的研究相关推荐

  1. Linux源码研究-用户管理员手册-内核命令行参数

    下面的列表是__setup(), core_param()和module_param()宏实现的内核参数,内核从命令-开始解析参数,如果参数不被识别,也不包含".",参数会被用来启 ...

  2. 深航App劫持微信;Apple News上线首日遭遇各种崩溃;华为P30“望远镜手机”正式发布 | 雷锋早报...

    董明珠回应"10亿赌局":我没有去找雷军要钱 3月26日,在2019博鳌亚洲论坛上,格力电器董事长兼总裁董明珠被腾讯<一线>问及与雷军的10亿赌局时,董明珠回应称自己没 ...

  3. 深航App劫持微信;Apple News上线首日遭遇各种崩溃;华为P30“望远镜手机”正式发布 | 雷锋早报... 1

    董明珠回应"10亿赌局":我没有去找雷军要钱 3月26日,在2019博鳌亚洲论坛上,格力电器董事长兼总裁董明珠被腾讯<一线>问及与雷军的10亿赌局时,董明珠回应称自己没 ...

  4. 三维点云的深度学习研究综述

    作者丨aaa 来源丨https://zhuanlan.zhihu.com/p/455210291 编辑丨3D视觉工坊 摘要 点云学习由于在计算机视觉.自动驾驶.机器人等领域的广泛应用,近年来受到越来越 ...

  5. linux kernel rcu 读复制更新 并发控制机制 简介

    目录 RCU原理 普通RCU 变种RCU的特点 可睡眠RCU(SRCU) RCU原理 RCU特点:RCU全称Read Copy Update 读复制更新,是一种完全不同于锁的并发控制机制. 主要保护的 ...

  6. linux内核研究(一)

    http://antkillerfarm.github.io/ 驱动开发 推荐入门读物<Beginning Linux Programming>,该书第3版已有中译本. 但第3版中的例子在 ...

  7. Linux内核RCU(Read Copy Update)锁简析

    在非常早曾经,大概是2009年的时候.写过一篇关于Linux RCU锁的文章<RCU锁在linux内核的演变>,如今我承认.那个时候我尽管懂了RCU锁,可是我没有能力用一种非常easy的描 ...

  8. RCU(1)- 概述

    RCU(1)- 概述http://www.wowotech.net/kernel_synchronization/461.html 作者简介:余华兵,在网络通信行业工作十多年,负责IPv4协议栈.IP ...

  9. RCU前传:从同步到RCU的引入

    一.从同步开始 1.1 同步的产生 在阅读或者编写内核代码的时候,总是需要带着一个默认的前提条件:任意的一条执行流,都可能在任意一条指令之后被中断执行,然后在并不确定的时间后再次回来执行. 因此,常常 ...

  10. 从自旋锁、睡眠锁、读写锁到 Linux RCU 机制讲解

    总结一下 O/S 课程里面和锁相关的内容. 本文是 6.S081 课程的相关内容总结回顾结合 Real World 的 Linux 讲解各种锁和 RCU lock free 机制原理, 前置知识是基本 ...

最新文章

  1. GPT分区无损转MBR分区的操作
  2. 通过公网ip或域名下载自己的文件的一些思路
  3. Java IO模型:BIO NIO AIO及netty介绍
  4. ddos攻击工具_简单有效的ddos攻击防御方法
  5. flutter引入高德地图_Flutter笔记-调用原生IOS高德地图sdk
  6. 工程计算软件_同望BIM工程量计算软件—土石方
  7. linkedhashmap中关于LRU算法的实现
  8. 微信新功能能够给企业、个人商家带来什么?
  9. Spring StringUtils类中几个有用的字符串处理方法
  10. linux定时任务的配置详解
  11. 利用python中的pygame模块开发fc坦克大战(可自定义地图,包括部分素材)
  12. Ubuntu常用软件安装
  13. C#检测ocx控件是否注册
  14. linux gif录制工具,教学?演示?在Linux下安装超好用的屏幕录像机来录制gif动画...
  15. Spark算子:RDD行动Action操作–aggregate、fold、lookup;reduce/fold/aggregate区别
  16. 支付公司如何赚钱?支付网关如何设计?
  17. python线性回归预测pm2.5_线性回归预测PM2.5----台大李宏毅机器学习作业1(HW1)
  18. 手把手教你如何用Python从PDF文件中导出数据(附链接)
  19. 中国科学技术大学计算机科学夏令营,中国科学技术大学计算机科学与技术学院(专业学位)软件工程保研夏令营...
  20. 华中科技大学 计算机 排名,计算机最强14所高校排名,清华第2,浙大第4,南大第6,华科第10...

热门文章

  1. 带你飞过PMP—备考上篇•乖乖看书就对了-GZ1610吴慧敏
  2. 小说体验报告测试用例设计点
  3. 孩子台灯怎么选?双12儿童护眼台灯测评
  4. 联想G50笔记本如何安装系统
  5. 《如何阅读一本书》读书摘记
  6. 入职两年的人写给刚入职的人
  7. 微信公众号开发之回复消息的模板
  8. plupload实现多文件上传
  9. 第一次到学校的电子阅览室上网
  10. IDEA上集成log4j将SQL语句打印在控制台上