Fix (sort of) for OOM swap deadlock.

George (greerga@nidhogg.ham.muohio.edu)
Mon, 22 Jun 1998 00:27:13 -0400 (EDT)


Of course, I have no idea if this has a race since I'm not an experienced
kernel hacker, but "it works for me."

----
/usr/include/unistd.h:678: virtual memory exhaustedvirtual memory
exhaustedvirtual memory exhausted

virtual memory exhausted
virtual memory exhausted
virtual memory exhausted
virtual memory exhausted
virtual memory exhausted
In file included from /usr/include/sys/time.h:6,
----

diff -upr 2.1.106/linux/mm/vmscan.c linux/mm/vmscan.c
--- 2.1.106/linux/mm/vmscan.c Mon Jun 22 00:01:49 1998
+++ linux/mm/vmscan.c Sun Jun 21 23:58:53 1998
@@ -511,6 +511,28 @@ void kswapd_setup(void)
printk ("Starting kswapd v%.*s\n", i, s);
}

+/* Code borrowed from 'get_swaparea_info' in mm/swapfile.c */
+int out_of_swap(void)
+{
+ struct swap_info_struct *ptr = swap_info;
+ int i, j, usedswap;
+ int bytes_total = 0, bytes_used = 0;
+
+ for (i = 0 ; i < nr_swapfiles ; i++, ptr++) {
+ if ((ptr->flags & SWP_USED) == 0)
+ continue;
+ for (usedswap = 0, j = 0; j < ptr->max; ++j)
+ if (ptr->swap_map[j] != 128 && ptr->swap_map[j] != 0)
+ usedswap++;
+ bytes_total += (ptr->pages << (PAGE_SHIFT - 10));
+ bytes_used += (usedswap << (PAGE_SHIFT - 10));
+ }
+#ifdef DEBUG
+ printk("VM: Swap total: %6d Swap used: %6d\n", bytes_total, bytes_used);
+#endif
+ return (bytes_total == bytes_used);
+}
+
/*
* The background pageout daemon.
* Started as a kernel thread from the init process.
@@ -564,6 +586,13 @@ int kswapd(void *unused)
* woken up more often and the rate will be even
* higher).
*/
+ if (out_of_swap()) {
+#ifdef DEBUG
+ printk("kswapd: No swap left, not paging.\n");
+#endif
+ continue;
+ }
+
tries = pager_daemon.tries_base >> free_memory_available(3);

while (tries--) {

-George

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu