Skip to content

Commit d92cff8

Browse files
zx2c4davem330
authored andcommitted
net_dbg_ratelimited: turn into no-op when !DEBUG
The pr_debug family of functions turns into a no-op when -DDEBUG is not specified, opting instead to call "no_printk", which gets compiled to a no-op (but retains gcc's nice warnings about printf-style arguments). The problem with net_dbg_ratelimited is that it is defined to be a variant of net_ratelimited_function, which expands to essentially: if (net_ratelimit()) pr_debug(fmt, ...); When DEBUG is not defined, then this becomes, if (net_ratelimit()) ; This seems benign, except it isn't. Firstly, there's the obvious overhead of calling net_ratelimit needlessly, which does quite some book keeping for the rate limiting. Given that the pr_debug and net_dbg_ratelimited family of functions are sprinkled liberally through performance critical code, with developers assuming they'll be compiled out to a no-op most of the time, we certainly do not want this needless book keeping. Secondly, and most visibly, even though no debug message is printed when DEBUG is not defined, if there is a flood of invocations, dmesg winds up peppered with messages such as "net_ratelimit: 320 callbacks suppressed". This is because our aforementioned net_ratelimit() function actually prints this text in some circumstances. It's especially odd to see this when there isn't any other accompanying debug message. So, in sum, it doesn't make sense to have this function's current behavior, and instead it should match what every other debug family of functions in the kernel does with !DEBUG -- nothing. This patch replaces calls to net_dbg_ratelimited when !DEBUG with no_printk, keeping with the idiom of all the other debug print helpers. Also, though not strictly neccessary, it guards the call with an if (0) so that all evaluation of any arguments are sure to be compiled out. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 3dcb615 commit d92cff8

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

include/linux/net.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,16 @@ do { \
239239
net_ratelimited_function(pr_warn, fmt, ##__VA_ARGS__)
240240
#define net_info_ratelimited(fmt, ...) \
241241
net_ratelimited_function(pr_info, fmt, ##__VA_ARGS__)
242+
#if defined(DEBUG)
242243
#define net_dbg_ratelimited(fmt, ...) \
243244
net_ratelimited_function(pr_debug, fmt, ##__VA_ARGS__)
245+
#else
246+
#define net_dbg_ratelimited(fmt, ...) \
247+
do { \
248+
if (0) \
249+
no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__); \
250+
} while (0)
251+
#endif
244252

245253
bool __net_get_random_once(void *buf, int nbytes, bool *done,
246254
struct static_key *done_key);

0 commit comments

Comments
 (0)