svc_exit_thread(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… svc_exit_thread(9) β€” the Kernel API Manual page, bestie edition

okay so this is svc_exit_thread(9) from the Kernel API Manual and it's lowkey one of those tiny functions that's super important. it's about shutting down a sunrpc server thread the right way. no cap, do it wrong and it's giving chaos. let's go 🫢


✨ NAME ✨

svc_exit_thread β€” finalise the termination of a sunrpc server thread 🌸

πŸŽ€ SYNOPSIS πŸŽ€

void svc_exit_thread (struct svc_rqst *rqstp );

🌈 ARGUMENTS 🌈

  • rqstp β€” the svc_rqst which represents the thread. that's it, that's the whole argument πŸ’–

πŸ’« DESCRIPTION πŸ’«

okay so picture this: a thread was started with svc_new_thread, right? when it exits, it must call svc_exit_thread as its very last act. like, last thing, periodt. πŸ”₯

and here's the part where people mess up πŸ‘€ β€” this must be done with the service mutex held. normally it's held by a DIFFERENT thread, specifically the one that's calling svc_set_num_threads, and that thread will wait for SP_VICTIM_REMAINS to be cleared before dropping the mutex. iykyk.

but if the thread exits for any reason other than svc_thread_should_stop returning true β€” and that returning true is what indicates that svc_set_num_threads is waiting for it to exit β€” then it has to take the service mutex itself. and taking it itself can only be done safely using mutex_try_lock. 🫑

bestie, seriously: the mutex_try_lock part is not a suggestion. it's the only safe way to grab it in that case. πŸ’€

πŸ‘‘ SEE ALSO πŸ‘‘

Kernel file ./net/sunrpc/svc.c, plus all of these lovelies:


and that's the whole page bestie, go forth and exit your threads correctly πŸ¦‹βœ¨

sign-off time πŸŽ€ this one lives in ./net/sunrpc, and it's dated October 2026. mwah, iconic. πŸ’œ

πŸ“¦ where this page comes from