🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

23 total messages Started by Joseph Seigh Sun, 11 Oct 2026 15:11
Re: Consequential RCU
#170
Author: Joseph Seigh
Date: Sun, 11 Oct 2026 15:11
25 lines
2521 bytes
On 9/16/26 6:25 PM, Joseph Seigh wrote:
> https://jseigh.wordpress.com/2026/09/07/consequential-concurrent- 
> sequential-rcu/
> 
> The name doesn't really mean anything. I was just generalizing something
> that's been around forever.*  It's simple enough that it must be in use
> somewhere.  I just haven't noticed it.  I looked up the linux kernal
> seqlock documentation and it specifically says not to use pointers in
> seqlock protected data and no idea why that is unless the linux kernel
> is doing something weird with memory mapping.
> 
> Like seqlock, it is obstruction-free.  If you have qsbr (RCU) or ebr,
> that would be a better choice.  It might be good for libraries where
> the memory reclamation is hidden from the application.
> 
> * tangentially related to something that I was working on which if far
> more perverse but mostly in a solution that is looking for a problem
> phase so it probably won't go anywhere.

I threw together a really quick and dirty test to see how much
overhead all those extra loads would cause.  Doesn't appear to
add any.  I will have to add it to the proxies project testcase
for more extensive testing but it will take a bit of work since
all the other proxies implement BasicLock and consequential RCU
readers do not.
Re: Consequential RCU
#206
Author: Chris M. Thomasson
Date: Sun, 11 Oct 2026 21:10
34 lines
2932 bytes
On 10/11/2026 8:11 AM, Joseph Seigh wrote:
> On 9/16/26 6:25 PM, Joseph Seigh wrote:
>> https://jseigh.wordpress.com/2026/09/07/consequential-concurrent- 
>> sequential-rcu/
>>
>> The name doesn't really mean anything. I was just generalizing something
>> that's been around forever.*  It's simple enough that it must be in use
>> somewhere.  I just haven't noticed it.  I looked up the linux kernal
>> seqlock documentation and it specifically says not to use pointers in
>> seqlock protected data and no idea why that is unless the linux kernel
>> is doing something weird with memory mapping.
>>
>> Like seqlock, it is obstruction-free.  If you have qsbr (RCU) or ebr,
>> that would be a better choice.  It might be good for libraries where
>> the memory reclamation is hidden from the application.
>>
>> * tangentially related to something that I was working on which if far
>> more perverse but mostly in a solution that is looking for a problem
>> phase so it probably won't go anywhere.
> 
> I threw together a really quick and dirty test to see how much
> overhead all those extra loads would cause.  Doesn't appear to
> add any.  I will have to add it to the proxies project testcase
> for more extensive testing but it will take a bit of work since
> all the other proxies implement BasicLock and consequential RCU
> readers do not.

If you get some free time to burn, add my proxy to your test bench. Its 
simply not meant to beat fancy asymmetric RCU+SMR type algos, but it 
works in 100% std C++. Which is fairly decent.

https://pastebin.com/raw/CYZ78gVj

It should just compile right up and run.
Re: Consequential RCU
#210
Author: Joseph Seigh
Date: Mon, 12 Oct 2026 01:44
29 lines
2548 bytes
On 10/11/26 5:10 PM, Chris M. Thomasson wrote:

> 
> If you get some free time to burn, add my proxy to your test bench. Its 
> simply not meant to beat fancy asymmetric RCU+SMR type algos, but it 
> works in 100% std C++. Which is fairly decent.
> 
> https://pastebin.com/raw/CYZ78gVj
> 
> It should just compile right up and run.

SMRProxy read lock is just an atomic load and store w/o membar.
I did a quick and dirty perf test of what would be the typical
user space RCU read lock logic, incrementing a local counter.

An atomic load, increment of loaded value, and atomic store
of that value is basically just as fast as SMRProxy, despite
that increment.   An atomic increment is quite a bit slower
on x86 since you have a full memory barrier there.  You
can't use asymmetric memory barriers to avoid that in this
case.

QSBR and EBR are basically the same thing.  Grace periods are
epochs.  The only difference is the QSBR logic to decide what
grace period each reader is referencing is a bit more indirect.
You are looking at events rather than conditions.  I didn't
do a user space RCU implementation since I didn't want to
deal with that extra logic.  And there are enough user space
RCU implementations out there already.
Re: Consequential RCU
#211
Author: Chris M. Thomasson
Date: Mon, 12 Oct 2026 03:04
114 lines
5238 bytes
On 10/11/2026 6:44 PM, Joseph Seigh wrote:
> On 10/11/26 5:10 PM, Chris M. Thomasson wrote:
> 
>>
>> If you get some free time to burn, add my proxy to your test bench. 
>> Its simply not meant to beat fancy asymmetric RCU+SMR type algos, but 
>> it works in 100% std C++. Which is fairly decent.
>>
>> https://pastebin.com/raw/CYZ78gVj
>>
>> It should just compile right up and run.
> 
> SMRProxy read lock is just an atomic load and store w/o membar.
> I did a quick and dirty perf test of what would be the typical
> user space RCU read lock logic, incrementing a local counter.

I don't have any of my old tests anymore from 2003-2010 ish. Damn. It 
was fun to compare and contrast different proxys back in the day. My 
collector is always going to lose against a proper RCU, or SMRProxy, 
RCU-SMR hybrid. But, iirc, they can be useful for the writer side of the 
algo. Also, its fun to see them beat a read/write lock. Some of those 
tests where pretty lop sided where I had to terminate the read-write 
lock version because it was taking way too long. Remember when you first 
came up with the proxy using your atomic_ptr way back on c.p.t?

Fwiw, I think your old tests measured reads per-thread per-second?


> An atomic load, increment of loaded value, and atomic store
> of that value is basically just as fast as SMRProxy, despite
> that increment.   An atomic increment is quite a bit slower
> on x86 since you have a full memory barrier there.  You
> can't use asymmetric memory barriers to avoid that in this
> case.

Well, if your "crafty" there is a way to "amortize" it... But it 
involves a certain usage pattern. A user needs to be familiar with it so 
it tends to be a hard sell. Anyway, basically in my proxy, or any proxy, 
I think.

try_to_iterate just tries to iterate a linked structure or something. If 
its empty it returns false. Otherwise, true:
_______________
collector& c = proxy_acquire();

for (unsigned long i = 1 ;; ++i)
{
     if (! try_to_iterate(c, shared_lock_free_list))
     {
         break;
     }

     if (! (i % 4096))
     {
         c = proxy_sync(c);
     }
}

proxy_release(c);
_______________

basically, proxy_sync is the following function in my old code:
_______________
     collector& sync(collector& c)
     {
         // check if the `c' is in the middle of a quiescence process.
         if (c.m_count.load(std::memory_order_relaxed) & ct_proxy_quiescent)
         {
             // drop `c' and get the next collector.
             release(c);

             return acquire();
         }

         return c;
     }
_______________

So, it actually works way better when its under load! Funny.


> QSBR and EBR are basically the same thing.  Grace periods are
> epochs.  The only difference is the QSBR logic to decide what
> grace period each reader is referencing is a bit more indirect.
> You are looking at events rather than conditions.  I didn't
> do a user space RCU implementation since I didn't want to
> deal with that extra logic.  And there are enough user space
> RCU implementations out there already.

Yeah. I just always liked my single word proxy. Its nice that its 100% 
portable wrt std C++. I remember your first one using atomic_ptr. Iirc, 
it had the backlink and called dtors recursively. Fwiw, mine old proxy 
just calls:
_______________
     static std::uint32_t prv_destroy(ct_node* n)
     {
         std::uint32_t count = 0;

         while (n)
         {
             ct_node* next = n->m_defer_next;
             delete n;
             count++;
             n = next;
         }

         return count;
     }
_______________


Sometimes I feel like getting back into these. Too busy with vector 
fields and fractals now. Having a lot of fun with compute and frag 
shaders, etc...
Re: Consequential RCU
#214
Author: Chris M. Thomasson
Date: Mon, 12 Oct 2026 03:07
11 lines
1900 bytes
On 10/11/2026 8:04 PM, Chris M. Thomasson wrote:
> On 10/11/2026 6:44 PM, Joseph Seigh wrote:
>> On 10/11/26 5:10 PM, Chris M. Thomasson wrote:
[...]
> Sometimes I feel like getting back into these. Too busy with vector 
> fields and fractals now. Having a lot of fun with compute and frag 
> shaders, etc...

Actually, I need to find out if the current Relacy can simulate async 
membars, akin to FlushProcessWriteBuffers. If it can, wow! I should just 
ask Dmitriy. Have not conversed with him for a while.
Re: Consequential RCU
#245
Author: Chris M. Thomasson
Date: Mon, 12 Oct 2026 03:34
14 lines
2278 bytes
On 10/11/2026 8:07 PM, Chris M. Thomasson wrote:
> On 10/11/2026 8:04 PM, Chris M. Thomasson wrote:
>> On 10/11/2026 6:44 PM, Joseph Seigh wrote:
>>> On 10/11/26 5:10 PM, Chris M. Thomasson wrote:
> [...]
>> Sometimes I feel like getting back into these. Too busy with vector 
>> fields and fractals now. Having a lot of fun with compute and frag 
>> shaders, etc...
> 
> Actually, I need to find out if the current Relacy can simulate async 
> membars, akin to FlushProcessWriteBuffers. If it can, wow! I should just 
> ask Dmitriy. Have not conversed with him for a while.

