sys_membarrier(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… sys_membarrier β€” NAME πŸ’…

okay so bestie, welcome to sys_membarrier(9) from the Kernel API Manual, section 9 πŸŽ€ β€” the syscall that literally issues memory barriers on a set of threads. yes, that one. sit down, hydrate, let's go ✨


✨ SYNOPSIS ✨

long sys_membarrier (int cmd , unsigned int flags , int cpu_id );

three args, one long return, zero chill. slay 🫢


πŸŽ€ ARGUMENTS πŸŽ€

  • cmd β€” takes command values defined in enum membarrier_cmd. that's the whole vibe, it's an enum, it picks what you're doing πŸ‘‘
  • flags β€” currently needs to be 0 for all commands other than MEMBARRIER_CMD_PRIVATE_EXPEDITED_RSEQ. in that one specific case it can be MEMBARRIER_CMD_FLAG_CPU, which means "hey, cpu_id contains the CPU on which to interrupt (= restart) the RSEQ critical section" πŸ‘€
  • cpu_id β€” if flags == MEMBARRIER_CMD_FLAG_CPU, this indicates the cpu on which the RSEQ CS should be interrupted (and cmd must be MEMBARRIER_CMD_PRIVATE_EXPEDITED_RSEQ). no flag, no cpu-picking, that's the rule πŸ’…

πŸ¦‹ DESCRIPTION πŸ¦‹

first things first, the error lore 😭

  • if this system call is not implemented, -ENOSYS is returned.
  • if the command specified does not exist, isn't available on the running kernel, or if the command argument is invalid, this system call returns -EINVAL.
  • for a given command, with the flags argument set to 0, if this system call returns -ENOSYS or -EINVAL, it is guaranteed to always return the same value until reboot. like, it's locked in fr fr πŸ”’
  • in addition, it can return -ENOMEM if there is not enough memory available to perform the system call. memory said no πŸ’€

and now the actual promise of the thing, which is honestly kind of iconic:

all memory accesses performed in program order from each targeted thread is guaranteed to be ordered with respect to sys_membarrier. 🧚

if we use the semantic "barrier" to represent a compiler barrier forcing memory accesses to be performed in program order across the barrier, and smp_mb to represent explicit memory barriers forcing full memory ordering across the barrier, we have the following ordering table for each pair of barrier, sys_membarrier and smp_mb:

the pair ordering is detailed as (O: ordered, X: not ordered):

       barrier   smp_mb sys_membarrier barrier          X           X
       O smp_mb           X           O            O sys_membarrier   O
       O            O
ngl bestie, this table arrived looking a lil scrambled from the source β€” I'm handing it to you character for character exactly as it appears, no fixing, no guessing πŸ’… the meaning you can trust is the O = ordered / X = not ordered key above πŸ‘‘

🌸 SEE ALSO 🌸

  • Kernel file ./kernel/sched/membarrier.c β€” go read the source, it's giving main character energy πŸ“–βœ¨

and that's the page, bestie πŸŽ€ source is ./kernel/sched, dated October 2026, and it signs off as sys_membarrier(9) β€” periodt πŸ’–πŸ¦‹πŸŒˆ

πŸ“¦ where this page comes from