__sink(9)
β¨ __sink(9) β¨
okay bestie, welcome to the Kernel API Manual entry for __sink β and no, it does not mean what you think it means, it's not about your dishes, it's about hiding stuff from the compiler π
π NAME π
__sink β hide @expr's value from the compiler and the BPF verifier π«Ά
π¦ SYNOPSIS π¦
__sink (expr );
π ARGUMENTS π
exprβ the expression whose value should be opacified π (yes, "opacified", that's the actual word, we love a vocabulary moment)
πΈ DESCRIPTION πΈ
So here's the tea: this thing is a no-op at runtime. literally does nothing when the program actually runs. but the empty inline assembly with a read-write constraint ("+g") is doing main character energy work at compile/verify time, and it has exactly two effects:
- Compiler: it treats
expras both read and written, which prevents dead-code elimination and keepsexpr(plus any side effects that produced it) alive. so it can't get ghosted π©· - BPF verifier: it forgets the precise value/range of
exprβ it "makes it imprecise". The verifier normally tracks exact ranges for every register and stack slot. Which is useful, sure, but precision means each distinct value creates a separate verifier state. And inside loops? that's where it gets ugly β state explosion π every iteration carries different precise values, so states never merge and the verifier ends up exploring every single iteration individually. not slay.
π§ example β preventing loop state explosion
u32 nr_intersects = 0, nr_covered = 0;
__sink(nr_intersects);
__sink(nr_covered);
bpf_for(i, 0, nr_nodes) {
if (intersects(cpumask, node_mask[i]))
nr_intersects++;
if (covers(cpumask, node_mask[i]))
nr_covered++;
}
Without __sink, the verifier tracks every possible (nr_intersects, nr_covered) pair across iterations, and you get hit with "BPF program is too large" π With __sink, the values become unknown scalars, so all iterations collapse into one reusable state. iconic behaviour, honestly π
π example β keeping a reference alive
struct task_struct *t = bpf_task_acquire(task);
__sink(t);
Follows the convention from BPF selftests (bpf_misc.h) β¨
π SEE ALSO π
- Kernel file
./tools/sched_ext/include/scx/common.bpf.h RESIZABLE_ARRAY(9),MEMBER_VPTR(9),ARRAY_ELEM_PTR(9),time_delta(9),time_after(9),time_before(9),time_after_eq(9),time_before_eq(9),time_in_range(9),time_in_range_open(9)
π and that's the whole page, bestie π this lil' gem lives at ./tools/sched_ext/include/scx and it's dated October 2026 β go forth and sink responsibly, mwah π«Άπ
π¦ 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