HEY NOW!!!! Relacy has systemwide_fence!
Re: Consequential RCU
#499
Author: Joseph Seigh
Date: Tue, 13 Oct 2026 17:01
59 lines
3480 bytes
On 10/11/26 11:11 AM, Joseph Seigh wrote:
> On 9/16/26 6:25 PM, Joseph Seigh wrote:
>> https://jseigh.wordpress.com/2026/09/07/consequential-concurrent- 
>> sequential-rcu/
>>
>> The name doesn't really mean anything. I was just generalizing something
>> that's been around forever.*  It's simple enough that it must be in use
>> somewhere.  I just haven't noticed it.  I looked up the linux kernal
>> seqlock documentation and it specifically says not to use pointers in
>> seqlock protected data and no idea why that is unless the linux kernel
>> is doing something weird with memory mapping.
>>
>> Like seqlock, it is obstruction-free.  If you have qsbr (RCU) or ebr,
>> that would be a better choice.  It might be good for libraries where
>> the memory reclamation is hidden from the application.
>>
>> * tangentially related to something that I was working on which if far
>> more perverse but mostly in a solution that is looking for a problem
>> phase so it probably won't go anywhere.
> 
> I threw together a really quick and dirty test to see how much
> overhead all those extra loads would cause.  Doesn't appear to
> add any.  I will have to add it to the proxies project testcase
> for more extensive testing but it will take a bit of work since
> all the other proxies implement BasicLock and consequential RCU
> readers do not.

This is what the code I did a quick and dirty test with looked like

using csequence_t = uint64_t;

inline bool cseq_retry(csequence_t mark, std::atomic<csequence_t> & 
sequence)
{
     std::atomic_thread_fence(std::memory_order_acquire);
     return mark != sequence.load(std::memory_order_acquire);
}
	
csequence_t mark;

retry:
do {

     mark = cseq_count.load(std::memory_order_acquire);
     node_t * item = list.load(std::memory_order_acquire);

     for (int ndx2 = 0; ndx2 < depth; ndx2++) {
         item = item->next.load(std::memory_order_acquire);
         if (cseq_retry(mark, cseq_count)) [[unlikely]]
             goto retry;
     }

} while (cseq_retry(mark, cseq_count));


As you can see, not a heck of lot of room in that loop
for the cpu pipeline to deal with the extra load and
conditional logic.
Re: Consequential RCU
#518
Author: Chris M. Thomasson
Date: Tue, 13 Oct 2026 19:36
73 lines
4274 bytes
On 10/13/2026 10:01 AM, Joseph Seigh wrote:
> On 10/11/26 11:11 AM, Joseph Seigh wrote:
>> On 9/16/26 6:25 PM, Joseph Seigh wrote:
>>> https://jseigh.wordpress.com/2026/09/07/consequential-concurrent- 
>>> sequential-rcu/
>>>
>>> The name doesn't really mean anything. I was just generalizing something
>>> that's been around forever.*  It's simple enough that it must be in use
>>> somewhere.  I just haven't noticed it.  I looked up the linux kernal
>>> seqlock documentation and it specifically says not to use pointers in
>>> seqlock protected data and no idea why that is unless the linux kernel
>>> is doing something weird with memory mapping.
>>>
>>> Like seqlock, it is obstruction-free.  If you have qsbr (RCU) or ebr,
>>> that would be a better choice.  It might be good for libraries where
>>> the memory reclamation is hidden from the application.
>>>
>>> * tangentially related to something that I was working on which if far
>>> more perverse but mostly in a solution that is looking for a problem
>>> phase so it probably won't go anywhere.
>>
>> I threw together a really quick and dirty test to see how much
>> overhead all those extra loads would cause.  Doesn't appear to
>> add any.  I will have to add it to the proxies project testcase
>> for more extensive testing but it will take a bit of work since
>> all the other proxies implement BasicLock and consequential RCU
>> readers do not.
> 
> This is what the code I did a quick and dirty test with looked like
> 
> using csequence_t = uint64_t;
> 
> inline bool cseq_retry(csequence_t mark, std::atomic<csequence_t> & 
> sequence)
> {
>      std::atomic_thread_fence(std::memory_order_acquire);
>      return mark != sequence.load(std::memory_order_acquire);
> }
> 
> csequence_t mark;
> 
> retry:
> do {
> 
>      mark = cseq_count.load(std::memory_order_acquire);
>      node_t * item = list.load(std::memory_order_acquire);
> 
>      for (int ndx2 = 0; ndx2 < depth; ndx2++) {
>          item = item->next.load(std::memory_order_acquire);
>          if (cseq_retry(mark, cseq_count)) [[unlikely]]
>              goto retry;
>      }
> 
> } while (cseq_retry(mark, cseq_count));
> 
> 
> As you can see, not a heck of lot of room in that loop
> for the cpu pipeline to deal with the extra load and
> conditional logic.
> 

It seems like cseq_retry on "every" iteration with its, two?, #LoadStore 
| #LoadLoad barriers is a bit much. Now that I have Relacy working fine 
on my end, and it has all I need for simulating even advanced RCU+SMR 
algos. Well, I will get back into it from time to time. Actually, can 
you get it working? Its a neat way to simulate your sync experiments.

Wait I count an acquire on the item->next.load and then two acquires 
from cseq_retry? Am I missing something critical here Joe?

https://github.com/dvyukov/relacy

Its header only.
Re: Consequential RCU
#535
Author: Joseph Seigh
Date: Tue, 13 Oct 2026 23:34
51 lines
3131 bytes
On 10/13/26 3:36 PM, Chris M. Thomasson wrote:
> On 10/13/2026 10:01 AM, Joseph Seigh wrote:

>> This is what the code I did a quick and dirty test with looked like
>>
>> using csequence_t = uint64_t;
>>
>> inline bool cseq_retry(csequence_t mark, std::atomic<csequence_t> & 
>> sequence)
>> {
>>      std::atomic_thread_fence(std::memory_order_acquire);
>>      return mark != sequence.load(std::memory_order_acquire);
>> }
>>
>> csequence_t mark;
>>
>> retry:
>> do {
>>
>>      mark = cseq_count.load(std::memory_order_acquire);
>>      node_t * item = list.load(std::memory_order_acquire);
>>
>>      for (int ndx2 = 0; ndx2 < depth; ndx2++) {
>>          item = item->next.load(std::memory_order_acquire);
>>          if (cseq_retry(mark, cseq_count)) [[unlikely]]
>>              goto retry;
>>      }
>>
>> } while (cseq_retry(mark, cseq_count));
>>
>>
>> As you can see, not a heck of lot of room in that loop
>> for the cpu pipeline to deal with the extra load and
>> conditional logic.
>>
> 
> It seems like cseq_retry on "every" iteration with its, two?, #LoadStore 
> | #LoadLoad barriers is a bit much. Now that I have Relacy working fine 
> on my end, and it has all I need for simulating even advanced RCU+SMR 
> algos. Well, I will get back into it from time to time. Actually, can 
> you get it working? Its a neat way to simulate your sync experiments.
> 
> Wait I count an acquire on the item->next.load and then two acquires 
> from cseq_retry? Am I missing something critical here Joe?

It would appear that way.   That's what quick and dirty means. :)
If the redundant load/load gets take out then there needs to be
some other mechanism or documentation to ensure the loads are in
order.

Re: Consequential RCU
#536
Author: Chris M. Thomasson
Date: Tue, 13 Oct 2026 23:46
218 lines
7768 bytes
On 10/13/2026 4:34 PM, Joseph Seigh wrote:
> On 10/13/26 3:36 PM, Chris M. Thomasson wrote:
>> On 10/13/2026 10:01 AM, Joseph Seigh wrote:
> 
>>> This is what the code I did a quick and dirty test with looked like
>>>
>>> using csequence_t = uint64_t;
>>>
>>> inline bool cseq_retry(csequence_t mark, std::atomic<csequence_t> & 
>>> sequence)
>>> {
>>>      std::atomic_thread_fence(std::memory_order_acquire);
>>>      return mark != sequence.load(std::memory_order_acquire);
>>> }
>>>
>>> csequence_t mark;
>>>
>>> retry:
>>> do {
>>>
>>>      mark = cseq_count.load(std::memory_order_acquire);
>>>      node_t * item = list.load(std::memory_order_acquire);
>>>
>>>      for (int ndx2 = 0; ndx2 < depth; ndx2++) {
>>>          item = item->next.load(std::memory_order_acquire);
>>>          if (cseq_retry(mark, cseq_count)) [[unlikely]]
>>>              goto retry;
>>>      }
>>>
>>> } while (cseq_retry(mark, cseq_count));
>>>
>>>
>>> As you can see, not a heck of lot of room in that loop
>>> for the cpu pipeline to deal with the extra load and
>>> conditional logic.
>>>
>>
>> It seems like cseq_retry on "every" iteration with its, two?, 
>> #LoadStore | #LoadLoad barriers is a bit much. Now that I have Relacy 
>> working fine on my end, and it has all I need for simulating even 
>> advanced RCU+SMR algos. Well, I will get back into it from time to 
>> time. Actually, can you get it working? Its a neat way to simulate 
>> your sync experiments.
>>
>> Wait I count an acquire on the item->next.load and then two acquires 
>> from cseq_retry? Am I missing something critical here Joe?
> 
> It would appear that way.   That's what quick and dirty means. :)
> If the redundant load/load gets take out then there needs to be
> some other mechanism or documentation to ensure the loads are in
> order.
> 
> 

Shit. Yeah... Well, humm... For some damn reason Joe, it kinda sorta 
makes me ponder on why Relacy experiment goes "berserk" if I remove the 
consume membar from my smr_load: I sent an email to Dmitriy about it.

I need to start getting dinner ready right now, but I am a bit baffled 
by it:

___________________
per_node*
smr_load(
     unsigned long tidx
) {
     for (;;)
     {
         per_node* node0 = m_node.load(rl::mo_relaxed, $);

         if (! node0)
         {
             RL_ASSERT(0);
             break;
         }

         m_threads[tidx].m_haz_0.store(node0, rl::mo_relaxed, $);

         // actually, iirc, a single seq_cst right here should work?

         per_node* node1 = m_node.load(rl::mo_consume, $);

         if (node0 == node1)
         {
             return node0;
         }
     }

     return nullptr;
}
___________________



my poller uses the systemwide_fence to get the async working:

________________________
struct poller
{
     rl::mutex m_poll;
     VAR_T(per_node*) m_defer0 = nullptr;

     void
     prv_poll(
         per_node*& defer,
         std::array<per_thread, CT_THREADS>& threads
     ) {
         per_node* head = defer;
         defer = nullptr; // Take ownership of the caller's local batch

         // Merge any previously deferred nodes from m_defer0 into the 
processing batch
         per_node* curr = VAR(m_defer0);
         VAR(m_defer0) = nullptr;
         while (curr)
         {
             per_node* next_node = VAR(curr->m_defer);
             VAR(curr->m_defer) = head;
             head = curr;
             curr = next_node;
         }

         // Two-Pass Hazard Pointer Scan:
         // Pass 1: Capture all thread hazard slots
         std::vector<per_node*> haz_pass1(threads.size());
         for (size_t i = 0; i < threads.size(); ++i)
         {
             haz_pass1[i] = threads[i].m_haz_0.load(rl::mo_relaxed, $);
         }

         // Synchronization barrier between scans
         rl::systemwide_fence($);

         // Pass 2: Capture all thread hazard slots again
         std::vector<per_node*> haz_pass2(threads.size());
         for (size_t i = 0; i < threads.size(); ++i)
         {
             haz_pass2[i] = threads[i].m_haz_0.load(rl::mo_relaxed, $);
         }

         per_node* remaining = nullptr;

         while (head)
         {
             per_node* next = VAR(head->m_defer);
             bool protected_node = false;

             // Check if the node is protected in either pass snapshot
             for (auto haz : haz_pass1)
             {
                 if (haz == head)
                 {
                     protected_node = true;
                     break;
                 }
             }

             if (!protected_node)
             {
                 for (auto haz : haz_pass2)
                 {
                     if (haz == head)
                     {
                         protected_node = true;
                         break;
                     }
                 }
             }

             if (protected_node)
             {
                 // Keep it in the deferred list
                 VAR(head->m_defer) = remaining;
                 remaining = head;
             }
             else
             {
                 // Safe to reclaim!
                 delete head;
             }

             head = next;
         }

         // Store any still-protected nodes back into the central poller 
queue
         VAR(m_defer0) = remaining;
     }

     bool
     try_poll(
         per_node*& defer,
         std::array<per_thread, CT_THREADS>& threads
     ) {
         if (m_poll.try_lock($))
         {
             prv_poll(defer, threads);
             m_poll.unlock($);
             return true;
         }

         return false;
     }

     void
     poll(
         per_node*& defer,
         std::array<per_thread, CT_THREADS>& threads
     ) {
         m_poll.lock($);
         prv_poll(defer, threads);
         m_poll.unlock($);
     }
};
________________________


Two passes with the async member in between them.
Re: Consequential RCU
#555
Author: Chris M. Thomasson
Date: Wed, 14 Oct 2026 21:16
55 lines
2874 bytes
On 10/13/2026 4:34 PM, Joseph Seigh wrote:
> On 10/13/26 3:36 PM, Chris M. Thomasson wrote:
>> On 10/13/2026 10:01 AM, Joseph Seigh wrote:
> 
>>> This is what the code I did a quick and dirty test with looked like
>>>
>>> using csequence_t = uint64_t;
>>>
>>> inline bool cseq_retry(csequence_t mark, std::atomic<csequence_t> & 
>>> sequence)
>>> {
>>>      std::atomic_thread_fence(std::memory_order_acquire);
>>>      return mark != sequence.load(std::memory_order_acquire);
>>> }
>>>
>>> csequence_t mark;
>>>
>>> retry:
>>> do {
>>>
>>>      mark = cseq_count.load(std::memory_order_acquire);
>>>      node_t * item = list.load(std::memory_order_acquire);
>>>
>>>      for (int ndx2 = 0; ndx2 < depth; ndx2++) {
>>>          item = item->next.load(std::memory_order_acquire);
>>>          if (cseq_retry(mark, cseq_count)) [[unlikely]]
>>>              goto retry;
>>>      }
>>>
>>> } while (cseq_retry(mark, cseq_count));
>>>
>>>
>>> As you can see, not a heck of lot of room in that loop
>>> for the cpu pipeline to deal with the extra load and
>>> conditional logic.
[...]

Its interesting. Btw, I don't even need traditional SMR logic! This 
works fine:
________________
per_node*
smr_load(
     unsigned long tidx
) {
     per_node* node0 = m_node.load(rl::mo_relaxed, $);
     m_threads[tidx].m_haz_0.store(node0, rl::mo_relaxed, $);
     return node0;
}
________________





Re: Consequential RCU
#556
Author: Chris M. Thomasson
Date: Wed, 14 Oct 2026 21:46
86 lines
4077 bytes
On 10/14/2026 2:16 PM, Chris M. Thomasson wrote:
> On 10/13/2026 4:34 PM, Joseph Seigh wrote:
>> On 10/13/26 3:36 PM, Chris M. Thomasson wrote:
>>> On 10/13/2026 10:01 AM, Joseph Seigh wrote:
>>
>>>> This is what the code I did a quick and dirty test with looked like
>>>>
>>>> using csequence_t = uint64_t;
>>>>
>>>> inline bool cseq_retry(csequence_t mark, std::atomic<csequence_t> & 
>>>> sequence)
>>>> {
>>>>      std::atomic_thread_fence(std::memory_order_acquire);
>>>>      return mark != sequence.load(std::memory_order_acquire);
>>>> }
>>>>
>>>> csequence_t mark;
>>>>
>>>> retry:
>>>> do {
>>>>
>>>>      mark = cseq_count.load(std::memory_order_acquire);
>>>>      node_t * item = list.load(std::memory_order_acquire);
>>>>
>>>>      for (int ndx2 = 0; ndx2 < depth; ndx2++) {
>>>>          item = item->next.load(std::memory_order_acquire);
>>>>          if (cseq_retry(mark, cseq_count)) [[unlikely]]
>>>>              goto retry;
>>>>      }
>>>>
>>>> } while (cseq_retry(mark, cseq_count));
>>>>
>>>>
>>>> As you can see, not a heck of lot of room in that loop
>>>> for the cpu pipeline to deal with the extra load and
>>>> conditional logic.
> [...]
> 
> Its interesting. Btw, I don't even need traditional SMR logic! This 
> works fine:
> ________________
> per_node*
> smr_load(
>      unsigned long tidx
> ) {
>      per_node* node0 = m_node.load(rl::mo_relaxed, $);
>      m_threads[tidx].m_haz_0.store(node0, rl::mo_relaxed, $);
>      return node0;
> }
> ________________
Oh OUCH! Sorry Joe. This does not work in Relacy. I forgot to run that 
test in my ct_main.cpp launcher. So, god damn it. I still need a consume 
barrier, or I think C++ fold that into acquire right?

  per_node*
  smr_load(
      unsigned long tidx
  ) {
      for (;;)
      {
          per_node* node0 = m_node.load(rl::mo_relaxed, $);

          if (! node0)
          {
              RL_ASSERT(0); // hould never happen in this test!
              m_threads[tidx].m_haz_0.store(nullptr, rl::mo_relaxed, $);
              break;
          }

          m_threads[tidx].m_haz_0.store(node0, rl::mo_relaxed, $);

          // actually, iirc, a single seq_cst right here should work?
          // well, this is an async test...

          per_node* node1 = m_node.load(rl::mo_consume, $);

          // uncomment below, Relacy goes berserker!
          //per_node* node1 = m_node.load(rl::mo_relaxed, $);
          if (node0 == node1)
          {
              return node0;
          }
      }

      return nullptr;
  }
Re: Consequential RCU
#571
Author: Chris M. Thomasson
Date: Thu, 15 Oct 2026 18:23
412 lines
13703 bytes
On 10/13/2026 4:34 PM, Joseph Seigh wrote:
> On 10/13/26 3:36 PM, Chris M. Thomasson wrote:
>> On 10/13/2026 10:01 AM, Joseph Seigh wrote:
> 
>>> This is what the code I did a quick and dirty test with looked like
>>>
>>> using csequence_t = uint64_t;
>>>
>>> inline bool cseq_retry(csequence_t mark, std::atomic<csequence_t> & 
>>> sequence)
>>> {
>>>      std::atomic_thread_fence(std::memory_order_acquire);
>>>      return mark != sequence.load(std::memory_order_acquire);
>>> }
>>>
>>> csequence_t mark;
>>>
>>> retry:
>>> do {
>>>
>>>      mark = cseq_count.load(std::memory_order_acquire);
>>>      node_t * item = list.load(std::memory_order_acquire);
>>>
>>>      for (int ndx2 = 0; ndx2 < depth; ndx2++) {
>>>          item = item->next.load(std::memory_order_acquire);
>>>          if (cseq_retry(mark, cseq_count)) [[unlikely]]
>>>              goto retry;
>>>      }
>>>
>>> } while (cseq_retry(mark, cseq_count));
>>>
>>>
>>> As you can see, not a heck of lot of room in that loop
>>> for the cpu pipeline to deal with the extra load and
>>> conditional logic.
[...]


std::atomic_thread_fence(std::memory_order_acquire);
return mark != sequence.load(std::memory_order_acquire);

Sometimes I get nervous wrt how c++ deals with integrating the 
standalone fence with the per atomic fences. Humm... As you know I 
recently got back into relacy. Its interesting to work with. When you 
get really bored, and have nothing to do, give it a go! Sigh. Might be 
fun for you?

I should try to model your cseq_retry. Anyway, after talking to some 
people about the most recent Relacy, here is what we came up with. 
Apparently this is the most "relaxed" version of my async SMR test. I am 
not sure how to make it any more relaxed! Notice smr_load, smr_unload, 
and the prv_poll functions if you have the time and the interest.

smr_unload cannot use relaxed, grrr!!!. It needs the release to allow 
C++ mem model to get into the second pass of the smr polling logic. So, 
pass 1, relaxed sample, systemwide_fence, then the second sample needs 
acquire:


____________________
#pragma once

#include <relacy/relacy.hpp>
#include <cstdio>
#include <cstddef>
#include <cstdlib>

#include <array>
#include <string>
#include <vector>

namespace ct
{
     namespace smr_test
     {
         constexpr unsigned long CT_THREADS_READERS = 5;
         constexpr unsigned long CT_THREADS_WRITERS = 3;
         constexpr unsigned long CT_THREADS = CT_THREADS_READERS + 
CT_THREADS_WRITERS;
         constexpr unsigned long CT_THREADS_READER_ITER_N = 12;
         constexpr unsigned long CT_THREADS_WRITER_ITER_N = 8;

         struct per_node
         {
             VAR_T(per_node*) m_defer = { nullptr };
             VAR_T(unsigned long) m_data = { 0 };
         };

         struct per_thread
         {
             rl::atomic<per_node*> m_haz_0 = { nullptr };
         };

         struct poller
         {
             rl::mutex m_poll;
             VAR_T(per_node*) m_defer0 = nullptr;

             void
             prv_poll(
                 per_node*& defer,
                 std::array<per_thread, CT_THREADS>& threads
             ) {
                 per_node* head = defer;
                 defer = nullptr; // Take ownership of the caller's 
local batch

                 // Merge any previously deferred nodes from m_defer0 
into the processing batch
                 per_node* curr = VAR(m_defer0);
                 VAR(m_defer0) = nullptr;
                 while (curr)
                 {
                     per_node* next_node = VAR(curr->m_defer);
                     VAR(curr->m_defer) = head;
                     head = curr;
                     curr = next_node;
                 }

                 // Two-Pass Hazard Pointer Scan:
                 // Pass 1: Capture all thread hazard slots
                 std::vector<per_node*> haz_pass1(threads.size());
                 for (size_t i = 0; i < threads.size(); ++i)
                 {
                     haz_pass1[i] = 
threads[i].m_haz_0.load(rl::mo_relaxed, $);
                 }

                 // Synchronization barrier between scans
                 rl::systemwide_fence($);

                 // Pass 2: Capture all thread hazard slots again
                 std::vector<per_node*> haz_pass2(threads.size());
                 for (size_t i = 0; i < threads.size(); ++i)
                 {
                     haz_pass2[i] = 
threads[i].m_haz_0.load(rl::mo_acquire, $);
                 }

                 per_node* remaining = nullptr;

                 while (head)
                 {
                     per_node* next = VAR(head->m_defer);
                     bool protected_node = false;

                     // Check if the node is protected in either pass 
snapshot
                     for (auto haz : haz_pass1)
                     {
                         if (haz == head)
                         {
                             protected_node = true;
                             break;
                         }
                     }

                     if (! protected_node)
                     {
                         for (auto haz : haz_pass2)
                         {
                             if (haz == head)
                             {
                                 protected_node = true;
                                 break;
                             }
                         }
                     }

                     if (protected_node)
                     {
                         // Keep it in the deferred list
                         VAR(head->m_defer) = remaining;
                         remaining = head;
                     }
                     else
                     {
                         // Safe to reclaim!
                         VAR(head->m_data) = 0xDEADBEEF;
                         delete head;
                     }

                     head = next;
                 }

                 // Store any still-protected nodes back into the 
central poller queue
                 VAR(m_defer0) = remaining;
             }

             bool
             try_poll(
                 per_node*& defer,
                 std::array<per_thread, CT_THREADS>& threads
             ) {
                 if (m_poll.try_lock($))
                 {
                     prv_poll(defer, threads);
                     m_poll.unlock($);
                     return true;
                 }

                 return false;
             }

             void
             poll(
                 per_node*& defer,
                 std::array<per_thread, CT_THREADS>& threads
             ) {
                 m_poll.lock($);
                 prv_poll(defer, threads);
                 m_poll.unlock($);
             }
         };

         struct state
         {
             std::array<per_thread, CT_THREADS> m_threads;
             poller m_poller = { };
             rl::atomic<per_node*> m_node = { };

             // relacy hooks, so to speak... ;^o
             // relaxed because everything either has not
             // started yet, or everything is already done...
             void
             before()
             {
                 per_node* node = new per_node();
                 VAR(node->m_data) = 456;
                 VAR(node->m_defer) = nullptr;

                 m_node.store(node, rl::mo_relaxed, $);
             }


             void
             after()
             {
                 per_node* node = m_node.load(rl::mo_relaxed, $);

                 if (node)
                 {
                     delete node;
                 }

                 // Also clean up any lingering nodes left in the 
poller's m_defer0 at teardown
                 per_node* poll_defer = VAR(m_poller.m_defer0);
                 while (poll_defer)
                 {
                     per_node* next = VAR(poll_defer->m_defer);
                     delete poll_defer;
                     poll_defer = next;
                 }
             }

             per_node*
             smr_load(
                 unsigned long tidx
             ) {
                 for (;;)
                 {
                     per_node* node0 = m_node.load(rl::mo_relaxed, $);

                     if (! node0)
                     {
                         RL_ASSERT(0); // hould never happen in this test!
                         m_threads[tidx].m_haz_0.store(nullptr, 
rl::mo_relaxed, $);
                         break;
                     }

                     m_threads[tidx].m_haz_0.store(node0, 
rl::mo_relaxed, $);

                     // change this to relaxed and it fails...
                     per_node* node1 = m_node.load(rl::mo_consume, $);

                     if (node0 == node1)
                     {
                         return node0;
                     }
                 }

                 return nullptr;
             }


             void
             smr_unload(
                 unsigned long tidx
             ) {
                 // humm...
                 m_threads[tidx].m_haz_0.store(nullptr, rl::mo_release, $);
             }
         };

         // the actual test unit...
         struct smr_test_v000
         :   rl::test_suite<smr_test_v000, CT_THREADS>
         {
             state m_state = { };

             void before()
             {
                 m_state.before();
             }

             void after()
             {
                 m_state.after();
             }

             void
             thread_reader(
                 unsigned int tidx
             ) {
                 for (unsigned long i = 0; i < CT_THREADS_READER_ITER_N; 
++i)
                 {
                     per_node* node = m_state.smr_load(tidx);

                     if (node)
                     {
                         // dummy load to poke Relacy... ;^)
  
(void)m_state.m_threads[tidx].m_haz_0.load(rl::mo_relaxed, $);

                         unsigned long data = VAR(node->m_data);
                         RL_ASSERT((data == 123 || data == 456) && (data 
!= 0xDEADBEEF));

                         m_state.smr_unload(tidx);
                     }
                 }
             }

             void
             thread_writer(
                 unsigned int tidx
             ) {
                 per_node* my_defer = nullptr;

                 for (unsigned long i = 0; i < CT_THREADS_WRITER_ITER_N; 
++i)
                 {
                     per_node* node = new per_node();
                     VAR(node->m_data) = 456;
                     VAR(node->m_defer) = nullptr;
                     per_node* old = m_state.m_node.exchange(node, 
rl::mo_acq_rel, $);

                     if (old)
                     {
                         VAR(old->m_defer) = my_defer;
                         my_defer = old;
                     }

                     // Opportunistically try to poll and sweep nodes
                     m_state.m_poller.try_poll(my_defer, m_state.m_threads);
                 }

                 // Drain remaining deferred nodes upon thread exit
                 m_state.m_poller.poll(my_defer, m_state.m_threads);
             }

             void
             thread(
                 unsigned int tidx
             ) {
                 if (tidx < CT_THREADS_READERS)
                 {
                     thread_reader(tidx);
                 }

                 else
                 {
                     thread_writer(tidx);
                 }
             }
         };
     }
}

namespace ct
{
     namespace smr_test
     {
         namespace test
         {
             inline void
             manifest(
                 rl::test_params& p
             ) {
                 rl::simulate<ct::smr_test::smr_test_v000>(p);
             }
         }
     }
}




____________________






Re: Consequential RCU
#572
Author: Chris M. Thomasson
Date: Thu, 15 Oct 2026 18:26
56 lines
3463 bytes
On 10/13/2026 4:34 PM, Joseph Seigh wrote:
> On 10/13/26 3:36 PM, Chris M. Thomasson wrote:
>> On 10/13/2026 10:01 AM, Joseph Seigh wrote:
> 
>>> This is what the code I did a quick and dirty test with looked like
>>>
>>> using csequence_t = uint64_t;
>>>
>>> inline bool cseq_retry(csequence_t mark, std::atomic<csequence_t> & 
>>> sequence)
>>> {
>>>      std::atomic_thread_fence(std::memory_order_acquire);
>>>      return mark != sequence.load(std::memory_order_acquire);
>>> }
>>>
>>> csequence_t mark;
>>>
>>> retry:
>>> do {
>>>
>>>      mark = cseq_count.load(std::memory_order_acquire);
>>>      node_t * item = list.load(std::memory_order_acquire);
>>>
>>>      for (int ndx2 = 0; ndx2 < depth; ndx2++) {
>>>          item = item->next.load(std::memory_order_acquire);
>>>          if (cseq_retry(mark, cseq_count)) [[unlikely]]
>>>              goto retry;
>>>      }
>>>
>>> } while (cseq_retry(mark, cseq_count));
>>>
>>>
>>> As you can see, not a heck of lot of room in that loop
>>> for the cpu pipeline to deal with the extra load and
>>> conditional logic.
>>>
>>
>> It seems like cseq_retry on "every" iteration with its, two?, 
>> #LoadStore | #LoadLoad barriers is a bit much. Now that I have Relacy 
>> working fine on my end, and it has all I need for simulating even 
>> advanced RCU+SMR algos. Well, I will get back into it from time to 
>> time. Actually, can you get it working? Its a neat way to simulate 
>> your sync experiments.
>>
>> Wait I count an acquire on the item->next.load and then two acquires 
>> from cseq_retry? Am I missing something critical here Joe?
> 
> It would appear that way.   That's what quick and dirty means. :)
> If the redundant load/load gets take out then there needs to be
> some other mechanism or documentation to ensure the loads are in
> order.

Also, cseq_retry on x86/x64 should be native to their TSO anyway? So, no 
ops? But on a SPARC in RMO mode. The damn MEMBAR #LoadStore | #LoadLoad 
would kick in?
Re: Consequential RCU
#573
Author: Chris M. Thomasson
Date: Thu, 15 Oct 2026 18:49
72 lines
4073 bytes
On 10/13/2026 10:01 AM, Joseph Seigh wrote:
> On 10/11/26 11:11 AM, Joseph Seigh wrote:
>> On 9/16/26 6:25 PM, Joseph Seigh wrote:
>>> https://jseigh.wordpress.com/2026/09/07/consequential-concurrent- 
>>> sequential-rcu/
>>>
>>> The name doesn't really mean anything. I was just generalizing something
>>> that's been around forever.*  It's simple enough that it must be in use
>>> somewhere.  I just haven't noticed it.  I looked up the linux kernal
>>> seqlock documentation and it specifically says not to use pointers in
>>> seqlock protected data and no idea why that is unless the linux kernel
>>> is doing something weird with memory mapping.
>>>
>>> Like seqlock, it is obstruction-free.  If you have qsbr (RCU) or ebr,
>>> that would be a better choice.  It might be good for libraries where
>>> the memory reclamation is hidden from the application.
>>>
>>> * tangentially related to something that I was working on which if far
>>> more perverse but mostly in a solution that is looking for a problem
>>> phase so it probably won't go anywhere.
>>
>> I threw together a really quick and dirty test to see how much
>> overhead all those extra loads would cause.  Doesn't appear to
>> add any.  I will have to add it to the proxies project testcase
>> for more extensive testing but it will take a bit of work since
>> all the other proxies implement BasicLock and consequential RCU
>> readers do not.
> 
> This is what the code I did a quick and dirty test with looked like
> 
> using csequence_t = uint64_t;
> 
> inline bool cseq_retry(csequence_t mark, std::atomic<csequence_t> & 
> sequence)
> {
>      std::atomic_thread_fence(std::memory_order_acquire);
>      return mark != sequence.load(std::memory_order_acquire);
> }
> 
> csequence_t mark;
> 
> retry:
> do {
> 
>      mark = cseq_count.load(std::memory_order_acquire);
>      node_t * item = list.load(std::memory_order_acquire);
> 
>      for (int ndx2 = 0; ndx2 < depth; ndx2++) {
>          item = item->next.load(std::memory_order_acquire);
>          if (cseq_retry(mark, cseq_count)) [[unlikely]]
>              goto retry;
>      }
> 
> } while (cseq_retry(mark, cseq_count));

Oh shit. This looks like it can be _potential_ "livelock" nation under 
some sustained periods of "heavy enough" load? Can we iterate the whole 
list before many (n) retrys have occurred? Or how many retrys on average 
does it take to iterate a decent sized list from head to tail? Writers 
churning along in the background...



> 
> 
> As you can see, not a heck of lot of room in that loop
> for the cpu pipeline to deal with the extra load and
> conditional logic.
> 

Indeed!
Re: Consequential RCU
#574
Author: Joseph Seigh
Date: Thu, 15 Oct 2026 23:26
51 lines
3151 bytes
On 10/15/26 2:49 PM, Chris M. Thomasson wrote:
> On 10/13/2026 10:01 AM, Joseph Seigh wrote:
>> On 10/11/26 11:11 AM, Joseph Seigh wrote:


>> This is what the code I did a quick and dirty test with looked like
>>
>> using csequence_t = uint64_t;
>>
>> inline bool cseq_retry(csequence_t mark, std::atomic<csequence_t> & 
>> sequence)
>> {
>>      std::atomic_thread_fence(std::memory_order_acquire);
>>      return mark != sequence.load(std::memory_order_acquire);
>> }
>>
>> csequence_t mark;
>>
>> retry:
>> do {
>>
>>      mark = cseq_count.load(std::memory_order_acquire);
>>      node_t * item = list.load(std::memory_order_acquire);
>>
>>      for (int ndx2 = 0; ndx2 < depth; ndx2++) {
>>          item = item->next.load(std::memory_order_acquire);
>>          if (cseq_retry(mark, cseq_count)) [[unlikely]]
>>              goto retry;
>>      }
>>
>> } while (cseq_retry(mark, cseq_count));
> 
> Oh shit. This looks like it can be _potential_ "livelock" nation under 
> some sustained periods of "heavy enough" load? Can we iterate the whole 
> list before many (n) retrys have occurred? Or how many retrys on average 
> does it take to iterate a decent sized list from head to tail? Writers 
> churning along in the background...
> 

The list was used to give an idea how much overhead there would be.
I wouldn't use this for O(n) stuff where n is very large.

In that this is similar to SEQLOCK, its docs mention the livelock issue.
The term for these kind of algorithms is obstruction-free (Herlihy).

You could avoid this with a conventional rwlock. Probably slow you
down by orders of magnitude.

You could use RCU since the readers are wait-free.  With that many
updates deferring that much memory, you might OOM.
Re: Consequential RCU
#1050
Author: Chris M. Thomasson
Date: Sun, 29 Nov 2026 08:57
61 lines
3579 bytes
On 10/15/2026 4:26 PM, Joseph Seigh wrote:
> On 10/15/26 2:49 PM, Chris M. Thomasson wrote:
>> On 10/13/2026 10:01 AM, Joseph Seigh wrote:
>>> On 10/11/26 11:11 AM, Joseph Seigh wrote:
> 
> 
>>> This is what the code I did a quick and dirty test with looked like
>>>
>>> using csequence_t = uint64_t;
>>>
>>> inline bool cseq_retry(csequence_t mark, std::atomic<csequence_t> & 
>>> sequence)
>>> {
>>>      std::atomic_thread_fence(std::memory_order_acquire);
>>>      return mark != sequence.load(std::memory_order_acquire);
>>> }
>>>
>>> csequence_t mark;
>>>
>>> retry:
>>> do {
>>>
>>>      mark = cseq_count.load(std::memory_order_acquire);
>>>      node_t * item = list.load(std::memory_order_acquire);
>>>
>>>      for (int ndx2 = 0; ndx2 < depth; ndx2++) {
>>>          item = item->next.load(std::memory_order_acquire);
>>>          if (cseq_retry(mark, cseq_count)) [[unlikely]]
>>>              goto retry;
>>>      }
>>>
>>> } while (cseq_retry(mark, cseq_count));
>>
>> Oh shit. This looks like it can be _potential_ "livelock" nation under 
>> some sustained periods of "heavy enough" load? Can we iterate the 
>> whole list before many (n) retrys have occurred? Or how many retrys on 
>> average does it take to iterate a decent sized list from head to tail? 
>> Writers churning along in the background...
>>
> 
> The list was used to give an idea how much overhead there would be.
> I wouldn't use this for O(n) stuff where n is very large.
> 
> In that this is similar to SEQLOCK, its docs mention the livelock issue.
> The term for these kind of algorithms is obstruction-free (Herlihy).

Fwiw, speaking of SEQLOCK I think Dmitry had a nifty distributed one. 
Let me try to find it...

https://sites.google.com/site/1024cores/home/lock-free-algorithms/reader-writer-problem/improved-lock-free-seqlock

> 
> You could avoid this with a conventional rwlock. Probably slow you
> down by orders of magnitude.
> 
> You could use RCU since the readers are wait-free.  With that many
> updates deferring that much memory, you might OOM.
> 

Yeah. I remember some old stress tests that would make malloc fail. Man 
that was a long time ago.
Re: Consequential RCU
#1051
Author: Ross Finlayson
Date: Sun, 29 Nov 2026 17:36
77 lines
4296 bytes
On 11/29/2026 12:57 AM, Chris M. Thomasson wrote:
> On 10/15/2026 4:26 PM, Joseph Seigh wrote:
>> On 10/15/26 2:49 PM, Chris M. Thomasson wrote:
>>> On 10/13/2026 10:01 AM, Joseph Seigh wrote:
>>>> On 10/11/26 11:11 AM, Joseph Seigh wrote:
>>
>>
>>>> This is what the code I did a quick and dirty test with looked like
>>>>
>>>> using csequence_t = uint64_t;
>>>>
>>>> inline bool cseq_retry(csequence_t mark, std::atomic<csequence_t> &
>>>> sequence)
>>>> {
>>>>      std::atomic_thread_fence(std::memory_order_acquire);
>>>>      return mark != sequence.load(std::memory_order_acquire);
>>>> }
>>>>
>>>> csequence_t mark;
>>>>
>>>> retry:
>>>> do {
>>>>
>>>>      mark = cseq_count.load(std::memory_order_acquire);
>>>>      node_t * item = list.load(std::memory_order_acquire);
>>>>
>>>>      for (int ndx2 = 0; ndx2 < depth; ndx2++) {
>>>>          item = item->next.load(std::memory_order_acquire);
>>>>          if (cseq_retry(mark, cseq_count)) [[unlikely]]
>>>>              goto retry;
>>>>      }
>>>>
>>>> } while (cseq_retry(mark, cseq_count));
>>>
>>> Oh shit. This looks like it can be _potential_ "livelock" nation
>>> under some sustained periods of "heavy enough" load? Can we iterate
>>> the whole list before many (n) retrys have occurred? Or how many
>>> retrys on average does it take to iterate a decent sized list from
>>> head to tail? Writers churning along in the background...
>>>
>>
>> The list was used to give an idea how much overhead there would be.
>> I wouldn't use this for O(n) stuff where n is very large.
>>
>> In that this is similar to SEQLOCK, its docs mention the livelock issue.
>> The term for these kind of algorithms is obstruction-free (Herlihy).
>
> Fwiw, speaking of SEQLOCK I think Dmitry had a nifty distributed one.
> Let me try to find it...
>
> https://sites.google.com/site/1024cores/home/lock-free-algorithms/reader-writer-problem/improved-lock-free-seqlock
>
>
>>
>> You could avoid this with a conventional rwlock. Probably slow you
>> down by orders of magnitude.
>>
>> You could use RCU since the readers are wait-free.  With that many
>> updates deferring that much memory, you might OOM.
>>
>
> Yeah. I remember some old stress tests that would make malloc fail. Man
> that was a long time ago.

Didn't "memory_order" get deprecated.


You either have opportunistic-locking about cmp-exchange |
load-linked+store-conditional with a datum of 64-bits about AMD
and aligned and padded to 64-bytes or 128 for ARM's cache-line pairs,
or you don't, then about that there's basically always a necessary
UUID-vendor to prevent ABA (i.e., "race conditions"),
one thing that guarantees another being the same ("unique"),
and another guaranteeing another being different ("unique").


Re: Consequential RCU
#1052
Author: Chris M. Thomasson
Date: Sun, 29 Nov 2026 21:08
90 lines
4986 bytes
On 11/29/2026 9:36 AM, Ross Finlayson wrote:
> On 11/29/2026 12:57 AM, Chris M. Thomasson wrote:
>> On 10/15/2026 4:26 PM, Joseph Seigh wrote:
>>> On 10/15/26 2:49 PM, Chris M. Thomasson wrote:
>>>> On 10/13/2026 10:01 AM, Joseph Seigh wrote:
>>>>> On 10/11/26 11:11 AM, Joseph Seigh wrote:
>>>
>>>
>>>>> This is what the code I did a quick and dirty test with looked like
>>>>>
>>>>> using csequence_t = uint64_t;
>>>>>
>>>>> inline bool cseq_retry(csequence_t mark, std::atomic<csequence_t> &
>>>>> sequence)
>>>>> {
>>>>>      std::atomic_thread_fence(std::memory_order_acquire);
>>>>>      return mark != sequence.load(std::memory_order_acquire);
>>>>> }
>>>>>
>>>>> csequence_t mark;
>>>>>
>>>>> retry:
>>>>> do {
>>>>>
>>>>>      mark = cseq_count.load(std::memory_order_acquire);
>>>>>      node_t * item = list.load(std::memory_order_acquire);
>>>>>
>>>>>      for (int ndx2 = 0; ndx2 < depth; ndx2++) {
>>>>>          item = item->next.load(std::memory_order_acquire);
>>>>>          if (cseq_retry(mark, cseq_count)) [[unlikely]]
>>>>>              goto retry;
>>>>>      }
>>>>>
>>>>> } while (cseq_retry(mark, cseq_count));
>>>>
>>>> Oh shit. This looks like it can be _potential_ "livelock" nation
>>>> under some sustained periods of "heavy enough" load? Can we iterate
>>>> the whole list before many (n) retrys have occurred? Or how many
>>>> retrys on average does it take to iterate a decent sized list from
>>>> head to tail? Writers churning along in the background...
>>>>
>>>
>>> The list was used to give an idea how much overhead there would be.
>>> I wouldn't use this for O(n) stuff where n is very large.
>>>
>>> In that this is similar to SEQLOCK, its docs mention the livelock issue.
>>> The term for these kind of algorithms is obstruction-free (Herlihy).
>>
>> Fwiw, speaking of SEQLOCK I think Dmitry had a nifty distributed one.
>> Let me try to find it...
>>
>> https://sites.google.com/site/1024cores/home/lock-free-algorithms/ 
>> reader-writer-problem/improved-lock-free-seqlock
>>
>>
>>>
>>> You could avoid this with a conventional rwlock. Probably slow you
>>> down by orders of magnitude.
>>>
>>> You could use RCU since the readers are wait-free.  With that many
>>> updates deferring that much memory, you might OOM.
>>>
>>
>> Yeah. I remember some old stress tests that would make malloc fail. Man
>> that was a long time ago.
> 
> Didn't "memory_order" get deprecated.

When did that occur? Yikes!

I highly doubt that c++ got rid of memory_order.

Afaict, memory_order_consume got folded into memory_order_acquire. Sigh.


