RCU 如何处理 reader 在 synchronize_rcu() 等待时开始读取临界区的情况
How RCU handles the condition of a reader started reading critical section while synchronize_rcu() is waiting
根据 RCU 文档(我相信内核和用户空间 RCU 框架是相似的),synchronize_rcu()
等待所有读者(在调用 synchronize_rcu
之前开始的读者)完成。
在 synchronize_rcu()
等待宽限期后启动的阅读器会发生什么情况?
synchronize_rcu()
returns 之后启动的读取器与 synchronize_rcu()
等待时启动的读取器之间有什么区别? 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_assign_pointer()
之后进入临界区的读者读取新的数据结构。
What is the difference between the readers started after
synchronize_rcu() returns, and readers started while synchronize_rcu()
waits?
您所说的一切都取决于if/when 分配了新指针。分配和阅读是相关的事情。
synchronize_rcu()
on Linux 通常会等到所有 CPU 都具有它们的 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. 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. Once all CPUs
have executed a context switch, then all preceding RCU read-side
critical sections will have completed.
So, suppose that we remove a data item from its structure and then
invoke 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.
新读者对旧数据结构一无所知。 "Swapping" 个指针是原子的。
再一次:synchronize_rcu()
对读者没有影响——它只是保证在它 returns 之后,我们可以释放指针指向的内存 (kfree()
).
看来您还没有探索 Linux RCU 的基础知识。
必读:
根据 RCU 文档(我相信内核和用户空间 RCU 框架是相似的),synchronize_rcu()
等待所有读者(在调用 synchronize_rcu
之前开始的读者)完成。
在 synchronize_rcu()
等待宽限期后启动的阅读器会发生什么情况?
synchronize_rcu()
returns 之后启动的读取器与 synchronize_rcu()
等待时启动的读取器之间有什么区别? 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_assign_pointer()
之后进入临界区的读者读取新的数据结构。
What is the difference between the readers started after synchronize_rcu() returns, and readers started while synchronize_rcu() waits?
您所说的一切都取决于if/when 分配了新指针。分配和阅读是相关的事情。
synchronize_rcu()
on Linux 通常会等到所有 CPU 都具有它们的 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. 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. Once all CPUs have executed a context switch, then all preceding RCU read-side critical sections will have completed.
So, suppose that we remove a data item from its structure and then invoke 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.
新读者对旧数据结构一无所知。 "Swapping" 个指针是原子的。
再一次:synchronize_rcu()
对读者没有影响——它只是保证在它 returns 之后,我们可以释放指针指向的内存 (kfree()
).
看来您还没有探索 Linux RCU 的基础知识。
必读: