Re: Allow swapping over nbd and more similar magic

Pavel Machek (pavel@suse.cz)
Wed, 22 Dec 1999 21:30:54 +0100


Hi!

> > What I tried to do is to just free _clean_ pages when short on
> > memory. I did not want to touch anything else in order not to break
> > some balance. That do_try_to_free_pages(0) should kill one clean
> > page. (Do you have idea how to write it in short piece of code?)
>
> I don't know if we can do it in a short piece
> of code, but I have (2.5?) ideas on how to fix
> the problem for good.

:-). Is it problem for someone else then me trying to swap over network?

> > > > + while (do_try_to_free_pages(0) && count--) /* We don't want it to do any I/O */
> > > > + ;
> >
> > Kreclaimd should not try to swap out anything...
>
> It is trying to do just that with the call above.

Then it has to be changed (new patch attached)...

> > Does that mean that I should call shrink_mmap(6, 0) instead?
>
> That will only work if we have clean, unshared pages
> in the swap or page cache. I guess we want to keep
> count of those pages and make sure that there always
> are enough of them.

I was told that is "almost always" true. sct, could you comment on
this? (This patch does not count them)

> Then we can have a kreclaimd reclaiming those pages
> and kernel caches and a kswapd unmapping pages from
> processes and shared memory.

That's the way kreclaimd was expected to work...

...with one slight change. I wanted kswapd to _also_ reclaiming those
pages. That can't hurt, and is closer to current system. That ways,
kreclaimd should be called only very rarely.

Pavel

--- clean/mm/vmscan.c Sat Dec 11 21:44:13 1999
+++ linux/mm/vmscan.c Mon Dec 20 21:06:29 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 (shrink_mmap(6, 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/