raw_write_seqcount_barrier(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… raw_write_seqcount_barrier β€” Kernel API Manual ✨

okay bestie, so this whole page is about raw_write_seqcount_barrier(9), from the Kernel API Manual, and it's genuinely one of those tiny functions that does a lot of heavy lifting. lowkey iconic. let's get into it 🫢


🌸 NAME 🌸

raw_write_seqcount_barrier β€” do a seqcount_t write barrier. that's it, that's the whole job, and she does it flawlessly πŸ’…


✨ SYNOPSIS ✨

raw_write_seqcount_barrier (s );

yep, one argument, no notes, main character energy πŸ‘‘


πŸŽ€ ARGUMENTS πŸŽ€

  • s β€” a pointer to a seqcount_t, or literally any of the seqcount_LOCKNAME_t variants. she's flexible like that πŸ’–

πŸ¦‹ DESCRIPTION πŸ¦‹

so here's the vibe: this one gives you an ordering guarantee instead of the usual consistency guarantee. different flavor, same friend group. and it's one wmb cheaper than the alternative, because it can collapse the two back-to-back wmbs into one. frugal queen, we stan 🌈

⚠️ okay important bit, don't skip this: the writes surrounding the barrier should be declared atomic (like, via WRITE_ONCE). why? two reasons, both real: a) so the writes actually become visible to other threads atomically β€” this dodges compiler optimizations doing sneaky little things behind your back πŸ™ˆ b) so you document which writes are meant to propagate to the reader's critical section. future you (and everyone else) will thank you, fr fr.

and this is necessary because neither the writes before nor the writes after the barrier are enclosed in a seq-writer critical section β€” the kind that would normally make sure readers know about ongoing writes. so like, nobody's got your back here except this barrier. no cap 😭

here's the example, copied exactly, do not touch:

     seqcount_t seq;
     bool X = true, Y = false;

     void read(void)
     {
             bool x, y;

             do {
                     int s = read_seqcount_begin(seq);

                     x = X; y = Y;

             } while (read_seqcount_retry(seq, s));

             BUG_ON(!x && !y);
     }

     void write(void)
     {
             WRITE_ONCE(Y, true);

             raw_write_seqcount_barrier(seq);

             WRITE_ONCE(X, false);
     }

like, see how both WRITE_ONCEs are outside any seq-writer critical section? that's the whole point bestie, that's the assignment πŸ’€βœ¨


πŸ‘‘ SEE ALSO πŸ‘‘

the kernel file that lives at ./include/linux/seqlock.h, plus this entire friend group β€” every single one, no skipping, we respect all of them equally 🫢:


and that's the whole page, bestie!! πŸ§šβ€β™€οΈ this lil masterpiece came out of ./include/linux, dated October 2026, and it's page raw_write_seqcount_barrier(9) of the Kernel API Manual. go forth and barrier responsibly, ily, bye πŸ’œπŸŽ€πŸ“

πŸ“¦ where this page comes from