Re: swapper: page allocation failure. order:3, mode:0x20

Andrew Morton
2004-01-01T20:48:03Z

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"?