Skip to content

Commit 9698cc6

Browse files
Jaewon31Kimgtpitch
authored andcommitted
ratelimit: fix bug in time interval by resetting right begin time
commit c2594bc upstream. rs->begin in ratelimit is set in two cases. 1) when rs->begin was not initialized 2) when rs->interval was passed For case Grarak#2, current ratelimit sets the begin to 0. This incurrs improper suppression. The begin value will be set in the next ratelimit call by 1). Then the time interval check will be always false, and rs->printed will not be initialized. Although enough time passed, ratelimit may return 0 if rs->printed is not less than rs->burst. To reset interval properly, begin should be jiffies rather than 0. For an example code below: static DEFINE_RATELIMIT_STATE(mylimit, 1, 1); for (i = 1; i <= 10; i++) { if (__ratelimit(&mylimit)) printk("ratelimit test count %d\n", i); msleep(3000); } test result in the current code shows suppression even there is 3 seconds sleep. [ 78.391148] ratelimit test count 1 [ 81.295988] ratelimit test count 2 [ 87.315981] ratelimit test count 4 [ 93.336267] ratelimit test count 6 [ 99.356031] ratelimit test count 8 [ 105.376367] ratelimit test count 10 Signed-off-by: Jaewon Kim <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]> Signed-off-by: Willy Tarreau <[email protected]>
1 parent 0088216 commit 9698cc6

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

lib/ratelimit.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ int ___ratelimit(struct ratelimit_state *rs, const char *func)
4949
if (rs->missed)
5050
printk(KERN_WARNING "%s: %d callbacks suppressed\n",
5151
func, rs->missed);
52-
rs->begin = 0;
52+
rs->begin = jiffies;
5353
rs->printed = 0;
5454
rs->missed = 0;
5555
}

0 commit comments

Comments
 (0)