lkml.org 
[lkml]   [2004]   [Jan]   [1]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: swapper: page allocation failure. order:3, mode:0x20
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"?

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-03-22 13:59    [from the cache]
©2003-2011 Jasper Spaans