Read-Copy Update


RCU is a method that can manage multiple process execution and can be deployed to any operating system and one among them is the Linux kernel. It is an easy process synchronization method and it splits the RCU update into two phases namely removal and reclamation. This mechanism allows the reads along with the updates to occur simultaneously. The process occurs concurrently between the many readers and updaters of the operating system. Apart from the easy process, it is also reliable to access for the simultaneous process.

Read-Copy Update

Definition

Read-copy update (RCU) is one of the best data structures that follow concurrent process synchronization which restricts the use of mutexes or locks when multithreads run concurrently to read and update the shared resources like memory, device, or file.

Phases of Read-Copy update (RCU):

The Update is divided into two phases namely,

  • Removal

  • Reclamation

Without the use of RCU, the leaving or removing thread has to lock the element so no other element can access it. But with the RCU, the removal phase is used to reference the element and is easily removed without affecting the traversal lists. The thread must wait for all prior readers to finish their RCU read-side essential sections before moving on to the reclamation phase after removing the reference to the element from the list during the removal phase.

Read/Write-side Code

The Data structure is divided into read and write operations. Read-side is the concurrent type that does not change the data structure model, while the write side changes the data structure. RCU uses Process synchronization to avoid the vulnerabilities between the reader and writer side.

Only when read-side concurrent code uses memory similar to an unsynchronized code can run as quickly as the latter. Because atomic writes are slow and lock memory buses, read-side code cannot write to shared data structures. Essentially, each writes on a shared cache line in a shared data structure causes the shared line to be removed from the caches of other processors.

The other processor’s caches will need to reload the data after this eviction, which will take at least hundreds of cycles. Cache line bouncing is the issue where ownership of the cache line alternates between cores. Other expensive instructions, such as memory fences, cannot be used by read-side programs.

These conditions essentially rule out read or write locking as an option. Read-side operations must carry out atomic writes to shared data structures in the simplest read/write locks, which keep track of the number of concurrent readers.

RCU operations

The readers in the conventional method use a lock to stop an update from erasing the data items. Currently, RCU readers can use greatly lighter-weight synchronization or even no synchronization at all, by waiting until all readers have finished.

Application Program Interface −

Some of the RCU API is given below,

  • rcu_read_lock  It marks a data structure that RCU is protected which cannot be recovered for the entire time and is the initial operation of the critical section.

  • rcu_read_unlock  This function is used by the Reader to inform that it is leaving the critical section.

  • Synchronize_rcu()  The Synchronize_rcu() function is used by a reader that waits until the read side of the critical section exits the process and does not return immediately.

  • Call_rcu − It is a function that is called synchronize_rcu when all active RCU read-side critical sections have finished, as opposed to blocking. This callback type is particularly helpful when blocking is prohibited or when update-side efficiency is crucial.

  • Call_rcu  This function is more concerned about the safety of informing the reader about the value of the updates. It is also responsible for recording the data about the pointers which are safeguarded by RCU.

  • rcu_dereference  This function is used exclusively for getting information regarding the pointers that are put into safety by RCU. During the threads in the critical section, these functions are involved within only this function

Implementation of RCU

The RCU can be implemented in the Linux operating system in two different ways. One of them is using the lock method and the other is the classic method of RCU.

Even though the Locking method is easy, it cannot be implemented in real-time use as it switches between the two read-side critical sections. In the classic way of RCU, it shows less performance on the updates.

Disadvantages of Read-Copy Update

The main disadvantage of read-copy update is that preemption as it cannot be used in user mode. These Read-copy updates cannot be used by the tree data structure as it may depend on many updates which cannot be done automatically

Conclusion

RCU mechanism is one which can be used in any operating system to avoid the locking methods. An RCU read starts from the lock function and ends in the unlock function. The basic algorithm followed by RCU is making the changes, waiting for the existing RCU read-side critical section to end and finally cleaning up the process.

Updated on: 17-Jul-2023

248 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements