SCHED_4BSD(9)

πŸ“¦ version 11.0, in nixpkgs unstable

πŸ’… SCHED_4BSD β€” the 4.4BSD thread scheduler ✨

okay so bestie, welcome to the sched_4bsd page from the Kernel Developer's Manual πŸŽ€ β€” yes it's a section 9 manpage, yes it's about the kernel's vibes-based (no, actually very much algorithm-based, ngl) thread scheduler. buckle up πŸ¦‹


✨ NAME ✨

sched_4bsd β€” the classic 4.4BSD thread scheduler, the OG main character of kernel scheduling πŸ‘‘


🌸 SYNOPSIS 🌸

#include <sys/sched.h>

void
resetpriority(lwp_t *l);

void
sched_tick(struct cpu_info *ci);

void
sched_schedclock(lwp_t *l);

void
sched_pstats_hook(struct proc *p, int minslp);

void
sched_setrunnable(lwp_t *l);

void
updatepri(lwp_t *l);

like, that's the whole cast of characters πŸ’–


πŸ’– DESCRIPTION πŸ’–

So the traditional 4.4BSD scheduler uses a β€œmultilevel feedback queues” algorithm β€” and honestly its whole personality is: it favours interactive, short-running threads over CPU-bound ones. lowkey biased but in a cute way 🫢. the chatty little threads get priority, the CPU hogs get pushed back, iykyk.

  • resetpriority() β€” recomputes the priority of a thread that's running in user mode. and if the resulting priority is higher than that of the current thread? πŸ‘€ a reschedule gets arranged. politely. but firmly.
  • sched_tick() β€” gets called from hardclock(9) every 100ms to force a switch between equal priority threads. it's giving referee energy πŸ’€
  • sched_schedclock() β€” this is where the current thread's priority gets adjusted. heads up: the priority of a thread gets worse as it accumulates CPU time. yes literally, the more CPU you eat the more the scheduler side-eyes you πŸ™ˆ
  • sched_pstats_hook() β€” gets called from sched_pstats() every Hz ticks, all so it can recompute the priorities of all the threads. group project energy, everyone gets recalculated ✨
  • sched_setrunnable() β€” checks if an LWP has slept for more than one second πŸ›Œ. if it has, its priority gets updated by updatepri(). nap girlies stay winning 🧚

⭐ EXAMPLES ⭐

wanna know which scheduler is currently in use? bestie just ask it:

$ sysctl kern.sched.name
kern.sched.name = 4.4BSD

slay, confirmed 4.4BSD πŸ”₯


πŸŽ€ CODE REFERENCES πŸŽ€

The 4.4BSD scheduler subsystem is implemented within the file sys/kern/sched_4bsd.c β€” that's where the magic lives, go read it πŸ’œ


🌈 SEE ALSO 🌈

and if you're feeling academic (respect, honestly πŸ‘‘): Marshall Kirk McKusick, Keith Bostic, Michael J. Karels, and John S. Quarterman, The Design and Implementation of the 4.4BSD Operating System, Addison Wesley, 1996.

πŸ’€ fr fr if you're touching this, remember: priority isn't a personality, it changes. don't hardcode assumptions about it, bestie.

okay that's the whole page, you ate that πŸ’… stay iconic, read your manpages, and remember β€” this little number shipped on Debian, dated April 9, 2019 πŸ—“οΈπŸŒΈ bye bestie, mwah πŸ«ΆπŸ’–

πŸ“¦ where this page comes from