Re: [PATCH] Warn if we run out of swap space

Christoph Lameter
2009-05-27T13:54:32Z

On Wed, 27 May 2009, KAMEZAWA Hiroyuki wrote:

> > 3 files changed, 17 insertions(+)
> >
> > Index: linux-2.6/mm/swapfile.c
> > ===================================================================
> > --- linux-2.6.orig/mm/swapfile.c 2009-05-22 14:03:37.000000000 -0500
> > +++ linux-2.6/mm/swapfile.c 2009-05-26 09:11:52.000000000 -0500
> > @@ -374,6 +374,8 @@ no_page:
> > return 0;
> > }
> >
> > +int out_of_swap_message_printed = 0;
> > +
> > swp_entry_t get_swap_page(void)
> > {
> > struct swap_info_struct *si;
> > @@ -410,6 +412,11 @@ swp_entry_t get_swap_page(void)
> > }
> >
> > nr_swap_pages++;
> > + if (!out_of_swap_message_printed) {
> > + out_of_swap_message_printed = 1;
> > + printk(KERN_WARNING "All of swap is in use. Some pages "
> > + "cannot be swapped out.\n");
> > + }
> > noswap:
> > spin_unlock(&swap_lock);
> BTW, hmm
>
> Isn't this should be
> ==
> noswap:
> if (total_swap_pages && !out_of_swap_message_printed) {
> ....
> }

Look at the beginning of get_swap_page():

spin_lock(&swap_lock);
if (nr_swap_pages <= 0)
goto noswap;
nr_swap_pages--;

I placed the printk intentionally before the noswap label.