> You either have opportunistic-locking about cmp-exchange |
> load-linked+store-conditional with a datum of 64-bits about AMD
> and aligned and padded to 64-bytes or 128 for ARM's cache-line pairs,
> or you don't, then about that there's basically always a necessary
> UUID-vendor to prevent ABA (i.e., "race conditions"),
> one thing that guarantees another being the same ("unique"),
> and another guaranteeing another being different ("unique").

Well, memory_order is about ordering the visibility of operations on the 
arch. ABA has nothing to do with that. And what is that UUID-vendor that 
you mentioned? A monotonic counter works. For say a traditional 
lock-free stack, actually, ABA only needs to be incremented for a pop 
operation. For a flush op, it is not needed at all. So for a lock-free 
stack that has push/flush ABA is not a concern at all.
Re: Consequential RCU
#1054
Author: Chris M. Thomasson
Date: Sun, 29 Nov 2026 21:24
8 lines
1584 bytes
On 10/15/2026 4:26 PM, Joseph Seigh wrote:
[...]
> You could use RCU since the readers are wait-free.  With that many
> updates deferring that much memory, you might OOM.
> 

Actually, for heavy writer load, a proxy collector should perform better 
than raw RCU?
Re: Consequential RCU
#1058
Author: Ross Finlayson
Date: Mon, 30 Nov 2026 09:05
151 lines
8366 bytes
On 11/29/2026 01:08 PM, Chris M. Thomasson wrote:
> On 11/29/2026 9:36 AM, Ross Finlayson wrote:
>> On 11/29/2026 12:57 AM, Chris M. Thomasson wrote:
>>> On 10/15/2026 4:26 PM, Joseph Seigh wrote:
>>>> On 10/15/26 2:49 PM, Chris M. Thomasson wrote:
>>>>> On 10/13/2026 10:01 AM, Joseph Seigh wrote:
>>>>>> On 10/11/26 11:11 AM, Joseph Seigh wrote:
>>>>
>>>>
>>>>>> This is what the code I did a quick and dirty test with looked like
>>>>>>
>>>>>> using csequence_t = uint64_t;
>>>>>>
>>>>>> inline bool cseq_retry(csequence_t mark, std::atomic<csequence_t> &
>>>>>> sequence)
>>>>>> {
>>>>>>      std::atomic_thread_fence(std::memory_order_acquire);
>>>>>>      return mark != sequence.load(std::memory_order_acquire);
>>>>>> }
>>>>>>
>>>>>> csequence_t mark;
>>>>>>
>>>>>> retry:
>>>>>> do {
>>>>>>
>>>>>>      mark = cseq_count.load(std::memory_order_acquire);
>>>>>>      node_t * item = list.load(std::memory_order_acquire);
>>>>>>
>>>>>>      for (int ndx2 = 0; ndx2 < depth; ndx2++) {
>>>>>>          item = item->next.load(std::memory_order_acquire);
>>>>>>          if (cseq_retry(mark, cseq_count)) [[unlikely]]
>>>>>>              goto retry;
>>>>>>      }
>>>>>>
>>>>>> } while (cseq_retry(mark, cseq_count));
>>>>>
>>>>> Oh shit. This looks like it can be _potential_ "livelock" nation
>>>>> under some sustained periods of "heavy enough" load? Can we iterate
>>>>> the whole list before many (n) retrys have occurred? Or how many
>>>>> retrys on average does it take to iterate a decent sized list from
>>>>> head to tail? Writers churning along in the background...
>>>>>
>>>>
>>>> The list was used to give an idea how much overhead there would be.
>>>> I wouldn't use this for O(n) stuff where n is very large.
>>>>
>>>> In that this is similar to SEQLOCK, its docs mention the livelock
>>>> issue.
>>>> The term for these kind of algorithms is obstruction-free (Herlihy).
>>>
>>> Fwiw, speaking of SEQLOCK I think Dmitry had a nifty distributed one.
>>> Let me try to find it...
>>>
>>> https://sites.google.com/site/1024cores/home/lock-free-algorithms/
>>> reader-writer-problem/improved-lock-free-seqlock
>>>
>>>
>>>>
>>>> You could avoid this with a conventional rwlock. Probably slow you
>>>> down by orders of magnitude.
>>>>
>>>> You could use RCU since the readers are wait-free.  With that many
>>>> updates deferring that much memory, you might OOM.
>>>>
>>>
>>> Yeah. I remember some old stress tests that would make malloc fail. Man
>>> that was a long time ago.
>>
>> Didn't "memory_order" get deprecated.
>
> When did that occur? Yikes!
>
> I highly doubt that c++ got rid of memory_order.
>
> Afaict, memory_order_consume got folded into memory_order_acquire. Sigh.
>
>
>> You either have opportunistic-locking about cmp-exchange |
>> load-linked+store-conditional with a datum of 64-bits about AMD
>> and aligned and padded to 64-bytes or 128 for ARM's cache-line pairs,
>> or you don't, then about that there's basically always a necessary
>> UUID-vendor to prevent ABA (i.e., "race conditions"),
>> one thing that guarantees another being the same ("unique"),
>> and another guaranteeing another being different ("unique").
>
> Well, memory_order is about ordering the visibility of operations on the
> arch. ABA has nothing to do with that. And what is that UUID-vendor that
> you mentioned? A monotonic counter works. For say a traditional
> lock-free stack, actually, ABA only needs to be incremented for a pop
> operation. For a flush op, it is not needed at all. So for a lock-free
> stack that has push/flush ABA is not a concern at all.
>


I think "memory_order considered deprecated" is because what would
support that, or "mfence", is hardware and the model of invention has
that the only atomic memory hardware primitive is compare-and-swap,
which is load-linked/store-conditional on ARM though ARM is also
adding or added compare-and-swap, LL/SC because the value to be checked
should usually be checked immediately under contention to reduce the
window of ABA (i.e., TA checks A, TB checksA/writes B, TC checks
B/writes A, TA writes A, -> TA duplicated TC, race-condition TA
duplicated TC). Then, "counters" either may collide or be atomic, about
then that for "no-drops/no-dupes" that to get an atomic now requires two
of them. If the instruction-set-architecture had an instruction that
guaranteeed a system-wide counter, or basically the core ID, I suppose
the core ID would suffice for the UUID part, which though would be
volatile in the abstract, if threads ever migrated.

The UUID-vendor is the usual idea that in a distributed-system there's
a bottleneck to critical-transactionality that unique messages, for
no-drops/no-dupes, need each a unique ID, to be otherwise
"horizontally-independent" thus "horizontally-scale-able", then for
example about "forward-safe state-machines", since that in the case of
other components not being "drop/dupe-safe", like message queues of the
usual distributed variety that usually guarantee "no drops" (for
submissions that make it successfully to the queue) yet don't guarantee
"no dupes", about idempotency and so on that then the state of the
machine of the "model of asynchronous, distributed operation" is
well-defined. This is that a "forward-safe state-machine" is a usual
key sort of fundamental concept itself, that besides tagging an atomic
with the actor-ID, and workflow-ID, then that the states are only valid
A -> B -> C, and that whatever makes A -> B and B -> C are "idempotent",
here meaning side-effect free and returning same results for same
inputs. I.e. that there's an ID table (critically transactional to vend
the UUID) and a data table (not critically transactional throughout the
life of the workflow, updating the row idempotently).

The "no-drops" is a usual idea for vending _serial_ IDs, for detecting
gaps, then "no-dupes" is a usual common error-mode in
distributed-systems that rely on message-queues and so on.


So, "horizontally-scaleable self-healing distributed workflow-item
processing-systems with no-drops/no-dupes" involve this kind of thing,
for example "models of asynchronous operation that aren't idempotent
and thus need assurance of no-drops/no-dupes".



I haven't seen the worst code in the world when it comes to
"message-queues and the message-bus", yet, usually it's
not so great, and there's either a UUID that's also serial,
or there are dupes (duplicates).

"Matching & Reconciliation" is a usual sort of idea,
which though can be reduced problems with "no ABA dupes".



