Allow swapping over nbd and more similar magic

Pavel Machek (pavel@suse.cz)
Sat, 18 Dec 1999 22:32:28 +0100


Hi!

This is (quite simple) patch to linux, which makes it possible to use
things like nbd and crypted file for swapping. It was tested by
several people and seems to work. It makes linux less picky about
devices it can swap on...
Pavel

--- clean/mm/vmscan.c Sat Dec 11 21:44:13 1999
+++ linux/mm/vmscan.c Tue Dec 7 22:17:22 1999
@@ -7,6 +7,7 @@
* kswapd added: 7.1.96 sct
* Removed kswapd_ctl limits, and swap out as many pages as needed
* to bring the system back to freepages.high: 2.4.97, Rik van Riel.
+ * kreclaimd by Pavel Machek <pavel@ucw.cz>
* Version: $Id: vmscan.c,v 1.5 1998/02/23 22:14:28 sct Exp $
*/

@@ -515,6 +516,48 @@
}

/*
+ * The background page discarder, started from the init process.
+ *
+ * This basically executes once a second, trickling out pages
+ * so that we have _some_ free memory available even if there
+ * is no other activity that frees anything up.
+ * We want this to be separate from kswapd, because we do not
+ * want to block, no matter what happens. As long as there are
+ * some clean pages backed it file (which is true under normal
+ * conditions, SCT tells me), we can swap over anything.
+ *
+ * See comments on kswapd for more details.
+ */
+int kreclaimd(void *unused)
+{
+ struct task_struct *tsk = current;
+
+ kswapd_process = tsk;
+ tsk->session = 1;
+ tsk->pgrp = 1;
+ strcpy(tsk->comm, "kreclaimd");
+ sigfillset(&tsk->blocked);
+
+ tsk->flags |= PF_MEMALLOC;
+
+ while (1) {
+ do {
+ int count = SWAP_CLUSTER_MAX;
+
+ /* Normally, lets let kswapd do its work. If memory gets really low,
+ we'll want to clean up something to break the deadlock. */
+ if (nr_free_pages() >= freepages.low)
+ break;
+ while (do_try_to_free_pages(0) && count--) /* We don't want it to do any I/O */
+ ;
+// printk( "kreclaimd: Freed %d pages\n", SWAP_CLUSTER_MAX - count );
+ } while (!tsk->need_resched);
+ tsk->state = TASK_INTERRUPTIBLE;
+ schedule_timeout(HZ);
+ }
+}
+
+/*
* Called by non-kswapd processes when they want more
* memory.
*
@@ -544,6 +587,7 @@
printk("Starting kswapd v1.6\n");
swap_setup();
kernel_thread(kswapd, NULL, CLONE_FS | CLONE_FILES | CLONE_SIGHAND);
+ kernel_thread(kreclaimd, NULL, CLONE_FS | CLONE_FILES | CLONE_SIGHAND);
return 0;
}

-- 
I'm pavel@ucw.cz. "In my country we have almost anarchy and I don't care."
Panos Katsaloulis describing me w.r.t. patents me at discuss@linmodems.org

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