From dd3e8b9ec62cec77cea5ff9bdda64084a9e436d0 Mon Sep 17 00:00:00 2001 From: seantywork Date: Mon, 20 Oct 2025 14:07:21 +0900 Subject: [PATCH] krcu cmap relocated to medium --- krcu-cmap/{README.md => 2509-29.xyz.md} | 44 ++++--------------------- 1 file changed, 7 insertions(+), 37 deletions(-) rename krcu-cmap/{README.md => 2509-29.xyz.md} (73%) diff --git a/krcu-cmap/README.md b/krcu-cmap/2509-29.xyz.md similarity index 73% rename from krcu-cmap/README.md rename to krcu-cmap/2509-29.xyz.md index 489fe5a..6a0b838 100644 --- a/krcu-cmap/README.md +++ b/krcu-cmap/2509-29.xyz.md @@ -3,25 +3,7 @@ - source: [linuxyz/krcu-cmap](https://github.com/seantywork/linuxyz/tree/main/krcu-cmap) - date: 2509-24 -In user space on Linux, we can utilize `pthread_rwlock` to design a read-heavy data structure. - -A similar thing in the Linux kernel space is called `rcu`, a shorthand for "read, copy, update". - -Full documentation on it is [here](https://www.kernel.org/doc/html/next/RCU/whatisRCU.html) - -However, with `pthread_rwlock` in mind, it could be a little bit puzzling (at least it was for me) \ -to grasp the proper use and order of apis unlike in the case of \ -pthread_rwlock where you simply call *_rdlock on read and *_wrlock \ -on update - -Reading the docs wasn't enough for me. - -So I did the thing when I'm confused about the concept of multi-threading \ -and syncing mechanism: \ -**Building a concurrent map example!** - -Here, this is the outlay of this example. - +# 01 ```shell # a regular old concurrent map... @@ -43,8 +25,7 @@ concurrent_map | | --------------- ``` -However, in this case, our `node` data structure here \ -contains the magic element +# 02 ```c struct node { @@ -55,13 +36,7 @@ struct node { }; ``` -With all these, our scenario will flow like the diagram below. -The critical part to look for (in my opinion) is \ -`delete all nodes` part from writer thread. - -If this `rcu` thing cannot guarantee the basic functionality\ -we expect from things such as `pthread_rwlock`, then this part\ -will cause the GD kernel panic. +# 03 ```shell @@ -84,21 +59,19 @@ will cause the GD kernel panic. -------------------------------------------------------------- ``` -Now, let's compile the kernel module. +# 04 ```shell $ make ``` -Pop up another terminal, and use `dmesg` command to follow. + # 05 ```shell $ sudo dmesg -wH ``` -Load the kernel module with `insmod` command. \ -As soon as you do this, `dmesg` will output the result \ -described in the diagram above. +# 06 ```shell $ sudo insmod rcucmap.ko @@ -178,10 +151,7 @@ $ sudo insmod rcucmap.ko ``` -As you can see, the program is working as expected and (thank god) \ -there is no kernel panic! - -Pleased, unload the kernel module. +# 07 ```shell $ sudo rmmod rcucmap -- 2.43.0