doc: Convert arrayRCU.txt to arrayRCU.rst

This patch converts arrayRCU from .txt to .rst format, and also adds
it to the index.rst file.

Signed-off-by: Madhuparna Bhowmik <madhuparnabhowmik04@gmail.com>
[ paulmck: Trimmed trailing whitespace. ]
Tested-by: Phong Tran <tranmanphong@gmail.com>
Tested-by: Amol Grover <frextrite@gmail.com>
Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
This commit is contained in:
Madhuparna Bhowmik 2019-10-29 01:54:17 +05:30 committed by Paul E. McKenney
parent e42617b825
commit 9ffdd79824
2 changed files with 24 additions and 11 deletions

View File

@ -1,19 +1,21 @@
Using RCU to Protect Read-Mostly Arrays .. _array_rcu_doc:
Using RCU to Protect Read-Mostly Arrays
=======================================
Although RCU is more commonly used to protect linked lists, it can Although RCU is more commonly used to protect linked lists, it can
also be used to protect arrays. Three situations are as follows: also be used to protect arrays. Three situations are as follows:
1. Hash Tables 1. :ref:`Hash Tables <hash_tables>`
2. Static Arrays 2. :ref:`Static Arrays <static_arrays>`
3. Resizeable Arrays 3. :ref:`Resizable Arrays <resizable_arrays>`
Each of these three situations involves an RCU-protected pointer to an Each of these three situations involves an RCU-protected pointer to an
array that is separately indexed. It might be tempting to consider use array that is separately indexed. It might be tempting to consider use
of RCU to instead protect the index into an array, however, this use of RCU to instead protect the index into an array, however, this use
case is -not- supported. The problem with RCU-protected indexes into case is **not** supported. The problem with RCU-protected indexes into
arrays is that compilers can play way too many optimization games with arrays is that compilers can play way too many optimization games with
integers, which means that the rules governing handling of these indexes integers, which means that the rules governing handling of these indexes
are far more trouble than they are worth. If RCU-protected indexes into are far more trouble than they are worth. If RCU-protected indexes into
@ -24,16 +26,20 @@ to be safely used.
That aside, each of the three RCU-protected pointer situations are That aside, each of the three RCU-protected pointer situations are
described in the following sections. described in the following sections.
.. _hash_tables:
Situation 1: Hash Tables Situation 1: Hash Tables
------------------------
Hash tables are often implemented as an array, where each array entry Hash tables are often implemented as an array, where each array entry
has a linked-list hash chain. Each hash chain can be protected by RCU has a linked-list hash chain. Each hash chain can be protected by RCU
as described in the listRCU.txt document. This approach also applies as described in the listRCU.txt document. This approach also applies
to other array-of-list situations, such as radix trees. to other array-of-list situations, such as radix trees.
.. _static_arrays:
Situation 2: Static Arrays Situation 2: Static Arrays
--------------------------
Static arrays, where the data (rather than a pointer to the data) is Static arrays, where the data (rather than a pointer to the data) is
located in each array element, and where the array is never resized, located in each array element, and where the array is never resized,
@ -41,13 +47,17 @@ have not been used with RCU. Rik van Riel recommends using seqlock in
this situation, which would also have minimal read-side overhead as long this situation, which would also have minimal read-side overhead as long
as updates are rare. as updates are rare.
Quick Quiz: Why is it so important that updates be rare when Quick Quiz:
using seqlock? Why is it so important that updates be rare when using seqlock?
:ref:`Answer to Quick Quiz <answer_quick_quiz_seqlock>`
Situation 3: Resizeable Arrays .. _resizable_arrays:
Use of RCU for resizeable arrays is demonstrated by the grow_ary() Situation 3: Resizable Arrays
------------------------------
Use of RCU for resizable arrays is demonstrated by the grow_ary()
function formerly used by the System V IPC code. The array is used function formerly used by the System V IPC code. The array is used
to map from semaphore, message-queue, and shared-memory IDs to the data to map from semaphore, message-queue, and shared-memory IDs to the data
structure that represents the corresponding IPC construct. The grow_ary() structure that represents the corresponding IPC construct. The grow_ary()
@ -60,7 +70,7 @@ the remainder of the new, updates the ids->entries pointer to point to
the new array, and invokes ipc_rcu_putref() to free up the old array. the new array, and invokes ipc_rcu_putref() to free up the old array.
Note that rcu_assign_pointer() is used to update the ids->entries pointer, Note that rcu_assign_pointer() is used to update the ids->entries pointer,
which includes any memory barriers required on whatever architecture which includes any memory barriers required on whatever architecture
you are running on. you are running on::
static int grow_ary(struct ipc_ids* ids, int newsize) static int grow_ary(struct ipc_ids* ids, int newsize)
{ {
@ -112,7 +122,7 @@ a simple check suffices. The pointer to the structure corresponding
to the desired IPC object is placed in "out", with NULL indicating to the desired IPC object is placed in "out", with NULL indicating
a non-existent entry. After acquiring "out->lock", the "out->deleted" a non-existent entry. After acquiring "out->lock", the "out->deleted"
flag indicates whether the IPC object is in the process of being flag indicates whether the IPC object is in the process of being
deleted, and, if not, the pointer is returned. deleted, and, if not, the pointer is returned::
struct kern_ipc_perm* ipc_lock(struct ipc_ids* ids, int id) struct kern_ipc_perm* ipc_lock(struct ipc_ids* ids, int id)
{ {
@ -144,8 +154,10 @@ deleted, and, if not, the pointer is returned.
return out; return out;
} }
.. _answer_quick_quiz_seqlock:
Answer to Quick Quiz: Answer to Quick Quiz:
Why is it so important that updates be rare when using seqlock?
The reason that it is important that updates be rare when The reason that it is important that updates be rare when
using seqlock is that frequent updates can livelock readers. using seqlock is that frequent updates can livelock readers.

View File

@ -7,6 +7,7 @@ RCU concepts
.. toctree:: .. toctree::
:maxdepth: 3 :maxdepth: 3
arrayRCU
rcu rcu
listRCU listRCU
UP UP