svc_exit_thread(9)
π 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β thesvc_rqstwhich 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:
sunrpc_get_pool_mode(9)svc_serv_nrpools(9)svc_pool_for_cpu(9)svc_create(9)svc_create_pooled(9)svc_pool_wake_idle_thread(9)svc_new_thread(9)svc_set_pool_threads(9)svc_set_num_threads(9)svc_serv_maxthreads(9)svc_rqst_replace_page(9)svc_rqst_release_pages(9)svc_register(9)svc_stat_alloc_counts(9)svc_stat_free_counts(9)svc_process(9)svc_process_bc(9)svc_max_payload(9)svc_proc_name(9)svc_encode_result_payload(9)svc_fill_symlink_pathname(9)
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
- 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