RATECHECK(9)
π RATECHECK(9) π
okay so bestie, we're in the Kernel Developer's Manual, section 9 β that's the big-kid section, kernel internals, no cap. this one's called RATECHECK and it's literally just about β¨*vibes per second control*β¨ for events. sit down, grab a boba, we're doing rate limiting π§
πΈ NAME πΈ
ratecheck, ppsratecheck β event rate limiting π¦
like. it stops your events from being extra. that's the whole job. π
β¨ SYNOPSIS β¨
#include <sys/time.h>
int
ratecheck(struct timeval *lasttime, struct timeval *mininterval);
int
ppsratecheck(struct timeval *lasttime, int *curpps, int maxpps);
two functions, both return int, both take pointers, both are giving "gatekeeper but make it polite" π«Ά
π DESCRIPTION π
so ratecheck and ppsratecheck are the two functions that handle rate-limiting of arbitrary events. and when we say arbitrary, we mean arbitrary β whatever event you got going on, these two will tell you if it's allowed to happen rn or not. iconic behaviour honestly.
the difference between them is lowkey the whole plot:
ratecheckenforces a minimum interval between events. think "bestie you literally just texted me, wait a sec" β³ppsratecheckenforces a maximum number of events per second. think "okay you can text, but only this many times per second, we're not doing 400 messages again" π²
π ratecheck π
here's what it does, step by step, no skips:
- it compares the current time to the value pointed to by
lasttime. - if that difference is equal to or greater than
minintervalβ it returns a non-zero value AND updateslasttimeto the current time. (green flag behaviour: it actually updates the timestamp so you can't just spam it.) - otherwise β it returns zero. that's a no from her. π βοΈ
π ppsratecheck π
this one's got a lil more going on, she's the main character:
- first, it compares the current time to
lasttime. - if at least a full second has passed β the value pointed to by the
curppsargument gets reset to1, andlasttimeis updated to the current time. fresh second, fresh count, we move π - otherwise β
curppsgets incremented, andlasttimeis left untouched. don't touch her, she's fine where she is. - and in either case β listen, this part matters β
ppsratecheckreturns a non-zero value if and only if the updatedcurppsis less than or equal tomaxpps, ormaxppsis negative. yep, negativemaxppsmeans unlimited, it's giving "no rules just vibes" π
ngl the negative-maxpps thing is a cute lil escape hatch and it's easy to miss, so likeβ¦ noted. π«‘
π¦ SEE ALSO π¦
counter(9)β go read that one too, she's related, iykyk π«
β HISTORY β
the ratecheck and ppsratecheck functions first appeared in FreeBSD 5.1. so yeah, they've been slaying since way before you were born, respectfully π
and that's the whole page, bestie!! π this was the Debian build of the RATECHECK(9) man page, dated September 25, 2017 β so yeah, she's a 2017 girlie and she's still relevant. periodt. π β¨πΈ
π¦ where this page comes from
- debian bookworm: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- debian trixie: freebsd-manpages 12.2-2 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu jammy: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu noble: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu questing: freebsd-manpages 12.2-2
- ubuntu resolute: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu stonking: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- Copyright (c) 2017 Dag-Erling SmΓΈrgrav
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms