small patch for mm/vmscan.c

Benjamin C R LaHaise (blah@dot.superaje.com)
Mon, 8 Jul 1996 13:52:38 -0400 (EDT)


Hello all!

A while back there was some talk of machines freezing when they ran
out of swap. Upon further investigation, I found that kswapd was looping
in get_swap_page. Thanks to some other patches, we no longer run out of
swap in *normal* cases. The following patch speeds kswapd up almost a
thousand fold when we do run out of swap, and has caused no ill effects
so far as I can tell. It's pretty simple: instead of continuing to attempt
swap outs once we have failed to allocate a swap page, we switch to
our 'other' methods of freeing up memory (sharing, etc...). It also
adds a printk telling the user what has happened.

--- dist/mm/vmscan.c Sat Jul 6 17:48:41 1996
+++ linux/mm/vmscan.c Wed Jul 3 14:22:39 1996
@@ -109,7 +109,7 @@
if (page_map->count != 1)
return 0;
if (!(entry = get_swap_page()))
- return 0;
+ return -1; /* Aieee!!! Out of swap space! */
vma->vm_mm->rss--;
flush_cache_page(vma, address);
set_pte(page_table, __pte(entry));
@@ -312,6 +312,8 @@
if (!--p->swap_cnt)
swap_task++;
switch (swap_out_process(p, dma, wait)) {
+ case -1:
+ return 0;
case 0:
if (p->swap_cnt)
swap_task++;
@@ -367,7 +369,7 @@
*/
int kswapd(void *unused)
{
- int i;
+ int i, fails;
char *revision="$Revision: 1.4.2.2 $", *s, *e;

current->session = 1;
@@ -409,8 +411,14 @@
kswapd_awake = 1;
swapstats.wakeups++;
/* Do the background pageout: */
- for (i=0; i < kswapd_ctl.maxpages; i++)
- try_to_free_page(GFP_KERNEL, 0, 0);
+ for (fails=i=0; i < kswapd_ctl.maxpages; i++)
+ if (!try_to_free_page(GFP_KERNEL, 0, 0))
+ fails ++;
+ if (fails == i)
+ printk(KERN_ALERT "kswapd: Unable to free pages!\n");
+ /* FIXME: something should be done
+ now - we are completely out of memory.
+ Kill the largest process? -blah */
}
}