printk_ratelimit and net_ratelimit conflict and tunable behavior
Subsystems (2)
From: Steve Hawkes <[email protected]>
The printk_ratelimit() and net_ratelimit() functions each have their own tunable parameters to control their respective rate limiting feature, but they share common state variables, preventing independent tuning of the parameters from working correctly. Also, changes to rate limiting tunable parameters do not always take effect properly since state is not recomputed when changes occur. For example, if ratelimit_burst is increased while rate limiting is occurring, the change won't take full effect until at least enough time between messages occurs so that the toks value reaches ratelimit_burst * ratelimit_jiffies. This can result in messages being suppressed when they should be allowed.
Implement independent state for printk_ratelimit() and net_ratelimit(), and update state when tunables are changed.
---
include/linux/kernel.h +12 -1
@@ -196,8 +196,19 @@ static inline int log_buf_copy(char *desunsigned long int_sqrt (unsigned long ); +struct printk_ratelimit_state +{ +unsigned long toks; +unsigned long last_jiffies; +int missed; +int limit_jiffies; +int limit_burst; +char const *facility; +}; +extern int printk_ratelimit (void ); -extern int __printk_ratelimit (int ratelimit_jiffies,int ratelimit_burst); +extern int __printk_ratelimit (int ratelimit_jiffies,int ratelimit_burst, +struct printk_ratelimit_state *state);extern bool printk_timed_ratelimit (unsigned long *caller_jiffies,unsigned int interval_msec);
kernel/printk.c +35 -20
78 lines not on this page · raw message
net/core/utils.c +10 -1
@@ -41,7 +41,16 @@ EXPORT_SYMBOL(net_msg_warn);*/ int net_ratelimit (void ) { -return __printk_ratelimit (net_msg_cost, net_msg_burst); +static struct printk_ratelimit_state limit_state = { + .toks =10 *5 *HZ , + .last_jiffies =0 , + .missed =0 , + .limit_jiffies =5 *HZ , + .limit_burst =10 , + .facility ="net" + }; + +return __printk_ratelimit (net_msg_cost, net_msg_burst, &limit_state); }EXPORT_SYMBOL (net_ratelimit);
Quoted 13 lines · On Mon, 25 Feb 2008 14:36:40 -0600 Steven Hawkes <[email protected]> wrote:
From: Steve Hawkes <[email protected]>
The
printk_ratelimit()andnet_ratelimit()functions each have their own tunable parameters to control their respective rate limiting feature, but they share common state variables, preventing independent tuning of the parameters from working correctly. Also, changes to rate limiting tunable parameters do not always take effect properly since state is not recomputed when changes occur. For example, ifratelimit_burstis increased while rate limiting is occurring, the change won't take full effect until at least enough time between messages occurs so that the toks value reachesratelimit_burst*ratelimit_jiffies. This can result in messages being suppressed when they should be allowed.
Quoted 3 lines
Implement independent state for
printk_ratelimit()andnet_ratelimit(), and update state when tunables are changed.
This patch causes a large and nasty reject.
include/linux/kernel.h
Quoted 3 lines
---
include/linux/kernel.h +0
-0
Probably because you patched 2.6.24. We're developing 2.6.25 now, and the difference between the two is very large inded. Please raise patches against Linus's latest tree?
There are other patches pending against printk.c (in -mm and in git-sched) but afacit they won't collide.
include/linux/kernel.h static inline int log_buf_copy(char *des · line 200
Quoted 6 lines
include/linux/kernel.h +2
-0@@ -196,8 +196,19 @@ static inline int log_buf_copy(char *desunsigned long int_sqrt (unsigned long ); +struct printk_ratelimit_state +{
Please do
struct printk_ratelimit_state {
include/linux/kernel.h static inline int log_buf_copy(char *des · line 207
Quoted 7 lines
include/linux/kernel.h +7
-0+unsigned long toks; +unsigned long last_jiffies; +int missed; +int limit_jiffies; +int limit_burst; +char const *facility; +};
I find that the best-value comments one can add to kernel code are to the members of structures. If the reader understands what all the fields do, the code becomes simple to follow.
Quoted 7 lines
net/core/utils.c +0
-1@@ -41,7 +41,16 @@ EXPORT_SYMBOL(net_msg_warn);*/ int net_ratelimit (void ) { -return __printk_ratelimit (net_msg_cost, net_msg_burst);
net/core/utils.c EXPORT_SYMBOL(net_msg_warn); · line 53
Quoted 10 lines
net/core/utils.c +10
-0+static struct printk_ratelimit_state limit_state = { + .toks =10 *5 *HZ , + .last_jiffies =0 , + .missed =0 , + .limit_jiffies =5 *HZ , + .limit_burst =10 , + .facility ="net" + }; + +return __printk_ratelimit (net_msg_cost, net_msg_burst, &limit_state);
I don't get it. There's one instance of limit_state, kernel-wide, and __printk_ratelimit() modifies it. What prevents one CPU's activities from interfering with a second CPU's activities?
Quoted 3 lines · Andrew Morton
This patch causes a large and nasty reject.
Probably because you patched 2.6.24. We're developing 2.6.25 now, and the difference between the two is very large inded. Please raise
patches
Quoted 1 line
against Linus's latest tree?
Will do. I'm learning the process. I assume Linus's latest tree is the one
listed as the latest prepatch for the stable Linux kernel tree.
Quoted 10 lines · Andrew Morton
include/linux/kernel.h static inline int log_buf_copy(char *des · line 207
Quoted 8 lines
struct
printk_ratelimit_state{include/linux/kernel.h +7
-0+unsigned long toks; +unsigned long last_jiffies; +int missed; +int limit_jiffies; +int limit_burst; +char const *facility; +};I find that the best-value comments one can add to kernel code are to
the
Quoted 1 line
members of structures. If the reader understands what all the fields
do, the
Quoted 1 line
code becomes simple to follow.
Agreed. Although the current kernel source doesn't document these attributes, there's no reason I couldn't add documentation for them.
Quoted 5 lines · Andrew Morton
Quoted 5 lines
int
net_ratelimit(void)
{net/core/utils.c +2
-1-return __printk_ratelimit (net_msg_cost, net_msg_burst); +static struct printk_ratelimit_state limit_state = { + .toks =10 *5 *HZ ,
Quoted 8 lines
net/core/utils.c EXPORT_SYMBOL(net_msg_warn);
Quoted 8 lines
net/core/utils.c +8
-0+ .last_jiffies = 0, + .missed = 0, + .limit_jiffies = 5 * HZ, + .limit_burst = 10, + .facility = "net" + }; + + return __printk_ratelimit(net_msg_cost, net_msg_burst,
&limit_state);
Quoted 3 lines
I don't get it. There's one instance of
limit_state, kernel-wide, and__printk_ratelimit()modifies it. What prevents one CPU's activities
from
Quoted 1 line
interfering with a second CPU's activities?
The state is protected by the spinlock in __printk_ratelimit, like it is in
the current kernel. Am I missing something?
Quoted 11 lines · On Thu, 28 Feb 2008 10:19:02 -0600 "Hawkes Steve-FSH016"…
Quoted 3 lines · Andrew Morton
This patch causes a large and nasty reject.
Probably because you patched 2.6.24. We're developing 2.6.25 now, and the difference between the two is very large inded. Please raisepatches
Quoted 1 line
against Linus's latest tree?
Will do. I'm learning the process. I assume Linus's latest tree is the one
listed as the latest prepatch for the stable Linux kernel tree.
No, the stable tree is 2.6.24. You'll want ftp://ftp.kernel.org/pub/linux/kernel/v2.6/snapshots/
Quoted 15 lines
Quoted 5 lines
Quoted 5 lines
int
net_ratelimit(void)
{net/core/utils.c +2
-1-return __printk_ratelimit (net_msg_cost, net_msg_burst); +static struct printk_ratelimit_state limit_state = { + .toks =10 *5 *HZ ,Quoted 8 lines
net/core/utils.c EXPORT_SYMBOL(net_msg_warn);
Quoted 8 lines
net/core/utils.c +8
-0+ .last_jiffies = 0, + .missed = 0, + .limit_jiffies = 5 * HZ, + .limit_burst = 10, + .facility = "net" + }; + + return __printk_ratelimit(net_msg_cost, net_msg_burst,
&limit_state);Quoted 1 line
Quoted 8 lines
Quoted 2 lines
I don't get it. There's one instance of
limit_state, kernel-wide, and__printk_ratelimit()modifies it. What prevents one CPU's activitiesfrom
Quoted 1 line
interfering with a second CPU's activities?
The state is protected by the spinlock in
__printk_ratelimit, like it is in
the current kernel. Am I missing something?
ah, OK.
I've occasionally wondered if ratelimiting should be per-callsite rather than kernel-wide, but I'm not aware of the present setup causing anyone any problems.