Re: Consequential RCU
#1061
Author: David Brown
Date: Mon, 30 Nov 2026 20:18
108 lines
5930 bytes
On 29/11/2026 22:08, Chris M. Thomasson wrote:
> On 11/29/2026 9:36 AM, Ross Finlayson wrote:
>> On 11/29/2026 12:57 AM, Chris M. Thomasson wrote:
>>> On 10/15/2026 4:26 PM, Joseph Seigh wrote:
>>>> On 10/15/26 2:49 PM, Chris M. Thomasson wrote:
>>>>> On 10/13/2026 10:01 AM, Joseph Seigh wrote:
>>>>>> On 10/11/26 11:11 AM, Joseph Seigh wrote:
>>>>
>>>>
>>>>>> This is what the code I did a quick and dirty test with looked like
>>>>>>
>>>>>> using csequence_t = uint64_t;
>>>>>>
>>>>>> inline bool cseq_retry(csequence_t mark, std::atomic<csequence_t> &
>>>>>> sequence)
>>>>>> {
>>>>>>      std::atomic_thread_fence(std::memory_order_acquire);
>>>>>>      return mark != sequence.load(std::memory_order_acquire);
>>>>>> }
>>>>>>
>>>>>> csequence_t mark;
>>>>>>
>>>>>> retry:
>>>>>> do {
>>>>>>
>>>>>>      mark = cseq_count.load(std::memory_order_acquire);
>>>>>>      node_t * item = list.load(std::memory_order_acquire);
>>>>>>
>>>>>>      for (int ndx2 = 0; ndx2 < depth; ndx2++) {
>>>>>>          item = item->next.load(std::memory_order_acquire);
>>>>>>          if (cseq_retry(mark, cseq_count)) [[unlikely]]
>>>>>>              goto retry;
>>>>>>      }
>>>>>>
>>>>>> } while (cseq_retry(mark, cseq_count));
>>>>>
>>>>> Oh shit. This looks like it can be _potential_ "livelock" nation
>>>>> under some sustained periods of "heavy enough" load? Can we iterate
>>>>> the whole list before many (n) retrys have occurred? Or how many
>>>>> retrys on average does it take to iterate a decent sized list from
>>>>> head to tail? Writers churning along in the background...
>>>>>
>>>>
>>>> The list was used to give an idea how much overhead there would be.
>>>> I wouldn't use this for O(n) stuff where n is very large.
>>>>
>>>> In that this is similar to SEQLOCK, its docs mention the livelock 
>>>> issue.
>>>> The term for these kind of algorithms is obstruction-free (Herlihy).
>>>
>>> Fwiw, speaking of SEQLOCK I think Dmitry had a nifty distributed one.
>>> Let me try to find it...
>>>
>>> https://sites.google.com/site/1024cores/home/lock-free-algorithms/ 
>>> reader-writer-problem/improved-lock-free-seqlock
>>>
>>>
>>>>
>>>> You could avoid this with a conventional rwlock. Probably slow you
>>>> down by orders of magnitude.
>>>>
>>>> You could use RCU since the readers are wait-free.  With that many
>>>> updates deferring that much memory, you might OOM.
>>>>
>>>
>>> Yeah. I remember some old stress tests that would make malloc fail. Man
>>> that was a long time ago.
>>
>> Didn't "memory_order" get deprecated.
> 
> When did that occur? Yikes!
> 
> I highly doubt that c++ got rid of memory_order.
> 
> Afaict, memory_order_consume got folded into memory_order_acquire. Sigh.
> 
> 
>> You either have opportunistic-locking about cmp-exchange |
>> load-linked+store-conditional with a datum of 64-bits about AMD
>> and aligned and padded to 64-bytes or 128 for ARM's cache-line pairs,
>> or you don't, then about that there's basically always a necessary
>> UUID-vendor to prevent ABA (i.e., "race conditions"),
>> one thing that guarantees another being the same ("unique"),
>> and another guaranteeing another being different ("unique").
> 
> Well, memory_order is about ordering the visibility of operations on the 
> arch. ABA has nothing to do with that. And what is that UUID-vendor that 
> you mentioned? A monotonic counter works. For say a traditional lock- 
> free stack, actually, ABA only needs to be incremented for a pop 
> operation. For a flush op, it is not needed at all. So for a lock-free 
> stack that has push/flush ABA is not a concern at all.
> 

Chris, Ross' posts are just a random jumble of badly expressed ideas 
that are usually unconnected with the topic being discussed, and often 
completely unconnected with reality.  When he started posting here, I 
tried hard to understand him and help him see why many people see his 
posts as incomprehensible, and not worth trying to read.

So don't worry about the things he says.  A lot of it is wrong, and even 
when he has got something right, he is incapable of writing about it 
accurately.

No, "memory order" did not get "deprecated" (whatever that might mean in 
this context).  Yes, memory_order_consume is going away (because it is 
very rarely used or implemented appropriately, and just makes a 
difficult subject more difficult than it need be).
Re: Consequential RCU
#1062
Author: Ross Finlayson
Date: Mon, 30 Nov 2026 20:39
115 lines
6272 bytes
On 11/30/2026 12:18 PM, David Brown wrote:
> On 29/11/2026 22:08, Chris M. Thomasson wrote:
>> On 11/29/2026 9:36 AM, Ross Finlayson wrote:
>>> On 11/29/2026 12:57 AM, Chris M. Thomasson wrote:
>>>> On 10/15/2026 4:26 PM, Joseph Seigh wrote:
>>>>> On 10/15/26 2:49 PM, Chris M. Thomasson wrote:
>>>>>> On 10/13/2026 10:01 AM, Joseph Seigh wrote:
>>>>>>> On 10/11/26 11:11 AM, Joseph Seigh wrote:
>>>>>
>>>>>
>>>>>>> This is what the code I did a quick and dirty test with looked like
>>>>>>>
>>>>>>> using csequence_t = uint64_t;
>>>>>>>
>>>>>>> inline bool cseq_retry(csequence_t mark, std::atomic<csequence_t> &
>>>>>>> sequence)
>>>>>>> {
>>>>>>>      std::atomic_thread_fence(std::memory_order_acquire);
>>>>>>>      return mark != sequence.load(std::memory_order_acquire);
>>>>>>> }
>>>>>>>
>>>>>>> csequence_t mark;
>>>>>>>
>>>>>>> retry:
>>>>>>> do {
>>>>>>>
>>>>>>>      mark = cseq_count.load(std::memory_order_acquire);
>>>>>>>      node_t * item = list.load(std::memory_order_acquire);
>>>>>>>
>>>>>>>      for (int ndx2 = 0; ndx2 < depth; ndx2++) {
>>>>>>>          item = item->next.load(std::memory_order_acquire);
>>>>>>>          if (cseq_retry(mark, cseq_count)) [[unlikely]]
>>>>>>>              goto retry;
>>>>>>>      }
>>>>>>>
>>>>>>> } while (cseq_retry(mark, cseq_count));
>>>>>>
>>>>>> Oh shit. This looks like it can be _potential_ "livelock" nation
>>>>>> under some sustained periods of "heavy enough" load? Can we iterate
>>>>>> the whole list before many (n) retrys have occurred? Or how many
>>>>>> retrys on average does it take to iterate a decent sized list from
>>>>>> head to tail? Writers churning along in the background...
>>>>>>
>>>>>
>>>>> The list was used to give an idea how much overhead there would be.
>>>>> I wouldn't use this for O(n) stuff where n is very large.
>>>>>
>>>>> In that this is similar to SEQLOCK, its docs mention the livelock
>>>>> issue.
>>>>> The term for these kind of algorithms is obstruction-free (Herlihy).
>>>>
>>>> Fwiw, speaking of SEQLOCK I think Dmitry had a nifty distributed one.
>>>> Let me try to find it...
>>>>
>>>> https://sites.google.com/site/1024cores/home/lock-free-algorithms/
>>>> reader-writer-problem/improved-lock-free-seqlock
>>>>
>>>>
>>>>>
>>>>> You could avoid this with a conventional rwlock. Probably slow you
>>>>> down by orders of magnitude.
>>>>>
>>>>> You could use RCU since the readers are wait-free.  With that many
>>>>> updates deferring that much memory, you might OOM.
>>>>>
>>>>
>>>> Yeah. I remember some old stress tests that would make malloc fail. Man
>>>> that was a long time ago.
>>>
>>> Didn't "memory_order" get deprecated.
>>
>> When did that occur? Yikes!
>>
>> I highly doubt that c++ got rid of memory_order.
>>
>> Afaict, memory_order_consume got folded into memory_order_acquire. Sigh.
>>
>>
>>> You either have opportunistic-locking about cmp-exchange |
>>> load-linked+store-conditional with a datum of 64-bits about AMD
>>> and aligned and padded to 64-bytes or 128 for ARM's cache-line pairs,
>>> or you don't, then about that there's basically always a necessary
>>> UUID-vendor to prevent ABA (i.e., "race conditions"),
>>> one thing that guarantees another being the same ("unique"),
>>> and another guaranteeing another being different ("unique").
>>
>> Well, memory_order is about ordering the visibility of operations on
>> the arch. ABA has nothing to do with that. And what is that
>> UUID-vendor that you mentioned? A monotonic counter works. For say a
>> traditional lock- free stack, actually, ABA only needs to be
>> incremented for a pop operation. For a flush op, it is not needed at
>> all. So for a lock-free stack that has push/flush ABA is not a concern
>> at all.
>>
>
> Chris, Ross' posts are just a random jumble of badly expressed ideas
> that are usually unconnected with the topic being discussed, and often
> completely unconnected with reality.  When he started posting here, I
> tried hard to understand him and help him see why many people see his
> posts as incomprehensible, and not worth trying to read.
>
> So don't worry about the things he says.  A lot of it is wrong, and even
> when he has got something right, he is incapable of writing about it
> accurately.
>
> No, "memory order" did not get "deprecated" (whatever that might mean in
> this context).  Yes, memory_order_consume is going away (because it is
> very rarely used or implemented appropriately, and just makes a
> difficult subject more difficult than it need be).
>


So, Chris, tell me I'm wrong.

Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads