file_ref_put_close(9)
π file_ref_put_close β the "last one out, hit the lights" of file refs π
So this little cutie lives in the kernel API manual, section 9, and it's called file_ref_put_close. Its whole personality? Drop a reference, but do it expecting that reference was the last one and the count is gonna slide all the way down to FILE_REF_NOREF. β¨
πΈ SYNOPSIS πΈ
bool file_ref_put_close (file_ref_t *ref );
π¦ ARGUMENTS π¦
refβ Pointer to the reference count. That's it, that's the whole argument list, bestie π
π₯ DESCRIPTION π₯
Okay so semantically? It's literally equivalent to calling file_ref_put. Same vibe, same meaning, no cap. But it makes a trade-off: it gives up some performance when other CPUs are also out here modifying the refcount π in exchange for higher performance when this particular call happens to be the last reference π.
Here's the tea on why that matters: for the last reference, file_ref_put issues 2 atomics. One to drop the reference, and another to transition it to FILE_REF_DEAD. Two whole atomics, the way that's just so much work π. This routine does all of it in one step, which is iconic β but to pull that off it has to pre-read the variable, and that pre-read decreases scalability π.
Use withcloseet al, but stick tofile_ref_putby default. Like, this one is the special-occasion fit, not the everyday outfit π
β SEE ALSO β
Kernel file ./include/linux/file_ref.h:
okay that's the whole page, go forth and manage your references responsibly π«Ά
sign-off szn: this one's from ./include/linux, dated October 2026, and it's the file_ref_put_close(9) page β mwah, catch you in the next manpage πβ¨
π¦ 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