kref_put(9)
π
kref_put β the kref_put(9) glow-up π
okay bestie, gather round, because we're talking about the Kernel API Manual entry for kref_put and honestly? she's kind of a big deal. this is the function that says "yeah I'm done with this object, one less person is holding on" β and when the count hits zero, she lets the release function do its little cleanup dance. iconic behavior. β¨
πΈ NAME πΈ
kref_put β decrement refcount for object π
(that's it. that's the whole vibe. decrement the refcount, bestie.)
π¦ SYNOPSIS π¦
int kref_put (struct kref *kref , void (*release)(struct kref *kref) );
literally right there. two arguments, one int coming back at you. no cap. π«Ά
π ARGUMENTS π
krefβ Object. yeah, that's the thing you're holding a reference to. the object. the main character. πreleaseβ Pointer to the function that will clean up the object when the last reference to the object is released. so like, when everyone's finally gone home and the party's over, this is the function that turns off the lights and locks the door. π₯
π DESCRIPTION π
Decrement the refcount, and if 0, call release. simple as. the count goes down by one, and if it lands on zero, boom β release gets called to handle the cleanup. π
β οΈ okay so this is the important part, do NOT skip it: the caller may not passNULLorkfreeas the release function. that's a hard no. notNULL, notkfree. periodt. π
likeβ¦ just don't. the kernel is trusting you and you don't want to be the one who broke it, fr fr. π
β RETURN β
- Returns
1if this call removed the object. congrats, you did it, the object is gone, slay. π - Otherwise it returns
0. β¨
π big caveat time bestie: beware, if this function returns0, another caller may have removed the object by the time this function returns. so that0is not a promise, it's more of a vibe. the return value is only certain if you want to see if the object is definitely released β like, that's the one thing you can actually trust it for. π«Ά
π SEE ALSO π
Kernel file: ./include/linux/kref.h
and her friends, who are also in ./include/linux/kref.h and are all absolutely worth a read:
iykyk β go read them, they're all in the same little header file family and they all eat. π
π§ and that's the page!! this little beauty lives under ./include/linux, dated October 2026, and yes the kref_put(9) title card at the bottom is still serving exactly the same energy as the one at the top. consistent queen. πβ¨
π¦ 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