sys_membarrier(9)
π 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 inenum membarrier_cmd. that's the whole vibe, it's an enum, it picks what you're doing πflagsβ currently needs to be0for all commands other thanMEMBARRIER_CMD_PRIVATE_EXPEDITED_RSEQ. in that one specific case it can beMEMBARRIER_CMD_FLAG_CPU, which means "hey,cpu_idcontains the CPU on which to interrupt (= restart) the RSEQ critical section" πcpu_idβ ifflags == MEMBARRIER_CMD_FLAG_CPU, this indicates the cpu on which the RSEQ CS should be interrupted (andcmdmust beMEMBARRIER_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,
-ENOSYSis 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
flagsargument set to0, if this system call returns-ENOSYSor-EINVAL, it is guaranteed to always return the same value until reboot. like, it's locked in fr fr π - in addition, it can return
-ENOMEMif 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
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms