From: Andrew Morton <akpm@osdl.org>
To: Anton Blanchard <anton@samba.org>
Cc: joneskoo@derbian.org, linux-kernel@vger.kernel.org
Subject: Re: swapper: page allocation failure. order:3, mode:0x20
Date: Thu, 1 Jan 2004 12:45:04 -0800 [thread overview]
Message-ID: <20040101124504.69c80a14.akpm@osdl.org> (raw)
In-Reply-To: <20040101130147.GM28023@krispykreme>
Anton Blanchard <anton@samba.org> wrote:
>
>
> > So sure, ratelimit it, make it KERN_INFO and maybe add a dump_stack()?
>
> Sounds good, I always end up adding a dump_stack there when debugging
> these problems anyway.
>
> > (printk_ratelimit() may be a suitable name)
>
> How does this look?
Good. I guess we need to make net_ratelimit() use this sometime.
> +/*
> + * printk rate limiting, lifted from the networking subsystem.
> + *
> + * This enforces a rate limit: not more than one kernel message
> + * every printk_ratelimit_jiffies to make a denial-of-service
> + * attack impossible.
> + */
> +int printk_ratelimit(void)
> +{
> + static spinlock_t ratelimit_lock = SPIN_LOCK_UNLOCKED;
> + static unsigned long toks = 10*5*HZ;
> + static unsigned long last_msg;
> + static int missed;
> + unsigned long flags;
> + unsigned long now = jiffies;
> +
> + spin_lock_irqsave(&ratelimit_lock, flags);
> + toks += now - last_msg;
> + last_msg = now;
> + if (toks > (printk_ratelimit_burst * printk_ratelimit_jiffies))
> + toks = printk_ratelimit_burst * printk_ratelimit_jiffies;
> + if (toks >= printk_ratelimit_jiffies) {
> + int lost = missed;
> + missed = 0;
> + toks -= printk_ratelimit_jiffies;
> + spin_unlock_irqrestore(&ratelimit_lock, flags);
> + if (lost)
> + printk(KERN_WARNING "printk: %d messages suppressed.\n", lost);
> + return 1;
> + }
> + missed++;
> + spin_unlock_irqrestore(&ratelimit_lock, flags);
> + return 0;
> +}
This seems a bit odd. It means that the further apart the message bursts
are, the longer they are allowed to be. Or something.
Wouldn't it be better to say "after each greater-than-five second window,
allow up to ten printk's as long as they happen in the next five
milliseconds"?
next prev parent reply other threads:[~2004-01-01 20:48 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-01-01 9:35 swapper: page allocation failure. order:3, mode:0x20 Joonas Kortesalmi
2004-01-01 10:15 ` Anton Blanchard
2004-01-01 10:25 ` Andrew Morton
2004-01-01 13:01 ` Anton Blanchard
2004-01-01 20:45 ` Andrew Morton [this message]
2004-01-01 22:43 ` Anton Blanchard
2004-01-01 22:08 ` Christophe Saout
2004-01-01 22:45 ` Anton Blanchard
2004-01-01 23:13 ` Christophe Saout
2004-01-01 10:27 ` Anton Blanchard
2004-01-01 10:42 ` Arjan van de Ven
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20040101124504.69c80a14.akpm@osdl.org \
--to=akpm@osdl.org \
--cc=anton@samba.org \
--cc=joneskoo@derbian.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox