简体   繁体   English

RCU 如何处理在 synchronized_rcu() 等待时读者开始读取临界区的情况

[英]How RCU handles the condition of a reader started reading critical section while synchronize_rcu() is waiting

As per the RCU documentation (I believe kernel and userspace RCU frameworks are similar), synchronize_rcu() waits for all the readers (who started before synchronize_rcu was called ) to finish.根据 RCU 文档(我相信内核和用户空间 RCU 框架是相似的), synchronize_rcu()等待所有读取器(在调用synchronize_rcu之前启动的)完成。
What happens to the readers which are started after synchronize_rcu() is waiting in its grace period?synchronize_rcu()在其宽限期内等待之后启动的读取器会发生什么?
What is the difference between the readers started after synchronize_rcu() returns, and readers started while synchronize_rcu() waits?synchronize_rcu()返回后启动的阅读器和synchronize_rcu()等待时启动的阅读器有什么区别? How RCU framework handles this? RCU 框架如何处理这个问题?

The new reader (which started executing in critical section after synchronize_rcu() is waiting in its grace period) reads the new data structure?新的读取器(在同步 rcu() 在其宽限期内等待后开始在临界区执行)读取新的数据结构?

All the readers entering the critical section after rcu_assign_pointer() read the new data structure.所有在rcu_assign_pointer()之后进入临界区的读者读取新的数据结构。

What is the difference between the readers started after synchronize_rcu() returns, and readers started while synchronize_rcu() waits?在synchronize_rcu()返回后启动的阅读器和synchronize_rcu()等待时启动的阅读器有什么区别?

All you are talking about depends on if/when the new pointer is assigned.您所谈论的一切都取决于是否/何时分配了新指针。 Assigning and reading are related things.分配和阅读是相关的事情。


synchronize_rcu() on Linux generally waits until all CPUs will have their context switched - it guarantees that no one who saw the old pointer doesn't use it anymore (context switch happens after reader exits their critical section) - so we can free this memory. Linux上的synchronize_rcu()通常会等到所有CPU都切换上下文——它保证没有人看到旧指针不再使用它(上下文切换发生在读者退出临界区之后)——所以我们可以释放这个内存. From this post :这篇文章

..if a given CPU executes a context switch, we know that it must have completed all preceding RCU read-side critical sections. ..如果给定的 CPU 执行上下文切换,我们知道它必须已完成所有前面的 RCU 读端临界区。 Once all CPUs have executed a context switch, then all preceding RCU read-side critical sections will have completed.一旦所有 CPU 都执行了上下文切换,则所有前面的 RCU 读端临界区都将完成。
So, suppose that we remove a data item from its structure and then invoke synchronize_rcu().所以,假设我们从它的结构中删除一个数据项,然后调用synchronize_rcu()。 Once synchronize_rcu() returns, we are guaranteed that there are no RCU read-side critical sections holding a reference to that data item, so we can safely reclaim it.一旦synchronize_rcu() 返回,我们就可以保证没有RCU 读取端临界区持有对该数据项的引用,因此我们可以安全地回收它。

New readers know nothing about old data structure.新读者对旧数据结构一无所知。 "Swapping" of pointers is atomic.指针的“交换”是原子的。
One more time: synchronize_rcu() has no effect on readers - it just guarantees that after it returns, we can free the memory the pointer points to ( kfree() ).再一次: synchronize_rcu()对读者没有影响——它只是保证在它返回后,我们可以释放指针指向的内存( kfree() )。

It seems you have not explored the basics of Linux RCU.看来您还没有探索过 Linux RCU 的基础知识。
Must read:必读:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM