Bug 996613 - printk_ratelimited function doesn't work always
printk_ratelimited function doesn't work always
Status: CLOSED NOTABUG
Product: Bugzilla
Classification: Community
Component: Bugzilla General (Show other bugs)
4.4
x86_64 Linux
unspecified Severity urgent (vote)
: ---
: ---
Assigned To: PnT DevOps Devs
tools-bugs
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2013-08-13 10:23 EDT by caiqiuming
Modified: 2013-08-21 00:25 EDT (History)
2 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2013-08-21 00:25:52 EDT
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description caiqiuming 2013-08-13 10:23:31 EDT
Description of problem:
The purpose of "ratelimit for printk" doesn't work always in rhel6.2 or above release.








Version-Release number of selected component (if applicable):
[root@r64-115 linux]# cat /etc/redhat-release 
Red Hat Enterprise Linux Server release 6.4 (Santiago)
[root@r64-115 linux]# uname -a
Linux r64-115 2.6.32-358.el6.x86_64 #1 SMP Tue Jan 29 11:47:41 EST 2013 x86_64 x86_64 x86_64 GNU/Linux

The problem existed in rhel6.2, rhel6.2... also.








How reproducible:
sure occur!





Steps to Reproduce:
1. don't need to change the following parameters, left them as default value.
/proc/sys/kernel/printk_ratelimit
/proc/sys/kernel/printk_ratelimit_burst

2.write an ordinary kernel module, using "printk_ratelimited" function to printk some messages in loop about 1000 or more times.
 
Actual results:
You can see it will print All the times your loop, the purpose of "ratelimit for printk" out of work. In my system it may lead to panic coz print too much in console.

Expected results:
The print items should be limited.



Additional info:
See the code file: linux-2.6.32-358.el6.x86_64/include/linux/kernel.h
in "Red Hat Enterprise Linux Server release 6.4" kernel source:
************************************************
 626 #define printk_ratelimited(fmt, ...)  ({                \
 627         static struct ratelimit_state _rs = {           \
 628                 .interval = DEFAULT_RATELIMIT_INTERVAL, \
 629                 .burst = DEFAULT_RATELIMIT_BURST,       \
 630         };                                              \
 631                                                         \
 632         if (!__ratelimit(&_rs))                         \
 633                 printk(fmt, ##__VA_ARGS__);             \
 634 })
************************************************

In line 632 the condition is negatived, which make the problem wrong.
Because the fact is printk will work when __ratelimit is true.
See the Suse kernel source correspondingly, which work perfect:
--------------------------------------------
#ifdef CONFIG_PRINTK
#define printk_ratelimited(fmt, ...)  ({                \
    static DEFINE_RATELIMIT_STATE(_rs,                \
                      DEFAULT_RATELIMIT_INTERVAL,    \
                      DEFAULT_RATELIMIT_BURST);        \
                                    \
    if (__ratelimit(&_rs))                        \
        printk(fmt, ##__VA_ARGS__);                \
})
-------------------------------------------------
Comment 1 Jason McDonald 2013-08-21 00:25:52 EDT
This is not a bug in the Red Hat Bugzilla product. Please file the bug under the correct product and component.

Note You need to log in before you can comment on or make changes to this bug.