Skip to contentSkip to conversation

2.2.0 Bug summary

PATCH In review Andrea Arcangeli 37 participants 243 messages Dec 31, 1998 – Feb 1, 1999 1 message not in the archive Page 1 of 2

Subsystems (15)
Memory management VFS Kbuild MM core +11 more subsystems
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw
Quoted 2 lines · Alan Cox

o Linus VM is still 20% slower than sct vm on an 8Mb machine
[benchmarks kernel build and netscape]

Today I start playing with Linus's vm in 2.2.0-pre1 and I changed the semantics of many things and I added heuristic to avoid that one process trashing memory will hang other "normal" processes. This my new VM I developed today is _far_ better than sct's ac11 vm and anything I tried before. I would like if somebody could try it also on low memory machines and feedback what happens there. I don't have enough spare time to test it on many kind of hardware too.

The same benchmark that was taking 106 sec on clean 2.2.0-pre1 to dirtifying 160Mbyte of virtual memory (run with 128RAM and 72swap of phis mem), now runs in 90 sec but this is not the most important thing, the good point is that the cache/buffer/swap levels now are perfectly stable and all other processes runs fine and get not out of cache even if there's a memory trahser running at the same time.

Comments?

Ah, the shrink_mmap limit was wrong since we account only not referenced pages.

Patch against 2.2.0-pre1:

Index: linux/mm/filemap.c

mm/filemap.c renamed from mm/filemap.c:1.1.1.7 +3 -1
diff -u linux/mm/filemap.c:1.1.1.7 linux/mm/filemap.c:1.1.1.1.2.29
@@ -125,7 +129,7 @@
 	struct page * page;
 	int count;
 
-	count = (limit<<1) >> (priority);
+	count = limit >> priority;
 
 	page = mem_map + clock;
 	do {
@@ -182,6 +186,7 @@
 	return 0;
 }
 
+#if 0
 /*
  * This is called from try_to_swap_out() when we try to get rid of some
  * pages..  If we're unmapping the last occurrence of this page, we also
@@ -201,6 +206,7 @@
 	remove_inode_page(page);
 	return 1;
 }
+#endif
 
 /*
  * Update a page cache copy, when we're doing a "write()" system call

Index: linux/mm/page_alloc.c

mm/page_alloc.c renamed from mm/page_alloc.c:1.1.1.3 +23 -1
diff -u linux/mm/page_alloc.c:1.1.1.3 linux/mm/page_alloc.c:1.1.1.1.2.11
@@ -241,7 +241,29 @@
 			goto nopage;
 		}
 
-		if (freepages.min > nr_free_pages) {
+		if (freepages.high < nr_free_pages)
+		{
+			if (current->trashing_memory)
+			{
+				current->trashing_memory = 0;
+#if 0
+				printk("trashing end for %s\n", current->comm);
+#endif
+			}
+		} else if (freepages.min > nr_free_pages) {
+			if (!current->trashing_memory)
+			{
+				current->trashing_memory = 1;
+#if 0
+				printk("trashing start for %s\n", current->comm);
+#endif
+			}
+		}
+
+		/*
+		 * Block the process that is trashing memory. -arca
+		 */
+		if (current->trashing_memory) {
 			int freed;
 			freed = try_to_free_pages(gfp_mask, SWAP_CLUSTER_MAX);
 			/*

Index: linux/mm/swap_state.c

mm/swap_state.c renamed from mm/swap_state.c:1.1.1.3 +9 -2
diff -u linux/mm/swap_state.c:1.1.1.3 linux/mm/swap_state.c:1.1.1.1.2.8
@@ -248,7 +248,7 @@
 		delete_from_swap_cache(page);
 	}
 	
-	free_page(addr);
+	__free_page(page);
 }
 
 
@@ -261,6 +261,9 @@
 struct page * lookup_swap_cache(unsigned long entry)
 {
 	struct page *found;
+#ifdef	SWAP_CACHE_INFO
+	swap_cache_find_total++;
+#endif
 	
 	while (1) {
 		found = find_page(&swapper_inode, entry);
@@ -268,8 +271,12 @@
 			return 0;
 		if (found->inode != &swapper_inode || !PageSwapCache(found))
 			goto out_bad;
-		if (!PageLocked(found))
+		if (!PageLocked(found)) {
+#ifdef	SWAP_CACHE_INFO
+			swap_cache_find_success++;
+#endif
 			return found;
+		}
 		__free_page(found);
 		__wait_on_page(found);
 	}

Index: linux/mm/vmalloc.c

mm/vmalloc.c renamed from mm/vmalloc.c:1.1.1.2 +2 -1
diff -u linux/mm/vmalloc.c:1.1.1.2 linux/mm/vmalloc.c:1.1.1.1.2.2
@@ -185,7 +185,8 @@
 	for (p = &vmlist ; (tmp = *p) ; p = &tmp->next) {
 		if (tmp->addr == addr) {
 			*p = tmp->next;
-			vmfree_area_pages(VMALLOC_VMADDR(tmp->addr), tmp->size);
+			vmfree_area_pages(VMALLOC_VMADDR(tmp->addr),
+					  tmp->size - PAGE_SIZE);
 			kfree(tmp);
 			return;
 		}

Index: linux/mm/vmscan.c

mm/vmscan.c renamed from mm/vmscan.c:1.1.1.6 +94 -73

265 lines not on this page · raw message

Index: linux/kernel/fork.c

kernel/fork.c renamed from kernel/fork.c:1.1.1.3 +1 -0
diff -u linux/kernel/fork.c:1.1.1.3 linux/kernel/fork.c:1.1.1.1.2.6
@@ -567,6 +570,7 @@
 
 	/* ok, now we should be set up.. */
 	p->swappable = 1;
+	p->trashing_memory = 0;
 	p->exit_signal = clone_flags & CSIGNAL;
 	p->pdeath_signal = 0;
 

Index: linux/include/linux/sched.h

include/linux/sched.h renamed from include/linux/sched.h:1.1.1.2 +2 -1
diff -u linux/include/linux/sched.h:1.1.1.2 linux/include/linux/sched.h:1.1.1.1.2.7
@@ -268,6 +273,7 @@
 /* mm fault and swap info: this can arguably be seen as either mm-specific or thread-specific */
 	unsigned long min_flt, maj_flt, nswap, cmin_flt, cmaj_flt, cnswap;
 	int swappable:1;
+	int trashing_memory:1;
 	unsigned long swap_address;
 	unsigned long old_maj_flt;	/* old value of maj_flt */
 	unsigned long dec_flt;		/* page fault count of the last time */
@@ -353,7 +359,7 @@
 /* utime */	{0,0,0,0},0, \
 /* per CPU times */ {0, }, {0, }, \
 /* flt */	0,0,0,0,0,0, \
-/* swp */	0,0,0,0,0, \
+/* swp */	0,0,0,0,0,0, \
 /* process credentials */					\
 /* uid etc */	0,0,0,0,0,0,0,0,				\
 /* suppl grps*/ 0, {0,},					\

--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#2 lore raw

PATCH 1/1 new-vm improvement [Re: 2.2.0 Bug summary]

Quoted 6 lines · Andrea Arcangeli

Comments?

Ah, the shrink_mmap limit was wrong since we account only not referenced pages.

Patch against 2.2.0-pre1:

whoops in the last email I forget to change a bit the subject (adding [patch]) and this printk:

Index: linux/mm/vmscan.c

mm/vmscan.c renamed from mm/vmscan.c:1.1.1.1.2.43 +0 -4
diff -u linux/mm/vmscan.c:1.1.1.1.2.43 linux/mm/vmscan.c:1.1.1.1.2.45
@@ -449,11 +449,7 @@
 	case 0:
 		/* swap_out() failed to swapout */
 		if (shrink_mmap(priority, gfp_mask))
-		{
-			printk("swapout 0 shrink 1\n");
 			return 1;
-		}
-		printk("swapout 0 shrink 0\n");
 		return 0;
 	case 1:
 		/* this would be the best but should not happen right now */

Andrea Arcangeli

--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#3 lore raw

Re: [patch] new-vm improvement [Re: 2.2.0 Bug summary]

Quoted 5 lines · Andrea Arcangeli
Quoted 2 lines · Andrea Arcangeli

Comments?

Quoted 7 lines
Quoted 4 lines

Ah, the shrink_mmap limit was wrong since we account only not referenced pages.

Patch against 2.2.0-pre1:

whoops in the last email I forget to change a bit the subject (adding [patch]) and this printk:

Hi,

I just tried out the patch and got very disappointing results on my 128MB AMD K6-3. I tested by loading 117 good sized images all at once. This kicks it ~ 165MB into the swap (~ 293 MB mem total). The standard 2.2.0-pre1 kernel streamed out to swap at an average of >1MB/sec and finished in 184 seconds. WIth the patched kernel I stopped at 280 sec. At that time it had about 65 mb swapped out or < 250K/sec. I then rebooted, brought up X and an xterm and went to compile the 2.1.131-ac11 patch (still running under the patched 2.2.0-pre1) and noted that during the compile I had 17MB in the swap with nothing else going on. Bringing
up netscape put it up to 25MB. Suggestions? Requests? Let me know if
you want me to try anything else.

Thanks,
Steve
--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#4 lore raw

Re: [patch] new-vm improvement [Re: 2.2.0 Bug summary]

Quoted 2 lines · Steve Bergman

I just tried out the patch and got very disappointing results on my 128MB AMD K6-3. I tested by loading 117 good sized images all at once.

The point of my patch is to balance the VM and improve performance for not memory trashing proggy. It make sense that the trashing program is been slowed down... Once the proggy will stop allocating RAM but it will continue to use only pages just allocated (eventually in swap) performance should return normal.

Quoted 3 lines

patch (still running under the patched 2.2.0-pre1) and noted that during the compile I had 17MB in the swap with nothing else going on. Bringing
up netscape put it up to 25MB. Suggestions? Requests? Let me know if

I am going to still change something for sure. But please don't care the size of the SWAP, care only performances. The pages in the swap right now are likely to be present also in the swap cache so you' ll handle both aging and a little cost in a swapin using more the swap cache. Really there's also the cost of an async swapout to disk but it seems to not harm here.

Quoted 1 line

you want me to try anything else.

Yes you should tell me if the performances decreased with normal usage (like netscape + kernel compile).

Andrea Arcangeli

--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#5 lore raw

Re: [patch] new-vm improvement [Re: 2.2.0 Bug summary]

In reply to Andrea Arcangeli

I' ll try to comment my latest VM patch.

The patch basically do two things.

It add an heuristic to block trashing tasks in try_to_free_pages() and allow normal tasks to run fine in the meantime.

It returns to the old do_try_to_free_pages() way to do things. I think the reason the old way was no longer working well is that we are using swap_out() as other freeing-methods while swapout has really nothing to do with them.

To get VM stability under low memory we must use both swap_out() (that put pages from the user process Vmemory to the swap cache) and shrink_mmap() in a new method. My new method put user pages in the swap cache because there we can handle aging very well. Then shrink_mmap() can free a not refernced page to really do some progress in the memory freeing (and not only in the swapout).

So basically my patch cause sure the system to swapout more than we was used to do, but most of the time we will not need a swapin to reput the pages in the process Vmemory.

Somebody reported a big slowdown of the trashing application. Right now I don't know which bit of the patch caused this slowdown (yesterday my benchmark here didn't showed this slowdown). My new trashing_memory heuristic will probably decrease performance for the trashing application (but hey you know that if you need performance you can alwaws buy more RAM ;), but it will improve a lot performance for normal not-trashing tasks.

I' ll try to change do_free_user_and_cache() to see if I can achieve something better.

I changed also the swap_out() since the best way to choose a process it to compare the raw RSS I think. And I don' t want that swap_cnt is decreased of something every time something is swapped out. I want that the kernel will continue passing throught all the pages of one process once it started playing with it (if it will still exists of course ;). I changed also the pressure of swap_out() since it make no sense to me to pass more than one time over the VM of all tasks in the system. Now at priority 6 swap_out() is trying to swapout something at max from nr_tasks/7 (low bound to 1 task). I changed also the pressure of shrink_mmap() because it was making no sense to me to do two passes on just not referenced pages.

I also changed swapout() allowing it to return 0 1 or more.

0 means that swap_out() is been not able to put in the swap cache something.

1 means that swap_out() is been able to swapout something and has also freed up one page (how??? it can't right now because the page should always be still at least present in the swap cache)

2 means that swap_out() has swapped out 1 page and that the page is still referenced somewhere (probably by the swap cache)

So in case 2 and case 0 we must use shrink_mmap() to really do some progress in the page freeing. This the idea that my new do_free_user_and_cache() follows.

Comments?

--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#6 lore raw

Re: [patch] new-vm improvement [Re: 2.2.0 Bug summary]

I rediffed my VM patch against test1-patch-2.2.0-pre3.gz. I also fixed some bug (not totally critical but..) pointed out by Linus in my last code. I also changed the shrink_mmap(0) to shrink_mmap(priority) because it was completly sucking a lot performance. There is no need to do a shrink_mmap(0) for example if the cache/buffer are under min. In such case we must allow the swap_out() to grow the cache before start shrinking it.

So basically this new patch is _far_ more efficient than the last one (I never seen so good/stable/fast behavior before!).

This my new patch is against testing/test1-patch-2.2.0-pre3.gz that is against v2.1/2.2.0-pre2 that is against patch-2.2.0-pre1-vs-2.1.132.gz (where is this last one now?).

Ah, from testing/test1-patch-2.2.0-pre3.gz was missing the trashing memory initialization that will allow every process to do a fast start.

Index: linux/kernel/fork.c

kernel/fork.c renamed from kernel/fork.c:1.1.1.3 +1 -0
diff -u linux/kernel/fork.c:1.1.1.3 linux/kernel/fork.c:1.1.1.1.2.6
@@ -567,6 +570,7 @@
 
 	/* ok, now we should be set up.. */
 	p->swappable = 1;
+	p->trashing_memory = 0;
 	p->exit_signal = clone_flags & CSIGNAL;
 	p->pdeath_signal = 0;
 

Index: linux/mm/vmscan.c

mm/vmscan.c renamed from mm/vmscan.c:1.1.1.8 +92 -73

268 lines not on this page · raw message

Index: linux/mm/swap_state.c

mm/swap_state.c renamed from mm/swap_state.c:1.1.1.4 +8 -1
diff -u linux/mm/swap_state.c:1.1.1.4 linux/mm/swap_state.c:1.1.1.1.2.9
@@ -262,6 +262,9 @@
 struct page * lookup_swap_cache(unsigned long entry)
 {
 	struct page *found;
+#ifdef	SWAP_CACHE_INFO
+	swap_cache_find_total++;
+#endif
 	
 	while (1) {
 		found = find_page(&swapper_inode, entry);
@@ -269,8 +272,12 @@
 			return 0;
 		if (found->inode != &swapper_inode || !PageSwapCache(found))
 			goto out_bad;
-		if (!PageLocked(found))
+		if (!PageLocked(found)) {
+#ifdef	SWAP_CACHE_INFO
+			swap_cache_find_success++;
+#endif
 			return found;
+		}
 		__free_page(found);
 		__wait_on_page(found);
 	}

If this patch is decreasing performance for you (eventually due too much memory swapped out) you can try this incremental patch (I never tried here btw):

Index: mm//vmscan.c
===================================================================
RCS file: /var/cvs/linux/mm/vmscan.c,v
retrieving revision 1.1.1.1.2.49

mm/vmscan.c renamed from vmscan.c +3 -0
diff -u -r1.1.1.1.2.49 vmscan.c
@@ -441,6 +441,9 @@
 
 static int do_free_user_and_cache(int priority, int gfp_mask)
 {
+	if (shrink_mmap(priority, gfp_mask))
+		return 1;
+
 	switch (swap_out(priority, gfp_mask))
 	{
 	default:

I written a swap benchmark that is dirtifying 160Mbyte of VM. For the first loop 2.2-pre1 was taking 106 sec, for the second loop 120 and then worse.

test1-pre3 + my new patch in this email, instead takes 120 sec in the first loop (since it's allocating it's probably slowed down a bit by the trashing_memory heuristic, and that's right), then it takes 90 sec in the second loop and 77 sec in the third loop!! and the system was far to be idle (as when I measured 2.2-pre1), but I was using it without special regards and was perfectly usable (2.2-pre1 was unusable instead).

Comments?

--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#7 lore raw

Re: [patch] new-vm improvement [Re: 2.2.0 Bug summary]

Quoted 3 lines · Andrea Arcangeli

Please stop and try my new patch against Linus's test1-pre3 (that just merge some of my new stuff).

I got the patch and I must say I'm impressed. I ran my "117 image" test and got these results:

[Note: This loads 117 different images at the same time using 117 separate instances of 'xv' started in the background and results in ~ 165 MB of swap area usage. The machine is an AMD K6-2 300 with 128MB]

2.1.131-ac11 172 sec (This was previously the
best)
2.2.0-pre1 + Arcangeli's 1st patch 400 sec
test1-pre + Arcangeli's 2nd patch 119 sec (!)

Processor utilization was substantially greater with the new patch compared to either of the others. Before it starts using swap, memory is being consumed at ~ 4MB/sec. After it starts to swap out, it streams out at ~ 2MB/sec.

The performance is ~ 45% better than ac11 and ~ 70% better than 2.2.0-pre1 in this test.

I was going to test the low memory case but got side tracked.

Thanks,
Steve
--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#8 lore raw

Re: [patch] new-vm improvement [Re: 2.2.0 Bug summary]

Quoted 7 lines · Steve Bergman

I got the patch and I must say I'm impressed. I ran my "117 image" test and got these results:

2.1.131-ac11                         172 sec  (This was previously the best)
2.2.0-pre1 + Arcangeli's 1st patch   400 sec
test1-pre  + Arcangeli's 2nd patch   119 sec (!)

Would you care to do some more testing? In particular, I'd like to hear how basic 2.2.0pre3 works (that's essentially the same as test1-pre, with only minor updates)? I'd like to calibrate the numbers against that, rather than against kernels that I haven't actually ever run myself.

The other thing I'd like to hear is how pre3 looks with this patch, which should behave basically like Andrea's latest patch but without the obfuscation he put into his patch..

Linus

-----

Makefile renamed from linux/Makefile +1 -1
diff -u --recursive --new-file v2.2.0-pre3/linux/Makefile linux/Makefile
@@ -1,7 +1,7 @@
 VERSION = 2
 PATCHLEVEL = 2
 SUBLEVEL = 0
-EXTRAVERSION =-pre3
+EXTRAVERSION =-pre4
 
 ARCH := $(shell uname -m | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ -e s/arm.*/arm/ -e s/sa110/arm/)
 
drivers/misc/parport_procfs.c renamed from linux/drivers/misc/parport_procfs.c +1 -2
diff -u --recursive --new-file v2.2.0-pre3/linux/drivers/misc/parport_procfs.c linux/drivers/misc/parport_procfs.c
@@ -305,12 +305,11 @@
 {
 	base = new_proc_entry("parport", S_IFDIR, &proc_root,PROC_PARPORT,
 			      NULL);
-	base->fill_inode = &parport_modcount;
-
 	if (base == NULL) {
 		printk(KERN_ERR "Unable to initialise /proc/parport.\n");
 		return 0;
 	}
+	base->fill_inode = &parport_modcount;
 
 	return 1;
 }
fs/binfmt_misc.c renamed from linux/fs/binfmt_misc.c +10 -0
diff -u --recursive --new-file v2.2.0-pre3/linux/fs/binfmt_misc.c linux/fs/binfmt_misc.c
@@ -30,6 +30,16 @@
 #include <asm/uaccess.h>
 #include <asm/spinlock.h>
 
+/*
+ * We should make this work with a "stub-only" /proc,
+ * which would just not be able to be configured.
+ * Right now the /proc-fs support is too black and white,
+ * though, so just remind people that this should be
+ * fixed..
+ */
+#ifndef CONFIG_PROC_FS
+#error You really need /proc support for binfmt_misc. Please reconfigure!
+#endif
 
 #define VERBOSE_STATUS /* undef this to save 400 bytes kernel memory */
 
include/linux/swapctl.h renamed from linux/include/linux/swapctl.h +0 -12
diff -u --recursive --new-file v2.2.0-pre3/linux/include/linux/swapctl.h linux/include/linux/swapctl.h
@@ -90,18 +90,6 @@
 #define PAGE_DECLINE		(swap_control.sc_page_decline)
 #define PAGE_INITIAL_AGE	(swap_control.sc_page_initial_age)
 
-/* Given a resource of N units (pages or buffers etc), we only try to
- * age and reclaim AGE_CLUSTER_FRACT per 1024 resources each time we
- * scan the resource list. */
-static inline int AGE_CLUSTER_SIZE(int resources)
-{
-	unsigned int n = (resources * AGE_CLUSTER_FRACT) >> 10;
-	if (n < AGE_CLUSTER_MIN)
-		return AGE_CLUSTER_MIN;
-	else
-		return n;
-}
-
 #endif /* __KERNEL */
 
 #endif /* _LINUX_SWAPCTL_H */
mm/vmscan.c renamed from linux/mm/vmscan.c +20 -19
diff -u --recursive --new-file v2.2.0-pre3/linux/mm/vmscan.c linux/mm/vmscan.c
@@ -363,13 +363,23 @@
 	/* 
 	 * We make one or two passes through the task list, indexed by 
 	 * assign = {0, 1}:
-	 *   Pass 1: select the swappable task with maximal swap_cnt.
-	 *   Pass 2: assign new swap_cnt values, then select as above.
+	 *   Pass 1: select the swappable task with maximal RSS that has
+	 *         not yet been swapped out. 
+	 *   Pass 2: re-assign rss swap_cnt values, then select as above.
+	 *
 	 * With this approach, there's no need to remember the last task
 	 * swapped out.  If the swap-out fails, we clear swap_cnt so the 
 	 * task won't be selected again until all others have been tried.
+	 *
+	 * Think of swap_cnt as a "shadow rss" - it tells us which process
+	 * we want to page out (always try largest first).
 	 */
-	counter = ((PAGEOUT_WEIGHT * nr_tasks) >> 10) >> priority;
+	counter = nr_tasks / (priority+1);
+	if (counter < 1)
+		counter = 1;
+	if (counter > nr_tasks)
+		counter = nr_tasks;
+
 	for (; counter >= 0; counter--) {
 		assign = 0;
 		max_cnt = 0;
@@ -382,15 +392,9 @@
 				continue;
 	 		if (p->mm->rss <= 0)
 				continue;
-			if (assign) {
-				/* 
-				 * If we didn't select a task on pass 1, 
-				 * assign each task a new swap_cnt.
-				 * Normalise the number of pages swapped
-				 * by multiplying by (RSS / 1MB)
-				 */
-				p->swap_cnt = AGE_CLUSTER_SIZE(p->mm->rss);
-			}
+			/* Refresh swap_cnt? */
+			if (assign)
+				p->swap_cnt = p->mm->rss;
 			if (p->swap_cnt > max_cnt) {
 				max_cnt = p->swap_cnt;
 				pbest = p;
@@ -404,14 +408,13 @@
 			}
 			goto out;
 		}
-		pbest->swap_cnt--;
 
 		/*
 		 * Nonzero means we cleared out something, but only "1" means
 		 * that we actually free'd up a page as a result.
 		 */
 		if (swap_out_process(pbest, gfp_mask) == 1)
-				return 1;
+			return 1;
 	}
 out:
 	return 0;
@@ -451,19 +454,17 @@
 	/* max one hundreth of a second */
 	end_time = jiffies + (HZ-1)/100;
 	do {
-		int priority = 5;
+		int priority = 8;
 		int count = pager_daemon.swap_cluster;
 
 		switch (kswapd_state) {
 			do {
 			default:
 				free_memory(shrink_mmap(priority, 0));
+				free_memory(swap_out(priority, 0));
 				kswapd_state++;
 			case 1:
 				free_memory(shm_swap(priority, 0));
-				kswapd_state++;
-			case 2:
-				free_memory(swap_out(priority, 0));
 				shrink_dcache_memory(priority, 0);
 				kswapd_state = 0;
 			} while (--priority >= 0);
@@ -562,7 +563,7 @@
 
 		current->flags |= PF_MEMALLOC;
 	
-		priority = 5;
+		priority = 8;
 		do {
 			free_memory(shrink_mmap(priority, gfp_mask));
 			free_memory(shm_swap(priority, gfp_mask));

--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#9 lore raw

Re: [patch] new-vm improvement [Re: 2.2.0 Bug summary]

Quoted 10 lines · Linus Torvalds
Quoted 7 lines · Steve Bergman

I got the patch and I must say I'm impressed. I ran my "117 image" test and got these results:

2.1.131-ac11                         172 sec  (This was previously the best)
2.2.0-pre1 + Arcangeli's 1st patch   400 sec
test1-pre  + Arcangeli's 2nd patch   119 sec (!)
Quoted 7 lines

Would you care to do some more testing? In particular, I'd like to hear how basic 2.2.0pre3 works (that's essentially the same as test1-pre, with only minor updates)? I'd like to calibrate the numbers against that, rather than against kernels that I haven't actually ever run myself.

The other thing I'd like to hear is how pre3 looks with this patch, which should behave basically like Andrea's latest patch

Hi Linus,

Andrea sent another patch to correct a problem with i/o bound processes, which he also posted to linux-kernel. The performance in this test is unchanged.

Here are the results:

2.1.131-ac11 172 sec

2.2.0-pre1 + Arcangeli's 1st patch              400 sec
test1-pre  + Arcangeli's 2nd patch              119 sec 
test1-pre  + Arcangeli's 3rd patch              119 sec
test1-pre  + Arcangeli's 3rd patch              117 sec 

(changed to priority = 9 in mm/vmscan.c)

2.2.0-pre3 175 sec
2.2.0-pre3 + Linus's patch 129 sec

RH5.2 Stock (2.0.36-0.7) 280 sec

I noticed that in watching the 'vmstat 1' during the test that '2.2.0+Linus patch' was not *quite* as smooth as the Archangeli patches, in that there were periods of 2 or 3 seconds in which the swap out rate would fall to ~800k/sec and then jump back up to 1.8-2.5MB/sec. I have only run your patch once though. I'll check it further tomorrow to confirm that that is really the case. Note how much better 2.2 is doing compared to 2.0.36-0.7 in this situation.

I should be available for a good part of this weekend for further testing; Just let me know.

As a reference:

AMD K6-2 300
128MB ram
2GB seagate scsi2 dedicated to swap
Data drive is 6.5GB UDMA

Steve Bergman
[email protected]
--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#10 lore raw

Re: [patch] new-vm improvement [Re: 2.2.0 Bug summary]

In reply to Linus Torvalds
Quoted 3 lines · Linus Torvalds

The other thing I'd like to hear is how pre3 looks with this patch, which should behave basically like Andrea's latest patch but without the obfuscation he put into his patch..

I still think the most important part of all my latest VM patches is my new do_free_user_and_cache(). It allow the VM to scale very better and be perfectly balanced.

Why to run `count' times swap_out() without take a look if the cache grows too much?

Andrea Arcangeli

--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#11 lore raw

Re: [patch] new-vm improvement [Re: 2.2.0 Bug summary]

In reply to Linus Torvalds
Quoted 3 lines · Linus Torvalds

The other thing I'd like to hear is how pre3 looks with this patch, which should behave basically like Andrea's latest patch but without the obfuscation he put into his patch..

I rediffed my latest swapout stuff against your latest tree (I consider your latest patch as test1-pre4, right?).

Index: linux/mm/vmscan.c

mm/vmscan.c renamed from mm/vmscan.c:1.1.1.9 +79 -59
diff -u linux/mm/vmscan.c:1.1.1.9 linux/mm/vmscan.c:1.1.1.1.2.52
@@ -10,6 +10,11 @@
  *  Version: $Id: vmscan.c,v 1.5 1998/02/23 22:14:28 sct Exp $
  */
 
+/*
+ * Revisioned the page freeing algorithm: do_free_user_and_cache().
+ * Copyright (C) 1998  Andrea Arcangeli
+ */
+
 #include <linux/slab.h>
 #include <linux/kernel_stat.h>
 #include <linux/swap.h>
@@ -162,8 +167,9 @@
 			 * copy in memory, so we add it to the swap
 			 * cache. */
 			if (PageSwapCache(page_map)) {
+				entry = atomic_read(&page_map->count);
 				__free_page(page_map);
-				return (atomic_read(&page_map->count) == 0);
+				return entry;
 			}
 			add_to_swap_cache(page_map, entry);
 			/* We checked we were unlocked way up above, and we
@@ -180,8 +186,9 @@
 		 * asynchronously.  That's no problem, shrink_mmap() can
 		 * correctly clean up the occassional unshared page
 		 * which gets left behind in the swap cache. */
+		entry = atomic_read(&page_map->count);
 		__free_page(page_map);
-		return 1;	/* we slept: the process may not exist any more */
+		return entry;	/* we slept: the process may not exist any more */
 	}
 
 	/* The page was _not_ dirty, but still has a zero age.  It must
@@ -194,8 +201,9 @@
 		set_pte(page_table, __pte(entry));
 		flush_tlb_page(vma, address);
 		swap_duplicate(entry);
+		entry = atomic_read(&page_map->count);
 		__free_page(page_map);
-		return (atomic_read(&page_map->count) == 0);
+		return entry;
 	} 
 	/* 
 	 * A clean page to be discarded?  Must be mmap()ed from
@@ -210,7 +218,7 @@
 	flush_cache_page(vma, address);
 	pte_clear(page_table);
 	flush_tlb_page(vma, address);
-	entry = (atomic_read(&page_map->count) == 1);
+	entry = atomic_read(&page_map->count);
 	__free_page(page_map);
 	return entry;
 }
@@ -381,6 +389,7 @@
 		counter = nr_tasks;
 
 	for (; counter >= 0; counter--) {
+		int retval;
 		assign = 0;
 		max_cnt = 0;
 		pbest = NULL;
@@ -413,8 +422,9 @@
 		 * Nonzero means we cleared out something, but only "1" means
 		 * that we actually free'd up a page as a result.
 		 */
-		if (swap_out_process(pbest, gfp_mask) == 1)
-			return 1;
+		retval = swap_out_process(pbest, gfp_mask);
+		if (retval)
+			return retval;
 	}
 out:
 	return 0;
@@ -441,42 +451,64 @@
        printk ("Starting kswapd v%.*s\n", i, s);
 }
 
-#define free_memory(fn) \
-	count++; do { if (!--count) goto done; } while (fn)
+static int do_free_user_and_cache(int priority, int gfp_mask)
+{
+	if (shrink_mmap(priority, gfp_mask))
+		return 1;
 
-static int kswapd_free_pages(int kswapd_state)
+	if (swap_out(priority, gfp_mask))
+		/*
+		 * We done at least some swapping progress so return 1 in
+		 * this case. -arca
+		 */
+		return 1;
+
+	return 0;
+}
+
+static int do_free_page(int * state, int gfp_mask)
 {
-	unsigned long end_time;
+	int priority = 8;
 
-	/* Always trim SLAB caches when memory gets low. */
-	kmem_cache_reap(0);
+	switch (*state) {
+		do {
+		default:
+			if (do_free_user_and_cache(priority, gfp_mask))
+				return 1;
+			*state = 1;
+		case 1:
+			if (shm_swap(priority, gfp_mask))
+				return 1;
+			*state = 2;
+		case 2:
+			shrink_dcache_memory(priority, gfp_mask);
+			kmem_cache_reap(gfp_mask);
+			*state = 0;
+		} while (--priority >= 0);
+	}
+	return 0;
+}
 
+static int kswapd_free_pages(int kswapd_state)
+{
 	/* max one hundreth of a second */
-	end_time = jiffies + (HZ-1)/100;
-	do {
-		int priority = 8;
-		int count = pager_daemon.swap_cluster;
+	unsigned long end_time = jiffies + (HZ-1)/100;
 
-		switch (kswapd_state) {
-			do {
-			default:
-				free_memory(shrink_mmap(priority, 0));
-				free_memory(swap_out(priority, 0));
-				kswapd_state++;
-			case 1:
-				free_memory(shm_swap(priority, 0));
-				shrink_dcache_memory(priority, 0);
-				kswapd_state = 0;
-			} while (--priority >= 0);
-			return kswapd_state;
-		}
-done:
-		if (nr_free_pages > freepages.high + pager_daemon.swap_cluster)
+	do {
+		do_free_page(&kswapd_state, 0);
+		if (nr_free_pages > freepages.high)
 			break;
 	} while (time_before_eq(jiffies,end_time));
+	/* take kswapd_state on the stack to save some byte of memory */
 	return kswapd_state;
 }
 
+static inline void enable_swap_tick(void)
+{
+	timer_table[SWAP_TIMER].expires = jiffies+(HZ+99)/100;
+	timer_active |= 1<<SWAP_TIMER;
+}
+
 /*
  * The background pageout daemon.
  * Started as a kernel thread from the init process.
@@ -524,6 +556,7 @@
 		current->state = TASK_INTERRUPTIBLE;
 		flush_signals(current);
 		run_task_queue(&tq_disk);
+		enable_swap_tick();
 		schedule();
 		swapstats.wakeups++;
 		state = kswapd_free_pages(state);
@@ -543,35 +576,23 @@
  * if we need more memory as part of a swap-out effort we
  * will just silently return "success" to tell the page
  * allocator to accept the allocation.
- *
- * We want to try to free "count" pages, and we need to 
- * cluster them so that we get good swap-out behaviour. See
- * the "free_memory()" macro for details.
  */
 int try_to_free_pages(unsigned int gfp_mask, int count)
 {
-	int retval;
-
+	int retval = 1;
 	lock_kernel();
 
-	/* Always trim SLAB caches when memory gets low. */
-	kmem_cache_reap(gfp_mask);
-
-	retval = 1;
 	if (!(current->flags & PF_MEMALLOC)) {
-		int priority;
-
 		current->flags |= PF_MEMALLOC;
-	
-		priority = 8;
-		do {
-			free_memory(shrink_mmap(priority, gfp_mask));
-			free_memory(shm_swap(priority, gfp_mask));
-			free_memory(swap_out(priority, gfp_mask));
-			shrink_dcache_memory(priority, gfp_mask);
-		} while (--priority >= 0);
-		retval = 0;
-done:
+		while (count--)
+		{
+			static int state = 0;
+			if (!do_free_page(&state, gfp_mask))
+			{
+				retval = 0;
+				break;
+			}
+		}
 		current->flags &= ~PF_MEMALLOC;
 	}
 	unlock_kernel();
@@ -594,7 +615,8 @@
 	if (priority) {
 		p->counter = p->priority << priority;
 		wake_up_process(p);
-	}
+	} else
+		enable_swap_tick();
 }
 
 /* 
@@ -632,9 +654,8 @@
 			want_wakeup = 3;
 	
 		kswapd_wakeup(p,want_wakeup);
-	}
-
-	timer_active |= (1<<SWAP_TIMER);
+	} else
+		enable_swap_tick();
 }
 
 /* 
@@ -643,7 +664,6 @@
 
 void init_swap_timer(void)
 {
-	timer_table[SWAP_TIMER].expires = jiffies;
 	timer_table[SWAP_TIMER].fn = swap_tick;
-	timer_active |= (1<<SWAP_TIMER);
+	enable_swap_tick();
 }

The try_to_swap_out() changes (entry = atomic_read()) are really not important for the performance. We could always return 1 instead of atomic_read() and consider the retval 1 from swap_out() as every current retval >1. Since I can't see a big performance impact by atomic_read() I left it here since it will give us more info than returning a plain 1 and so knowing only that we have succesfully unliked a page from the user process memory.

I have also a new experimental patch against the one above, that here improve a _lot_ the swapout performance. The benchmark that dirtify 160 Mbyte in loop was used to take near 106 sec and now takes 89sec. It will also avoid all not trashing process to be swapped out.

I don't consider this production code though but I am interested if somebody will try it ;):

Index: mm//vmscan.c
===================================================================
RCS file: /var/cvs/linux/mm/vmscan.c,v
retrieving revision 1.1.1.1.2.52

mm/vmscan.c renamed from vmscan.c +8 -1
diff -u -r1.1.1.1.2.52 vmscan.c
@@ -353,7 +353,6 @@
 	}
 
 	/* We didn't find anything for the process */
-	p->swap_cnt = 0;
 	p->swap_address = 0;
 	return 0;
 }
@@ -423,6 +422,14 @@
 		 * that we actually free'd up a page as a result.
 		 */
 		retval = swap_out_process(pbest, gfp_mask);
+		/*
+		 * Don't play with other tasks next time if the huge one
+		 * is been swapedin in the meantime. This can be considered
+		 * a bit experimental, but it seems to improve a lot the
+		 * swapout performances here. -arca
+		 */
+		p->swap_cnt = p->mm->rss;
+
 		if (retval)
 			return retval;
 	}

--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#12 lore raw

Re: [patch] new-vm improvement [Re: 2.2.0 Bug summary]

Quoted 7 lines · Andrea Arcangeli
Quoted 4 lines

The other thing I'd like to hear is how pre3 looks with this patch, which should behave basically like Andrea's latest patch but without the obfuscation he put into his patch..

I rediffed my latest swapout stuff against your latest tree (I consider your latest patch as test1-pre4, right?).

Andrea, I already told you that I refuse to apply patches that include this many obvious cases of pure obfuscation.

As I already told you in an earlier mail, your state machine only has two states, not three like the code makes you believe. Gratuitous changes like that that only show that the writer didn't actually _think_ about the code is not something I want at any stage, much less now.

Linus

--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#13 lore raw

Re: [patch] new-vm improvement [Re: 2.2.0 Bug summary]

In reply to Andrea Arcangeli
Quoted 2 lines · Andrea Arcangeli

I rediffed my latest swapout stuff against your latest tree (I consider your latest patch as test1-pre4, right?).

I developed new exiting stuff this afternoon! The most important thing is the swapout smart weight code. Basing the priority on the number of process to try to swapout was really ugly and not smart.

The second change is done over shrink_mmap(), this will cause shrink_mmap() to care very more about aging. We have only one bit and we must use it carefully to get not out of cache ;)

I also added/removed some PG_referenced. But please, don't trust too much the pg_refernced changes since I have not thought about it too much (maybe they are not needed?).

I returned to put the minimum of cache and buffer to 5%. This allow me to run every trashing memory proggy I can for every time but I still have all my last command run (free) and filesystem (ls -l) in cache (because the trashing memory _only_ play with its VM and asks nothing to the kernel of course).

Ah and woops, in the last patch I do a mistake and I forget to change max_cnt to unsigned long. This should be changed also in your tree, Linus.

This new patch seems to really rocks here and seems _far_ better than anything I tried before! Steve, could try it and feedback? Thanks ;)

Please excuse me Linus if I have not yet cleanedup things, but my spare time is very small and I would _try_ to improve things a bit more before...

This patch is against 2.2.0-pre4 (the lateest patch posted by Linus here).

Index: linux/include/linux/mm.h

include/linux/mm.h renamed from include/linux/mm.h:1.1.1.3 +1 -3
diff -u linux/include/linux/mm.h:1.1.1.3 linux/include/linux/mm.h:1.1.1.1.2.11
@@ -118,7 +118,6 @@
 	unsigned long offset;
 	struct page *next_hash;
 	atomic_t count;
-	unsigned int unused;
 	unsigned long flags;	/* atomic flags, some possibly updated asynchronously */
 	struct wait_queue *wait;
 	struct page **pprev_hash;
@@ -295,8 +294,7 @@
 
 /* filemap.c */
 extern void remove_inode_page(struct page *);
-extern unsigned long page_unuse(struct page *);
-extern int shrink_mmap(int, int);
+extern int FASTCALL(shrink_mmap(int, int));
 extern void truncate_inode_pages(struct inode *, unsigned long);
 extern unsigned long get_cached_page(struct inode *, unsigned long, int);
 extern void put_cached_page(unsigned long);

Index: linux/include/linux/pagemap.h

include/linux/pagemap.h renamed from include/linux/pagemap.h:1.1.1.1 +1 -0
diff -u linux/include/linux/pagemap.h:1.1.1.1 linux/include/linux/pagemap.h:1.1.1.1.2.1
@@ -77,6 +77,7 @@
 		*page->pprev_hash = page->next_hash;
 		page->pprev_hash = NULL;
 	}
+	clear_bit(PG_referenced, &page->flags);
 	page_cache_size--;
 }
 

Index: linux/mm/filemap.c

mm/filemap.c renamed from mm/filemap.c:1.1.1.8 +14 -6
diff -u linux/mm/filemap.c:1.1.1.8 linux/mm/filemap.c:1.1.1.1.2.35
@@ -118,6 +122,10 @@
 	__free_page(page);
 }
 
+#define HANDLE_AGING(page)					\
+	if (test_and_clear_bit(PG_referenced, &(page)->flags))	\
+		continue;
+
 int shrink_mmap(int priority, int gfp_mask)
 {
 	static unsigned long clock = 0;
@@ -140,12 +148,11 @@
 			page = page->next_hash;
 			clock = page->map_nr;
 		}
-		
-		if (test_and_clear_bit(PG_referenced, &page->flags))
-			continue;
 
 		/* Decrement count only for non-referenced pages */
-		count--;
+		if (!test_bit(PG_referenced, &page->flags))
+			count--;
+
 		if (PageLocked(page))
 			continue;
 
@@ -160,6 +167,7 @@
 		if (page->buffers) {
 			if (buffer_under_min())
 				continue;
+			HANDLE_AGING(page);
 			if (!try_to_free_buffers(page))
 				continue;
 			return 1;
@@ -167,12 +175,14 @@
 
 		/* is it a swap-cache or page-cache page? */
 		if (page->inode) {
-			if (pgcache_under_min())
-				continue;
 			if (PageSwapCache(page)) {
+				HANDLE_AGING(page);
 				delete_from_swap_cache(page);
 				return 1;
 			}
+			if (pgcache_under_min())
+				continue;
+			HANDLE_AGING(page);
 			remove_inode_page(page);
 			return 1;
 		}
@@ -181,6 +191,8 @@
 	return 0;
 }
 
+#undef HANDLE_AGING
+
 /*
  * Update a page cache copy, when we're doing a "write()" system call
  * See also "update_vm_cache()".

Index: linux/mm/swap.c

mm/swap.c renamed from mm/swap.c:1.1.1.5 +2 -2
diff -u linux/mm/swap.c:1.1.1.5 linux/mm/swap.c:1.1.1.1.2.8
@@ -64,13 +64,13 @@
 swapstat_t swapstats = {0};
 
 buffer_mem_t buffer_mem = {
-	2,	/* minimum percent buffer */
+	5,	/* minimum percent buffer */
 	10,	/* borrow percent buffer */
 	60	/* maximum percent buffer */
 };
 
 buffer_mem_t page_cache = {
-	2,	/* minimum percent page cache */
+	5,	/* minimum percent page cache */
 	15,	/* borrow percent page cache */
 	75	/* maximum */
 };

Index: linux/mm/vmscan.c

mm/vmscan.c renamed from mm/vmscan.c:1.1.1.9 +122 -74

360 lines not on this page · raw message

Index: linux/fs/buffer.c

fs/buffer.c renamed from fs/buffer.c:1.1.1.5 +1 -0
diff -u linux/fs/buffer.c:1.1.1.5 linux/fs/buffer.c:1.1.1.1.2.6
@@ -1263,6 +1263,7 @@
 		panic("brw_page: page not locked for I/O");
 	clear_bit(PG_uptodate, &page->flags);
 	clear_bit(PG_error, &page->flags);
+	set_bit(PG_referenced, &page->flags);
 	/*
 	 * Allocate async buffer heads pointing to this page, just for I/O.
 	 * They do _not_ show up in the buffer hash table!

Andrea Arcangeli

--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#14 lore raw

Re: [patch] new-vm improvement [Re: 2.2.0 Bug summary]

Quoted 2 lines · Andrea Arcangeli

is the swapout smart weight code. Basing the priority on the number of process to try to swapout was really ugly and not smart.

But I done two mistakes in it. Benjamin pointed out after one msec that there was no need for putting the address on the stack, and looking a _bit_ more at swap_out_pmd() I noticed that the old code was just updating swap_address, woops ;).

I noticed the second very more important mistakes running at 8Mbyte because the trashing memory proggy was segfaulting. The bug was to base the maximal weight of swap_out() on the total_rss and not on the sum of the total_vm of all processes. With 8Mbyte all my processes got swapped out and so swap_out stopped working ;). It's fixed now...

Quoted 3 lines

The second change is done over shrink_mmap(), this will cause shrink_mmap() to care very more about aging. We have only one bit and we must use it carefully to get not out of cache ;)

This change is pretty buggy too. The only good thing was to not care about the pgcache min limits before to shrink the _swap_cache_. Now I also changed pgcache_under_min to don't care about the swapcache size (now the swap cache is a bit more fast-variable/crazy).

Quoted 3 lines

I also added/removed some PG_referenced. But please, don't trust too much the pg_refernced changes since I have not thought about it too much (maybe they are not needed?).

Hmm I guess at least the brw_page set_bit was not needed because before to run such function is been run or a __find_page() or an add_to_...cache().

Quoted 2 lines

Ah and woops, in the last patch I do a mistake and I forget to change max_cnt to unsigned long. This should be changed also in your tree, Linus.

Also some count should be moved from int to unsigned long to handle huge RAM sizes.

Quoted 2 lines

This new patch seems to really rocks here and seems _far_ better than anything I tried before! Steve, could try it and feedback? Thanks ;)

Here Steve's feedback:

                      128MB       8MB
                      -------     -------
Your previous patch:  132 sec     218 sec
This patch         :  118 sec     226 sec       

Even if `This patch' was pretty buggy (as pointed out above) it was going sligtly _faster_. I guess the reason for the 8Mbyte slowdown was the s/rss/total_vm/ thing (but I am not 100% sure).

I fixed the bugs and so I repost the fixed diff against pre4. I also cleaned up a bit some thing...

Index: linux/include/linux/mm.h

include/linux/mm.h renamed from include/linux/mm.h:1.1.1.3 +3 -5
diff -u linux/include/linux/mm.h:1.1.1.3 linux/include/linux/mm.h:1.1.1.1.2.12
@@ -118,7 +118,6 @@
 	unsigned long offset;
 	struct page *next_hash;
 	atomic_t count;
-	unsigned int unused;
 	unsigned long flags;	/* atomic flags, some possibly updated asynchronously */
 	struct wait_queue *wait;
 	struct page **pprev_hash;
@@ -295,8 +294,7 @@
 
 /* filemap.c */
 extern void remove_inode_page(struct page *);
-extern unsigned long page_unuse(struct page *);
-extern int shrink_mmap(int, int);
+extern int FASTCALL(shrink_mmap(int, int));
 extern void truncate_inode_pages(struct inode *, unsigned long);
 extern unsigned long get_cached_page(struct inode *, unsigned long, int);
 extern void put_cached_page(unsigned long);
@@ -379,8 +377,8 @@
 
 #define buffer_under_min()	((buffermem >> PAGE_SHIFT) * 100 < \
 				buffer_mem.min_percent * num_physpages)
-#define pgcache_under_min()	(page_cache_size * 100 < \
-				page_cache.min_percent * num_physpages)
+#define pgcache_under_min()	((page_cache_size-swapper_inode.i_nrpages)*100\
+				< page_cache.min_percent * num_physpages)
 
 #endif /* __KERNEL__ */
 

Index: linux/include/linux/pagemap.h

include/linux/pagemap.h renamed from include/linux/pagemap.h:1.1.1.1 +1 -0
diff -u linux/include/linux/pagemap.h:1.1.1.1 linux/include/linux/pagemap.h:1.1.1.1.2.1
@@ -77,6 +77,7 @@
 		*page->pprev_hash = page->next_hash;
 		page->pprev_hash = NULL;
 	}
+	clear_bit(PG_referenced, &page->flags);
 	page_cache_size--;
 }
 

Index: linux/mm/filemap.c

mm/filemap.c renamed from mm/filemap.c:1.1.1.8 +6 -5
diff -u linux/mm/filemap.c:1.1.1.8 linux/mm/filemap.c:1.1.1.1.2.36
@@ -122,13 +126,14 @@
 {
 	static unsigned long clock = 0;
 	unsigned long limit = num_physpages;
+	unsigned long count;
 	struct page * page;
-	int count;
 
 	count = limit >> priority;
 
 	page = mem_map + clock;
-	do {
+	while (count != 0)
+	{
 		page++;
 		clock++;
 		if (clock >= max_mapnr) {
@@ -167,17 +172,17 @@
 
 		/* is it a swap-cache or page-cache page? */
 		if (page->inode) {
-			if (pgcache_under_min())
-				continue;
 			if (PageSwapCache(page)) {
 				delete_from_swap_cache(page);
 				return 1;
 			}
+			if (pgcache_under_min())
+				continue;
 			remove_inode_page(page);
 			return 1;
 		}
 
-	} while (count > 0);
+	}
 	return 0;
 }
 

Index: linux/mm/swap.c

mm/swap.c renamed from mm/swap.c:1.1.1.5 +2 -2
diff -u linux/mm/swap.c:1.1.1.5 linux/mm/swap.c:1.1.1.1.2.8
@@ -64,13 +64,13 @@
 swapstat_t swapstats = {0};
 
 buffer_mem_t buffer_mem = {
-	2,	/* minimum percent buffer */
+	5,	/* minimum percent buffer */
 	10,	/* borrow percent buffer */
 	60	/* maximum percent buffer */
 };
 
 buffer_mem_t page_cache = {
-	2,	/* minimum percent page cache */
+	5,	/* minimum percent page cache */
 	15,	/* borrow percent page cache */
 	75	/* maximum */
 };

Index: linux/mm/vmscan.c

mm/vmscan.c renamed from mm/vmscan.c:1.1.1.9 +114 -79

359 lines not on this page · raw message

As usual if you Steve or other will try this I am interested about numbers ;). Thanks.

Andrea Arcangeli

--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#15 lore raw

PATCH 1/1 arca-vm-6, killed kswapd [Re: [patch] new-vm improvement , [Re: 2.2.0 Bug summary]]

I have a new revolutionary patch. The main thing is that I killed kswapd just to make Rik happy ;).

Ah and my last patches had a little bug that was sure hurting performances against Linus's VM since I was stopping kswapd when nr_free_pages > freepages.high was true and not as right Linus was doing when nr_free_pages > freepages.high + swap_cluster. So I was causing a lot of kswapd wakeup.

There was also a not improved thing in the trashing_memory heuristic, that is to remove the trashing bit only if PF_MEMALLOC is not set.

Ah and the swapout code seems to like a linear and not exponential priority handling. Probably it likes more to succeed than shrink_mmap().

If you'll try it let me know. I am interested about the image load test (that should be the most near to the real world).

With this patch the swapout performances are doubled. The swapout benchmark that was used to take 100 sec with my old code and with Linus's VM, now run in 50sec! Now I go to 6Mbyte at sec (3so and 3si) instead of 3Mbyte sec (1.5so, 1.5si). 6mbyte/sec is the performance reported by hdparm -t btw ;). And all the system is perfectly fluid (far more fuild than with the old code). I open an xterm without wait seconds. The cache get not kiked out. It seems really great here. When the system goes OOM it seems to recover fine.

Here arca-vm-6 against 2.2.0-pre4:

Index: linux/mm/vmscan.c

mm/vmscan.c renamed from mm/vmscan.c:1.1.1.9 +94 -227
diff -u linux/mm/vmscan.c:1.1.1.9 linux/mm/vmscan.c:1.1.1.1.2.62
@@ -10,6 +10,12 @@
  *  Version: $Id: vmscan.c,v 1.5 1998/02/23 22:14:28 sct Exp $
  */
 
+/*
+ * Revisioned the page freeing algorithm (do_free_user_and_cache), and
+ * developed a smart mechanism to handle the swapout weight. Removed kswapd.
+ * Copyright (C) 1998  Andrea Arcangeli
+ */
+
 #include <linux/slab.h>
 #include <linux/kernel_stat.h>
 #include <linux/swap.h>
@@ -20,13 +26,6 @@
 
 #include <asm/pgtable.h>
 
-/* 
- * The wait queue for waking up the pageout daemon:
- */
-static struct task_struct * kswapd_task = NULL;
-
-static void init_swap_timer(void);
-
 /*
  * The swap-out functions return 1 if they successfully
  * threw something out, and we got a free page. It returns
@@ -163,7 +162,7 @@
 			 * cache. */
 			if (PageSwapCache(page_map)) {
 				__free_page(page_map);
-				return (atomic_read(&page_map->count) == 0);
+				return 1;
 			}
 			add_to_swap_cache(page_map, entry);
 			/* We checked we were unlocked way up above, and we
@@ -195,7 +194,7 @@
 		flush_tlb_page(vma, address);
 		swap_duplicate(entry);
 		__free_page(page_map);
-		return (atomic_read(&page_map->count) == 0);
+		return 1;
 	} 
 	/* 
 	 * A clean page to be discarded?  Must be mmap()ed from
@@ -210,9 +209,8 @@
 	flush_cache_page(vma, address);
 	pte_clear(page_table);
 	flush_tlb_page(vma, address);
-	entry = (atomic_read(&page_map->count) == 1);
 	__free_page(page_map);
-	return entry;
+	return 1;
 }
 
 /*
@@ -230,7 +228,7 @@
  */
 
 static inline int swap_out_pmd(struct task_struct * tsk, struct vm_area_struct * vma,
-	pmd_t *dir, unsigned long address, unsigned long end, int gfp_mask)
+	pmd_t *dir, unsigned long address, unsigned long end, int gfp_mask, unsigned long * counter)
 {
 	pte_t * pte;
 	unsigned long pmd_end;
@@ -251,18 +249,20 @@
 
 	do {
 		int result;
-		tsk->swap_address = address + PAGE_SIZE;
 		result = try_to_swap_out(tsk, vma, address, pte, gfp_mask);
+		address += PAGE_SIZE;
+		tsk->swap_address = address;
 		if (result)
 			return result;
-		address += PAGE_SIZE;
+		if (!--*counter)
+			return 0;
 		pte++;
 	} while (address < end);
 	return 0;
 }
 
 static inline int swap_out_pgd(struct task_struct * tsk, struct vm_area_struct * vma,
-	pgd_t *dir, unsigned long address, unsigned long end, int gfp_mask)
+	pgd_t *dir, unsigned long address, unsigned long end, int gfp_mask, unsigned long * counter)
 {
 	pmd_t * pmd;
 	unsigned long pgd_end;
@@ -282,9 +282,11 @@
 		end = pgd_end;
 	
 	do {
-		int result = swap_out_pmd(tsk, vma, pmd, address, end, gfp_mask);
+		int result = swap_out_pmd(tsk, vma, pmd, address, end, gfp_mask, counter);
 		if (result)
 			return result;
+		if (!*counter)
+			return 0;
 		address = (address + PMD_SIZE) & PMD_MASK;
 		pmd++;
 	} while (address < end);
@@ -292,7 +294,7 @@
 }
 
 static int swap_out_vma(struct task_struct * tsk, struct vm_area_struct * vma,
-	unsigned long address, int gfp_mask)
+	unsigned long address, int gfp_mask, unsigned long * counter)
 {
 	pgd_t *pgdir;
 	unsigned long end;
@@ -306,16 +308,19 @@
 
 	end = vma->vm_end;
 	while (address < end) {
-		int result = swap_out_pgd(tsk, vma, pgdir, address, end, gfp_mask);
+		int result = swap_out_pgd(tsk, vma, pgdir, address, end, gfp_mask, counter);
 		if (result)
 			return result;
+		if (!*counter)
+			return 0;
 		address = (address + PGDIR_SIZE) & PGDIR_MASK;
 		pgdir++;
 	}
 	return 0;
 }
 
-static int swap_out_process(struct task_struct * p, int gfp_mask)
+static int swap_out_process(struct task_struct * p, int gfp_mask,
+			    unsigned long * counter)
 {
 	unsigned long address;
 	struct vm_area_struct* vma;
@@ -334,9 +339,12 @@
 			address = vma->vm_start;
 
 		for (;;) {
-			int result = swap_out_vma(p, vma, address, gfp_mask);
+			int result = swap_out_vma(p, vma, address, gfp_mask,
+						  counter);
 			if (result)
 				return result;
+			if (!*counter)
+				return 0;
 			vma = vma->vm_next;
 			if (!vma)
 				break;
@@ -350,6 +358,25 @@
 	return 0;
 }
 
+static inline unsigned long calc_swapout_weight(int priority)
+{
+	struct task_struct * p;
+	unsigned long total_vm = 0;
+
+	read_lock(&tasklist_lock);
+	for_each_task(p)
+	{
+		if (!p->swappable)
+			continue;
+		if (p->mm->rss == 0)
+			continue;
+		total_vm += p->mm->total_vm;
+	}
+	read_unlock(&tasklist_lock);
+
+	return total_vm / (priority+1);
+}
+
 /*
  * Select the task with maximal swap_cnt and try to swap out a page.
  * N.B. This function returns only 0 or 1.  Return values != 1 from
@@ -358,8 +385,11 @@
 static int swap_out(unsigned int priority, int gfp_mask)
 {
 	struct task_struct * p, * pbest;
-	int counter, assign, max_cnt;
+	int assign;
+	unsigned long counter, max_cnt;
 
+	counter = calc_swapout_weight(priority);
+
 	/* 
 	 * We make one or two passes through the task list, indexed by 
 	 * assign = {0, 1}:
@@ -374,23 +404,17 @@
 	 * Think of swap_cnt as a "shadow rss" - it tells us which process
 	 * we want to page out (always try largest first).
 	 */
-	counter = nr_tasks / (priority+1);
-	if (counter < 1)
-		counter = 1;
-	if (counter > nr_tasks)
-		counter = nr_tasks;
-
-	for (; counter >= 0; counter--) {
+	while (counter != 0) {
 		assign = 0;
 		max_cnt = 0;
 		pbest = NULL;
 	select:
 		read_lock(&tasklist_lock);
-		p = init_task.next_task;
-		for (; p != &init_task; p = p->next_task) {
+		for_each_task(p)
+		{
 			if (!p->swappable)
 				continue;
-	 		if (p->mm->rss <= 0)
+	 		if (p->mm->rss == 0)
 				continue;
 			/* Refresh swap_cnt? */
 			if (assign)
@@ -410,127 +434,51 @@
 		}
 
 		/*
-		 * Nonzero means we cleared out something, but only "1" means
-		 * that we actually free'd up a page as a result.
+		 * Nonzero means we cleared out something, and "1" means
+		 * that we actually moved a page from the process memory
+		 * to the swap cache (it's not been freed yet).
 		 */
-		if (swap_out_process(pbest, gfp_mask) == 1)
+		if (swap_out_process(pbest, gfp_mask, &counter))
 			return 1;
 	}
 out:
 	return 0;
 }
 
-/*
- * Before we start the kernel thread, print out the 
- * kswapd initialization message (otherwise the init message 
- * may be printed in the middle of another driver's init 
- * message).  It looks very bad when that happens.
- */
-void __init kswapd_setup(void)
+static int do_free_user_and_cache(int priority, int gfp_mask)
 {
-       int i;
-       char *revision="$Revision: 1.5 $", *s, *e;
+	if (shrink_mmap(priority, gfp_mask))
+		return 1;
 
-       swap_setup();
-       
-       if ((s = strchr(revision, ':')) &&
-           (e = strchr(s, '$')))
-               s++, i = e - s;
-       else
-               s = revision, i = -1;
-       printk ("Starting kswapd v%.*s\n", i, s);
-}
-
-#define free_memory(fn) \
-	count++; do { if (!--count) goto done; } while (fn)
-
-static int kswapd_free_pages(int kswapd_state)
-{
-	unsigned long end_time;
-
-	/* Always trim SLAB caches when memory gets low. */
-	kmem_cache_reap(0);
-
-	/* max one hundreth of a second */
-	end_time = jiffies + (HZ-1)/100;
-	do {
-		int priority = 8;
-		int count = pager_daemon.swap_cluster;
+	if (swap_out(priority, gfp_mask & ~__GFP_WAIT))
+		/*
+		 * We done at least some swapping progress so return 1 in
+		 * this case. -arca
+		 */
+		return 1;
 
-		switch (kswapd_state) {
-			do {
-			default:
-				free_memory(shrink_mmap(priority, 0));
-				free_memory(swap_out(priority, 0));
-				kswapd_state++;
-			case 1:
-				free_memory(shm_swap(priority, 0));
-				shrink_dcache_memory(priority, 0);
-				kswapd_state = 0;
-			} while (--priority >= 0);
-			return kswapd_state;
-		}
-done:
-		if (nr_free_pages > freepages.high + pager_daemon.swap_cluster)
-			break;
-	} while (time_before_eq(jiffies,end_time));
-	return kswapd_state;
+	return 0;
 }
 
-/*
- * The background pageout daemon.
- * Started as a kernel thread from the init process.
- */
-int kswapd(void *unused)
+static int do_free_page(int * state, int gfp_mask)
 {
-	current->session = 1;
-	current->pgrp = 1;
-	strcpy(current->comm, "kswapd");
-	sigfillset(&current->blocked);
-	
-	/*
-	 *	As a kernel thread we want to tamper with system buffers
-	 *	and other internals and thus be subject to the SMP locking
-	 *	rules. (On a uniprocessor box this does nothing).
-	 */
-	lock_kernel();
+	int priority = 6;
 
-	/*
-	 * Set the base priority to something smaller than a
-	 * regular process. We will scale up the priority
-	 * dynamically depending on how much memory we need.
-	 */
-	current->priority = (DEF_PRIORITY * 2) / 3;
-
-	/*
-	 * Tell the memory management that we're a "memory allocator",
-	 * and that if we need more memory we should get access to it
-	 * regardless (see "try_to_free_pages()"). "kswapd" should
-	 * never get caught in the normal page freeing logic.
-	 *
-	 * (Kswapd normally doesn't need memory anyway, but sometimes
-	 * you need a small amount of memory in order to be able to
-	 * page out something else, and this flag essentially protects
-	 * us from recursively trying to free more memory as we're
-	 * trying to free the first piece of memory in the first place).
-	 */
-	current->flags |= PF_MEMALLOC;
+	switch (*state) {
+		do {
+		case 0:
+			if (do_free_user_and_cache(priority, gfp_mask))
+				return 1;
+			*state = 1;
+		case 1:
+			if (shm_swap(priority, gfp_mask))
+				return 1;
+			*state = 0;
 
-	init_swap_timer();
-	kswapd_task = current;
-	while (1) {
-		int state = 0;
-
-		current->state = TASK_INTERRUPTIBLE;
-		flush_signals(current);
-		run_task_queue(&tq_disk);
-		schedule();
-		swapstats.wakeups++;
-		state = kswapd_free_pages(state);
+			shrink_dcache_memory(priority, gfp_mask);
+			kmem_cache_reap(gfp_mask);
+		} while (--priority >= 0);
 	}
-	/* As if we could ever get here - maybe we want to make this killable */
-	kswapd_task = NULL;
-	unlock_kernel();
 	return 0;
 }
 
@@ -543,107 +491,26 @@
  * if we need more memory as part of a swap-out effort we
  * will just silently return "success" to tell the page
  * allocator to accept the allocation.
- *
- * We want to try to free "count" pages, and we need to 
- * cluster them so that we get good swap-out behaviour. See
- * the "free_memory()" macro for details.
  */
 int try_to_free_pages(unsigned int gfp_mask, int count)
 {
-	int retval;
-
+	int retval = 1;
 	lock_kernel();
 
-	/* Always trim SLAB caches when memory gets low. */
-	kmem_cache_reap(gfp_mask);
-
-	retval = 1;
 	if (!(current->flags & PF_MEMALLOC)) {
-		int priority;
-
 		current->flags |= PF_MEMALLOC;
-	
-		priority = 8;
-		do {
-			free_memory(shrink_mmap(priority, gfp_mask));
-			free_memory(shm_swap(priority, gfp_mask));
-			free_memory(swap_out(priority, gfp_mask));
-			shrink_dcache_memory(priority, gfp_mask);
-		} while (--priority >= 0);
-		retval = 0;
-done:
+		while (count--)
+		{
+			static int state = 0;
+			if (!do_free_page(&state, gfp_mask))
+			{
+				retval = 0;
+				break;
+			}
+		}
 		current->flags &= ~PF_MEMALLOC;
 	}
 	unlock_kernel();
 
 	return retval;
-}
-
-/*
- * Wake up kswapd according to the priority
- *	0 - no wakeup
- *	1 - wake up as a low-priority process
- *	2 - wake up as a normal process
- *	3 - wake up as an almost real-time process
- *
- * This plays mind-games with the "goodness()"
- * function in kernel/sched.c.
- */
-static inline void kswapd_wakeup(struct task_struct *p, int priority)
-{
-	if (priority) {
-		p->counter = p->priority << priority;
-		wake_up_process(p);
-	}
-}
-
-/* 
- * The swap_tick function gets called on every clock tick.
- */
-void swap_tick(void)
-{
-	struct task_struct *p = kswapd_task;
-
-	/*
-	 * Only bother to try to wake kswapd up
-	 * if the task exists and can be woken.
-	 */
-	if (p && (p->state & TASK_INTERRUPTIBLE)) {
-		unsigned int pages;
-		int want_wakeup;
-
-		/*
-		 * Schedule for wakeup if there isn't lots
-		 * of free memory or if there is too much
-		 * of it used for buffers or pgcache.
-		 *
-		 * "want_wakeup" is our priority: 0 means
-		 * not to wake anything up, while 3 means
-		 * that we'd better give kswapd a realtime
-		 * priority.
-		 */
-		want_wakeup = 0;
-		pages = nr_free_pages;
-		if (pages < freepages.high)
-			want_wakeup = 1;
-		if (pages < freepages.low)
-			want_wakeup = 2;
-		if (pages < freepages.min)
-			want_wakeup = 3;
-	
-		kswapd_wakeup(p,want_wakeup);
-	}
-
-	timer_active |= (1<<SWAP_TIMER);
-}
-
-/* 
- * Initialise the swap timer
- */
-
-void init_swap_timer(void)
-{
-	timer_table[SWAP_TIMER].expires = jiffies;
-	timer_table[SWAP_TIMER].fn = swap_tick;
-	timer_active |= (1<<SWAP_TIMER);
 }

Index: linux/mm/page_alloc.c

mm/page_alloc.c renamed from mm/page_alloc.c:1.1.1.5 +3 -2
diff -u linux/mm/page_alloc.c:1.1.1.5 linux/mm/page_alloc.c:1.1.1.1.2.14
@@ -260,7 +260,8 @@
 		if (nr_free_pages > freepages.min) {
 			if (!current->trashing_memory)
 				goto ok_to_allocate;
-			if (nr_free_pages > freepages.low) {
+			if (!(current->flags & PF_MEMALLOC) &&
+			    nr_free_pages > freepages.low) {
 				current->trashing_memory = 0;
 				goto ok_to_allocate;
 			}
@@ -271,7 +272,7 @@
 		 * memory.
 		 */
 		current->trashing_memory = 1;
-		if (!try_to_free_pages(gfp_mask, SWAP_CLUSTER_MAX) && !(gfp_mask & (__GFP_MED | __GFP_HIGH)))
+		if (!try_to_free_pages(gfp_mask, freepages.high - nr_free_pages + 1<<order) && !(gfp_mask & (__GFP_MED | __GFP_HIGH)))
 			goto nopage;
 	}
 ok_to_allocate:

Index: linux/init/main.c

init/main.c renamed from init/main.c:1.1.1.5 +0 -5
diff -u linux/init/main.c:1.1.1.5 linux/init/main.c:1.1.1.1.2.9
@@ -63,8 +63,6 @@
 
 static int init(void *);
 extern int bdflush(void *);
-extern int kswapd(void *);
-extern void kswapd_setup(void);
 
 extern void init_IRQ(void);
 extern void init_modules(void);
@@ -1269,9 +1267,6 @@
 
 	/* Launch bdflush from here, instead of the old syscall way. */
 	kernel_thread(bdflush, NULL, CLONE_FS | CLONE_FILES | CLONE_SIGHAND);
-	/* Start the background pageout daemon. */
-	kswapd_setup();
-	kernel_thread(kswapd, NULL, CLONE_FS | CLONE_FILES | CLONE_SIGHAND);
 
 #if CONFIG_AP1000
 	/* Start the async paging daemon. */

Index: linux/include/linux/mm.h

include/linux/mm.h renamed from include/linux/mm.h:1.1.1.3 +1 -3
diff -u linux/include/linux/mm.h:1.1.1.3 linux/include/linux/mm.h:1.1.1.1.2.13
@@ -118,7 +118,6 @@
 	unsigned long offset;
 	struct page *next_hash;
 	atomic_t count;
-	unsigned int unused;
 	unsigned long flags;	/* atomic flags, some possibly updated asynchronously */
 	struct wait_queue *wait;
 	struct page **pprev_hash;
@@ -295,8 +294,7 @@
 
 /* filemap.c */
 extern void remove_inode_page(struct page *);
-extern unsigned long page_unuse(struct page *);
-extern int shrink_mmap(int, int);
+extern int FASTCALL(shrink_mmap(int, int));
 extern void truncate_inode_pages(struct inode *, unsigned long);
 extern unsigned long get_cached_page(struct inode *, unsigned long, int);
 extern void put_cached_page(unsigned long);

Index: linux/mm/swap.c

mm/swap.c renamed from mm/swap.c:1.1.1.5 +2 -2
diff -u linux/mm/swap.c:1.1.1.5 linux/mm/swap.c:1.1.1.1.2.8
@@ -64,13 +64,13 @@
 swapstat_t swapstats = {0};
 
 buffer_mem_t buffer_mem = {
-	2,	/* minimum percent buffer */
+	5,	/* minimum percent buffer */
 	10,	/* borrow percent buffer */
 	60	/* maximum percent buffer */
 };
 
 buffer_mem_t page_cache = {
-	2,	/* minimum percent page cache */
+	5,	/* minimum percent page cache */
 	15,	/* borrow percent page cache */
 	75	/* maximum */
 };

Index: linux/include/linux/swap.h

include/linux/swap.h renamed from include/linux/swap.h:1.1.1.4 +2 -0
diff -u linux/include/linux/swap.h:1.1.1.4 linux/include/linux/swap.h:1.1.1.1.2.9
@@ -167,9 +167,11 @@
 	count = atomic_read(&page->count);
 	if (PageSwapCache(page))
 	{
+#if 0
 		/* PARANOID */
 		if (page->inode != &swapper_inode)
 			panic("swap cache page has wrong inode\n");
+#endif
 		count += swap_count(page->offset) - 2;
 	}
 	if (PageFreeAfter(page))

--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#16 lore raw

Re: [patch] arca-vm-6, killed kswapd [Re: [patch] new-vm improvement , [Re: 2.2.0 Bug summary]]

Quoted 3 lines · Andrea Arcangeli

I have a new revolutionary patch. The main thing is that I killed kswapd just to make Rik happy ;).

Ehh..

You may have made Rik happy, but you totally missed the reason for kswapd. And while your patch looked interesting (a lot cleaner than the previous ones, and I _like_ patches that remove code), the fact that you killed kswapd means that it is essentially useless.

Basically, we _have_ to have kswapd, and I'll tell you why:
- imagine running low on memory due to GFP_ATOMIC
- imagine not having any normal processes that do memory alloction.

Boom. You just killed the machine with your patch, because maybe the GPF_ATOMIC things are what the machine is doing. Imagine a machine that acts as a router - it might not even be running any normal user processes at _all_, but it had damn well better make sure that memory is always available some way. "kswapd" did that for us, and Rik's happiness counts as nothing in face of basic facts of life like that. Sorry.

Linus

--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#17 lore raw

Re: [patch] arca-vm-6, killed kswapd [Re: [patch] new-vm improvement , [Re: 2.2.0 Bug summary]]

Quoted 6 lines

Boom. You just killed the machine with your patch, because maybe the GPF_ATOMIC things are what the machine is doing. Imagine a machine that acts as a router - it might not even be running any normal user processes at _all_, but it had damn well better make sure that memory is always available some way. "kswapd" did that for us, and Rik's happiness counts as nothing in face of basic facts of life like that. Sorry.

Its performance properties are very interesting however. They do seem to suggest kswapd should be more of a last resort.

Alan

--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#18 lore raw

Re: [patch] arca-vm-6, killed kswapd [Re: [patch] new-vm improvement , [Re: 2.2.0 Bug summary]]

Quoted 9 lines · Alan Cox
Quoted 6 lines

Boom. You just killed the machine with your patch, because maybe the GPF_ATOMIC things are what the machine is doing. Imagine a machine that acts as a router - it might not even be running any normal user processes at _all_, but it had damn well better make sure that memory is always available some way. "kswapd" did that for us, and Rik's happiness counts as nothing in face of basic facts of life like that. Sorry.

Its performance properties are very interesting however. They do seem to suggest kswapd should be more of a last resort.

Agreed, I found that interesting too. The solution may just be to make kswapd run a lot less often rather than removing it - for the machine-killing out-of-memory situation it doesn't matter if kswapd runs just a few times a second or something like that.

However, one of the things I found so appealing with the patch was the fact that it removed a lot of code, and that wouldn't be true for something that just changed kswapd to run less often. Oh, well.

Linus

--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#19 lore raw

Re: [patch] arca-vm-6, killed kswapd [Re: [patch] new-vm improvement , [Re: 2.2.0 Bug summary]]

Quoted 3 lines · Linus Torvalds

However, one of the things I found so appealing with the patch was the fact that it removed a lot of code, and that wouldn't be true for something that just changed kswapd to run less often. Oh, well.

We can still remove the dynamic prio thing and the run-one-jiffy-and-schedule thing since we don't need to give swapout performances via kswapd anymore allowing the process to swapout async and take credits from the bank some time after...

We can more simply schedule() if need_resched is set inside the kswapd engine.

I am going to do something like that right now...

Andrea Arcangeli

--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#20 lore raw

Re: [patch] arca-vm-6, killed kswapd [Re: [patch] new-vm improvement , [Re: 2.2.0 Bug summary]]

Quoted 1 line · Andrea Arcangeli

I am going to do something like that right now...

Here a new patch (arca-vm-7). It pratically removes kswapd for all places except the ATOMIC memory allocation if there aren't process that are just freeing memory.

It returns also to the stock/arca-vm-3 shrink_mmap() (even if it seems slower).

Index: linux/mm/vmscan.c

mm/vmscan.c renamed from mm/vmscan.c:1.1.1.9 +133 -151
diff -u linux/mm/vmscan.c:1.1.1.9 linux/mm/vmscan.c:1.1.1.1.2.64
@@ -10,6 +10,14 @@
  *  Version: $Id: vmscan.c,v 1.5 1998/02/23 22:14:28 sct Exp $
  */
 
+/*
+ * Developed the balanced page freeing algorithm (do_free_user_and_cache).
+ * Developed a smart mechanism to handle the swapout weight.
+ * Allowed the process to swapout async and only then get the credit from
+ * the bank. This has doubled swapout performances and fluidness.
+ * Copyright (C) 1998  Andrea Arcangeli
+ */
+
 #include <linux/slab.h>
 #include <linux/kernel_stat.h>
 #include <linux/swap.h>
@@ -21,12 +29,15 @@
 #include <asm/pgtable.h>
 
 /* 
+ * When are we next due for a page scan? 
+ */
+static atomic_t nr_tasks_freeing_memory = ATOMIC_INIT(0);
+
+/* 
  * The wait queue for waking up the pageout daemon:
  */
 static struct task_struct * kswapd_task = NULL;
 
-static void init_swap_timer(void);
-
 /*
  * The swap-out functions return 1 if they successfully
  * threw something out, and we got a free page. It returns
@@ -163,7 +174,7 @@
 			 * cache. */
 			if (PageSwapCache(page_map)) {
 				__free_page(page_map);
-				return (atomic_read(&page_map->count) == 0);
+				return 1;
 			}
 			add_to_swap_cache(page_map, entry);
 			/* We checked we were unlocked way up above, and we
@@ -195,7 +206,7 @@
 		flush_tlb_page(vma, address);
 		swap_duplicate(entry);
 		__free_page(page_map);
-		return (atomic_read(&page_map->count) == 0);
+		return 1;
 	} 
 	/* 
 	 * A clean page to be discarded?  Must be mmap()ed from
@@ -210,9 +221,8 @@
 	flush_cache_page(vma, address);
 	pte_clear(page_table);
 	flush_tlb_page(vma, address);
-	entry = (atomic_read(&page_map->count) == 1);
 	__free_page(page_map);
-	return entry;
+	return 1;
 }
 
 /*
@@ -230,7 +240,7 @@
  */
 
 static inline int swap_out_pmd(struct task_struct * tsk, struct vm_area_struct * vma,
-	pmd_t *dir, unsigned long address, unsigned long end, int gfp_mask)
+	pmd_t *dir, unsigned long address, unsigned long end, int gfp_mask, unsigned long * counter)
 {
 	pte_t * pte;
 	unsigned long pmd_end;
@@ -251,18 +261,20 @@
 
 	do {
 		int result;
-		tsk->swap_address = address + PAGE_SIZE;
 		result = try_to_swap_out(tsk, vma, address, pte, gfp_mask);
+		address += PAGE_SIZE;
+		tsk->swap_address = address;
 		if (result)
 			return result;
-		address += PAGE_SIZE;
+		if (!--*counter)
+			return 0;
 		pte++;
 	} while (address < end);
 	return 0;
 }
 
 static inline int swap_out_pgd(struct task_struct * tsk, struct vm_area_struct * vma,
-	pgd_t *dir, unsigned long address, unsigned long end, int gfp_mask)
+	pgd_t *dir, unsigned long address, unsigned long end, int gfp_mask, unsigned long * counter)
 {
 	pmd_t * pmd;
 	unsigned long pgd_end;
@@ -282,9 +294,11 @@
 		end = pgd_end;
 	
 	do {
-		int result = swap_out_pmd(tsk, vma, pmd, address, end, gfp_mask);
+		int result = swap_out_pmd(tsk, vma, pmd, address, end, gfp_mask, counter);
 		if (result)
 			return result;
+		if (!*counter)
+			return 0;
 		address = (address + PMD_SIZE) & PMD_MASK;
 		pmd++;
 	} while (address < end);
@@ -292,7 +306,7 @@
 }
 
 static int swap_out_vma(struct task_struct * tsk, struct vm_area_struct * vma,
-	unsigned long address, int gfp_mask)
+	unsigned long address, int gfp_mask, unsigned long * counter)
 {
 	pgd_t *pgdir;
 	unsigned long end;
@@ -306,16 +320,19 @@
 
 	end = vma->vm_end;
 	while (address < end) {
-		int result = swap_out_pgd(tsk, vma, pgdir, address, end, gfp_mask);
+		int result = swap_out_pgd(tsk, vma, pgdir, address, end, gfp_mask, counter);
 		if (result)
 			return result;
+		if (!*counter)
+			return 0;
 		address = (address + PGDIR_SIZE) & PGDIR_MASK;
 		pgdir++;
 	}
 	return 0;
 }
 
-static int swap_out_process(struct task_struct * p, int gfp_mask)
+static int swap_out_process(struct task_struct * p, int gfp_mask,
+			    unsigned long * counter)
 {
 	unsigned long address;
 	struct vm_area_struct* vma;
@@ -334,9 +351,12 @@
 			address = vma->vm_start;
 
 		for (;;) {
-			int result = swap_out_vma(p, vma, address, gfp_mask);
+			int result = swap_out_vma(p, vma, address, gfp_mask,
+						  counter);
 			if (result)
 				return result;
+			if (!*counter)
+				return 0;
 			vma = vma->vm_next;
 			if (!vma)
 				break;
@@ -350,6 +370,25 @@
 	return 0;
 }
 
+static inline unsigned long calc_swapout_weight(int priority)
+{
+	struct task_struct * p;
+	unsigned long total_vm = 0;
+
+	read_lock(&tasklist_lock);
+	for_each_task(p)
+	{
+		if (!p->swappable)
+			continue;
+		if (p->mm->rss == 0)
+			continue;
+		total_vm += p->mm->total_vm;
+	}
+	read_unlock(&tasklist_lock);
+
+	return total_vm / (priority+1);
+}
+
 /*
  * Select the task with maximal swap_cnt and try to swap out a page.
  * N.B. This function returns only 0 or 1.  Return values != 1 from
@@ -358,7 +397,10 @@
 static int swap_out(unsigned int priority, int gfp_mask)
 {
 	struct task_struct * p, * pbest;
-	int counter, assign, max_cnt;
+	int assign;
+	unsigned long counter, max_cnt;
+
+	counter = calc_swapout_weight(priority);
 
 	/* 
 	 * We make one or two passes through the task list, indexed by 
@@ -374,23 +416,17 @@
 	 * Think of swap_cnt as a "shadow rss" - it tells us which process
 	 * we want to page out (always try largest first).
 	 */
-	counter = nr_tasks / (priority+1);
-	if (counter < 1)
-		counter = 1;
-	if (counter > nr_tasks)
-		counter = nr_tasks;
-
-	for (; counter >= 0; counter--) {
+	while (counter != 0) {
 		assign = 0;
 		max_cnt = 0;
 		pbest = NULL;
 	select:
 		read_lock(&tasklist_lock);
-		p = init_task.next_task;
-		for (; p != &init_task; p = p->next_task) {
+		for_each_task(p)
+		{
 			if (!p->swappable)
 				continue;
-	 		if (p->mm->rss <= 0)
+	 		if (p->mm->rss == 0)
 				continue;
 			/* Refresh swap_cnt? */
 			if (assign)
@@ -410,10 +446,11 @@
 		}
 
 		/*
-		 * Nonzero means we cleared out something, but only "1" means
-		 * that we actually free'd up a page as a result.
+		 * Nonzero means we cleared out something, and "1" means
+		 * that we actually moved a page from the process memory
+		 * to the swap cache (it's not been freed yet).
 		 */
-		if (swap_out_process(pbest, gfp_mask) == 1)
+		if (swap_out_process(pbest, gfp_mask, &counter))
 			return 1;
 	}
 out:
@@ -441,39 +478,62 @@
        printk ("Starting kswapd v%.*s\n", i, s);
 }
 
-#define free_memory(fn) \
-	count++; do { if (!--count) goto done; } while (fn)
+static int do_free_user_and_cache(int priority, int gfp_mask)
+{
+	if (shrink_mmap(priority, gfp_mask))
+		return 1;
 
-static int kswapd_free_pages(int kswapd_state)
+	/*
+	 * NOTE: Here we allow also the process to do async swapout
+	 * because the swapout is really only a credit at the bank of
+	 * free memory right now. So we don't care to have it _now_.
+	 * Allowing async I/O we are going to improve drammatically
+	 * swapout performance -arca (discovered this afternoon ;) 980105
+	 */
+	if (swap_out(priority, gfp_mask & ~__GFP_WAIT))
+		/*
+		 * We done at least some swapping progress so return 1 in
+		 * this case. -arca
+		 */
+		return 1;
+
+	return 0;
+}
+
+static int do_free_page(int * state, int gfp_mask)
 {
-	unsigned long end_time;
+	int priority = 8;
 
-	/* Always trim SLAB caches when memory gets low. */
-	kmem_cache_reap(0);
+	switch (*state) {
+		do {
+		case 0:
+			if (do_free_user_and_cache(priority, gfp_mask))
+				return 1;
+			*state = 1;
+		case 1:
+			if (shm_swap(priority, gfp_mask))
+				return 1;
+			*state = 0;
 
-	/* max one hundreth of a second */
-	end_time = jiffies + (HZ-1)/100;
-	do {
-		int priority = 8;
-		int count = pager_daemon.swap_cluster;
+			shrink_dcache_memory(priority, gfp_mask);
+			kmem_cache_reap(gfp_mask);
+		} while (--priority >= 0);
+	}
+	return 0;
+}
 
-		switch (kswapd_state) {
-			do {
-			default:
-				free_memory(shrink_mmap(priority, 0));
-				free_memory(swap_out(priority, 0));
-				kswapd_state++;
-			case 1:
-				free_memory(shm_swap(priority, 0));
-				shrink_dcache_memory(priority, 0);
-				kswapd_state = 0;
-			} while (--priority >= 0);
-			return kswapd_state;
-		}
-done:
-		if (nr_free_pages > freepages.high + pager_daemon.swap_cluster)
+static int kswapd_free_pages(int kswapd_state)
+{
+	for(;;)
+	{
+		do_free_page(&kswapd_state, 0);
+		if (nr_free_pages > freepages.high)
+			break;
+		if (atomic_read(&nr_tasks_freeing_memory))
 			break;
-	} while (time_before_eq(jiffies,end_time));
+		if (kswapd_task->need_resched)
+			schedule();
+	};
 	return kswapd_state;
 }
 
@@ -496,13 +556,6 @@
 	lock_kernel();
 
 	/*
-	 * Set the base priority to something smaller than a
-	 * regular process. We will scale up the priority
-	 * dynamically depending on how much memory we need.
-	 */
-	current->priority = (DEF_PRIORITY * 2) / 3;
-
-	/*
 	 * Tell the memory management that we're a "memory allocator",
 	 * and that if we need more memory we should get access to it
 	 * regardless (see "try_to_free_pages()"). "kswapd" should
@@ -516,7 +569,6 @@
 	 */
 	current->flags |= PF_MEMALLOC;
 
-	init_swap_timer();
 	kswapd_task = current;
 	while (1) {
 		int state = 0;
@@ -543,107 +595,37 @@
  * if we need more memory as part of a swap-out effort we
  * will just silently return "success" to tell the page
  * allocator to accept the allocation.
- *
- * We want to try to free "count" pages, and we need to 
- * cluster them so that we get good swap-out behaviour. See
- * the "free_memory()" macro for details.
  */
 int try_to_free_pages(unsigned int gfp_mask, int count)
 {
-	int retval;
-
+	int retval = 1;
 	lock_kernel();
 
-	/* Always trim SLAB caches when memory gets low. */
-	kmem_cache_reap(gfp_mask);
-
-	retval = 1;
 	if (!(current->flags & PF_MEMALLOC)) {
-		int priority;
-
 		current->flags |= PF_MEMALLOC;
-	
-		priority = 8;
-		do {
-			free_memory(shrink_mmap(priority, gfp_mask));
-			free_memory(shm_swap(priority, gfp_mask));
-			free_memory(swap_out(priority, gfp_mask));
-			shrink_dcache_memory(priority, gfp_mask);
-		} while (--priority >= 0);
-		retval = 0;
-done:
+		atomic_inc(&nr_tasks_freeing_memory);
+		while (count--)
+		{
+			static int state = 0;
+			if (!do_free_page(&state, gfp_mask))
+			{
+				retval = 0;
+				break;
+			}
+		}
+		atomic_dec(&nr_tasks_freeing_memory);
 		current->flags &= ~PF_MEMALLOC;
 	}
 	unlock_kernel();
 
 	return retval;
 }
-
-/*
- * Wake up kswapd according to the priority
- *	0 - no wakeup
- *	1 - wake up as a low-priority process
- *	2 - wake up as a normal process
- *	3 - wake up as an almost real-time process
- *
- * This plays mind-games with the "goodness()"
- * function in kernel/sched.c.
- */
-static inline void kswapd_wakeup(struct task_struct *p, int priority)
-{
-	if (priority) {
-		p->counter = p->priority << priority;
-		wake_up_process(p);
-	}
-}
 
-/* 
- * The swap_tick function gets called on every clock tick.
- */
-void swap_tick(void)
+void kswapd_wakeup(void)
 {
-	struct task_struct *p = kswapd_task;
-
-	/*
-	 * Only bother to try to wake kswapd up
-	 * if the task exists and can be woken.
-	 */
-	if (p && (p->state & TASK_INTERRUPTIBLE)) {
-		unsigned int pages;
-		int want_wakeup;
-
-		/*
-		 * Schedule for wakeup if there isn't lots
-		 * of free memory or if there is too much
-		 * of it used for buffers or pgcache.
-		 *
-		 * "want_wakeup" is our priority: 0 means
-		 * not to wake anything up, while 3 means
-		 * that we'd better give kswapd a realtime
-		 * priority.
-		 */
-		want_wakeup = 0;
-		pages = nr_free_pages;
-		if (pages < freepages.high)
-			want_wakeup = 1;
-		if (pages < freepages.low)
-			want_wakeup = 2;
-		if (pages < freepages.min)
-			want_wakeup = 3;
-	
-		kswapd_wakeup(p,want_wakeup);
-	}
-
-	timer_active |= (1<<SWAP_TIMER);
-}
+	struct task_struct * p = kswapd_task;
 
-/* 
- * Initialise the swap timer
- */
-
-void init_swap_timer(void)
-{
-	timer_table[SWAP_TIMER].expires = jiffies;
-	timer_table[SWAP_TIMER].fn = swap_tick;
-	timer_active |= (1<<SWAP_TIMER);
+	if (p && (p->state & TASK_INTERRUPTIBLE) &&
+	    !atomic_read(&nr_tasks_freeing_memory))
+		wake_up_process(p);
 }

Index: linux/mm/page_alloc.c

mm/page_alloc.c renamed from mm/page_alloc.c:1.1.1.5 +6 -4
diff -u linux/mm/page_alloc.c:1.1.1.5 linux/mm/page_alloc.c:1.1.1.1.2.15
@@ -151,7 +151,6 @@
 	if (!PageReserved(page) && atomic_dec_and_test(&page->count)) {
 		if (PageSwapCache(page))
 			panic ("Freeing swap cache page");
-		page->flags &= ~(1 << PG_referenced);
 		free_pages_ok(page->map_nr, 0);
 		return;
 	}
@@ -173,7 +172,6 @@
 		if (atomic_dec_and_test(&map->count)) {
 			if (PageSwapCache(map))
 				panic ("Freeing swap cache pages");
-			map->flags &= ~(1 << PG_referenced);
 			free_pages_ok(map_nr, order);
 			return;
 		}
@@ -260,7 +258,8 @@
 		if (nr_free_pages > freepages.min) {
 			if (!current->trashing_memory)
 				goto ok_to_allocate;
-			if (nr_free_pages > freepages.low) {
+			if (!(current->flags & PF_MEMALLOC) &&
+			    nr_free_pages > freepages.low) {
 				current->trashing_memory = 0;
 				goto ok_to_allocate;
 			}
@@ -271,8 +270,11 @@
 		 * memory.
 		 */
 		current->trashing_memory = 1;
-		if (!try_to_free_pages(gfp_mask, SWAP_CLUSTER_MAX) && !(gfp_mask & (__GFP_MED | __GFP_HIGH)))
+		if (!try_to_free_pages(gfp_mask, freepages.high - nr_free_pages + 1<<order) && !(gfp_mask & (__GFP_MED | __GFP_HIGH)))
 			goto nopage;
+	} else {
+		if (nr_free_pages < freepages.min)
+			kswapd_wakeup();
 	}
 ok_to_allocate:
 	spin_lock_irqsave(&page_alloc_lock, flags);

Index: linux/include/linux/mm.h

include/linux/mm.h renamed from include/linux/mm.h:1.1.1.3 +1 -3
diff -u linux/include/linux/mm.h:1.1.1.3 linux/include/linux/mm.h:1.1.1.1.2.13
@@ -118,7 +118,6 @@
 	unsigned long offset;
 	struct page *next_hash;
 	atomic_t count;
-	unsigned int unused;
 	unsigned long flags;	/* atomic flags, some possibly updated asynchronously */
 	struct wait_queue *wait;
 	struct page **pprev_hash;
@@ -295,8 +294,7 @@
 
 /* filemap.c */
 extern void remove_inode_page(struct page *);
-extern unsigned long page_unuse(struct page *);
-extern int shrink_mmap(int, int);
+extern int FASTCALL(shrink_mmap(int, int));
 extern void truncate_inode_pages(struct inode *, unsigned long);
 extern unsigned long get_cached_page(struct inode *, unsigned long, int);
 extern void put_cached_page(unsigned long);

Index: linux/mm/swap.c

mm/swap.c renamed from mm/swap.c:1.1.1.5 +2 -2
diff -u linux/mm/swap.c:1.1.1.5 linux/mm/swap.c:1.1.1.1.2.8
@@ -64,13 +64,13 @@
 swapstat_t swapstats = {0};
 
 buffer_mem_t buffer_mem = {
-	2,	/* minimum percent buffer */
+	5,	/* minimum percent buffer */
 	10,	/* borrow percent buffer */
 	60	/* maximum percent buffer */
 };
 
 buffer_mem_t page_cache = {
-	2,	/* minimum percent page cache */
+	5,	/* minimum percent page cache */
 	15,	/* borrow percent page cache */
 	75	/* maximum */
 };

Index: linux/include/linux/swap.h

include/linux/swap.h renamed from include/linux/swap.h:1.1.1.4 +3 -0
diff -u linux/include/linux/swap.h:1.1.1.4 linux/include/linux/swap.h:1.1.1.1.2.10
@@ -83,6 +83,7 @@
 
 /* linux/mm/vmscan.c */
 extern int try_to_free_pages(unsigned int gfp_mask, int count);
+extern void kswapd_wakeup(void);
 
 /* linux/mm/page_io.c */
 extern void rw_swap_page(int, unsigned long, char *, int);
@@ -167,9 +168,11 @@
 	count = atomic_read(&page->count);
 	if (PageSwapCache(page))
 	{
+#if 0
 		/* PARANOID */
 		if (page->inode != &swapper_inode)
 			panic("swap cache page has wrong inode\n");
+#endif
 		count += swap_count(page->offset) - 2;
 	}
 	if (PageFreeAfter(page))

Andrea Arcangeli

--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#21 lore raw

Re: [patch] arca-vm-6, killed kswapd [Re: [patch] new-vm improvement , [Re: 2.2.0 Bug summary]]

Review

Quoted 2 lines · Andrea Arcangeli
(quoted diff) +1 -1
-		if (!try_to_free_pages(gfp_mask, SWAP_CLUSTER_MAX) && !(gfp_mask & (__GFP_MED | __GFP_HIGH)))
+		if (!try_to_free_pages(gfp_mask, freepages.high - nr_free_pages + 1<<order) && !(gfp_mask & (__GFP_MED | __GFP_HIGH)))              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

How about a pair of parentheses at a strategic place? :)

Other than that, your previous (-6?) patch really works good here.

It was once that I wanted to get rid of kswapd, too, but I thought it would surely harm performance, so I dumped the idea. Now, I'm not at all sure. :)

Keep trying!

Signature · 4 lines
Zlatko
--
This is a majordomo managed list.  To unsubscribe, send a message with
the body 'unsubscribe linux-mm me@address' to: [email protected]
#22 lore raw

Re: [patch] arca-vm-6, killed kswapd [Re: [patch] new-vm improvement , [Re: 2.2.0 Bug summary]]

In reply to Andrea Arcangeli
Quoted 8 lines · Andrea Arcangeli
Quoted 1 line · Andrea Arcangeli

I am going to do something like that right now...

Here a new patch (arca-vm-7). It pratically removes kswapd for all places except the ATOMIC memory allocation if there aren't process that are just freeing memory.

You have a bug somewhere!

At this point (output of Alt-SysRq-M), machine locked:

Jan  5 03:49:14 atlas kernel: Free pages:         512kB 
Jan  5 03:49:14 atlas kernel:  ( Free: 128 (128 256 384) 
Jan  5 03:49:14 atlas kernel: 0*4kB 0*8kB 0*16kB 0*32kB 0*64kB 4*128kB = 512kB) 

Probably you have "< instead of <=", or similar logic problem somewhere.

Bug revealed itself during "mmap-sync" run. It's a program that utilises bug with shared mappings (you used to send patches for that one, I don't know if they made it to the tree, so I check occasionally).

Other than that, VM is really fast, in fact unbelievably fast. Kswapd is very light on the CPU and interactive feel is great.

Signature · 4 lines
Zlatko
--
This is a majordomo managed list.  To unsubscribe, send a message with
the body 'unsubscribe linux-mm me@address' to: [email protected]
#23 lore raw

Re: [patch] arca-vm-6, killed kswapd [Re: [patch] new-vm improvement , [Re: 2.2.0 Bug summary]]

Quoted 1 line · Zlatko Calusic

At this point (output of Alt-SysRq-M), machine locked:

Are you been able to continue using SysRq-K?

Could you reproduce and press ALT-right+Scroll-Lock and tell me what the kernel was executing at that time...

Could you send me also the proggy for the shared-mmaps to allow me to reproduce?

Andrea Arcangeli

--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#24 lore raw

Re: [patch] arca-vm-6, killed kswapd [Re: [patch] new-vm improvement , [Re: 2.2.0 Bug summary]]

Quoted 5 lines · Andrea Arcangeli
Quoted 1 line · Zlatko Calusic

At this point (output of Alt-SysRq-M), machine locked:

Are you been able to continue using SysRq-K?

Erm... I continued with *&#&%$ Alt-SysRq-{S,U,B}.
That worked for me. :)

Quoted 4 lines

Could you reproduce and press ALT-right+Scroll-Lock and tell me what the kernel was executing at that time...

I tried few times, but to no avail. Looks like subtle race, bad news for you, unfortunately.

*BUT*, after I pressed ctrl-c against mmap-sync in one of the torture tests, the program stuck in down_failed (loadav += 2). Few minutes later machine got very unstable and I decided to reboot it. Go figure.

Quoted 3 lines

Could you send me also the proggy for the shared-mmaps to allow me to reproduce?

Sure, just be careful. :)

P.S. Apologies for too many jokes, I didn't sleep at all last night. ;)

Signature · 1 line
Zlatko
#25 lore raw

Re: [patch] arca-vm-6, killed kswapd [Re: [patch] new-vm improvement , [Re: 2.2.0 Bug summary]]

Quoted 2 lines · Zlatko Calusic

I tried few times, but to no avail. Looks like subtle race, bad news for you, unfortunately.

Hmm, I gues it's been due the wrong order shifiting you pointed out a bit before...

The lockup could be due to one oom loop. Ingo pointed out at once that raid1 (if I remeber well) has one of them. Do you use raidx?

Quoted 1 line

Sure, just be careful. :)

Don't worry ;). Could you try if you can reproduce problems with arca-vm-8?

Andrea Arcangeli

--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#26 lore raw

Re: [patch] arca-vm-6, killed kswapd [Re: [patch] new-vm improvement , [Re: 2.2.0 Bug summary]]

Quoted 7 lines · Andrea Arcangeli
Quoted 2 lines · Zlatko Calusic

I tried few times, but to no avail. Looks like subtle race, bad news for you, unfortunately.

Hmm, I gues it's been due the wrong order shifiting you pointed out a bit before...

Nope. I fixed that before compiling. :)
It's even in my PRCS tree, your patches and my parentheses. :)

linux-2.1 2204.3 Tue, 05 Jan 1999 00:15:24 +0100 by zcalusic

Parent-Version:      2204.2
Version-Log:         MM & no kswapd (andrea)

linux-2.1 2204.4 Tue, 05 Jan 1999 03:34:57 +0100 by zcalusic

Parent-Version:      2204.2
Version-Log:         arca-vm-7
Quoted 4 lines

The lockup could be due to one oom loop. Ingo pointed out at once that raid1 (if I remeber well) has one of them. Do you use raidx?

Wow, that's a new variable in a story, I'm indeed using raid0 (IDE + SCSI). That is it, then. Should I contact Ingo about that? I'm not on linux-raid, so I never heard of a problem like that, in fact it happened only yesterday I lost control of machine in such a strange way.

Quoted 5 lines
Quoted 1 line

Sure, just be careful. :)

Don't worry ;). Could you try if you can reproduce problems with arca-vm-8?

Huh, I must refuse your proposal, at least til' I get some sleep. :(

Tomorrow is non-working day, so I'll spend some time reading stuff (recently I bought Rubini's Device Drivers), and on the Thursday I'm back to regular schedule, sleepless nights and arca-vm-10, at that time, probably. :)

While at VM changes, I have one (reborn) objection. It looks like recent kernels are once again very aggressive when it comes to copying lots of data. That is, if you cp few hundred of MB's, you effectively finish with cleansed memory (populated with page cache pages) and programs are on swap. Behaviour is practicaly identical in vanilla Linus' tree and with your changes applied. Maybe you could, when you're at it, see if that problem can be solved. With such a behaviour, Linux feels very slugish, feels like a NT crap.

I know it's tough job, because I spent lots of time trying, but my conclusion is that whenever you have good swapping speed, kernel will outswap too much. On the other side if you fix that, swapping speed drops. Tough luck. :(

I wish you good luck with your work, anyway.

Signature · 4 lines
Zlatko
--
This is a majordomo managed list.  To unsubscribe, send a message with
the body 'unsubscribe linux-mm me@address' to: [email protected]
#27 lore raw

arca-vm-8 [Re: [patch] arca-vm-6, killed kswapd [Re: [patch] new-vm , improvement , [Re: 2.2.0 Bug summary]]]

In reply to Andrea Arcangeli
Quoted 1 line · Andrea Arcangeli

Here a new patch (arca-vm-7). It pratically removes kswapd for all places

I fixed some thing in arca-vm-7. This new is arca-vm-8.

The main change is the fix of the trashing_memory heuristic. Now the the free memory is always between low and high and it's left to the trashing task to take the limits uptodate. This way I can run the swapout bench and while :; do free; done, and the shell script _never_ gets blocked (as opposed to arca-vm-7 and previous).

I return to right removing the referenced flag from the freed pages since it seems to make no performance differences and it looks cleaner to me (I removed it in the last patch because I didn't benchmarked it and I worried that it was the bit that made the difference between arca-vm-3).

The new patch returns to allow the pgcache to be shrunk even if pgcache is under min. This make sense since this way shrink_mmap() is able to really_swapout more pages even if we are really low on memory.

This new patches is very more efficient than the last one. I still don't need kswapd...

Forget to tell, I moved the swapout weight to an exponential behavior... (since the new global patch it's working very better I have not compared with the linear /(priority+1) thing).

I guess the lockup that Zlatko reported is due the bug he discovered (some missing `()' ;). Thanks Zlatko. I tried a proggy that sync some shared mmap and everything is fine here...

I guess that this new code will be very better also in low memory machines than the last one...

Index: linux/mm/vmscan.c

mm/vmscan.c renamed from mm/vmscan.c:1.1.1.9 +135 -155
diff -u linux/mm/vmscan.c:1.1.1.9 linux/mm/vmscan.c:1.1.1.1.2.67
@@ -10,6 +10,14 @@
  *  Version: $Id: vmscan.c,v 1.5 1998/02/23 22:14:28 sct Exp $
  */
 
+/*
+ * Developed the balanced page freeing algorithm (do_free_user_and_cache).
+ * Developed a smart mechanism to handle the swapout weight.
+ * Allowed the process to swapout async and only then get the credit from
+ * the bank. This has doubled swapout performances and fluidness.
+ * Copyright (C) 1998  Andrea Arcangeli
+ */
+
 #include <linux/slab.h>
 #include <linux/kernel_stat.h>
 #include <linux/swap.h>
@@ -21,12 +29,15 @@
 #include <asm/pgtable.h>
 
 /* 
+ * When are we next due for a page scan? 
+ */
+static atomic_t nr_tasks_freeing_memory = ATOMIC_INIT(0);
+
+/* 
  * The wait queue for waking up the pageout daemon:
  */
 static struct task_struct * kswapd_task = NULL;
 
-static void init_swap_timer(void);
-
 /*
  * The swap-out functions return 1 if they successfully
  * threw something out, and we got a free page. It returns
@@ -163,7 +174,7 @@
 			 * cache. */
 			if (PageSwapCache(page_map)) {
 				__free_page(page_map);
-				return (atomic_read(&page_map->count) == 0);
+				return 1;
 			}
 			add_to_swap_cache(page_map, entry);
 			/* We checked we were unlocked way up above, and we
@@ -195,7 +206,7 @@
 		flush_tlb_page(vma, address);
 		swap_duplicate(entry);
 		__free_page(page_map);
-		return (atomic_read(&page_map->count) == 0);
+		return 1;
 	} 
 	/* 
 	 * A clean page to be discarded?  Must be mmap()ed from
@@ -210,9 +221,8 @@
 	flush_cache_page(vma, address);
 	pte_clear(page_table);
 	flush_tlb_page(vma, address);
-	entry = (atomic_read(&page_map->count) == 1);
 	__free_page(page_map);
-	return entry;
+	return 1;
 }
 
 /*
@@ -230,7 +240,7 @@
  */
 
 static inline int swap_out_pmd(struct task_struct * tsk, struct vm_area_struct * vma,
-	pmd_t *dir, unsigned long address, unsigned long end, int gfp_mask)
+	pmd_t *dir, unsigned long address, unsigned long end, int gfp_mask, unsigned long * counter)
 {
 	pte_t * pte;
 	unsigned long pmd_end;
@@ -251,18 +261,20 @@
 
 	do {
 		int result;
-		tsk->swap_address = address + PAGE_SIZE;
 		result = try_to_swap_out(tsk, vma, address, pte, gfp_mask);
+		address += PAGE_SIZE;
+		tsk->swap_address = address;
 		if (result)
 			return result;
-		address += PAGE_SIZE;
+		if (!--*counter)
+			return 0;
 		pte++;
 	} while (address < end);
 	return 0;
 }
 
 static inline int swap_out_pgd(struct task_struct * tsk, struct vm_area_struct * vma,
-	pgd_t *dir, unsigned long address, unsigned long end, int gfp_mask)
+	pgd_t *dir, unsigned long address, unsigned long end, int gfp_mask, unsigned long * counter)
 {
 	pmd_t * pmd;
 	unsigned long pgd_end;
@@ -282,9 +294,11 @@
 		end = pgd_end;
 	
 	do {
-		int result = swap_out_pmd(tsk, vma, pmd, address, end, gfp_mask);
+		int result = swap_out_pmd(tsk, vma, pmd, address, end, gfp_mask, counter);
 		if (result)
 			return result;
+		if (!*counter)
+			return 0;
 		address = (address + PMD_SIZE) & PMD_MASK;
 		pmd++;
 	} while (address < end);
@@ -292,7 +306,7 @@
 }
 
 static int swap_out_vma(struct task_struct * tsk, struct vm_area_struct * vma,
-	unsigned long address, int gfp_mask)
+	unsigned long address, int gfp_mask, unsigned long * counter)
 {
 	pgd_t *pgdir;
 	unsigned long end;
@@ -306,16 +320,19 @@
 
 	end = vma->vm_end;
 	while (address < end) {
-		int result = swap_out_pgd(tsk, vma, pgdir, address, end, gfp_mask);
+		int result = swap_out_pgd(tsk, vma, pgdir, address, end, gfp_mask, counter);
 		if (result)
 			return result;
+		if (!*counter)
+			return 0;
 		address = (address + PGDIR_SIZE) & PGDIR_MASK;
 		pgdir++;
 	}
 	return 0;
 }
 
-static int swap_out_process(struct task_struct * p, int gfp_mask)
+static int swap_out_process(struct task_struct * p, int gfp_mask,
+			    unsigned long * counter)
 {
 	unsigned long address;
 	struct vm_area_struct* vma;
@@ -334,9 +351,12 @@
 			address = vma->vm_start;
 
 		for (;;) {
-			int result = swap_out_vma(p, vma, address, gfp_mask);
+			int result = swap_out_vma(p, vma, address, gfp_mask,
+						  counter);
 			if (result)
 				return result;
+			if (!*counter)
+				return 0;
 			vma = vma->vm_next;
 			if (!vma)
 				break;
@@ -350,6 +370,25 @@
 	return 0;
 }
 
+static inline unsigned long calc_swapout_weight(int priority)
+{
+	struct task_struct * p;
+	unsigned long total_vm = 0;
+
+	read_lock(&tasklist_lock);
+	for_each_task(p)
+	{
+		if (!p->swappable)
+			continue;
+		if (p->mm->rss == 0)
+			continue;
+		total_vm += p->mm->total_vm;
+	}
+	read_unlock(&tasklist_lock);
+
+	return total_vm >> (priority>>1);
+}
+
 /*
  * Select the task with maximal swap_cnt and try to swap out a page.
  * N.B. This function returns only 0 or 1.  Return values != 1 from
@@ -358,7 +397,10 @@
 static int swap_out(unsigned int priority, int gfp_mask)
 {
 	struct task_struct * p, * pbest;
-	int counter, assign, max_cnt;
+	int assign;
+	unsigned long counter, max_cnt;
+
+	counter = calc_swapout_weight(priority);
 
 	/* 
 	 * We make one or two passes through the task list, indexed by 
@@ -374,23 +416,17 @@
 	 * Think of swap_cnt as a "shadow rss" - it tells us which process
 	 * we want to page out (always try largest first).
 	 */
-	counter = nr_tasks / (priority+1);
-	if (counter < 1)
-		counter = 1;
-	if (counter > nr_tasks)
-		counter = nr_tasks;
-
-	for (; counter >= 0; counter--) {
+	while (counter != 0) {
 		assign = 0;
 		max_cnt = 0;
 		pbest = NULL;
 	select:
 		read_lock(&tasklist_lock);
-		p = init_task.next_task;
-		for (; p != &init_task; p = p->next_task) {
+		for_each_task(p)
+		{
 			if (!p->swappable)
 				continue;
-	 		if (p->mm->rss <= 0)
+	 		if (p->mm->rss == 0)
 				continue;
 			/* Refresh swap_cnt? */
 			if (assign)
@@ -410,10 +446,11 @@
 		}
 
 		/*
-		 * Nonzero means we cleared out something, but only "1" means
-		 * that we actually free'd up a page as a result.
+		 * Nonzero means we cleared out something, and "1" means
+		 * that we actually moved a page from the process memory
+		 * to the swap cache (it's not been freed yet).
 		 */
-		if (swap_out_process(pbest, gfp_mask) == 1)
+		if (swap_out_process(pbest, gfp_mask, &counter))
 			return 1;
 	}
 out:
@@ -440,40 +477,63 @@
                s = revision, i = -1;
        printk ("Starting kswapd v%.*s\n", i, s);
 }
+
+static int do_free_user_and_cache(int priority, int gfp_mask)
+{
+	if (shrink_mmap(priority, gfp_mask))
+		return 1;
 
-#define free_memory(fn) \
-	count++; do { if (!--count) goto done; } while (fn)
+	/*
+	 * NOTE: Here we allow also the process to do async swapout
+	 * because the swapout is really only a credit at the bank of
+	 * free memory right now. So we don't care to have it _now_.
+	 * Allowing async I/O we are going to improve drammatically
+	 * swapout performance -arca (discovered this afternoon ;) 980105
+	 */
+	if (swap_out(priority, gfp_mask & ~__GFP_WAIT))
+		/*
+		 * We done at least some swapping progress so return 1 in
+		 * this case. -arca
+		 */
+		return 1;
 
-static int kswapd_free_pages(int kswapd_state)
+	return 0;
+}
+
+static int do_free_page(int * state, int gfp_mask)
 {
-	unsigned long end_time;
+	int priority = 8;
 
-	/* Always trim SLAB caches when memory gets low. */
-	kmem_cache_reap(0);
+	switch (*state) {
+		do {
+		case 0:
+			if (do_free_user_and_cache(priority, gfp_mask))
+				return 1;
+			*state = 1;
+		case 1:
+			if (shm_swap(priority, gfp_mask))
+				return 1;
+			*state = 0;
 
-	/* max one hundreth of a second */
-	end_time = jiffies + (HZ-1)/100;
-	do {
-		int priority = 8;
-		int count = pager_daemon.swap_cluster;
+			shrink_dcache_memory(priority, gfp_mask);
+			kmem_cache_reap(gfp_mask);
+		} while (--priority >= 0);
+	}
+	return 0;
+}
 
-		switch (kswapd_state) {
-			do {
-			default:
-				free_memory(shrink_mmap(priority, 0));
-				free_memory(swap_out(priority, 0));
-				kswapd_state++;
-			case 1:
-				free_memory(shm_swap(priority, 0));
-				shrink_dcache_memory(priority, 0);
-				kswapd_state = 0;
-			} while (--priority >= 0);
-			return kswapd_state;
-		}
-done:
-		if (nr_free_pages > freepages.high + pager_daemon.swap_cluster)
+static int kswapd_free_pages(int kswapd_state)
+{
+	for(;;)
+	{
+		do_free_page(&kswapd_state, 0);
+		if (nr_free_pages > freepages.high)
 			break;
-	} while (time_before_eq(jiffies,end_time));
+		if (atomic_read(&nr_tasks_freeing_memory))
+			break;
+		if (kswapd_task->need_resched)
+			schedule();
+	};
 	return kswapd_state;
 }
 
@@ -496,13 +556,6 @@
 	lock_kernel();
 
 	/*
-	 * Set the base priority to something smaller than a
-	 * regular process. We will scale up the priority
-	 * dynamically depending on how much memory we need.
-	 */
-	current->priority = (DEF_PRIORITY * 2) / 3;
-
-	/*
 	 * Tell the memory management that we're a "memory allocator",
 	 * and that if we need more memory we should get access to it
 	 * regardless (see "try_to_free_pages()"). "kswapd" should
@@ -516,7 +569,6 @@
 	 */
 	current->flags |= PF_MEMALLOC;
 
-	init_swap_timer();
 	kswapd_task = current;
 	while (1) {
 		int state = 0;
@@ -543,107 +595,35 @@
  * if we need more memory as part of a swap-out effort we
  * will just silently return "success" to tell the page
  * allocator to accept the allocation.
- *
- * We want to try to free "count" pages, and we need to 
- * cluster them so that we get good swap-out behaviour. See
- * the "free_memory()" macro for details.
  */
 int try_to_free_pages(unsigned int gfp_mask, int count)
 {
-	int retval;
-
+	int retval = 1;
 	lock_kernel();
-
-	/* Always trim SLAB caches when memory gets low. */
-	kmem_cache_reap(gfp_mask);
-
-	retval = 1;
-	if (!(current->flags & PF_MEMALLOC)) {
-		int priority;
 
-		current->flags |= PF_MEMALLOC;
-	
-		priority = 8;
-		do {
-			free_memory(shrink_mmap(priority, gfp_mask));
-			free_memory(shm_swap(priority, gfp_mask));
-			free_memory(swap_out(priority, gfp_mask));
-			shrink_dcache_memory(priority, gfp_mask);
-		} while (--priority >= 0);
-		retval = 0;
-done:
-		current->flags &= ~PF_MEMALLOC;
+	current->flags |= PF_MEMALLOC;
+	atomic_inc(&nr_tasks_freeing_memory);
+	while (count--)
+	{
+		static int state = 0;
+		if (!do_free_page(&state, gfp_mask))
+		{
+			retval = 0;
+			break;
+		}
 	}
-	unlock_kernel();
+	atomic_dec(&nr_tasks_freeing_memory);
+	current->flags &= ~PF_MEMALLOC;
 
+	unlock_kernel();
 	return retval;
 }
 
-/*
- * Wake up kswapd according to the priority
- *	0 - no wakeup
- *	1 - wake up as a low-priority process
- *	2 - wake up as a normal process
- *	3 - wake up as an almost real-time process
- *
- * This plays mind-games with the "goodness()"
- * function in kernel/sched.c.
- */
-static inline void kswapd_wakeup(struct task_struct *p, int priority)
+void kswapd_wakeup(void)
 {
-	if (priority) {
-		p->counter = p->priority << priority;
-		wake_up_process(p);
-	}
-}
+	struct task_struct * p = kswapd_task;
 
-/* 
- * The swap_tick function gets called on every clock tick.
- */
-void swap_tick(void)
-{
-	struct task_struct *p = kswapd_task;
-
-	/*
-	 * Only bother to try to wake kswapd up
-	 * if the task exists and can be woken.
-	 */
-	if (p && (p->state & TASK_INTERRUPTIBLE)) {
-		unsigned int pages;
-		int want_wakeup;
-
-		/*
-		 * Schedule for wakeup if there isn't lots
-		 * of free memory or if there is too much
-		 * of it used for buffers or pgcache.
-		 *
-		 * "want_wakeup" is our priority: 0 means
-		 * not to wake anything up, while 3 means
-		 * that we'd better give kswapd a realtime
-		 * priority.
-		 */
-		want_wakeup = 0;
-		pages = nr_free_pages;
-		if (pages < freepages.high)
-			want_wakeup = 1;
-		if (pages < freepages.low)
-			want_wakeup = 2;
-		if (pages < freepages.min)
-			want_wakeup = 3;
-	
-		kswapd_wakeup(p,want_wakeup);
-	}
-
-	timer_active |= (1<<SWAP_TIMER);
-}
-
-/* 
- * Initialise the swap timer
- */
-
-void init_swap_timer(void)
-{
-	timer_table[SWAP_TIMER].expires = jiffies;
-	timer_table[SWAP_TIMER].fn = swap_tick;
-	timer_active |= (1<<SWAP_TIMER);
+	if (p && (p->state & TASK_INTERRUPTIBLE) &&
+	    !atomic_read(&nr_tasks_freeing_memory))
+		wake_up_process(p);
 }

Index: linux/mm/page_alloc.c

mm/page_alloc.c renamed from mm/page_alloc.c:1.1.1.5 +11 -6
diff -u linux/mm/page_alloc.c:1.1.1.5 linux/mm/page_alloc.c:1.1.1.1.2.18
@@ -3,6 +3,7 @@
  *
  *  Copyright (C) 1991, 1992, 1993, 1994  Linus Torvalds
  *  Swap reorganised 29.12.95, Stephen Tweedie
+ *  memory_trashing heuristic. Copyright (C) 1998  Andrea Arcangeli
  */
 
 #include <linux/config.h>
@@ -250,17 +251,18 @@
 		 * a bad memory situation, we're better off trying
 		 * to free things up until things are better.
 		 *
-		 * Normally we shouldn't ever have to do this, with
-		 * kswapd doing this in the background.
-		 *
 		 * Most notably, this puts most of the onus of
 		 * freeing up memory on the processes that _use_
 		 * the most memory, rather than on everybody.
 		 */
-		if (nr_free_pages > freepages.min) {
+		if (nr_free_pages > freepages.min+(1<<order)) {
 			if (!current->trashing_memory)
+				goto ok_to_allocate;
+			if (current->flags & PF_MEMALLOC)
+				goto ok_to_allocate;
+			if (nr_free_pages > freepages.low+(1<<order))
 				goto ok_to_allocate;
-			if (nr_free_pages > freepages.low) {
+			if (nr_free_pages > freepages.high+(1<<order)) {
 				current->trashing_memory = 0;
 				goto ok_to_allocate;
 			}
@@ -271,8 +273,11 @@
 		 * memory.
 		 */
 		current->trashing_memory = 1;
-		if (!try_to_free_pages(gfp_mask, SWAP_CLUSTER_MAX) && !(gfp_mask & (__GFP_MED | __GFP_HIGH)))
+		if (!try_to_free_pages(gfp_mask, freepages.high - nr_free_pages + (1<<order)) && !(gfp_mask & (__GFP_MED | __GFP_HIGH)))
 			goto nopage;
+	} else {
+		if (nr_free_pages < freepages.min)
+			kswapd_wakeup();
 	}
 ok_to_allocate:
 	spin_lock_irqsave(&page_alloc_lock, flags);

Index: linux/include/linux/mm.h

include/linux/mm.h renamed from include/linux/mm.h:1.1.1.3 +1 -3
diff -u linux/include/linux/mm.h:1.1.1.3 linux/include/linux/mm.h:1.1.1.1.2.13
@@ -118,7 +118,6 @@
 	unsigned long offset;
 	struct page *next_hash;
 	atomic_t count;
-	unsigned int unused;
 	unsigned long flags;	/* atomic flags, some possibly updated asynchronously */
 	struct wait_queue *wait;
 	struct page **pprev_hash;
@@ -295,8 +294,7 @@
 
 /* filemap.c */
 extern void remove_inode_page(struct page *);
-extern unsigned long page_unuse(struct page *);
-extern int shrink_mmap(int, int);
+extern int FASTCALL(shrink_mmap(int, int));
 extern void truncate_inode_pages(struct inode *, unsigned long);
 extern unsigned long get_cached_page(struct inode *, unsigned long, int);
 extern void put_cached_page(unsigned long);

Index: linux/mm/swap.c

mm/swap.c renamed from mm/swap.c:1.1.1.5 +2 -2
diff -u linux/mm/swap.c:1.1.1.5 linux/mm/swap.c:1.1.1.1.2.8
@@ -64,13 +64,13 @@
 swapstat_t swapstats = {0};
 
 buffer_mem_t buffer_mem = {
-	2,	/* minimum percent buffer */
+	5,	/* minimum percent buffer */
 	10,	/* borrow percent buffer */
 	60	/* maximum percent buffer */
 };
 
 buffer_mem_t page_cache = {
-	2,	/* minimum percent page cache */
+	5,	/* minimum percent page cache */
 	15,	/* borrow percent page cache */
 	75	/* maximum */
 };

Index: linux/include/linux/swap.h

include/linux/swap.h renamed from include/linux/swap.h:1.1.1.4 +3 -0
diff -u linux/include/linux/swap.h:1.1.1.4 linux/include/linux/swap.h:1.1.1.1.2.10
@@ -83,6 +83,7 @@
 
 /* linux/mm/vmscan.c */
 extern int try_to_free_pages(unsigned int gfp_mask, int count);
+extern void kswapd_wakeup(void);
 
 /* linux/mm/page_io.c */
 extern void rw_swap_page(int, unsigned long, char *, int);
@@ -167,9 +168,11 @@
 	count = atomic_read(&page->count);
 	if (PageSwapCache(page))
 	{
+#if 0
 		/* PARANOID */
 		if (page->inode != &swapper_inode)
 			panic("swap cache page has wrong inode\n");
+#endif
 		count += swap_count(page->offset) - 2;
 	}
 	if (PageFreeAfter(page))

--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#28 lore raw

Re: arca-vm-8 [Re: [patch] arca-vm-6, killed kswapd [Re: [patch] new-vm , improvement , [Re: 2.2.0 Bug summary]]]

Quoted 1 line · Andrea Arcangeli

I fixed some thing in arca-vm-7. This new is arca-vm-8.

I've put out arca-vm-9.

It seems that it's a lose marking as not referenced all freed pages in __free_pages(). Probably because shrink_mmap() doesn't like to decrease the `count' on just freed pages. So now I mark all freed pages as referenced.

In the last patches (arca-vm[78] I forgot to include the filemap.c diff) that seems to improve performances here (allowing the swap cache to be shrunk without care about pgcache_under_min()).

arca-vm-9 return to a linear behavior in cacluating the swapout weight.

You can donwload arca-vm-9 from here:

ftp://e-mind.com/pub/linux/kernel-patches/2.2.0-pre4-arca-VM-9

Let me know if you'll try it. Thanks!

Andrea Arcangeli

--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#29 lore raw

Re: arca-vm-8 [Re: [patch] arca-vm-6, killed kswapd [Re: [patch] new-vm , improvement , [Re: 2.2.0 Bug summary]]]

Quoted 1 line · Andrea Arcangeli

I've put out arca-vm-9.

Woops in both arca-vm-8 and arca-vm-9 there was a very stupid bug in my changes of the memory_trashing heuristic (done at too late time..). Basically when a process was masked to be a memory_trasher, it had no ways to return a not marked process................

I didn' t noticed the bug because I use swap only when I do my benchmarks (when there is not swapping in progress the slowdown due some shrink_mmap() can't be seen with eyes...) and when I run my benchmarks I always start before the memory trasher proggy...

Thanks to Benjamin who showed me the bugs some seconds ago ;)

I've put out a new arca-vm-10 with at least this bug fixed.

ftp://e-mind.com/pub/linux/kernel-patches/2.2.0-pre4-arca-VM-10

Excuse me...

BTW, I have reports that arca-vm-6/7 are faster than arca-vm-8/9 (arca-vm-7 is reported the fastest even more than arca-vm-3). Maybe it's been due this bug that the latest are slower, or maybe the whole new changes at the first memory_trashing code (the one in 2.2.0-pre4) are hurting... (even if here them seems to helps, with them the trashing process remains marked all the time and not only during low mem peak; and not trashing process never get marked as trashing)

And again thanks to Steve, Zlatko, Benjamin, Ben, Garst, MikeG, Kalle, Brent and all other testers for their good reports!

Andrea Arcangeli

--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#30 lore raw

Results: 2.2.0-pre5 vs arcavm10 vs arcavm9 vs arcavm7

Quoted 4 lines · Andrea Arcangeli

I've put out a new arca-vm-10 with at least this bug fixed.

ftp://e-mind.com/pub/linux/kernel-patches/2.2.0-pre4-arca-VM-10

Here are my latest numbers. This is timing a complete kernel compile (make clean;make depend;make;make modules;make modules_install) in 16MB memory with netscape, kde, and various daemons running. I unknowningly had two more daemons running in the background this time than last so the numbers can't be compared directly with my last test (Which I think I only sent to Andrea). But all of these numbers are consistent with *each other*.

kernel Time Maj pf Min pf Swaps
---------- ----- ------ ------ -----
2.2.0-pre5 18:19 522333 493803 27984
arcavm10 19:57 556299 494163 12035
arcavm9 19:55 553783 494444 12077
arcavm7 18:39 538520 493287 11526

Pre5 looks good.
Arcavm7 still looks better than arcavm10.

-Steve
--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#31 lore raw

Re: Results: 2.2.0-pre5 vs arcavm10 vs arcavm9 vs arcavm7

Quoted 6 lines · Steve Bergman

kernel Time Maj pf Min pf Swaps
---------- ----- ------ ------ -----
2.2.0-pre5 18:19 522333 493803 27984
arcavm10 19:57 556299 494163 12035
arcavm9 19:55 553783 494444 12077
arcavm7 18:39 538520 493287 11526

Happy to hear that ! ;)

The changes in 2.2.0-pre5 looks really cool! I think the only missing thing that I would like to see in is my calc_swapout_weight() thing. This my change would avoid swap_out() to stall too much the system in presence of huge tasks and so it would allow the VM to scale better... I'll do some test starting from pre5 now...

Andrea Arcangeli

--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#32 lore raw

Re: Results: 2.2.0-pre5 vs arcavm10 vs arcavm9 vs arcavm7

Quoted 5 lines · Andrea Arcangeli

The changes in 2.2.0-pre5 looks really cool! I think the only missing thing that I would like to see in is my calc_swapout_weight() thing. This my change would avoid swap_out() to stall too much the system in presence of huge tasks and so it would allow the VM to scale better...

Note that if swap_out swaps something out, it will always return 1 (it has to, as it sleeps), and that in turn will make us decrement our counter, which will make us stop paging things out soon enough..

So I really don't think it's a scaling issue either.

Linus

--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#33 lore raw

Re: Results: 2.2.0-pre5 vs arcavm10 vs arcavm9 vs arcavm7

Quoted 2 lines · Linus Torvalds

Note that if swap_out swaps something out, it will always return 1 (it has to, as it sleeps), and that in turn will make us decrement our counter,

Side note, when we swapout something we stop completly swapping out and we return to try_to_free_pages() (still better for the issue we was talking about ;).

Quoted 1 line

So I really don't think it's a scaling issue either.

Yes, I think you are right. I am rejecting the calc_swapout_weight code.

Andrea Arcangeli

--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#34 lore raw

Re: Results: 2.2.0-pre5 vs arcavm10 vs arcavm9 vs arcavm7

In reply to Steve Bergman
Quoted 9 lines · Steve Bergman

Here are my latest numbers. This is timing a complete kernel compile (make clean;make depend;make;make modules;make modules_install) in 16MB memory with netscape, kde, and various daemons running. I unknowningly had two more daemons running in the background this time than last so the numbers can't be compared directly with my last test (Which I think I only sent to Andrea). But all of these numbers are consistent with *each other*.

Quoted 6 lines

kernel Time Maj pf Min pf Swaps
---------- ----- ------ ------ -----
2.2.0-pre5 18:19 522333 493803 27984
arcavm10 19:57 556299 494163 12035
arcavm9 19:55 553783 494444 12077
arcavm7 18:39 538520 493287 11526

Don't look too closely at the "swaps" number - I think pre-5 just changed accounting a bit. A lot of the "swaps" are really just dropping a virtual mapping (that is later picked up again from the page cache or the swap cache).

Basically, pre-5 uses the page cache and the swap cache more actively as a "victim cache", and that inflates the "swaps" number simply due to the accounting issues.

I guess I shouldn't count the simple "drop_pte" operation as a swap at all, because it doesn't involve any IO.

Linus

--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#35 lore raw

Re: Results: 2.2.0-pre5 vs arcavm10 vs arcavm9 vs arcavm7

Quoted 22 lines · Linus Torvalds
Quoted 9 lines · Steve Bergman

Here are my latest numbers. This is timing a complete kernel compile (make clean;make depend;make;make modules;make modules_install) in 16MB memory with netscape, kde, and various daemons running. I unknowningly had two more daemons running in the background this time than last so the numbers can't be compared directly with my last test (Which I think I only sent to Andrea). But all of these numbers are consistent with *each other*.

Quoted 6 lines

kernel Time Maj pf Min pf Swaps
---------- ----- ------ ------ -----
2.2.0-pre5 18:19 522333 493803 27984
arcavm10 19:57 556299 494163 12035
arcavm9 19:55 553783 494444 12077
arcavm7 18:39 538520 493287 11526

Don't look too closely at the "swaps" number - I think pre-5 just changed accounting a bit. A lot of the "swaps" are really just dropping a virtual mapping (that is later picked up again from the page cache or the swap cache).

Quoted 7 lines

Basically, pre-5 uses the page cache and the swap cache more actively as a "victim cache", and that inflates the "swaps" number simply due to the accounting issues.

I guess I shouldn't count the simple "drop_pte" operation as a swap at all, because it doesn't involve any IO.

2.2.0-pre5 works very good, indeed, but it still has some not sufficiently explored nuisances:

1) Swap performance in pre-5 is much worse compared to pre-4 in *certain* circumstances. I'm using quite stupid and unintelligent program to check for raw swap speed (attached below). With 64 MB of RAM I usually run it as 'hogmem 100 3' and watch for result which is recently around 6 MB/sec. But when I lately decided to start two instances of it like "hogmem 50 3 & hogmem 50 3 &" in pre-4 I got 2 x 2.5 MB/sec and in pre-5 it is only 2 x 1 MB/sec and disk is making very weird and frightening sounds. My conclusion is that now (pre-5) system behaves much poorer when we have more than one thrashing task. *Please*, check this, it is a quite serious problem.

2) In pre-5, under heavy load, free memory is hovering around freepages.min instead of being somewhere between freepages.low & freepages.max. This could make trouble for bursts of atomic allocations (networking!).

3) Nitpick #1: /proc/swapstats exist but is only filled with zeros. Probably it should go away. I believe Stephen added it recently, but only part of his patch got actually applied.

4) Nitpick #2": "Swap cache:" line in report of Alt-SysRq-M is not useful as it is laid now. People have repeatedly sent patches (Rik, Andrea...) to fix this but it is still not fixed, as of pre-5.

5) There is lots of #if 0 constructs in MM code, and also lots of structures are not anymore used but still take precious memory in compiled kernel and uncover itself under /proc (/proc/sys/vm/swapctl for instance). Do you want a patch to remove this cruft?

6) Finally one suggestion of mine. In swapfile.c there is comment:

* We try to cluster swap pages by allocating them
* sequentially in swap. Once we've allocated
* SWAP_CLUSTER_MAX pages this way, however, we resort to
* first-free allocation, starting a new cluster. This
* prevents us from scattering swap pages all over the entire
* swap partition, so that we reduce overall disk seek times

This is good, but clustering of only 32 (SWAP_CLUSTER_MAX) * 4KB = 128KB is too small for today's disk and swap sizes. I tried to enlarge this value to something like 2 MB and got much much better results. This is very important now that we have swapin readahead to keep pages as adjacent as possible to each other so hit rate is big. It is trivial (one liner) and completely safe to make this constant much bigger, so I'm not even attaching a patch. 512 works very well and swapping is much faster than with default valuein place. Maybe this should even be sysctl controllable. If you agree with the last idea, I'll send you a patch, just confirm.

I promised memory hogger:

OK, that's it for today. Don't bang heads too hard and enjoy!

Signature · 1 line
Zlatko
#36 lore raw

Re: Results: 2.2.0-pre5 vs arcavm10 vs arcavm9 vs arcavm7

Quoted 11 lines · Zlatko Calusic

1) Swap performance in pre-5 is much worse compared to pre-4 in *certain* circumstances. I'm using quite stupid and unintelligent program to check for raw swap speed (attached below). With 64 MB of RAM I usually run it as 'hogmem 100 3' and watch for result which is recently around 6 MB/sec. But when I lately decided to start two instances of it like "hogmem 50 3 & hogmem 50 3 &" in pre-4 I got 2 x 2.5 MB/sec and in pre-5 it is only 2 x 1 MB/sec and disk is making very weird and frightening sounds. My conclusion is that now (pre-5) system behaves much poorer when we have more than one thrashing task. *Please*, check this, it is a quite serious problem.

Ok, will investigate. One thing you can test is to try out different "count" arguments to try_to_free_pages() (this was part of what Andrea did, btw). So instead of (page_alloc.c, line 285):

	freed = try_to_free_pages(gfp_mask, SWAP_CLUSTER_MAX);

you can try different things for the second argument: the thing Andrea did was something like

	freed = try_to_free_pages(gfp_mask, freepages.high - nr_free_pages);

which could work well (one thing I'm nervous about is that this probably needs to be limited some way - it can be quite a large number on large machines, and that's why I'd like to hear comments from people).

Quoted 4 lines

2) In pre-5, under heavy load, free memory is hovering around freepages.min instead of being somewhere between freepages.low & freepages.max. This could make trouble for bursts of atomic allocations (networking!).

The change above would change this too.

Quoted 3 lines

3) Nitpick #1: /proc/swapstats exist but is only filled with zeros. Probably it should go away. I believe Stephen added it recently, but only part of his patch got actually applied.

Maybe somebody can find a use for it.

Quoted 3 lines

4) Nitpick #2": "Swap cache:" line in report of Alt-SysRq-M is not useful as it is laid now. People have repeatedly sent patches (Rik, Andrea...) to fix this but it is still not fixed, as of pre-5.

I never use it, so it hasn't been a big issue.

Quoted 4 lines

5) There is lots of #if 0 constructs in MM code, and also lots of structures are not anymore used but still take precious memory in compiled kernel and uncover itself under /proc (/proc/sys/vm/swapctl for instance). Do you want a patch to remove this cruft?

Some of the #if 0 code should certainly be removed. Some of it is useful as a kind of commentary - sometimes code is removed not because it doesn't make sense, but because the implementation wasn't quite good enough.

Linus

--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#37 lore raw

Re: Results: 2.2.0-pre5 vs arcavm10 vs arcavm9 vs arcavm7

Quoted 19 lines · Linus Torvalds
Quoted 11 lines · Zlatko Calusic

1) Swap performance in pre-5 is much worse compared to pre-4 in *certain* circumstances. I'm using quite stupid and unintelligent program to check for raw swap speed (attached below). With 64 MB of RAM I usually run it as 'hogmem 100 3' and watch for result which is recently around 6 MB/sec. But when I lately decided to start two instances of it like "hogmem 50 3 & hogmem 50 3 &" in pre-4 I got 2 x 2.5 MB/sec and in pre-5 it is only 2 x 1 MB/sec and disk is making very weird and frightening sounds. My conclusion is that now (pre-5) system behaves much poorer when we have more than one thrashing task. *Please*, check this, it is a quite serious problem.

Ok, will investigate. One thing you can test is to try out different "count" arguments to try_to_free_pages() (this was part of what Andrea did, btw). So instead of (page_alloc.c, line 285):

	freed = try_to_free_pages(gfp_mask, SWAP_CLUSTER_MAX);
Quoted 8 lines

you can try different things for the second argument: the thing Andrea did was something like

	freed = try_to_free_pages(gfp_mask, freepages.high - nr_free_pages);

which could work well (one thing I'm nervous about is that this probably needs to be limited some way - it can be quite a large number on large machines, and that's why I'd like to hear comments from people).

OK, I'll check what can be done with that, as time permits.

Quoted 7 lines
Quoted 5 lines

2) In pre-5, under heavy load, free memory is hovering around freepages.min instead of being somewhere between freepages.low & freepages.max. This could make trouble for bursts of atomic allocations (networking!).

The change above would change this too.

Yes, probably.

Quoted 6 lines
Quoted 4 lines

3) Nitpick #1: /proc/swapstats exist but is only filled with zeros. Probably it should go away. I believe Stephen added it recently, but only part of his patch got actually applied.

Maybe somebody can find a use for it.

Of course it can, but *right now* it's useless. So if nobody gets in (Stephen?), I'll take it and fix it. I have a similar, even more verbose patch for MM statistics with ~15 columns of information, but that one does not apply cleanly on the latest kernels (obvious reasons).

Quoted 6 lines
Quoted 4 lines

4) Nitpick #2": "Swap cache:" line in report of Alt-SysRq-M is not useful as it is laid now. People have repeatedly sent patches (Rik, Andrea...) to fix this but it is still not fixed, as of pre-5.

I never use it, so it hasn't been a big issue.

But it is, cause if properly done, it could give valuable information about swap cache hit, and thus differentiate among various algorithms we use for memory management. If I understand correctly, lots of changes happened in MM in last few kernel revisions, but nobody knows exactly what we're doing (there were few macro benchmarks done, which are by definition not very useful for selecting among algorithms).

Quoted 10 lines
Quoted 5 lines

5) There is lots of #if 0 constructs in MM code, and also lots of structures are not anymore used but still take precious memory in compiled kernel and uncover itself under /proc (/proc/sys/vm/swapctl for instance). Do you want a patch to remove this cruft?

Some of the #if 0 code should certainly be removed. Some of it is useful as a kind of commentary - sometimes code is removed not because it doesn't make sense, but because the implementation wasn't quite good enough.

I'll see tomorrow if I can prepare one patch to fix few annoyances I reported.

Good night!

Signature · 4 lines
Zlatko
--
This is a majordomo managed list.  To unsubscribe, send a message with
the body 'unsubscribe linux-mm me@address' to: [email protected]
#38 lore raw

Re: Results: 2.2.0-pre5 vs arcavm10 vs arcavm9 vs arcavm7

In reply to Zlatko Calusic
Quoted 5 lines · Zlatko Calusic

2) In pre-5, under heavy load, free memory is hovering around freepages.min instead of being somewhere between freepages.low & freepages.max. This could make trouble for bursts of atomic allocations (networking!).

To followup myself, don't trust me, check your logfiles:

Jan  7 20:12:03 atlas kernel: eth0: Insufficient memory; nuking packet. 
Jan  7 20:12:05 atlas last message repeated 64 times

Uaaa, it's baaack... :)

Signature · 4 lines
Zlatko
--
This is a majordomo managed list.  To unsubscribe, send a message with
the body 'unsubscribe linux-mm me@address' to: [email protected]
#39 lore raw

Re: Results: 2.2.0-pre5 vs arcavm10 vs arcavm9 vs arcavm7

In reply to Zlatko Calusic
Quoted 4 lines · Zlatko Calusic

2) In pre-5, under heavy load, free memory is hovering around freepages.min instead of being somewhere between freepages.low & freepages.max. This could make trouble for bursts of atomic allocations (networking!).

Agreed and I just fixed that with my updates to the memory trashing heuristic (see also the second patch in one of my last emails).

A new minimal patch against 2.2.0-pre5 is this:

Index: page_alloc.c
===================================================================
RCS file: /var/cvs/linux/mm/page_alloc.c,v
retrieving revision 1.1.1.6

mm/page_alloc.c renamed from page_alloc.c +4 -5
diff -u -2 -r1.1.1.6 page_alloc.c
@@ -4,4 +4,5 @@
  *  Copyright (C) 1991, 1992, 1993, 1994  Linus Torvalds
  *  Swap reorganised 29.12.95, Stephen Tweedie
+ *  trashing_memory heuristic. Copyright (C) 1999  Andrea Arcangeli
  */
 
@@ -259,7 +260,4 @@
 		 * to free things up until things are better.
 		 *
-		 * Normally we shouldn't ever have to do this, with
-		 * kswapd doing this in the background.
-		 *
 		 * Most notably, this puts most of the onus of
 		 * freeing up memory on the processes that _use_
@@ -269,8 +267,9 @@
 			if (!current->trashing_memory)
 				goto ok_to_allocate;
-			if (nr_free_pages > freepages.low) {
+			if (nr_free_pages > freepages.high) {
 				current->trashing_memory = 0;
 				goto ok_to_allocate;
-			}
+			} else if (nr_free_pages > freepages.low)
+				goto ok_to_allocate;
 		}
 		/*

The problem is that I don't know if it's going to hurt performances... If somebody would try it out would be helpful... I don't think it can hurt but...

Andrea Arcangeli

--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#40 lore raw

2.2.0-pre[56] swap performance poor with > 1 thrashing task

In reply to Zlatko Calusic
Quoted 13 lines · Zlatko Calusic

2.2.0-pre5 works very good, indeed, but it still has some not sufficiently explored nuisances:

1) Swap performance in pre-5 is much worse compared to pre-4 in *certain* circumstances. I'm using quite stupid and unintelligent program to check for raw swap speed (attached below). With 64 MB of RAM I usually run it as 'hogmem 100 3' and watch for result which is recently around 6 MB/sec. But when I lately decided to start two instances of it like "hogmem 50 3 & hogmem 50 3 &" in pre-4 I got 2 x 2.5 MB/sec and in pre-5 it is only 2 x 1 MB/sec and disk is making very weird and frightening sounds. My conclusion is that now (pre-5) system behaves much poorer when we have more than one thrashing task. *Please*, check this, it is a quite serious problem.

I just tried this on 2.2.0-pre6 PentiumII 412Mhz, 128MB SDRAM, one IDE disk (/ & swap).

./hogmem 100 3 (no swapping)
Memory speed: 167.60 MB/sec

./hogmem 200 3
Memory speed: 9.01 MB/sec

./hogmem 100 3 & ./hogmem 100 3
Memory speed: 0.96 MB/sec
Memory speed: 0.96 MB/sec

./hogmem 100 3 (no swap)
Memory speed: 180.18 MB/sec

./hogmem 200 3
Memory speed: 8.68 MB/sec

I then tried

./hogmem 200 3 &

find / (on about 1.5GB of data on ext2 and vfat and nfs repeatedly)

And launched netscape. After 45 mins, I didn't restart the find, and about 3 mins later the hogmem completed at 0.75MB/sec. Netscape was surprisingly responsive however.

Dax Kelson

--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#41 lore raw

Re: 2.2.0-pre[56] swap performance poor with > 1 thrashing task

Quoted 16 lines · Dax Kelson
Quoted 11 lines · Zlatko Calusic

1) Swap performance in pre-5 is much worse compared to pre-4 in *certain* circumstances. I'm using quite stupid and unintelligent program to check for raw swap speed (attached below). With 64 MB of RAM I usually run it as 'hogmem 100 3' and watch for result which is recently around 6 MB/sec. But when I lately decided to start two instances of it like "hogmem 50 3 & hogmem 50 3 &" in pre-4 I got 2 x 2.5 MB/sec and in pre-5 it is only 2 x 1 MB/sec and disk is making very weird and frightening sounds. My conclusion is that now (pre-5) system behaves much poorer when we have more than one thrashing task. *Please*, check this, it is a quite serious problem.

I just tried this on 2.2.0-pre6 PentiumII 412Mhz, 128MB SDRAM, one IDE disk (/ & swap).

Quoted 7 lines

./hogmem 200 3
Memory speed: 9.01 MB/sec

./hogmem 100 3 & ./hogmem 100 3
Memory speed: 0.96 MB/sec
Memory speed: 0.96 MB/sec

I have a fix for this, together with a great improvement in swapping speed that I'll be sending in few moments, after some final testing.

pre6 is VERY good, and with my changes, we will have fastest MM ever!

Signature · 4 lines
Zlatko
--
This is a majordomo managed list.  To unsubscribe, send a message with
the body 'unsubscribe linux-mm me@address' to: [email protected]
#42 lore raw

Re: 2.2.0-pre[56] swap performance poor with > 1 thrashing task

Btw, if there are people there who actually like timing different things (something I _hate_ doing - I lose interest if things become just a matter of numbers rather than trying to get some algorithm right), then there's one thing I'd love to hear about: the effect of trying to do some access bit setting on buffer cache pages.

See my comments in linux/include/linux/fs.h, at around line 260 or so. It's the "touch_buffer()" macro which is currently a no-op, and it is entirely possible that it really should set the PG_referenced bit.

As a no-op, it can now randomly and unprectably result in even worthwhile buffers just being thrown out - possibly quite soon after they've been loaded in. I happen to believe that it doesn't actually matter (and I'm not convinced that marking the pages referenced has no downsides), but I'm too lazy to bother to test it.

Linus

--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#43 lore raw

Re: 2.2.0-pre[56] swap performance poor with > 1 thrashing task

I think there are problems with 2.2.0-pre6 VM (even if I have not tried it yet really). Latest time I tried on previous kernel to use in __get_free_pages() a try_to_free_pages weight > than MAX_SWAP_CLUSTER (aka freepages.high - nr_free_pages) I had bad impact of VM balance under swapping.

The problem is try_to_free_pages() implementation. Using a lower weight as in pre5 we was sure to return to shrink_mmap with more frequency and so getting more balance. Instead now we return to risk to only swapout without make real free memory space.

In the patch there's also some cosmetic change (like s/if/else if/). The priority = 8 is to go in the swap path more easily.

Ah and probably we could reinsert the swapout_interval sysctl with default value of HZ (not done yet due lack of time).

Index: linux/mm/vmscan.c

mm/vmscan.c renamed from mm/vmscan.c:1.1.1.11 +41 -28
diff -u linux/mm/vmscan.c:1.1.1.11 linux/mm/vmscan.c:1.1.1.1.2.81
@@ -10,6 +10,11 @@
  *  Version: $Id: vmscan.c,v 1.5 1998/02/23 22:14:28 sct Exp $
  */
 
+/*
+ * free_user_and_cache(), always async swapout.
+ * Copyright (C) 1999  Andrea Arcangeli
+ */
+
 #include <linux/slab.h>
 #include <linux/kernel_stat.h>
 #include <linux/swap.h>
@@ -199,11 +204,11 @@
 
 	do {
 		int result;
-		tsk->swap_address = address + PAGE_SIZE;
 		result = try_to_swap_out(tsk, vma, address, pte, gfp_mask);
+		address += PAGE_SIZE;
+		tsk->swap_address = address;
 		if (result)
 			return result;
-		address += PAGE_SIZE;
 		pte++;
 	} while (address < end);
 	return 0;
@@ -325,7 +330,7 @@
 	counter = nr_tasks / (priority+1);
 	if (counter < 1)
 		counter = 1;
-	if (counter > nr_tasks)
+	else if (counter > nr_tasks)
 		counter = nr_tasks;
 
 	for (; counter >= 0; counter--) {
@@ -438,13 +443,22 @@
 		 * point is to make sure that the system doesn't stay
 		 * forever in a really bad memory squeeze.
 		 */
-		if (nr_free_pages < freepages.high)
-			try_to_free_pages(0, 16);
+		if (nr_free_pages < freepages.low)
+			try_to_free_pages(0, freepages.high - nr_free_pages);
 	}
 
 	return 0;
 }
 
+static int free_user_and_cache(int priority, int gfp_mask)
+{
+	if (shrink_mmap(priority, gfp_mask))
+		return 1;
+	if (swap_out(priority, gfp_mask))
+		return 1;
+	return 0;
+}
+
 /*
  * We need to make the locks finer granularity, but right
  * now we need this so that we can do page allocations
@@ -457,33 +471,32 @@
 int try_to_free_pages(unsigned int gfp_mask, int count)
 {
 	int priority;
+	static int state = 0;
 
 	lock_kernel();
 
-	/* Always trim SLAB caches when memory gets low. */
-	kmem_cache_reap(gfp_mask);
-
-	priority = 6;
-	do {
-		while (shrink_mmap(priority, gfp_mask)) {
-			if (!--count)
-				goto done;
-		}
-
-		/* Try to get rid of some shared memory pages.. */
-		while (shm_swap(priority, gfp_mask)) {
-			if (!--count)
-				goto done;
-		}
-	
-		/* Then, try to page stuff out.. */
-		while (swap_out(priority, gfp_mask)) {
-			if (!--count)
-				goto done;
-		}
+	priority = 8;
+	switch (state)
+	{
+		do {
+		case 0:
+			while (free_user_and_cache(priority, gfp_mask)) {
+				if (!--count)
+					goto done;
+			}
+			state = 1;
+		case 1:
+			/* Try to get rid of some shared memory pages.. */
+			while (shm_swap(priority, gfp_mask)) {
+				if (!--count)
+					goto done;
+			}
+			state = 0;
 
-		shrink_dcache_memory(priority, gfp_mask);
-	} while (--priority >= 0);
+			kmem_cache_reap(gfp_mask);
+			shrink_dcache_memory(priority, gfp_mask);
+		} while (--priority >= 0);
+	}
 done:
 	unlock_kernel();
 

Another patch I consider right is this:

Index: linux/mm/page_alloc.c

mm/page_alloc.c renamed from mm/page_alloc.c:1.1.1.7 +4 -2
diff -u linux/mm/page_alloc.c:1.1.1.7 linux/mm/page_alloc.c:1.1.1.1.2.25
@@ -3,6 +3,7 @@
  *
  *  Copyright (C) 1991, 1992, 1993, 1994  Linus Torvalds
  *  Swap reorganised 29.12.95, Stephen Tweedie
+ *  trashing_memory heuristic. Copyright (C) 1999  Andrea Arcangeli
  */
 
 #include <linux/config.h>
@@ -265,10 +266,11 @@
 		if (nr_free_pages > freepages.min) {
 			if (!current->trashing_memory)
 				goto ok_to_allocate;
-			if (nr_free_pages > freepages.low) {
+			if (nr_free_pages > freepages.high) {
 				current->trashing_memory = 0;
 				goto ok_to_allocate;
-			}
+			} else if (nr_free_pages > freepages.low)
+				goto ok_to_allocate;
 		}
 		/*
 		 * Low priority (user) allocations must not

This will allow the system to be less close to freepages.min. Both the two patches applyed to pre6 make arca-vm-13-against-pre5 and arca-vm-13 is been reported by Steve to give the _same_ timing numbers as pre5 with its latest bench (with the difference that arca-vm-13 was generating 1/2 of swap hit than pre5). I guess he will try to do some other bench (as the image test soon) next days though.

--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#44 lore raw

Buffer handling (setting PG_referenced on access)

In reply to Linus Torvalds
Quoted 5 lines · Linus Torvalds

Btw, if there are people there who actually like timing different things (something I _hate_ doing - I lose interest if things become just a matter of numbers rather than trying to get some algorithm right), then there's one thing I'd love to hear about: the effect of trying to do some access bit setting on buffer cache pages.

OK, implementation was easy and simple, much simpler than it was made before (with BH_Touched copying...), but I must admit that even after lots of testing I couldn't find any difference. Not in performance, not in CPU usage, not in overall behaviour. Whatever results I have accomplished, they were too much in the statistical noise, so I don't have any useful data. Maybe, others can try and see.

But, nevertheless, four lines added to the kernel look very correct to me. My vote for including, if for nothing, then to make balance with page cache. It won't harm anything, that's for sure. Patch applies cleanly on pre-7, as found in testing directory on ftp.kernel.org.

Index: 2206.7/include/linux/fs.h

include/linux/fs.h Mon, 11 Jan 1999 08:31:48 +0100 zcalusic (linux-2.1/z/b/10_fs.h 1.1.5.1.1.3.1.1 644) renamed from include/linux/fs.h Mon, 04 Jan 1999 17:24:06 +0100 zcalusic (linux-2.1/z/b/10_fs.h 1.1.5.1.1.3 644) +3 -13
@@ -178,6 +178,9 @@
 #define BH_Req		3	/* 0 if the buffer has been invalidated */
 #define BH_Protected	6	/* 1 if the buffer is protected */
 
+#define buffer_page(bh)		(mem_map + MAP_NR((bh)->b_data))
+#define touch_buffer(bh)	set_bit(PG_referenced, &buffer_page(bh)->flags)
+
 /*
  * Try to keep the most commonly used fields in single cache lines (16
  * bytes) to improve performance.  This ordering should be
@@ -250,19 +253,6 @@
 {
 	return test_bit(BH_Protected, &bh->b_state);
 }
-
-/*
- * Deprecated - we don't keep per-buffer reference flags
- * any more.
- *
- * We _could_ try to update the page reference, but that
- * doesn't seem to really be worth it either. If we did,
- * it would look something like this:
- *
- *	#define buffer_page(bh)		(mem_map + MAP_NR((bh)->b_data))
- *	#define touch_buffer(bh)	set_bit(PG_referenced, &buffer_page(bh)->flags)
- */
-#define touch_buffer(bh)	do { } while (0)
 
 #include <linux/pipe_fs_i.h>
 #include <linux/minix_fs_i.h>

Index: 2206.7/fs/buffer.c

fs/buffer.c Mon, 11 Jan 1999 08:31:48 +0100 zcalusic (linux-2.1/G/b/41_buffer.c 1.1.1.1.1.3.2.1.2.1.1.1 644) renamed from fs/buffer.c Sat, 09 Jan 1999 03:44:23 +0100 zcalusic (linux-2.1/G/b/41_buffer.c 1.1.1.1.1.3.2.1.2.1 644) +2 -0
@@ -737,6 +737,7 @@
 				 put_last_lru(bh);
 			bh->b_flushtime = 0;
 		}
+		touch_buffer(bh);
 		return bh;
 	}
 
@@ -754,6 +755,7 @@
 	bh->b_lru_time	= jiffies;
 	bh->b_state=0;
 	insert_into_queues(bh);
+	touch_buffer(bh);
 	return bh;
 
 	/*

Regards,

Signature · 4 lines
Zlatko
--
This is a majordomo managed list.  To unsubscribe, send a message with
the body 'unsubscribe linux-mm me@address' to: [email protected]
#45 lore raw

Re: Buffer handling (setting PG_referenced on access)

Quoted 7 lines · Zlatko Calusic

OK, implementation was easy and simple, much simpler than it was made before (with BH_Touched copying...), but I must admit that even after lots of testing I couldn't find any difference. Not in performance, not in CPU usage, not in overall behaviour. Whatever results I have accomplished, they were too much in the statistical noise, so I don't have any useful data. Maybe, others can try and see.

This was what I saw in my very very inconclusive tests too - which is why I decided that there was no point in doing buffer cache aging at all.

Quoted 3 lines

But, nevertheless, four lines added to the kernel look very correct to me. My vote for including, if for nothing, then to make balance with page cache. It won't harm anything, that's for sure.

I can easily see it harming something - I actually think that not using the reference bit is "safer" in that it never allows the buffer cache to grow very aggressively for very long (and we definitely don't want to have an overlarge buffer cache - it's mostly used for temporary buffers for write-out anyway).

Basically I don't want to enable the aging code unless somebody shows me that it makes a marked improvement under some (reasonably real-world) circumstances.. So far the jury seems to say that it doesn't.

Linus

--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#46 lore raw

Re: Buffer handling (setting PG_referenced on access)

Quoted 11 lines · Linus Torvalds
Quoted 7 lines · Zlatko Calusic

OK, implementation was easy and simple, much simpler than it was made before (with BH_Touched copying...), but I must admit that even after lots of testing I couldn't find any difference. Not in performance, not in CPU usage, not in overall behaviour. Whatever results I have accomplished, they were too much in the statistical noise, so I don't have any useful data. Maybe, others can try and see.

This was what I saw in my very very inconclusive tests too - which is why I decided that there was no point in doing buffer cache aging at all.

Yes, looks like we finished our tests with same results.

Quoted 11 lines
Quoted 4 lines

But, nevertheless, four lines added to the kernel look very correct to me. My vote for including, if for nothing, then to make balance with page cache. It won't harm anything, that's for sure.

I can easily see it harming something - I actually think that not using the reference bit is "safer" in that it never allows the buffer cache to grow very aggressively for very long (and we definitely don't want to have an overlarge buffer cache - it's mostly used for temporary buffers for write-out anyway).

Quoted 4 lines

Basically I don't want to enable the aging code unless somebody shows me that it makes a marked improvement under some (reasonably real-world) circumstances.. So far the jury seems to say that it doesn't.

OK, I got one more idea in the meantime, and I'll try it as the time permits. In the meantime, I agree with you. If we can't prove it's actually worthwhile to add those four lines, then we really don't need them.

Regards,

Signature · 4 lines
Zlatko
--
This is a majordomo managed list.  To unsubscribe, send a message with
the body 'unsubscribe linux-mm me@address' to: [email protected]
#47 lore raw

Re: 2.2.0-pre[56] swap performance poor with > 1 thrashing task

In reply to Linus Torvalds
Quoted 3 lines · Linus Torvalds

As a no-op, it can now randomly and unprectably result in even worthwhile buffers just being thrown out - possibly quite soon after they've been loaded in. I happen to believe that it doesn't actually matter (and I'm

I think it doesn't matter because the buffer_under_min() check just protect the buffer cache enough. In arca-vm-22 I removed the specific buffer and cache min limitis so I applyed Zlatko patch ;).

Basically arca-vm-22 take the sum of the buffermem+page_cache_size always close to a percentage tunable via sysctl (10% as default) when _low_ on memory. So the buffer aging now make sense to me (not benchmarked though ;).

Somebody in the list asked for an algorithm that doens't work with magic but it's tunable. Having a constant cache+buffermem memory size under swapping seems to work very well and even if it doesn't work with magic I like it right now.

Andrea Arcangeli

--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#48 lore raw

Re: 2.2.0-pre[56] swap performance poor with > 1 thrashing task

In reply to Dax Kelson

Maybe this is not really a problem with swapping, but more with
concurrent I/O in general, because I KNOW that running low-priority niced jobs in the background (e.g. updatedb) can seriously degrade performance of tasks in the foreground (e.g. netscape) that are doing a minimal amount of I/O. I think I've seen a few people mention this in the past also.
In any case, I've kind of assumed that that was the way it is supposed
to be. Perhaps it is just that IDE drives really don't like writing 2 files at once. Or that the background task does a lot of I/O, and the clustering algorithm makes sure it all gets written before anything else happens. Anyway, I bet those explanations are wrong, but maybe there is another explanation.... I don't know.
Ah. So Zlatko has a patch. I look forward to it, and hope it improves
performance of non-swapping applications also.

-benRI

Signature · 8 lines
I don't need     education.
I don't need ANY education.
I don't need NO  education.

Benjamin Redelings I       <><      http://sdcc13.ucsd.edu/~bredelin
--
This is a majordomo managed list.  To unsubscribe, send a message with
the body 'unsubscribe linux-mm me@address' to: [email protected]
#49 lore raw

Re: 2.2.0-pre[56] swap performance poor with > 1 thrashing task

Quoted 3 lines · Benjamin Redelings I

Maybe this is not really a problem with swapping, but more with
concurrent I/O in general,

It's really easy to get really crappy performance with concurrent IO, if you end up just seeking back and forth on the disk - which is why we should be trying to cluster our IO. Sounds like we end up with silly behaviour where one process is paging in from one area of the disk while the other is paging out to another area, resulting in all the time spent in just moving the disk head rather than moving any actual data.

Or something silly like that. The fix is probably not all that complex:
the code is supposed to try to avoid it, but I bet I just had some idiotic braino that just completely defeated the whole idea. It sounds like Zlatko found my braino already.

Linus

--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#50 lore raw

Results: pre6 vs pre6+zlatko's_patch vs pre5 vs arcavm13

In reply to Steve Bergman

In an effort to streamline testing, I am now running just:

make depend; make clean; make bzlilo

and leaving out the modules part. I am also compiling only a minimal kernel with no options at all selected in menuconfig. I have added an idle mysql server to the mix, which still includes netscape and a number of the usual daemons (sendmail, lpd, inetd, etc.) along with vmstat 1, top, and ping remote_host. Please remember Linus' caution about the "swaps" number. Here are the latest results:

In 16MB:

pre6+zlatko_patch 5:29 192527 149728 3554
pre6 5:27 192002 149694 4257
pre5 5:28 188566 148674 5646
arcavm13 5:32 188560 148234 1594

Really putting on the squeeze, I tried out mem=12M which forced about 24MB into the swap area.

In 12MB:

pre6+zlatko_patch 22:14 383206 204482 57823
pre6 20:54 352934 191210 48678
pre5 Did not test
arcavm13 19:45 344452 180243 38977

They all seem about the same in 16MB. arcavm13 looks good in 12MB. Zlatko, let me know if you have any specific tests you want me to run on your patch.

-Steve
--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#51 lore raw

Re: Results: pre6 vs pre6+zlatko's_patch vs pre5 vs arcavm13

Steve Bergman wrote:

I ran the "image test" (loading 116 jpg images simultaneously) on the latest patches and got these results in 128MB (I end up with ~ 160MB in swap):

pre6+zlatko's_patch 2:35
pre6 2:27
pre5 1:58
arcavm13 9:13

Arcavm13 (the star performer in the low memory test) is having problems here. Pre5, which I performed about the same as the others in the my low memory test and which I ignored in my even lower 12MB test looks quite good here. Based on it's good performance here, I decided to run the 12MB kernel compile test on it, as well. (See what happens when I try to cut corners...)

In 12MB:

pre6+zlatko_patch       22:14   383206  204482  57823
pre6                    20:54   352934  191210  48678
pre5                    19:35	334680	183732	93427 
arcavm13                19:45   344452  180243  38977

Pre5 is looking good. Based upon the tests that I have run, anyway. I agree with the person who expressed a distrust of benchmarks. But numbers are necessary for tuning. "Feels faster" is just not a very trustworthy thing. So I also agree with one of the responses:

"Try out your favorite apps and time some portion of them and post any interesting numbers." (paraphrased)

Benchmarks are not the problem. The problem is the lack of comprehensiveness, or the tunnel-vision if you prefer, that benchmarks can lead one into. Find a way to quantify the things that you do everyday and post the results.

-Thanks
-Steve
--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#52 lore raw

Re: Results: pre6 vs pre6+zlatko's_patch vs pre5 vs arcavm13

Quoted 8 lines · Steve Bergman

I ran the "image test" (loading 116 jpg images simultaneously) on the latest patches and got these results in 128MB (I end up with ~ 160MB in swap):

pre6+zlatko's_patch 2:35
pre6 2:27
pre5 1:58
arcavm13 9:13

Can you run pre6+zlatko with just the mm/page_alloc.c one-liner reverted to pre5? That is, take pre6+zlatko, and just change

	try_to_free_pages(gfp_mask, freepages.high - nr_free_pages);

back to

	try_to_free_pages(gfp_mask, SWAP_CLUSTER_MAX);

That particular one-liner was almost certainly a mistake, it was done on the mistaken assumption that the clustering problem was due to insufficient write-time clustering - while zlatko found that it was actually due to fragmentation in the swap area. With zlatkos patch, the original SWAP_CLUSTER_MAX is probably better and almost certainly results in smoother behaviour due to less extreme free_pages..

Linus

--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#53 lore raw

Re: Results: pre6 vs pre6+zlatko's_patch vs pre5 vs arcavm13

Quoted 2 lines · Linus Torvalds

Can you run pre6+zlatko with just the mm/page_alloc.c one-liner reverted to pre5? That is, take pre6+zlatko, and just change

I have no time to try code these days :(

Quoted 4 lines
	try_to_free_pages(gfp_mask, freepages.high - nr_free_pages);

back to

Quoted 8 lines
	try_to_free_pages(gfp_mask, SWAP_CLUSTER_MAX);

That particular one-liner was almost certainly a mistake, it was done on the mistaken assumption that the clustering problem was due to insufficient write-time clustering - while zlatko found that it was actually due to fragmentation in the swap area. With zlatkos patch, the original SWAP_CLUSTER_MAX is probably better and almost certainly results in smoother behaviour due to less extreme free_pages..

I don't know which is zlatkos patch but my point is that it's try_to_free_pages that has to care to be balanced and to do things at best. I want to be allowed to ask try_to_free_pages to free any kind of space and such function has to run _always_ efficient.

My current free_user_and_cache() (arca-vm-13) is bad because it doesn't swapout aggressively. I am fixing it right now. When I'll have finished I'll post the new patch.

BTW, the reason pre6 is slower than my current _bad_ free_user_and_cache() (arca-vm-13) in low memory machines is that in high memory machines the freepages.min is something like 255 while in low memory machines freepages.min it's close to SWAP_CUSTER_MAX. So in low memory machines the swapout cluster has to be reduced (because now swapout doesn't free pages). free_user_and_cache() has to care about these issues and I see plain wrong to hardwire the swap cluster size to a constant number since the freepages values are dynamic (and also changable via sysctl).

I am not sure of all this, but this is currently my thought.

Comments?

Andrea Arcangeli

--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#54 lore raw

Re: Results: pre6 vs pre6+zlatko's_patch vs pre5 vs arcavm13

In reply to Linus Torvalds
Quoted 9 lines · Linus Torvalds

Can you run pre6+zlatko with just the mm/page_alloc.c one-liner reverted to pre5? That is, take pre6+zlatko, and just change

        try_to_free_pages(gfp_mask, freepages.high - nr_free_pages);

back to

        try_to_free_pages(gfp_mask, SWAP_CLUSTER_MAX);

OK, here are the updated results:

'Image test' in 128MB:

pre6+zlatko's_patch 2:35
and with requested change 3:09

pre6                    	2:27
pre5                    	1:58
arcavm13                	9:13

I also ran the kernel compile test:

In 12MB:

				Elapsed	Maj.	Min.	Swaps
				-----	------	------	-----
pre6+zlatko_patch       	22:14   383206  204482  57823
and with requested change	22:23	378662	198194	51445
pre6                    	20:54   352934  191210  48678
pre5                    	19:35   334680  183732  93427 
arcavm13                	19:45   344452  180243  38977

The change seems to have hurt it in both cases. What I am seeing on pre6 and it's derivitives is a *lot* of *swapin* activity. Pre5 almost exclusively swaps *out* during the image test, averaging about 1.25MB/sec (spends a lot of time at around 2000k/sec) with very little swapping in. All the pre6 derivitives swap *in* quite heavily during the test. The 'so' number sometimes drops to 0 for seconds at a time. It also looks like pre6 swaps out slightly more overall (~165MB vs 160MB).

-Steve
--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#55 lore raw

Re: Results: pre6 vs pre6+zlatko's_patch vs pre5 vs arcavm13

Quoted 8 lines · Steve Bergman

The change seems to have hurt it in both cases. What I am seeing on pre6 and it's derivitives is a *lot* of *swapin* activity. Pre5 almost exclusively swaps *out* during the image test, averaging about 1.25MB/sec (spends a lot of time at around 2000k/sec) with very little swapping in. All the pre6 derivitives swap *in* quite heavily during the test. The 'so' number sometimes drops to 0 for seconds at a time. It also looks like pre6 swaps out slightly more overall (~165MB vs 160MB).

This is interesting - the only thing that changed between pre5 and pre6 (apart from the line that I asked you to revert and that made things worse) was actually the deadlock code. And the only thing _that_ changes, in turn, is just the fact that when we allocate new buffers we cannot swap out.

Now, this all actally makes sense: what happens when we limit swap-out activity is that we limit our choices on what to do a _lot_.. That hurts performance - we had to avoid a really nice path because of the deadlock possibility, and due to that we can no longer make the best choice about what to free up. So performance goes down.

This shows up mainly on small memory machines, because on large memory machines we still have a lot of choice about what to free up, so it's not all that much of a problem.

But basically it seems that the reason pre-5 was so good was simply due to the bug that allowed it to deadlock. Sad, because there's no way I can re-introduce that nice behaviour without re-introducing the bug ;(

However, there are other things that we _can_ do. For example, we can easily make the memory management code less eager to try to free memory if it doesn't have the __GFP_IO bit set - because when it cannot swap it can no longer maintain a good balance of pages, so it doesn't make sense for it to try to free up all that many pages.

Also, if we cannot swap out, we shouldn't bother looking at the "trashing_memory" thing - there's just no point in making things worse.

The logic for that would be something like the attached patch to page_alloc.c..

Linus

mm/page_alloc.c renamed from linux/mm/page_alloc.c +8 -2
@@ -269,6 +231,9 @@
 				current->trashing_memory = 0;
 				goto ok_to_allocate;
 			}
+			/* If we cannot swap, ignore trashing_memory */
+			if (!(gfp_mask & __GFP_IO))
+				goto ok_to_allocate;
 		}
 		/*
 		 * Low priority (user) allocations must not
@@ -277,9 +242,12 @@
 		 */
 		current->trashing_memory = 1;
 		{
-			int freed;
+			int freed, pages;
+			pages = 16;
+			if (gfp_mask & __GFP_IO)
+				pages = freepages.high - nr_free_pages;
 			current->flags |= PF_MEMALLOC;
-			freed = try_to_free_pages(gfp_mask, freepages.high - nr_free_pages);
+			freed = try_to_free_pages(gfp_mask, pages);
 			current->flags &= ~PF_MEMALLOC;
 			if (!freed && !(gfp_mask & (__GFP_MED | __GFP_HIGH)))
 				goto nopage;

--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#56 lore raw

Re: Results: pre6 vs pre6+zlatko's_patch vs pre5 vs arcavm13

Quoted 9 lines

This shows up mainly on small memory machines, because on large memory machines we still have a lot of choice about what to free up, so it's not all that much of a problem.

But basically it seems that the reason pre-5 was so good was simply due to the bug that allowed it to deadlock. Sad, because there's no way I can re-introduce that nice behaviour without re-introducing the bug ;(

Stupid question: is it possible to teach it to recognize the deadlock ? If I understand things right "nice behaviour" happens when we don't have the deadlock and the deadlock occurs not very often. So we might check once a second whether we have been low on memory for a while with a lot of swap available and if so revert to "bug-proof" behaviour.

Vladimir Dergachev

--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#57 lore raw

Re: Results: pre6 vs pre6+zlatko's_patch vs pre5 vs arcavm13

In reply to Linus Torvalds
Quoted 2 lines · Linus Torvalds

The logic for that would be something like the attached patch to page_alloc.c..

I tried the patch in the 'image test' and it helped little if any. Still a lot of swapping in and the numbers are close enough that I'm not sure it helped at all. This was a comparison between vanilla pre6 and vanilla pre6+page_alloc_patch with no other patches applied.

-Steve
--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#58 lore raw

Re: Results: pre6 vs pre6+zlatko's_patch vs pre5 vs arcavm13

Quoted 5 lines · Steve Bergman

I tried the patch in the 'image test' and it helped little if any. Still a lot of swapping in and the numbers are close enough that I'm not sure it helped at all. This was a comparison between vanilla pre6 and vanilla pre6+page_alloc_patch with no other patches applied.

Ok, I think I now know why pre-6 looks so unbalanced. It's two issues.

Basically, trying to swap out a large number of pages from one process context is just doomed. It bascially sucks, because

- it has bad latency. This is further excerberated by the per-process "thrashing_memory" flag, which means that if we were unlucky enough to be selected to be the process that frees up memory, we'll probably be stuck with it for a long time. That can make it extremely unfair under some circumstances - other processes may allocate the pages we free'd up, so that we keep on being counted as a memory trasher even if we really aren't.

Note that this shows most under "moderate" load - the problem doesn't tend to show itself if you have some process that is _really_ allocating a lot of pages, because then that process will be correctly found by the trashing logic. But if you have lots of "normal load" processes, some of those can get really badly hurt by this.

In particular, the worst case you have a number of processes that all allocate memory, but not very quickly - certainly not more quickly than we can page things out. What happens is that under these circumstances one of them gets marked as a "scapegoat", and once that happens all the others will just live off the pages that the scapegoat frees up, while the scapegoat itself doesn't make much progress at all because it is always just freeing memory for others.

The really bad behaviour tends to go away reasonably quickly, but while it happens it's _really_ unfair.

- try_to_free_pages() just goes overboard, and starts paging stuff out without getting back to the nice balanced behaviour. This is what Andrea noticed.

Essentially, once it starts failing the shrink_mmap() tests, it will just page things out crazily. Normally this is avoided by just always starting from shrink_mmap(), but if you ask try_to_free_pages() to try to free up a ton of pages, the balancing that it does is basically bypassed.

So basically pre-6 works _really_ well for the kind of stress-me stuff that it was designed for: a few processes that are extremely memory hungry. It gets close to perfect swap-out behaviour, simply because it is optimized for getting into a paging rut.

That makes for nice benchmarks, but it also explains why (a) sometimes it's just not very nice for interactive behaviour and (b) why it under normal load can easily swap much too eagerly.

Anyway, the first problem is fixed by making "trashing" be a global flag rather than a per-process flag. Being per-process is really nice when it finds the right process, but it's really unfair under a lot of other circumstances. I'd rather be fair than get the best possible page-out speed.

Note that even a global flag helps: it still clusters the write-outs, and means that processes that allocate more pages tend to be more likely to be hit by it, so it still does a large part of what the per-process flag did
- without the unfairness (but admittedly being unfair sometimes gets you better performance - you just have to be _very_ careful whom you target with the unfairness, and that's the hard part).

The second problem actually goes away by simply just not asking try_to_free_pages() to free too many pages - and having the global trashing flag makes it unnecessary to do so anyway because the flag will essentially cluster the page-outs even without asking for them to be all done in one large chunk (and now it's not just one process that gets hit any more).

There's a "pre-7.gz" on ftp.kernel.org in testing, anybody interested? It's not the real thing, as I haven't done the write semaphore deadlock thing yet, but that one will not affect normal users anyway so for performance testing this should be equivalent.

Linus

--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#59 lore raw

testing/pre-7 and do_poll()

According to Linus Torvalds:

Quoted 1 line

There's a "pre-7.gz" on ftp.kernel.org in testing, anybody interested?

Got it, like it -- *except* the fix for overflow in do_poll() is a little bit off. Quoting testing/pre-7:

	if (timeout) {
		/* Carefula about overflow in the intermediate values */
		if ((unsigned long) timeout < MAX_SCHEDULE_TIMEOUT / HZ)
			timeout = (timeout*HZ+999)/1000+1;
		else /* Negative or overflow */
			timeout = MAX_SCHEDULE_TIMEOUT;
	}

However, the maximum legal millisecond timeout isn't (as shown) MAX_SCHEDULE_TIMEOUT/HZ, but rather MAX_SCHEDULE_TIMEOUT/(1000/HZ). So this code will turn some large timeouts into MAX_SCHEDULE_TIMEOUT unnecessarily.

Therefore, I suggest this patch:

Index: fs/select.c
*************** asmlinkage int sys_poll(struct pollfd * *** 336,346 ****
goto out;

! if (timeout) {
! /* Carefula about overflow in the intermediate values */
! if ((unsigned long) timeout < MAX_SCHEDULE_TIMEOUT / HZ)
! timeout = (timeout*HZ+999)/1000+1;
! else /* Negative or overflow */
! timeout = MAX_SCHEDULE_TIMEOUT;
! }

err = -ENOMEM;
--- 336,343 ----
goto out;

! if (timeout < 0)
! timeout = MAX_SCHEDULE_TIMEOUT;
! else if (timeout)
! timeout = ROUND_UP(timeout, 1000/HZ);

  	err = -ENOMEM;
Signature · 5 lines
Chip Salzenberg      - a.k.a. -      <[email protected]>
      "When do you work?"   "Whenever I'm not busy."
--
This is a majordomo managed list.  To unsubscribe, send a message with
the body 'unsubscribe linux-mm me@address' to: [email protected]
#60 lore raw

Re: testing/pre-7 and do_poll()

Quoted 12 lines · Chip Salzenberg

Got it, like it -- *except* the fix for overflow in do_poll() is a little bit off. Quoting testing/pre-7:

	if (timeout) {
		/* Carefula about overflow in the intermediate values */
		if ((unsigned long) timeout < MAX_SCHEDULE_TIMEOUT / HZ)
			timeout = (timeout*HZ+999)/1000+1;
		else /* Negative or overflow */
			timeout = MAX_SCHEDULE_TIMEOUT;
	}
Quoted 4 lines

However, the maximum legal millisecond timeout isn't (as shown) MAX_SCHEDULE_TIMEOUT/HZ, but rather MAX_SCHEDULE_TIMEOUT/(1000/HZ). So this code will turn some large timeouts into MAX_SCHEDULE_TIMEOUT unnecessarily.

Note the comment (and do NOT look at the speeling).

In particular, we need to make sure the _intermediate_ value doesn' toverflow. We could do that by using 64-bit arithmetic, but let's not.

Quoted 4 lines

! if (timeout < 0)
! timeout = MAX_SCHEDULE_TIMEOUT;
! else if (timeout)
! timeout = ROUND_UP(timeout, 1000/HZ);

Eh? And re-introduce the original bug?

Linus

--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#61 lore raw

Re: testing/pre-7 and do_poll()

According to Linus Torvalds:

Quoted 8 lines · Chip Salzenberg
Quoted 4 lines

However, the maximum legal millisecond timeout isn't (as shown) MAX_SCHEDULE_TIMEOUT/HZ, but rather MAX_SCHEDULE_TIMEOUT/(1000/HZ). So this code will turn some large timeouts into MAX_SCHEDULE_TIMEOUT unnecessarily.

Note the comment (and do NOT look at the speeling). In particular, we need to make sure the _intermediate_ value doesn' toverflow.

Of course; that's obvious. What's perhaps less obvious is that I'm suggesting a change in the calculation of timeout -- a change which avoids the creation of unnecessarily large _intermediate_ values.

Quoted 6 lines
Quoted 4 lines

! if (timeout < 0)
! timeout = MAX_SCHEDULE_TIMEOUT;
! else if (timeout)
! timeout = ROUND_UP(timeout, 1000/HZ);

Eh? And re-introduce the original bug?

Well, I forgot the (unsigned long) cast, as someone else noted:

	timeout = ROUND_UP((unsigned long) timeout, 1000/HZ);

Otherwise, the code is Just Right.

Signature · 5 lines
Chip Salzenberg      - a.k.a. -      <[email protected]>
      "When do you work?"   "Whenever I'm not busy."
--
This is a majordomo managed list.  To unsubscribe, send a message with
the body 'unsubscribe linux-mm me@address' to: [email protected]
#62 lore raw

Re: testing/pre-7 and do_poll()

Quoted 6 lines · Chip Salzenberg

Well, I forgot the (unsigned long) cast, as someone else noted:

	timeout = ROUND_UP((unsigned long) timeout, 1000/HZ);

Otherwise, the code is Just Right.

Duh?

The above code is basically just completely wrong.

Hint: HZ is a define - not 100.

You just ended up dividing by zero on certain architectures.

Linus

--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#63 lore raw

Re: testing/pre-7 and do_poll()

According to Linus Torvalds:

Quoted 7 lines · Chip Salzenberg
Quoted 3 lines

Well, I forgot the (unsigned long) cast, as someone else noted:

	timeout = ROUND_UP((unsigned long) timeout, 1000/HZ);

Otherwise, the code is Just Right.

Hint: HZ is a define - not 100.
You just ended up dividing by zero on certain architectures.

I didn't think HZ ranged over 1000 in practice, else of course I would not have written the above.

Signature · 5 lines
Chip Salzenberg      - a.k.a. -      <[email protected]>
      "When do you work?"   "Whenever I'm not busy."
--
This is a majordomo managed list.  To unsubscribe, send a message with
the body 'unsubscribe linux-mm me@address' to: [email protected]
#64 lore raw

Re: testing/pre-7 and do_poll()

Quoted 6 lines · Chip Salzenberg
Quoted 3 lines

Hint: HZ is a define - not 100.
You just ended up dividing by zero on certain architectures.

I didn't think HZ ranged over 1000 in practice, else of course I would not have written the above.

I made the same assumption wrt usecs (notice how I myself would divide by zero on any architecture where HZ is over 1000000).

Right now, HZ is 100 on most architectures, with alpha being the exception at 1024. Some of the PC speaker patches used to have HZ at 8192 even on a PC, although later versions scaled it down (and just internally used a timer tick happening at 8kHz, leaving HZ at 100).

With modern machines, 100Hz is just peanuts, and a HZ in the kilohertz certainly makes sense - and allows for nicer granularity for a lot of things. So far, megahertz are still far in the future, but maybe I some day will have to remove even that assumption. Unlikely to be a problem in my lifetime, but hey, I can hope (whether due to a long life or really fast CPU's, I don't care ;)

Linus

--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#65 lore raw

Re: testing/pre-7 and do_poll()

Quoted 4 lines · Linus Torvalds

things. So far, megahertz are still far in the future, but maybe I some day will have to remove even that assumption. Unlikely to be a problem in my lifetime, but hey, I can hope (whether due to a long life or really fast CPU's, I don't care ;)

Well, they've made a photonic chip, so we may be thinking about this sooner than you think... Think 200GHz processors.

-Shawn
<=========== America Held Hostage ===========>
Day 2182 for the poor and the middle class.
Day 2201 for the rich and the dead.
740 days remaining in the Raw Deal.
<============================================>

--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#66 lore raw

Re: testing/pre-7 and do_poll()

Quoted 9 lines · Shawn Leas
Quoted 4 lines · Linus Torvalds

things. So far, megahertz are still far in the future, but maybe I some day will have to remove even that assumption. Unlikely to be a problem in my lifetime, but hey, I can hope (whether due to a long life or really fast CPU's, I don't care ;)

Well, they've made a photonic chip, so we may be thinking about this sooner than you think... Think 200GHz processors.

Hey, I want to see the memory subsystems for it..

Linus

--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#67 lore raw

Re: testing/pre-7 and do_poll()

Quoted 11 lines · On 11-Jan-99 Linus Torvalds wrote:
Quoted 7 lines · Shawn Leas
Quoted 4 lines · Linus Torvalds

things. So far, megahertz are still far in the future, but maybe I some day will have to remove even that assumption. Unlikely to be a problem in my lifetime, but hey, I can hope (whether due to a long life or really fast CPU's, I don't care ;)

Quoted 6 lines
Quoted 2 lines

Well, they've made a photonic chip, so we may be thinking about this sooner than you think... Think 200GHz processors.

Hey, I want to see the memory subsystems for it..

Linus

Got any links to such technology? I've been working on it for a while, but making transistors from glass are not quite as easy as I would think.. Lemme know.

----------------------------------------

Ed Stafford            Of. (901)348-3487
iXL Hosting            Fx. (901)345-9992      
Programming Engineer   [email protected]

----------------------------------------

--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#68 lore raw

Re: testing/pre-7 and do_poll()

Quoted 16 lines · On Mon, 11 Jan 1999 [email protected] wrote:
Quoted 14 lines · On 11-Jan-99 Linus Torvalds wrote:
Quoted 9 lines · Shawn Leas
Quoted 4 lines · Linus Torvalds

things. So far, megahertz are still far in the future, but maybe I some day will have to remove even that assumption. Unlikely to be a problem in my lifetime, but hey, I can hope (whether due to a long life or really fast CPU's, I don't care ;)

Well, they've made a photonic chip, so we may be thinking about this sooner than you think... Think 200GHz processors.

Quoted 7 lines
Quoted 3 lines

Hey, I want to see the memory subsystems for it..

Linus

Got any links to such technology? I've been working on it for a while, but making transistors from glass are not quite as easy as I would think.. Lemme know.

Take a lewk at this! And yes, it aint digital logic, it's quantum logic. It used to be that photonic computers were not really processors as we know them. This is the real deal.

http://www.nbnn.com/pubNews/123239.html

-Shawn
<=========== America Held Hostage ===========>
Day 2183 for the poor and the middle class.
Day 2202 for the rich and the dead.
739 days remaining in the Raw Deal.
<============================================>

--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#69 lore raw

Re: testing/pre-7 and do_poll()

In reply to Linus Torvalds
Quoted 3 lines · Linus Torvalds

Hey, I want to see the memory subsystems for it..

Linus

Actually, I would imagine that such a processor could use a very long nano-manufactured fiber loop as memory. Sorta like mercury tube storage...

But.. You'd be the one to know about fancy processor dohickies wouldn't you? :)

--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#70 lore raw

Re: testing/pre-7 and do_poll()

In reply to Chip Salzenberg
Quoted 14 lines · Chip Salzenberg

According to Linus Torvalds:

Quoted 1 line

There's a "pre-7.gz" on ftp.kernel.org in testing, anybody interested?

Got it, like it -- *except* the fix for overflow in do_poll() is a little bit off. Quoting testing/pre-7:

	if (timeout) {
		/* Carefula about overflow in the intermediate values */
		if ((unsigned long) timeout < MAX_SCHEDULE_TIMEOUT / HZ)
			timeout = (timeout*HZ+999)/1000+1;
		else /* Negative or overflow */
			timeout = MAX_SCHEDULE_TIMEOUT;
	}
Quoted 4 lines

However, the maximum legal millisecond timeout isn't (as shown) MAX_SCHEDULE_TIMEOUT/HZ, but rather MAX_SCHEDULE_TIMEOUT/(1000/HZ). So this code will turn some large timeouts into MAX_SCHEDULE_TIMEOUT unnecessarily.

A/(B/C) = A * (C / B) = A / B * C (done this way to eliminate overflow)

MAX_SCHEDULE_TIMEOUT / 1000 * HZ

Adam

--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#71 lore raw

Re: Results: pre6 vs pre6+zlatko's_patch vs pre5 vs arcavm13

In reply to Steve Bergman

Here are updated results including arcavm16:

116 Image test in 128MB:

pre6+zlatko's_patch             2:35
and with requested change       3:09
pre6                            2:27
pre5                            1:58
arcavm13                        9:13
arcavm15                        1:59
pre-7                           2:41

arcavm16 1:54

For the kernel compile test in 12MB:

                                Elapsed Maj.    Min.    Swaps
                                -----   ------  ------  -----
pre6+zlatko_patch               22:14   383206  204482  57823
and with requested change       22:23   378662  198194  51445
pre6                            20:54   352934  191210  48678
pre5                            19:35   334680  183732  93427
arcavm13                        19:45   344452  180243  38977
arcavm15                        20:07   N/A     N/A     N/A
pre-7                           21:14   356386  192835  50912

arcavm16 20:09 N/A N/A N/A

I think it's better than arcavm15 on the image test and the same on the compile test.

-Steve
--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#72 lore raw

Re: Results: pre6 vs pre6+zlatko's_patch vs pre5 vs arcavm13

Quoted 5 lines · Steve Bergman

Here are updated results including arcavm16:

116 Image test in 128MB:

Quoted 8 lines
pre6+zlatko's_patch             2:35
and with requested change       3:09
pre6                            2:27
pre5                            1:58
arcavm13                        9:13
arcavm15                        1:59
pre-7                           2:41

arcavm16 1:54

Cool, now that arcavm16 (in pre6) is faster than pre5 I am courious to see what will happens with the one liner patch below applyed on the top of arcavm16 (maybe nothing but... ;). We can call the resulting code arcavm17 against pre6 (that pratically insteaed is arcavm16 applyed on pre5 ;).

Index: linux/mm/page_alloc.c

mm/page_alloc.c renamed from mm/page_alloc.c:1.1.1.7 +1 -1
diff -u linux/mm/page_alloc.c:1.1.1.7 linux/mm/page_alloc.c:1.1.1.1.2.27
@@ -279,7 +279,7 @@
 		{
 			int freed;
 			current->flags |= PF_MEMALLOC;
-			freed = try_to_free_pages(gfp_mask, freepages.high - nr_free_pages);
+			freed = try_to_free_pages(gfp_mask, SWAP_CLUSTER_MAX);
 			current->flags &= ~PF_MEMALLOC;
 			if (!freed && !(gfp_mask & (__GFP_MED | __GFP_HIGH)))
 				goto nopage;

Andrea Arcangeli

--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#73 lore raw

Re: Results: pre6 vs pre6+zlatko's_patch vs pre5 vs arcavm13

I've seen pre7 now and I produced arca-vm-18 against it.

In arca-vm-18 I avoided the swaping readahead if we would be forced to do _sync_ IO in the readahead. This make tons of sense to me.

I also reverted my trashing heuristic to a per-process thing. The point of the heuristic is not to penalyze processes. The pint is to _not_ penalyze processes that are not eating memory. Making it a static variable make sense of course but it's a completly different thing. And I think that having only a few processes that are in the free-pages-path will improve global performances.

Here arca-vm-18 against 2.2.0-pre7 in the testing directory (sent me by email by Steve).

Note: it's still very interesting how arca-vm-17 is performing since here I am following pre5/pre7/arca-vm-17 style of freeing every time only SWAP_CLUSTER_MAX pages. Here this change decrease a _lot_ swapout performances, but I don't know if the global system is faster... I am only running a trashing-swapout-benchmarking application, and I am not benchmarking how the rest of the system is responsive...

Another thing that would be interesting could be to change SWAPFILE_CLUSTER to 256 as in clean pre7. I think it's not needed because I am not hearing disk seeks under heavy swapping but may I guess there is some reason is 256 in pre7 ;)?

Index: linux/include/linux/mm.h

include/linux/mm.h renamed from include/linux/mm.h:1.1.1.6 +1 -3
diff -u linux/include/linux/mm.h:1.1.1.6 linux/include/linux/mm.h:1.1.1.1.2.18
@@ -118,7 +118,6 @@
 	unsigned long offset;
 	struct page *next_hash;
 	atomic_t count;
-	unsigned int unused;
 	unsigned long flags;	/* atomic flags, some possibly updated asynchronously */
 	struct wait_queue *wait;
 	struct page **pprev_hash;
@@ -302,8 +301,7 @@
 
 /* filemap.c */
 extern void remove_inode_page(struct page *);
-extern unsigned long page_unuse(struct page *);
-extern int shrink_mmap(int, int);
+extern int FASTCALL(shrink_mmap(int, int));
 extern void truncate_inode_pages(struct inode *, unsigned long);
 extern unsigned long get_cached_page(struct inode *, unsigned long, int);
 extern void put_cached_page(unsigned long);

Index: linux/include/linux/sched.h

include/linux/sched.h renamed from include/linux/sched.h:1.1.1.6 +2 -1
diff -u linux/include/linux/sched.h:1.1.1.6 linux/include/linux/sched.h:1.1.1.1.2.11
@@ -270,6 +275,7 @@
 /* mm fault and swap info: this can arguably be seen as either mm-specific or thread-specific */
 	unsigned long min_flt, maj_flt, nswap, cmin_flt, cmaj_flt, cnswap;
 	int swappable:1;
+	int trashing:1;
 	unsigned long swap_address;
 	unsigned long swap_cnt;		/* number of pages to swap on next pass */
 /* process credentials */
@@ -355,7 +361,7 @@
 /* utime */	{0,0,0,0},0, \
 /* per CPU times */ {0, }, {0, }, \
 /* flt */	0,0,0,0,0,0, \
-/* swp */	0,0,0, \
+/* swp */	0,0,0,0, \
 /* process credentials */					\
 /* uid etc */	0,0,0,0,0,0,0,0,				\
 /* suppl grps*/ 0, {0,},					\

Index: linux/kernel/fork.c

kernel/fork.c renamed from kernel/fork.c:1.1.1.6 +1 -0
diff -u linux/kernel/fork.c:1.1.1.6 linux/kernel/fork.c:1.1.1.1.2.10
@@ -511,6 +514,7 @@
 
 	p->did_exec = 0;
 	p->swappable = 0;
+	p->trashing = 0;
 	p->state = TASK_UNINTERRUPTIBLE;
 
 	copy_flags(clone_flags, p);

Index: linux/kernel/sysctl.c

kernel/sysctl.c renamed from kernel/sysctl.c:1.1.1.6 +3 -1
diff -u linux/kernel/sysctl.c:1.1.1.6 linux/kernel/sysctl.c:1.1.1.1.2.11
@@ -32,7 +32,7 @@
 
 /* External variables not in a header file. */
 extern int panic_timeout;
-extern int console_loglevel, C_A_D;
+extern int console_loglevel, C_A_D, swapout_interval;
 extern int bdf_prm[], bdflush_min[], bdflush_max[];
 extern char binfmt_java_interpreter[], binfmt_java_appletviewer[];
 extern int sysctl_overcommit_memory;
@@ -216,6 +216,8 @@
 };
 
 static ctl_table vm_table[] = {
+	{VM_SWAPOUT, "swapout_interval",
+	 &swapout_interval, sizeof(int), 0644, NULL, &proc_dointvec},
 	{VM_FREEPG, "freepages", 
 	 &freepages, sizeof(freepages_t), 0644, NULL, &proc_dointvec},
 	{VM_BDFLUSH, "bdflush", &bdf_prm, 9*sizeof(int), 0600, NULL,

Index: linux/mm/filemap.c

mm/filemap.c renamed from mm/filemap.c:1.1.1.9 +3 -5
diff -u linux/mm/filemap.c:1.1.1.9 linux/mm/filemap.c:1.1.1.1.2.44
@@ -122,13 +126,13 @@
 {
 	static unsigned long clock = 0;
 	unsigned long limit = num_physpages;
+	unsigned long count;
 	struct page * page;
-	int count;
 
 	count = (limit << 1) >> priority;
 
 	page = mem_map + clock;
-	do {
+	while (count-- != 0) {
 		int referenced;
 
 		/* This works even in the presence of PageSkip because
@@ -147,7 +151,6 @@
 			clock = page->map_nr;
 		}
 		
-		count--;
 		referenced = test_and_clear_bit(PG_referenced, &page->flags);
 
 		if (PageLocked(page))
@@ -191,8 +194,7 @@
 			remove_inode_page(page);
 			return 1;
 		}
-
-	} while (count > 0);
+	}
 	return 0;
 }
 

Index: linux/mm/page_alloc.c

mm/page_alloc.c renamed from mm/page_alloc.c:1.1.1.8 +6 -5
diff -u linux/mm/page_alloc.c:1.1.1.8 linux/mm/page_alloc.c:1.1.1.1.2.28
@@ -212,19 +212,18 @@
 		 * further thought.
 		 */
 		if (!(current->flags & PF_MEMALLOC)) {
-			static int trashing = 0;
 			int freed;
 
 			if (nr_free_pages > freepages.min) {
-				if (!trashing)
+				if (!current->trashing)
 					goto ok_to_allocate;
 				if (nr_free_pages > freepages.low) {
-					trashing = 0;
+					current->trashing = 0;
 					goto ok_to_allocate;
 				}
 			}
 
-			trashing = 1;
+			current->trashing = 1;
 			current->flags |= PF_MEMALLOC;
 			freed = try_to_free_pages(gfp_mask);
 			current->flags &= ~PF_MEMALLOC;
@@ -356,7 +355,9 @@
 	offset = (offset >> page_cluster) << page_cluster;
 	
 	for (i = 1 << page_cluster; i > 0; i--) {
-	      if (offset >= swapdev->max)
+	      if (offset >= swapdev->max ||
+		  /* don't block on I/O for doing readahead -arca */
+		  atomic_read(&nr_async_pages) > pager_daemon.swap_cluster)
 		      return;
 	      if (!swapdev->swap_map[offset] ||
 		  swapdev->swap_map[offset] == SWAP_MAP_BAD ||

Index: linux/mm/swapfile.c

mm/swapfile.c renamed from mm/swapfile.c:1.1.1.3 +1 -1
diff -u linux/mm/swapfile.c:1.1.1.3 linux/mm/swapfile.c:1.1.1.1.2.4
@@ -23,7 +23,7 @@
 
 struct swap_info_struct swap_info[MAX_SWAPFILES];
 
-#define SWAPFILE_CLUSTER 256
+#define SWAPFILE_CLUSTER	SWAP_CLUSTER_MAX
 
 static inline int scan_swap_map(struct swap_info_struct *si)
 {

Index: linux/mm/vmscan.c

mm/vmscan.c renamed from mm/vmscan.c:1.1.1.12 +56 -26

136 lines not on this page · raw message

--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#74 lore raw

Re: Results: pre6 vs pre6+zlatko's_patch vs pre5 vs arcavm13

Quoted 4 lines · Andrea Arcangeli

I've seen pre7 now and I produced arca-vm-18 against it.

In arca-vm-18 I avoided the swaping readahead if we would be forced to do _sync_ IO in the readahead. This make tons of sense to me.

Yes, I agree. I made a same change in my development patches, this morning, and it works well. We can only gain with policy like that.

Quoted 5 lines

Another thing that would be interesting could be to change SWAPFILE_CLUSTER to 256 as in clean pre7. I think it's not needed because I am not hearing disk seeks under heavy swapping but may I guess there is some reason is 256 in pre7 ;)?

Better clustering of pages on the disk. That will improve swapin readahead hit rate, and overall performance.

Regards,

Signature · 4 lines
Zlatko
--
This is a majordomo managed list.  To unsubscribe, send a message with
the body 'unsubscribe linux-mm me@address' to: [email protected]
#75 lore raw

Re: Results: pre6 vs pre6+zlatko's_patch vs pre5 vs arcavm13

In reply to Andrea Arcangeli
Quoted 5 lines · Andrea Arcangeli

Here arca-vm-18 against 2.2.0-pre7 in the testing directory (sent me by email by Steve).

(Zlatko, your patch is next. ;-) )

Here are the results:

116 Image test in 128MB:

pre6+zlatko's_patch             2:35
and with requested change       3:09
pre6                            2:27
pre5                            1:58
arcavm13                        9:13
arcavm15                        1:59
pre-7                           2:41
arcavm16                        1:54

arcavm18 1:57

For the kernel compile test in 12MB:

                                Elapsed Maj.    Min.    Swaps
                                -----   ------  ------  -----
pre6+zlatko_patch               22:14   383206  204482  57823
and with requested change       22:23   378662  198194  51445
pre6                            20:54   352934  191210  48678
pre5                            19:35   334680  183732  93427
arcavm13                        19:45   344452  180243  38977
arcavm15                        20:07   N/A     N/A     N/A
pre-7                           21:14   356386  192835  50912
arcavm16                        20:09   N/A     N/A     N/A

arcavm18 21:08 363438 190763 48982

-Steve
--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#76 lore raw

Results: Zlatko's new vm patch

Here are the results:

116 Image test in 128MB:

pre6                            2:27
pre5                            1:58
arcavm13                        9:13
arcavm15                        1:59
pre-7                           2:41
arcavm16                        1:54
arcavm18                        1:57

pre-7+zlatko's latest patch 2:14

For the kernel compile test in 12MB:

Elapsed Maj. Min. Swaps
----- ------ ------ -----

pre6                            20:54   352934  191210  48678
pre5                            19:35   334680  183732  93427
arcavm13                        19:45   344452  180243  38977
arcavm15                        20:07   N/A     N/A     N/A
pre-7                           21:14   356386  192835  50912
arcavm16                        20:09   N/A     N/A     N/A
arcavm18                        21:08   363438  190763  48982

pre-7+zlatko's latest patch 21:34 358408 193930 51813

The patch seems to help in the image test and hurt a bit in the 12MB compile test (vs pre-7).

-Steve
--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#77 lore raw

Re: Results: Zlatko's new vm patch

Note that there are very few people who are testing interactive feel. I'd be happier with more people giving more subjective comments on how the system feels under heavy memory load.

The only feedback I have so far says that pre-7 is much better than any of the pre-6 versions, but I'd be happier with more coverage depth and more comments from people in different circumstances. For example, what does it feel like when you're paging heavily and doing a "find" at the same time on a 16M machine?

I know this is harder than just trying to determine the throughput of something, but the pre-6 thing certainly showed how dangerous it was to just look at numbers.

Linus

--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#78 lore raw

Re: Results: Zlatko's new vm patch

Quoted 3 lines · Linus Torvalds

Note that there are very few people who are testing interactive feel. I'd be happier with more people giving more subjective comments on how the system feels under heavy memory load.

With my latest free_user_and_cache() (arca-vm >= 16) you can't get bad iteractive performances. Usually bad iteractive performances are due unbalaced algorithms in the big try_to_free_pages() path.

Andrea Arcangeli

--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#79 lore raw

Re: Results: Zlatko's new vm patch

In reply to Linus Torvalds

Well, sometimes the system writes to swap before I have used half my memory ( in X ) I view this with wmmon in windowmaker.. also on shutting down the system, it fails to unmount partitions saying they are busy and forcing checks next boot saying they were not cleanly unmounted. 2.2.0-pre4 - pre6 ( I do not have pre7 to test )

Quoted 16 lines · Linus Torvalds

Note that there are very few people who are testing interactive feel. I'd be happier with more people giving more subjective comments on how the system feels under heavy memory load.

The only feedback I have so far says that pre-7 is much better than any of the pre-6 versions, but I'd be happier with more coverage depth and more comments from people in different circumstances. For example, what does it feel like when you're paging heavily and doing a "find" at the same time on a 16M machine?

I know this is harder than just trying to determine the throughput of something, but the pre-6 thing certainly showed how dangerous it was to just look at numbers.

Quoted 8 lines

Linus

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
Please read the FAQ at http://www.tux.org/lkml/

---
*************************************

*          Joseph Anthony           *
*          [email protected]           *
*     http://wasteland.cowboy.net   *
*  -------------------------------  *
*  System Administrator Cowboy.net  *
*       http://www.cowboy.net       *

*************************************

--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#80 lore raw

Re: Results: Zlatko's new vm patch

Hi,

Quoted 2 lines · Joseph Anthony

Well, sometimes the system writes to swap before I have used half my memory ( in X ) I view this with wmmon in windowmaker..

Suspect wmmon in that case. If you can show this happening in a trace output from "vmstat 1", then I'll start to worry.

--Stephen
--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#81 lore raw

Re: Results: Zlatko's new vm patch

Quoted 5 lines · Stephen C. Tweedie
Quoted 2 lines

Well, sometimes the system writes to swap before I have used half my memory ( in X ) I view this with wmmon in windowmaker..

Suspect wmmon in that case. If you can show this happening in a trace output from "vmstat 1", then I'll start to worry.

wmmon stuffs both swap and physical mem in its "MEM" area, and also has a listing for "SWP", ie swap. I assume top is still reliable?

m.

Signature · 6 lines
"We watched her fall over and lay down,
 shouting the poetic truths of high school journal keepers."
 -- Lee Rinaldo, Sonic Youth
--
This is a majordomo managed list.  To unsubscribe, send a message with
the body 'unsubscribe linux-mm me@address' to: [email protected]
#82 lore raw

Re: Results: Zlatko's new vm patch

Hi,

Quoted 2 lines · Michael K Vance

wmmon stuffs both swap and physical mem in its "MEM" area, and also has a listing for "SWP", ie swap. I assume top is still reliable?

It should be, yes.

--Stephen
--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#83 lore raw

Re: Results: Zlatko's new vm patch

In reply to Linus Torvalds
Quoted 3 lines · Linus Torvalds

Note that there are very few people who are testing interactive feel. I'd be happier with more people giving more subjective comments on how the system feels under heavy memory load.

I left my machine today (64mb/80mb swap, running pre6 on an MMX/233) running netscape, xemacs, a few rxvt's, and xscreensaver. Many times when I get home after classes, xscreensaver's GL apps will have swapped large portions of netscape and xemacs out. Today when I came home, I tried to check my mail, and write a bit of code, but everything was swapping left and right. It wasn't just that netscape and xemacs got swapped back in, and then that was that--instead it just continually ground my hard drive as it downloaded email and I switched around to apps, etc, for a good few minutes. Very unpleasant.

FYI,

m.

Signature · 6 lines
"We watched her fall over and lay down,
 shouting the poetic truths of high school journal keepers."
 -- Lee Rinaldo, Sonic Youth
--
This is a majordomo managed list.  To unsubscribe, send a message with
the body 'unsubscribe linux-mm me@address' to: [email protected]
#84 lore raw

Where to find pre7. Was: Results: Zlatko's new vm patch

In reply to Linus Torvalds

On Mon, Jan 11, 1999 at 09:33:08PM -0800, Linus Torvalds wrote:
<snip>

Quoted 3 lines

The only feedback I have so far says that pre-7 is much better than any of the pre-6 versions, but I'd be happier with more coverage depth and more

I've not found the pre7 in the usual places on the mirrors. I found something that looks like it in /pub/linux/kernel/testing/pre-7.gz, is this the one, and is it a "real" pre-release? I'm a little uncertain since it's not in the same place as the others.

/robert

Signature · 5 lines
Robert Thorncrantz                                 [email protected]
Mundus Vult Decipi                              [email protected]
--
This is a majordomo managed list.  To unsubscribe, send a message with
the body 'unsubscribe linux-mm me@address' to: [email protected]
#85 lore raw

PATCH 1/1 arca-vm-19 [Re: Results: Zlatko's new vm patch]

In reply to Steve Bergman

I produced a new arca-vm-19. I would like if you could try it. I don't know if it will work well as previous one...

You could try it on 128Mbyte:

1. with the bootup pager settings (8 2 2 5 32 128 256).
2. after echo 10 2 2 5 32 128 256 >/proc/sys/vm/pager
3. after echo 8 2 2 10 32 128 256 >/proc/sys/vm/pager
4. after echo 8 2 2 5 32 32 256 >/proc/sys/vm/pager
5. after echo 8 2 2 5 32 128 512 >/proc/sys/vm/pager
6. after echo 8 2 2 5 64 128 512 >/proc/sys/vm/pager

NOTENOTE: if the performances of `1.' are worse than arca-vm-18, don't _waste_ time trying other pager settings of course ;).

Again the main differeces is free_user_and_cache() implementation. Now I try to balance the swap cache to the 5% of total memeory during heavy swapping activities. I do that growing the cache slowly from the point shrink_mmap start failing. This _seems_ to work pretty well (the cache levels seems more balanced than arca-vm-18). But again I based the behavior on an fixed number (this time tunable via sysctl). I tried inventing some new autotuning algorithm but it seems that everything I done was performing worse than both arca-vm-18 and arca-vm-19 (the new below).

Andrea Arcangeli

arca-vm-19 against pre7.gz (in the testing directory), I hope to have included everything in this diff...

Index: linux/mm/filemap.c

mm/filemap.c renamed from mm/filemap.c:1.1.1.9 +11 -23
diff -u linux/mm/filemap.c:1.1.1.9 linux/mm/filemap.c:1.1.1.1.2.46
@@ -121,14 +125,11 @@
 int shrink_mmap(int priority, int gfp_mask)
 {
 	static unsigned long clock = 0;
-	unsigned long limit = num_physpages;
 	struct page * page;
-	int count;
-
-	count = (limit << 1) >> priority;
+	unsigned long count = num_physpages / (priority+1);
 
 	page = mem_map + clock;
-	do {
+	while (count-- != 0) {
 		int referenced;
 
 		/* This works even in the presence of PageSkip because
@@ -147,7 +148,6 @@
 			clock = page->map_nr;
 		}
 		
-		count--;
 		referenced = test_and_clear_bit(PG_referenced, &page->flags);
 
 		if (PageLocked(page))
@@ -160,21 +160,6 @@
 		if (atomic_read(&page->count) != 1)
 			continue;
 
-		/*
-		 * Is it a page swap page? If so, we want to
-		 * drop it if it is no longer used, even if it
-		 * were to be marked referenced..
-		 */
-		if (PageSwapCache(page)) {
-			if (referenced && swap_count(page->offset) != 1)
-				continue;
-			delete_from_swap_cache(page);
-			return 1;
-		}	
-
-		if (referenced)
-			continue;
-
 		/* Is it a buffer page? */
 		if (page->buffers) {
 			if (buffer_under_min())
@@ -184,6 +169,14 @@
 			return 1;
 		}
 
+		if (referenced)
+			continue;
+
+		if (PageSwapCache(page)) {
+			delete_from_swap_cache(page);
+			return 1;
+		}	
+
 		/* is it a page-cache page? */
 		if (page->inode) {
 			if (pgcache_under_min())
@@ -191,8 +184,7 @@
 			remove_inode_page(page);
 			return 1;
 		}
-
-	} while (count > 0);
+	}
 	return 0;
 }
 

Index: linux/mm/mmap.c

mm/mmap.c renamed from mm/mmap.c:1.1.1.2 +1 -1
diff -u linux/mm/mmap.c:1.1.1.2 linux/mm/mmap.c:1.1.1.1.2.12
@@ -66,7 +66,7 @@
 	free += page_cache_size;
 	free += nr_free_pages;
 	free += nr_swap_pages;
-	free -= (page_cache.min_percent + buffer_mem.min_percent + 2)*num_physpages/100; 
+	free -= (pager_daemon.cache_min_percent + pager_daemon.buffer_min_percent + 2)*num_physpages/100; 
 	return free > pages;
 }
 

Index: linux/mm/page_alloc.c

mm/page_alloc.c renamed from mm/page_alloc.c:1.1.1.8 +6 -9
diff -u linux/mm/page_alloc.c:1.1.1.8 linux/mm/page_alloc.c:1.1.1.1.2.30
@@ -124,7 +124,6 @@
 	if (!PageReserved(page) && atomic_dec_and_test(&page->count)) {
 		if (PageSwapCache(page))
 			panic ("Freeing swap cache page");
-		page->flags &= ~(1 << PG_referenced);
 		free_pages_ok(page->map_nr, 0);
 		return;
 	}
@@ -141,7 +140,6 @@
 		if (atomic_dec_and_test(&map->count)) {
 			if (PageSwapCache(map))
 				panic ("Freeing swap cache pages");
-			map->flags &= ~(1 << PG_referenced);
 			free_pages_ok(map_nr, order);
 			return;
 		}
@@ -212,19 +210,18 @@
 		 * further thought.
 		 */
 		if (!(current->flags & PF_MEMALLOC)) {
-			static int trashing = 0;
 			int freed;
 
 			if (nr_free_pages > freepages.min) {
-				if (!trashing)
+				if (!current->trashing)
 					goto ok_to_allocate;
 				if (nr_free_pages > freepages.low) {
-					trashing = 0;
+					current->trashing = 0;
 					goto ok_to_allocate;
 				}
 			}
 
-			trashing = 1;
+			current->trashing = 1;
 			current->flags |= PF_MEMALLOC;
 			freed = try_to_free_pages(gfp_mask);
 			current->flags &= ~PF_MEMALLOC;
@@ -353,10 +350,10 @@
 	unsigned long offset = SWP_OFFSET(entry);
 	struct swap_info_struct *swapdev = SWP_TYPE(entry) + swap_info;
 	
-	offset = (offset >> page_cluster) << page_cluster;
-	
 	for (i = 1 << page_cluster; i > 0; i--) {
-	      if (offset >= swapdev->max)
+	      if (offset >= swapdev->max ||
+		  /* don't block on I/O for doing readahead -arca */
+		  atomic_read(&nr_async_pages) > pager_daemon.max_async_pages)
 		      return;
 	      if (!swapdev->swap_map[offset] ||
 		  swapdev->swap_map[offset] == SWAP_MAP_BAD ||

Index: linux/mm/page_io.c

mm/page_io.c renamed from mm/page_io.c:1.1.1.4 +1 -1
diff -u linux/mm/page_io.c:1.1.1.4 linux/mm/page_io.c:1.1.1.1.2.6
@@ -58,7 +58,7 @@
 	}
 
 	/* Don't allow too many pending pages in flight.. */
-	if (atomic_read(&nr_async_pages) > pager_daemon.swap_cluster)
+	if (atomic_read(&nr_async_pages) > pager_daemon.max_async_pages)
 		wait = 1;
 
 	p = &swap_info[type];

Index: linux/mm/swap.c

mm/swap.c renamed from mm/swap.c:1.1.1.6 +7 -30
diff -u linux/mm/swap.c:1.1.1.6 linux/mm/swap.c:1.1.1.1.2.13
@@ -40,41 +40,18 @@
 };
 
 /* How many pages do we try to swap or page in/out together? */
-int page_cluster = 4; /* Default value modified in swap_setup() */
+int page_cluster = 5; /* Default readahead 32 pages every time */
 
 /* We track the number of pages currently being asynchronously swapped
    out, so that we don't try to swap TOO many pages out at once */
 atomic_t nr_async_pages = ATOMIC_INIT(0);
 
-buffer_mem_t buffer_mem = {
+pager_daemon_t pager_daemon = {
+	8,	/* starting priority of try_to_free_pages() */
 	2,	/* minimum percent buffer */
-	10,	/* borrow percent buffer */
-	60	/* maximum percent buffer */
-};
-
-buffer_mem_t page_cache = {
 	2,	/* minimum percent page cache */
-	15,	/* borrow percent page cache */
-	75	/* maximum */
-};
-
-pager_daemon_t pager_daemon = {
-	512,	/* base number for calculating the number of tries */
-	SWAP_CLUSTER_MAX,	/* minimum number of tries */
-	SWAP_CLUSTER_MAX,	/* do swap I/O in clusters of this size */
+	5,	/* minimum percent swap page cache */
+	32,	/* number of tries we do on every try_to_free_pages() */
+	128,	/* do swap I/O in clusters of this size */
+	256	/* max number of async swapped-out pages on the fly */
 };
-
-/*
- * Perform any setup for the swap system
- */
-
-void __init swap_setup(void)
-{
-	/* Use a smaller cluster for memory <16MB or <32MB */
-	if (num_physpages < ((16 * 1024 * 1024) >> PAGE_SHIFT))
-		page_cluster = 2;
-	else if (num_physpages < ((32 * 1024 * 1024) >> PAGE_SHIFT))
-		page_cluster = 3;
-	else
-		page_cluster = 4;
-}

Index: linux/mm/swapfile.c

mm/swapfile.c renamed from mm/swapfile.c:1.1.1.3 +2 -3
diff -u linux/mm/swapfile.c:1.1.1.3 linux/mm/swapfile.c:1.1.1.1.2.6
@@ -23,7 +23,6 @@
 
 struct swap_info_struct swap_info[MAX_SWAPFILES];
 
-#define SWAPFILE_CLUSTER 256
 
 static inline int scan_swap_map(struct swap_info_struct *si)
 {
@@ -31,7 +30,7 @@
 	/* 
 	 * We try to cluster swap pages by allocating them
 	 * sequentially in swap.  Once we've allocated
-	 * SWAPFILE_CLUSTER pages this way, however, we resort to
+	 * SWAP_CLUSTER pages this way, however, we resort to
 	 * first-free allocation, starting a new cluster.  This
 	 * prevents us from scattering swap pages all over the entire
 	 * swap partition, so that we reduce overall disk seek times
@@ -47,7 +46,7 @@
 			goto got_page;
 		}
 	}
-	si->cluster_nr = SWAPFILE_CLUSTER;
+	si->cluster_nr = SWAP_CLUSTER;
 	for (offset = si->lowest_bit; offset <= si->highest_bit ; offset++) {
 		if (si->swap_map[offset])
 			continue;

Index: linux/mm/vmscan.c

mm/vmscan.c renamed from mm/vmscan.c:1.1.1.12 +81 -38

210 lines not on this page · raw message

Index: linux/kernel/fork.c

kernel/fork.c renamed from kernel/fork.c:1.1.1.6 +1 -0
diff -u linux/kernel/fork.c:1.1.1.6 linux/kernel/fork.c:1.1.1.1.2.10
@@ -511,6 +514,7 @@
 
 	p->did_exec = 0;
 	p->swappable = 0;
+	p->trashing = 0;
 	p->state = TASK_UNINTERRUPTIBLE;
 
 	copy_flags(clone_flags, p);

Index: linux/kernel/sysctl.c

kernel/sysctl.c renamed from kernel/sysctl.c:1.1.1.6 +4 -6
diff -u linux/kernel/sysctl.c:1.1.1.6 linux/kernel/sysctl.c:1.1.1.1.2.12
@@ -32,7 +32,7 @@
 
 /* External variables not in a header file. */
 extern int panic_timeout;
-extern int console_loglevel, C_A_D;
+extern int console_loglevel, C_A_D, swapout_interval;
 extern int bdf_prm[], bdflush_min[], bdflush_max[];
 extern char binfmt_java_interpreter[], binfmt_java_appletviewer[];
 extern int sysctl_overcommit_memory;
@@ -216,6 +216,8 @@
 };
 
 static ctl_table vm_table[] = {
+	{VM_SWAPOUT, "swapout_interval",
+	 &swapout_interval, sizeof(int), 0644, NULL, &proc_dointvec},
 	{VM_FREEPG, "freepages", 
 	 &freepages, sizeof(freepages_t), 0644, NULL, &proc_dointvec},
 	{VM_BDFLUSH, "bdflush", &bdf_prm, 9*sizeof(int), 0600, NULL,
@@ -223,11 +225,7 @@
 	 &bdflush_min, &bdflush_max},
 	{VM_OVERCOMMIT_MEMORY, "overcommit_memory", &sysctl_overcommit_memory,
 	 sizeof(sysctl_overcommit_memory), 0644, NULL, &proc_dointvec},
-	{VM_BUFFERMEM, "buffermem",
-	 &buffer_mem, sizeof(buffer_mem_t), 0644, NULL, &proc_dointvec},
-	{VM_PAGECACHE, "pagecache",
-	 &page_cache, sizeof(buffer_mem_t), 0644, NULL, &proc_dointvec},
-	{VM_PAGERDAEMON, "kswapd",
+	{VM_PAGERDAEMON, "pager",
 	 &pager_daemon, sizeof(pager_daemon_t), 0644, NULL, &proc_dointvec},
 	{VM_PGT_CACHE, "pagetable_cache", 
 	 &pgt_cache_water, 2*sizeof(int), 0600, NULL, &proc_dointvec},

Index: linux/include/linux/mm.h

include/linux/mm.h renamed from include/linux/mm.h:1.1.1.6 +6 -6
diff -u linux/include/linux/mm.h:1.1.1.6 linux/include/linux/mm.h:1.1.1.1.2.20
@@ -118,7 +118,6 @@
 	unsigned long offset;
 	struct page *next_hash;
 	atomic_t count;
-	unsigned int unused;
 	unsigned long flags;	/* atomic flags, some possibly updated asynchronously */
 	struct wait_queue *wait;
 	struct page **pprev_hash;
@@ -302,8 +301,7 @@
 
 /* filemap.c */
 extern void remove_inode_page(struct page *);
-extern unsigned long page_unuse(struct page *);
-extern int shrink_mmap(int, int);
+extern int FASTCALL(shrink_mmap(int, int));
 extern void truncate_inode_pages(struct inode *, unsigned long);
 extern unsigned long get_cached_page(struct inode *, unsigned long, int);
 extern void put_cached_page(unsigned long);
@@ -387,9 +385,11 @@
 }
 
 #define buffer_under_min()	((buffermem >> PAGE_SHIFT) * 100 < \
-				buffer_mem.min_percent * num_physpages)
-#define pgcache_under_min()	(page_cache_size * 100 < \
-				page_cache.min_percent * num_physpages)
+				pager_daemon.buffer_min_percent * num_physpages)
+#define pgcache_under_min()	((page_cache_size-swapper_inode.i_nrpages) * 100 < \
+				pager_daemon.cache_min_percent * num_physpages)
+#define swpcache_under_min()	(swapper_inode.i_nrpages * 100 < \
+				pager_daemon.swap_min_percent * num_physpages)
 
 #endif /* __KERNEL__ */
 

Index: linux/include/linux/sched.h

include/linux/sched.h renamed from include/linux/sched.h:1.1.1.6 +8 -6
diff -u linux/include/linux/sched.h:1.1.1.6 linux/include/linux/sched.h:1.1.1.1.2.12
@@ -169,6 +174,7 @@
 	unsigned long rss, total_vm, locked_vm;
 	unsigned long def_flags;
 	unsigned long cpu_vm_mask;
+	unsigned long swap_cnt, swap_address;
 	/*
 	 * This is an architecture-specific pointer: the portable
 	 * part of Linux does not know about any segments.
@@ -177,15 +183,17 @@
 };
 
 #define INIT_MM {					\
-		&init_mmap, NULL, swapper_pg_dir, 	\
+		&init_mmap, NULL, swapper_pg_dir,	\
 		ATOMIC_INIT(1), 1,			\
 		MUTEX,					\
 		0,					\
 		0, 0, 0, 0,				\
-		0, 0, 0, 				\
+		0, 0, 0,				\
 		0, 0, 0, 0,				\
 		0, 0, 0,				\
-		0, 0, NULL }
+		0, 0,					\
+		0, 0,					\
+		NULL }
 
 struct signal_struct {
 	atomic_t		count;
@@ -270,8 +278,7 @@
 /* mm fault and swap info: this can arguably be seen as either mm-specific or thread-specific */
 	unsigned long min_flt, maj_flt, nswap, cmin_flt, cmaj_flt, cnswap;
 	int swappable:1;
-	unsigned long swap_address;
-	unsigned long swap_cnt;		/* number of pages to swap on next pass */
+	int trashing:1;
 /* process credentials */
 	uid_t uid,euid,suid,fsuid;
 	gid_t gid,egid,sgid,fsgid;
@@ -355,7 +362,7 @@
 /* utime */	{0,0,0,0},0, \
 /* per CPU times */ {0, }, {0, }, \
 /* flt */	0,0,0,0,0,0, \
-/* swp */	0,0,0, \
+/* swp */	0,0, \
 /* process credentials */					\
 /* uid etc */	0,0,0,0,0,0,0,0,				\
 /* suppl grps*/ 0, {0,},					\

Index: linux/include/linux/swapctl.h

include/linux/swapctl.h renamed from include/linux/swapctl.h:1.1.1.4 +10 -18
diff -u linux/include/linux/swapctl.h:1.1.1.4 linux/include/linux/swapctl.h:1.1.1.1.2.5
@@ -4,32 +4,24 @@
 #include <asm/page.h>
 #include <linux/fs.h>
 
-typedef struct buffer_mem_v1
+typedef struct freepages_s
 {
-	unsigned int	min_percent;
-	unsigned int	borrow_percent;
-	unsigned int	max_percent;
-} buffer_mem_v1;
-typedef buffer_mem_v1 buffer_mem_t;
-extern buffer_mem_t buffer_mem;
-extern buffer_mem_t page_cache;
-
-typedef struct freepages_v1
-{
 	unsigned int	min;
 	unsigned int	low;
 	unsigned int	high;
-} freepages_v1;
-typedef freepages_v1 freepages_t;
+} freepages_t;
 extern freepages_t freepages;
 
-typedef struct pager_daemon_v1
+typedef struct pager_daemon_s
 {
-	unsigned int	tries_base;
-	unsigned int	tries_min;
+	unsigned int	priority;
+	unsigned int	buffer_min_percent;
+	unsigned int	cache_min_percent;
+	unsigned int	swap_min_percent;
+	unsigned int	tries;
 	unsigned int	swap_cluster;
-} pager_daemon_v1;
-typedef pager_daemon_v1 pager_daemon_t;
+	unsigned int	max_async_pages;
+} pager_daemon_t;
 extern pager_daemon_t pager_daemon;
 
 #endif /* _LINUX_SWAPCTL_H */

Index: linux/include/linux/swap.h

include/linux/swap.h renamed from include/linux/swap.h:1.1.1.6 +1 -4
diff -u linux/include/linux/swap.h:1.1.1.6 linux/include/linux/swap.h:1.1.1.1.2.17
@@ -33,7 +33,7 @@
 #define SWP_USED	1
 #define SWP_WRITEOK	3
 
-#define SWAP_CLUSTER_MAX 32
+#define SWAP_CLUSTER	(pager_daemon.swap_cluster)
 
 #define SWAP_MAP_MAX	0x7fff
 #define SWAP_MAP_BAD	0x8000
@@ -68,9 +68,6 @@
 
 /* linux/ipc/shm.c */
 extern int shm_swap (int, int);
-
-/* linux/mm/swap.c */
-extern void swap_setup (void);
 
 /* linux/mm/vmscan.c */
 extern int try_to_free_pages(unsigned int gfp_mask);

--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#86 lore raw

Re: [patch] arca-vm-19 [Re: Results: Zlatko's new vm patch]

Quoted 1 line · Andrea Arcangeli

I produced a new arca-vm-19. I would like if you could try it. I don't

It seems that the better algorithm I am be able to invent is been the growing_swap_cache one (the one in arca-vm-16). Steve could you try this new patch (arca-vm-20) against real 2.2.0-pre7? I think that it should be still better than arca-vm-16 + SWAP_CLUSTER_MAX=512.

If it will be not very good could you do:

echo 8 2 4 512 512 512 > /proc/sys/vm/pager

and try again? (such numbers should be the same of setting SWAP_CLUSTER_MAX in arca-vm-16, but as default only the max_async_pages is set to 512 because I think it's been the only one that made a difference).

If this will be not the best again you could apply the filemap.c patch I sent you in the last email (the one that return to put the shrink_mmap() weight exponential increasing in function of priority) and try again?

Many thanks!

Andrea Arcangeli

Here arca-vm-20 against 2.2.0-pre7:

Index: linux/mm/filemap.c

mm/filemap.c renamed from mm/filemap.c:1.1.1.9 +11 -23
diff -u linux/mm/filemap.c:1.1.1.9 linux/mm/filemap.c:1.1.1.1.2.48
@@ -121,14 +125,11 @@
 int shrink_mmap(int priority, int gfp_mask)
 {
 	static unsigned long clock = 0;
-	unsigned long limit = num_physpages;
 	struct page * page;
-	int count;
-
-	count = (limit << 1) >> priority;
+	unsigned long count = num_physpages / (priority+1);
 
 	page = mem_map + clock;
-	do {
+	while (count-- != 0) {
 		int referenced;
 
 		/* This works even in the presence of PageSkip because
@@ -147,7 +148,6 @@
 			clock = page->map_nr;
 		}
 		
-		count--;
 		referenced = test_and_clear_bit(PG_referenced, &page->flags);
 
 		if (PageLocked(page))
@@ -160,21 +160,6 @@
 		if (atomic_read(&page->count) != 1)
 			continue;
 
-		/*
-		 * Is it a page swap page? If so, we want to
-		 * drop it if it is no longer used, even if it
-		 * were to be marked referenced..
-		 */
-		if (PageSwapCache(page)) {
-			if (referenced && swap_count(page->offset) != 1)
-				continue;
-			delete_from_swap_cache(page);
-			return 1;
-		}	
-
-		if (referenced)
-			continue;
-
 		/* Is it a buffer page? */
 		if (page->buffers) {
 			if (buffer_under_min())
@@ -184,6 +169,14 @@
 			return 1;
 		}
 
+		if (referenced)
+			continue;
+
+		if (PageSwapCache(page)) {
+			delete_from_swap_cache(page);
+			return 1;
+		}	
+
 		/* is it a page-cache page? */
 		if (page->inode) {
 			if (pgcache_under_min())
@@ -191,8 +184,7 @@
 			remove_inode_page(page);
 			return 1;
 		}
-
-	} while (count > 0);
+	}
 	return 0;
 }
 

Index: linux/mm/mmap.c

mm/mmap.c renamed from mm/mmap.c:1.1.1.2 +1 -1
diff -u linux/mm/mmap.c:1.1.1.2 linux/mm/mmap.c:1.1.1.1.2.12
@@ -66,7 +66,7 @@
 	free += page_cache_size;
 	free += nr_free_pages;
 	free += nr_swap_pages;
-	free -= (page_cache.min_percent + buffer_mem.min_percent + 2)*num_physpages/100; 
+	free -= (pager_daemon.cache_min_percent + pager_daemon.buffer_min_percent + 2)*num_physpages/100; 
 	return free > pages;
 }
 

Index: linux/mm/page_alloc.c

mm/page_alloc.c renamed from mm/page_alloc.c:1.1.1.9 +4 -7
diff -u linux/mm/page_alloc.c:1.1.1.9 linux/mm/page_alloc.c:1.1.1.1.2.31
@@ -124,7 +124,6 @@
 	if (!PageReserved(page) && atomic_dec_and_test(&page->count)) {
 		if (PageSwapCache(page))
 			panic ("Freeing swap cache page");
-		page->flags &= ~(1 << PG_referenced);
 		free_pages_ok(page->map_nr, 0);
 		return;
 	}
@@ -141,7 +140,6 @@
 		if (atomic_dec_and_test(&map->count)) {
 			if (PageSwapCache(map))
 				panic ("Freeing swap cache pages");
-			map->flags &= ~(1 << PG_referenced);
 			free_pages_ok(map_nr, order);
 			return;
 		}
@@ -212,19 +210,18 @@
 		 * further thought.
 		 */
 		if (!(current->flags & PF_MEMALLOC)) {
-			static int trashing = 0;
 			int freed;
 
 			if (nr_free_pages > freepages.min) {
-				if (!trashing)
+				if (!current->trashing)
 					goto ok_to_allocate;
 				if (nr_free_pages > freepages.low) {
-					trashing = 0;
+					current->trashing = 0;
 					goto ok_to_allocate;
 				}
 			}
 
-			trashing = 1;
+			current->trashing = 1;
 			current->flags |= PF_MEMALLOC;
 			freed = try_to_free_pages(gfp_mask);
 			current->flags &= ~PF_MEMALLOC;
@@ -361,7 +358,7 @@
 		if (offset >= swapdev->max)
 			break;
 		/* Don't block on I/O for read-ahead */
-		if (atomic_read(&nr_async_pages) >= pager_daemon.swap_cluster)
+		if (atomic_read(&nr_async_pages) >= pager_daemon.max_async_pages)
 			break;
 		/* Don't read in bad or busy pages */
 		if (!swapdev->swap_map[offset])

Index: linux/mm/page_io.c

mm/page_io.c renamed from mm/page_io.c:1.1.1.4 +1 -1
diff -u linux/mm/page_io.c:1.1.1.4 linux/mm/page_io.c:1.1.1.1.2.6
@@ -58,7 +58,7 @@
 	}
 
 	/* Don't allow too many pending pages in flight.. */
-	if (atomic_read(&nr_async_pages) > pager_daemon.swap_cluster)
+	if (atomic_read(&nr_async_pages) > pager_daemon.max_async_pages)
 		wait = 1;
 
 	p = &swap_info[type];

Index: linux/mm/swap.c

mm/swap.c renamed from mm/swap.c:1.1.1.6 +7 -31
diff -u linux/mm/swap.c:1.1.1.6 linux/mm/swap.c:1.1.1.1.2.14
@@ -40,41 +40,17 @@
 };
 
 /* How many pages do we try to swap or page in/out together? */
-int page_cluster = 4; /* Default value modified in swap_setup() */
+int page_cluster = 5; /* Default readahead 32 pages every time */
 
 /* We track the number of pages currently being asynchronously swapped
    out, so that we don't try to swap TOO many pages out at once */
 atomic_t nr_async_pages = ATOMIC_INIT(0);
 
-buffer_mem_t buffer_mem = {
-	2,	/* minimum percent buffer */
-	10,	/* borrow percent buffer */
-	60	/* maximum percent buffer */
-};
-
-buffer_mem_t page_cache = {
-	2,	/* minimum percent page cache */
-	15,	/* borrow percent page cache */
-	75	/* maximum */
-};
-
 pager_daemon_t pager_daemon = {
-	512,	/* base number for calculating the number of tries */
-	SWAP_CLUSTER_MAX,	/* minimum number of tries */
-	SWAP_CLUSTER_MAX,	/* do swap I/O in clusters of this size */
+	8,	/* starting priority of try_to_free_pages() */
+	2,	/* minimum percent buffer */
+	4,	/* minimum percent page cache */
+	32,	/* number of tries we do on every try_to_free_pages() */
+	128,	/* do swap I/O in clusters of this size */
+	512	/* max number of async swapped-out pages on the fly */
 };
-
-/*
- * Perform any setup for the swap system
- */
-
-void __init swap_setup(void)
-{
-	/* Use a smaller cluster for memory <16MB or <32MB */
-	if (num_physpages < ((16 * 1024 * 1024) >> PAGE_SHIFT))
-		page_cluster = 2;
-	else if (num_physpages < ((32 * 1024 * 1024) >> PAGE_SHIFT))
-		page_cluster = 3;
-	else
-		page_cluster = 4;
-}

Index: linux/mm/swapfile.c

mm/swapfile.c renamed from mm/swapfile.c:1.1.1.3 +2 -3
diff -u linux/mm/swapfile.c:1.1.1.3 linux/mm/swapfile.c:1.1.1.1.2.6
@@ -23,7 +23,6 @@
 
 struct swap_info_struct swap_info[MAX_SWAPFILES];
 
-#define SWAPFILE_CLUSTER 256
 
 static inline int scan_swap_map(struct swap_info_struct *si)
 {
@@ -31,7 +30,7 @@
 	/* 
 	 * We try to cluster swap pages by allocating them
 	 * sequentially in swap.  Once we've allocated
-	 * SWAPFILE_CLUSTER pages this way, however, we resort to
+	 * SWAP_CLUSTER pages this way, however, we resort to
 	 * first-free allocation, starting a new cluster.  This
 	 * prevents us from scattering swap pages all over the entire
 	 * swap partition, so that we reduce overall disk seek times
@@ -47,7 +46,7 @@
 			goto got_page;
 		}
 	}
-	si->cluster_nr = SWAPFILE_CLUSTER;
+	si->cluster_nr = SWAP_CLUSTER;
 	for (offset = si->lowest_bit; offset <= si->highest_bit ; offset++) {
 		if (si->swap_map[offset])
 			continue;

Index: linux/mm/vmscan.c

mm/vmscan.c renamed from mm/vmscan.c:1.1.1.12 +80 -35

209 lines not on this page · raw message

Index: linux/kernel/fork.c

kernel/fork.c renamed from kernel/fork.c:1.1.1.6 +1 -0
diff -u linux/kernel/fork.c:1.1.1.6 linux/kernel/fork.c:1.1.1.1.2.10
@@ -511,6 +514,7 @@
 
 	p->did_exec = 0;
 	p->swappable = 0;
+	p->trashing = 0;
 	p->state = TASK_UNINTERRUPTIBLE;
 
 	copy_flags(clone_flags, p);

Index: linux/kernel/sysctl.c

kernel/sysctl.c renamed from kernel/sysctl.c:1.1.1.6 +4 -6
diff -u linux/kernel/sysctl.c:1.1.1.6 linux/kernel/sysctl.c:1.1.1.1.2.12
@@ -32,7 +32,7 @@
 
 /* External variables not in a header file. */
 extern int panic_timeout;
-extern int console_loglevel, C_A_D;
+extern int console_loglevel, C_A_D, swapout_interval;
 extern int bdf_prm[], bdflush_min[], bdflush_max[];
 extern char binfmt_java_interpreter[], binfmt_java_appletviewer[];
 extern int sysctl_overcommit_memory;
@@ -216,6 +216,8 @@
 };
 
 static ctl_table vm_table[] = {
+	{VM_SWAPOUT, "swapout_interval",
+	 &swapout_interval, sizeof(int), 0644, NULL, &proc_dointvec},
 	{VM_FREEPG, "freepages", 
 	 &freepages, sizeof(freepages_t), 0644, NULL, &proc_dointvec},
 	{VM_BDFLUSH, "bdflush", &bdf_prm, 9*sizeof(int), 0600, NULL,
@@ -223,11 +225,7 @@
 	 &bdflush_min, &bdflush_max},
 	{VM_OVERCOMMIT_MEMORY, "overcommit_memory", &sysctl_overcommit_memory,
 	 sizeof(sysctl_overcommit_memory), 0644, NULL, &proc_dointvec},
-	{VM_BUFFERMEM, "buffermem",
-	 &buffer_mem, sizeof(buffer_mem_t), 0644, NULL, &proc_dointvec},
-	{VM_PAGECACHE, "pagecache",
-	 &page_cache, sizeof(buffer_mem_t), 0644, NULL, &proc_dointvec},
-	{VM_PAGERDAEMON, "kswapd",
+	{VM_PAGERDAEMON, "pager",
 	 &pager_daemon, sizeof(pager_daemon_t), 0644, NULL, &proc_dointvec},
 	{VM_PGT_CACHE, "pagetable_cache", 
 	 &pgt_cache_water, 2*sizeof(int), 0600, NULL, &proc_dointvec},

Index: linux/include/linux/mm.h

include/linux/mm.h renamed from include/linux/mm.h:1.1.1.6 +4 -6
diff -u linux/include/linux/mm.h:1.1.1.6 linux/include/linux/mm.h:1.1.1.1.2.21
@@ -118,7 +118,6 @@
 	unsigned long offset;
 	struct page *next_hash;
 	atomic_t count;
-	unsigned int unused;
 	unsigned long flags;	/* atomic flags, some possibly updated asynchronously */
 	struct wait_queue *wait;
 	struct page **pprev_hash;
@@ -302,8 +301,7 @@
 
 /* filemap.c */
 extern void remove_inode_page(struct page *);
-extern unsigned long page_unuse(struct page *);
-extern int shrink_mmap(int, int);
+extern int FASTCALL(shrink_mmap(int, int));
 extern void truncate_inode_pages(struct inode *, unsigned long);
 extern unsigned long get_cached_page(struct inode *, unsigned long, int);
 extern void put_cached_page(unsigned long);
@@ -387,9 +385,9 @@
 }
 
 #define buffer_under_min()	((buffermem >> PAGE_SHIFT) * 100 < \
-				buffer_mem.min_percent * num_physpages)
-#define pgcache_under_min()	(page_cache_size * 100 < \
-				page_cache.min_percent * num_physpages)
+				pager_daemon.buffer_min_percent * num_physpages)
+#define pgcache_under_min()	((page_cache_size-swapper_inode.i_nrpages) * 100 < \
+				pager_daemon.cache_min_percent * num_physpages)
 
 #endif /* __KERNEL__ */
 

Index: linux/include/linux/sched.h

include/linux/sched.h renamed from include/linux/sched.h:1.1.1.6 +8 -6
diff -u linux/include/linux/sched.h:1.1.1.6 linux/include/linux/sched.h:1.1.1.1.2.13
@@ -169,6 +174,7 @@
 	unsigned long rss, total_vm, locked_vm;
 	unsigned long def_flags;
 	unsigned long cpu_vm_mask;
+	unsigned long swap_cnt, swap_address;
 	/*
 	 * This is an architecture-specific pointer: the portable
 	 * part of Linux does not know about any segments.
@@ -177,15 +183,17 @@
 };
 
 #define INIT_MM {					\
-		&init_mmap, NULL, swapper_pg_dir, 	\
+		&init_mmap, NULL, swapper_pg_dir,	\
 		ATOMIC_INIT(1), 1,			\
 		MUTEX,					\
 		0,					\
 		0, 0, 0, 0,				\
-		0, 0, 0, 				\
+		0, 0, 0,				\
 		0, 0, 0, 0,				\
 		0, 0, 0,				\
-		0, 0, NULL }
+		0, 0,					\
+		0, 0,					\
+		NULL }
 
 struct signal_struct {
 	atomic_t		count;
@@ -270,8 +278,7 @@
 /* mm fault and swap info: this can arguably be seen as either mm-specific or thread-specific */
 	unsigned long min_flt, maj_flt, nswap, cmin_flt, cmaj_flt, cnswap;
 	int swappable:1;
-	unsigned long swap_address;
-	unsigned long swap_cnt;		/* number of pages to swap on next pass */
+	int trashing:1;
 /* process credentials */
 	uid_t uid,euid,suid,fsuid;
 	gid_t gid,egid,sgid,fsgid;
@@ -355,7 +362,7 @@
 /* utime */	{0,0,0,0},0, \
 /* per CPU times */ {0, }, {0, }, \
 /* flt */	0,0,0,0,0,0, \
-/* swp */	0,0,0, \
+/* swp */	0,0, \
 /* process credentials */					\
 /* uid etc */	0,0,0,0,0,0,0,0,				\
 /* suppl grps*/ 0, {0,},					\

Index: linux/include/linux/swap.h

include/linux/swap.h renamed from include/linux/swap.h:1.1.1.6 +1 -4
diff -u linux/include/linux/swap.h:1.1.1.6 linux/include/linux/swap.h:1.1.1.1.2.17
@@ -33,7 +33,7 @@
 #define SWP_USED	1
 #define SWP_WRITEOK	3
 
-#define SWAP_CLUSTER_MAX 32
+#define SWAP_CLUSTER	(pager_daemon.swap_cluster)
 
 #define SWAP_MAP_MAX	0x7fff
 #define SWAP_MAP_BAD	0x8000
@@ -68,9 +68,6 @@
 
 /* linux/ipc/shm.c */
 extern int shm_swap (int, int);
-
-/* linux/mm/swap.c */
-extern void swap_setup (void);
 
 /* linux/mm/vmscan.c */
 extern int try_to_free_pages(unsigned int gfp_mask);

Index: linux/include/linux/swapctl.h

include/linux/swapctl.h renamed from include/linux/swapctl.h:1.1.1.4 +9 -18
diff -u linux/include/linux/swapctl.h:1.1.1.4 linux/include/linux/swapctl.h:1.1.1.1.2.6
@@ -4,32 +4,23 @@
 #include <asm/page.h>
 #include <linux/fs.h>
 
-typedef struct buffer_mem_v1
+typedef struct freepages_s
 {
-	unsigned int	min_percent;
-	unsigned int	borrow_percent;
-	unsigned int	max_percent;
-} buffer_mem_v1;
-typedef buffer_mem_v1 buffer_mem_t;
-extern buffer_mem_t buffer_mem;
-extern buffer_mem_t page_cache;
-
-typedef struct freepages_v1
-{
 	unsigned int	min;
 	unsigned int	low;
 	unsigned int	high;
-} freepages_v1;
-typedef freepages_v1 freepages_t;
+} freepages_t;
 extern freepages_t freepages;
 
-typedef struct pager_daemon_v1
+typedef struct pager_daemon_s
 {
-	unsigned int	tries_base;
-	unsigned int	tries_min;
+	unsigned int	priority;
+	unsigned int	buffer_min_percent;
+	unsigned int	cache_min_percent;
+	unsigned int	tries;
 	unsigned int	swap_cluster;
-} pager_daemon_v1;
-typedef pager_daemon_v1 pager_daemon_t;
+	unsigned int	max_async_pages;
+} pager_daemon_t;
 extern pager_daemon_t pager_daemon;
 
 #endif /* _LINUX_SWAPCTL_H */

--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#87 lore raw

PATCH 1/1 NEW: arca-vm-21, swapout via shrink_mmap using PG_dirty

I did not understood what PG_dirty means until this afternoon I thought "why not to move the rw_swap_page to shrink_mmap" and left swap_out() only to allocate the in-order-swap-entry and its swap cache page? So I brute moved the rw_swap_cache with obviously tons of races and worked for a bit well ;).

Then I seen the PG_dirty comment of Linus in vmscan.c, and if I have understood well it, I had to use PG_dirty to realize what I was going to do.

So I hacked heavily all the afternoon and the evening and now seems to work fine ;)). Really the free_user_and_cache() algorithm that I am using in this patch is "new", never seen how it works with the usual swapout code in swap_out() so I can't make raw comparison.

What I can say is that the global performances seems improved a lot (also the OOM handling seems improved, try and you'll see). But the raw swapout performances are been reduced (from 51 sec of arca-vm-19 to 61 sec). Seems very good here though.

The patch merge also other my stuff like my update_shared_mapping() that is safe right now (at last as vmtruncate ;). It fix also the for_each_mm issue. I can cut-out the garbage if somebody needs...

Ah and the patch removed also the map_nr field since x86 should perform equally well (and the removal saves some bits of memory). This is been an idea from Max.

Don't use the patch without first doing a backup though since mm corruption could happens since I could have done mistaken.

I would be interested if somebody could make comparison with arca-vm-19 or pre[57] for example... but don't waste time doing many benchmarks if it seems a lose under every side.

Probably in low memory (<=8m) this my new arca-vm-21 needs a:

echo 6 1 4 32 128 512 >/proc/sys/vm/pager

Thanks.

Here arca-vm-21 against 2.2.0-pre7:

Index: linux/mm/filemap.c

mm/filemap.c renamed from mm/filemap.c:1.1.1.9 +98 -24
diff -u linux/mm/filemap.c:1.1.1.9 linux/mm/filemap.c:1.1.1.1.2.52
@@ -5,6 +5,11 @@
  */
 
 /*
+ * update_shared_mappings(), Copyright (C) 1998  Andrea Arcangeli
+ * PG_dirty shrink_mmap swapout, Copyright (C) 1999  Andrea Arcangeli
+ */
+
+/*
  * This file handles the generic file mmap semantics used by
  * most "normal" filesystems (but you don't /have/ to use this:
  * the NFS filesystem used to do this differently, for example)
@@ -121,14 +126,11 @@
 int shrink_mmap(int priority, int gfp_mask)
 {
 	static unsigned long clock = 0;
-	unsigned long limit = num_physpages;
 	struct page * page;
-	int count;
-
-	count = (limit << 1) >> priority;
+	unsigned long count = (num_physpages << 1) >> priority;
 
 	page = mem_map + clock;
-	do {
+	while (count-- != 0) {
 		int referenced;
 
 		/* This works even in the presence of PageSkip because
@@ -144,10 +146,9 @@
 		if (PageSkip(page)) {
 			/* next_hash is overloaded for PageSkip */
 			page = page->next_hash;
-			clock = page->map_nr;
+			clock = page - mem_map;
 		}
 		
-		count--;
 		referenced = test_and_clear_bit(PG_referenced, &page->flags);
 
 		if (PageLocked(page))
@@ -160,21 +161,6 @@
 		if (atomic_read(&page->count) != 1)
 			continue;
 
-		/*
-		 * Is it a page swap page? If so, we want to
-		 * drop it if it is no longer used, even if it
-		 * were to be marked referenced..
-		 */
-		if (PageSwapCache(page)) {
-			if (referenced && swap_count(page->offset) != 1)
-				continue;
-			delete_from_swap_cache(page);
-			return 1;
-		}	
-
-		if (referenced)
-			continue;
-
 		/* Is it a buffer page? */
 		if (page->buffers) {
 			if (buffer_under_min())
@@ -184,6 +170,26 @@
 			return 1;
 		}
 
+		if (referenced)
+			continue;
+
+		if (PageSwapCache(page)) {
+			unsigned long entry = page->offset;
+			if (PageTestandClearDirty(page) &&
+			    swap_count(entry) > 1)
+			{
+				if (!(gfp_mask & __GFP_IO))
+					continue;
+				entry = page->offset;
+				set_bit(PG_locked, &page->flags);
+				atomic_inc(&page->count);
+				rw_swap_page(WRITE, entry, page, 0);
+				atomic_dec(&page->count);
+			}
+			delete_from_swap_cache(page);
+			return 1;
+		}
+
 		/* is it a page-cache page? */
 		if (page->inode) {
 			if (pgcache_under_min())
@@ -191,8 +197,7 @@
 			remove_inode_page(page);
 			return 1;
 		}
-
-	} while (count > 0);
+	}
 	return 0;
 }
 
@@ -1165,6 +1170,74 @@
 	return mk_pte(page,vma->vm_page_prot);
 }
 
+static void update_one_shared_mapping(struct vm_area_struct *shared,
+				      unsigned long address, pte_t orig_pte)
+{
+	pgd_t *pgd;
+	pmd_t *pmd;
+	pte_t *pte;
+
+	pgd = pgd_offset(shared->vm_mm, address);
+	if (pgd_none(*pgd))
+		goto out;
+	if (pgd_bad(*pgd)) {
+		printk(KERN_ERR "update_shared_mappings: bad pgd (%08lx)\n",
+		       pgd_val(*pgd));
+		pgd_clear(pgd);
+		goto out;
+	}
+
+	pmd = pmd_offset(pgd, address);
+	if (pmd_none(*pmd))
+		goto out;
+	if (pmd_bad(*pmd))
+	{
+		printk(KERN_ERR "update_shared_mappings: bad pmd (%08lx)\n",
+		       pmd_val(*pmd));
+		pmd_clear(pmd);
+		goto out;
+	}
+
+	pte = pte_offset(pmd, address);
+
+	if (pte_val(pte_mkclean(pte_mkyoung(*pte))) !=
+	    pte_val(pte_mkclean(pte_mkyoung(orig_pte))))
+		goto out;
+
+	flush_page_to_ram(page(pte));
+	flush_cache_page(shared, address);
+	set_pte(pte, pte_mkclean(*pte));
+	flush_tlb_page(shared, address);
+
+ out:
+}
+
+static void update_shared_mappings(struct vm_area_struct *this,
+				   unsigned long address,
+				   pte_t orig_pte)
+{
+	if (this->vm_flags & VM_SHARED)
+	{
+		struct file * filp = this->vm_file;
+		if (filp)
+		{
+			struct inode * inode = filp->f_dentry->d_inode;
+			struct semaphore * s = &inode->i_sem;
+			struct vm_area_struct * shared;
+
+			down(s);
+			for (shared = inode->i_mmap; shared;
+			     shared = shared->vm_next_share)
+			{
+				if (shared->vm_mm == this->vm_mm)
+					continue;
+				update_one_shared_mapping(shared, address,
+							  orig_pte);
+			}
+			up(s);
+		}
+	}
+}
 
 static inline int filemap_sync_pte(pte_t * ptep, struct vm_area_struct *vma,
 	unsigned long address, unsigned int flags)
@@ -1184,6 +1257,7 @@
 		flush_tlb_page(vma, address);
 		page = pte_page(pte);
 		atomic_inc(&mem_map[MAP_NR(page)].count);
+		update_shared_mappings(vma, address, pte);
 	} else {
 		if (pte_none(pte))
 			return 0;

Index: linux/mm/mmap.c

mm/mmap.c renamed from mm/mmap.c:1.1.1.2 +13 -4
diff -u linux/mm/mmap.c:1.1.1.2 linux/mm/mmap.c:1.1.1.1.2.12
@@ -66,7 +66,7 @@
 	free += page_cache_size;
 	free += nr_free_pages;
 	free += nr_swap_pages;
-	free -= (page_cache.min_percent + buffer_mem.min_percent + 2)*num_physpages/100; 
+	free -= (pager_daemon.cache_min_percent + pager_daemon.buffer_min_percent + 2)*num_physpages/100; 
 	return free > pages;
 }
 
@@ -76,11 +76,16 @@
 	struct file * file = vma->vm_file;
 
 	if (file) {
+		struct semaphore * sem = &file->f_dentry->d_inode->i_sem;
+		struct file * file = vma->vm_file;
+
+		down(sem);
 		if (vma->vm_flags & VM_DENYWRITE)
 			file->f_dentry->d_inode->i_writecount++;
 		if(vma->vm_next_share)
 			vma->vm_next_share->vm_pprev_share = vma->vm_pprev_share;
 		*vma->vm_pprev_share = vma->vm_next_share;
+		up(sem);
 	}
 }
 
@@ -514,9 +519,6 @@
 		free = free->vm_next;
 		freed = 1;
 
-		mm->map_count--;
-		remove_shared_vm_struct(mpnt);
-
 		st = addr < mpnt->vm_start ? mpnt->vm_start : addr;
 		end = addr+len;
 		end = end > mpnt->vm_end ? mpnt->vm_end : end;
@@ -525,6 +527,9 @@
 		if (mpnt->vm_ops && mpnt->vm_ops->unmap)
 			mpnt->vm_ops->unmap(mpnt, st, size);
 
+		mm->map_count--;
+		remove_shared_vm_struct(mpnt);
+
 		flush_cache_range(mm, st, end);
 		zap_page_range(mm, st, size);
 		flush_tlb_range(mm, st, end);
@@ -616,14 +621,18 @@
 	file = vmp->vm_file;
 	if (file) {
 		struct inode * inode = file->f_dentry->d_inode;
+		struct semaphore * sem = &inode->i_sem;
+
 		if (vmp->vm_flags & VM_DENYWRITE)
 			inode->i_writecount--;
       
+		down(sem);
 		/* insert vmp into inode's share list */
 		if((vmp->vm_next_share = inode->i_mmap) != NULL)
 			inode->i_mmap->vm_pprev_share = &vmp->vm_next_share;
 		inode->i_mmap = vmp;
 		vmp->vm_pprev_share = &inode->i_mmap;
+		up(sem);
 	}
 }
 

Index: linux/mm/page_alloc.c

mm/page_alloc.c renamed from mm/page_alloc.c:1.1.1.9 +6 -10
diff -u linux/mm/page_alloc.c:1.1.1.9 linux/mm/page_alloc.c:1.1.1.1.2.32
@@ -124,8 +124,7 @@
 	if (!PageReserved(page) && atomic_dec_and_test(&page->count)) {
 		if (PageSwapCache(page))
 			panic ("Freeing swap cache page");
-		page->flags &= ~(1 << PG_referenced);
-		free_pages_ok(page->map_nr, 0);
+		free_pages_ok(page - mem_map, 0);
 		return;
 	}
 }
@@ -141,7 +140,6 @@
 		if (atomic_dec_and_test(&map->count)) {
 			if (PageSwapCache(map))
 				panic ("Freeing swap cache pages");
-			map->flags &= ~(1 << PG_referenced);
 			free_pages_ok(map_nr, order);
 			return;
 		}
@@ -163,7 +161,7 @@
 			if (!dma || CAN_DMA(ret)) { \
 				unsigned long map_nr; \
 				(prev->next = ret->next)->prev = prev; \
-				map_nr = ret->map_nr; \
+				map_nr = ret - mem_map; \
 				MARK_USED(map_nr, new_order, area); \
 				nr_free_pages -= 1 << order; \
 				EXPAND(ret, map_nr, order, new_order, area); \
@@ -212,19 +210,18 @@
 		 * further thought.
 		 */
 		if (!(current->flags & PF_MEMALLOC)) {
-			static int trashing = 0;
 			int freed;
 
 			if (nr_free_pages > freepages.min) {
-				if (!trashing)
+				if (!current->trashing)
 					goto ok_to_allocate;
 				if (nr_free_pages > freepages.low) {
-					trashing = 0;
+					current->trashing = 0;
 					goto ok_to_allocate;
 				}
 			}
 
-			trashing = 1;
+			current->trashing = 1;
 			current->flags |= PF_MEMALLOC;
 			freed = try_to_free_pages(gfp_mask);
 			current->flags &= ~PF_MEMALLOC;
@@ -322,7 +319,6 @@
 		--p;
 		atomic_set(&p->count, 0);
 		p->flags = (1 << PG_DMA) | (1 << PG_reserved);
-		p->map_nr = p - mem_map;
 	} while (p > mem_map);
 
 	for (i = 0 ; i < NR_MEM_LISTS ; i++) {
@@ -361,7 +357,7 @@
 		if (offset >= swapdev->max)
 			break;
 		/* Don't block on I/O for read-ahead */
-		if (atomic_read(&nr_async_pages) >= pager_daemon.swap_cluster)
+		if (atomic_read(&nr_async_pages) >= pager_daemon.max_async_pages)
 			break;
 		/* Don't read in bad or busy pages */
 		if (!swapdev->swap_map[offset])

Index: linux/mm/page_io.c

mm/page_io.c renamed from mm/page_io.c:1.1.1.4 +3 -5
diff -u linux/mm/page_io.c:1.1.1.4 linux/mm/page_io.c:1.1.1.1.2.7
@@ -58,7 +58,7 @@
 	}
 
 	/* Don't allow too many pending pages in flight.. */
-	if (atomic_read(&nr_async_pages) > pager_daemon.swap_cluster)
+	if (atomic_read(&nr_async_pages) > pager_daemon.max_async_pages)
 		wait = 1;
 
 	p = &swap_info[type];
@@ -233,10 +233,8 @@
 /* A simple wrapper so the base function doesn't need to enforce
  * that all swap pages go through the swap cache!
  */
-void rw_swap_page(int rw, unsigned long entry, char *buf, int wait)
+void rw_swap_page(int rw, unsigned long entry, struct page *page, int wait)
 {
-	struct page *page = mem_map + MAP_NR(buf);
-
 	if (page->inode && page->inode != &swapper_inode)
 		panic ("Tried to swap a non-swapper page");
 
@@ -281,7 +279,7 @@
 	page->inode = &swapper_inode;
 	page->offset = entry;
 	atomic_inc(&page->count);	/* Protect from shrink_mmap() */
-	rw_swap_page(rw, entry, buffer, 1);
+	rw_swap_page(rw, entry, page, 1);
 	atomic_dec(&page->count);
 	page->inode = 0;
 	clear_bit(PG_swap_cache, &page->flags);

Index: linux/mm/swap.c

mm/swap.c renamed from mm/swap.c:1.1.1.6 +7 -18
diff -u linux/mm/swap.c:1.1.1.6 linux/mm/swap.c:1.1.1.1.2.18
@@ -40,28 +40,19 @@
 };
 
 /* How many pages do we try to swap or page in/out together? */
-int page_cluster = 4; /* Default value modified in swap_setup() */
+int page_cluster = 5; /* Default readahead 32 pages every time */
 
 /* We track the number of pages currently being asynchronously swapped
    out, so that we don't try to swap TOO many pages out at once */
 atomic_t nr_async_pages = ATOMIC_INIT(0);
 
-buffer_mem_t buffer_mem = {
-	2,	/* minimum percent buffer */
-	10,	/* borrow percent buffer */
-	60	/* maximum percent buffer */
-};
-
-buffer_mem_t page_cache = {
-	2,	/* minimum percent page cache */
-	15,	/* borrow percent page cache */
-	75	/* maximum */
-};
-
 pager_daemon_t pager_daemon = {
-	512,	/* base number for calculating the number of tries */
-	SWAP_CLUSTER_MAX,	/* minimum number of tries */
-	SWAP_CLUSTER_MAX,	/* do swap I/O in clusters of this size */
+	10,	/* starting priority of try_to_free_pages() */
+	1,	/* minimum percent buffer */
+	5,	/* minimum percent page cache */
+	32,	/* number of tries we do on every try_to_free_pages() */
+	128,	/* do swap I/O in clusters of this size */
+	512	/* max number of async swapped-out pages on the fly */
 };
 
 /*
@@ -75,6 +66,4 @@
 		page_cluster = 2;
 	else if (num_physpages < ((32 * 1024 * 1024) >> PAGE_SHIFT))
 		page_cluster = 3;
-	else
-		page_cluster = 4;
 }

Index: linux/mm/swap_state.c

mm/swap_state.c renamed from mm/swap_state.c:1.1.1.6 +2 -1
diff -u linux/mm/swap_state.c:1.1.1.6 linux/mm/swap_state.c:1.1.1.1.2.13
@@ -213,6 +213,7 @@
 	       "entry %08lx)\n",
 	       page_address(page), atomic_read(&page->count), entry);
 #endif
+	PageClearDirty(page);
 	remove_from_swap_cache (page);
 	swap_free (entry);
 }
@@ -320,7 +321,7 @@
 		goto out_free_page;
 
 	set_bit(PG_locked, &new_page->flags);
-	rw_swap_page(READ, entry, (char *) new_page_addr, wait);
+	rw_swap_page(READ, entry, new_page, wait);
 #ifdef DEBUG_SWAP
 	printk("DebugVM: read_swap_cache_async created "
 	       "entry %08lx at %p\n",

Index: linux/mm/swapfile.c

mm/swapfile.c renamed from mm/swapfile.c:1.1.1.3 +2 -3
diff -u linux/mm/swapfile.c:1.1.1.3 linux/mm/swapfile.c:1.1.1.1.2.6
@@ -23,7 +23,6 @@
 
 struct swap_info_struct swap_info[MAX_SWAPFILES];
 
-#define SWAPFILE_CLUSTER 256
 
 static inline int scan_swap_map(struct swap_info_struct *si)
 {
@@ -31,7 +30,7 @@
 	/* 
 	 * We try to cluster swap pages by allocating them
 	 * sequentially in swap.  Once we've allocated
-	 * SWAPFILE_CLUSTER pages this way, however, we resort to
+	 * SWAP_CLUSTER pages this way, however, we resort to
 	 * first-free allocation, starting a new cluster.  This
 	 * prevents us from scattering swap pages all over the entire
 	 * swap partition, so that we reduce overall disk seek times
@@ -47,7 +46,7 @@
 			goto got_page;
 		}
 	}
-	si->cluster_nr = SWAPFILE_CLUSTER;
+	si->cluster_nr = SWAP_CLUSTER;
 	for (offset = si->lowest_bit; offset <= si->highest_bit ; offset++) {
 		if (si->swap_map[offset])
 			continue;

Index: linux/mm/vmalloc.c

mm/vmalloc.c renamed from mm/vmalloc.c:1.1.1.2 +13 -2
diff -u linux/mm/vmalloc.c:1.1.1.2 linux/mm/vmalloc.c:1.1.1.1.2.3
@@ -10,6 +10,7 @@
 #include <asm/uaccess.h>
 
 static struct vm_struct * vmlist = NULL;
+static spinlock_t	  vmlist_spinlock;
 
 static inline void free_area_pte(pmd_t * pmd, unsigned long address, unsigned long size)
 {
@@ -158,17 +159,21 @@
 	if (!area)
 		return NULL;
 	addr = VMALLOC_START;
+	spin_lock(&vmlist_spinlock);
 	for (p = &vmlist; (tmp = *p) ; p = &tmp->next) {
 		if (size + addr < (unsigned long) tmp->addr)
 			break;
-		if (addr > VMALLOC_END-size)
+		if (addr > VMALLOC_END-size) {
+			spin_unlock(&vmlist_spinlock);
 			return NULL;
+		}
 		addr = tmp->size + (unsigned long) tmp->addr;
 	}
 	area->addr = (void *)addr;
 	area->size = size + PAGE_SIZE;
 	area->next = *p;
 	*p = area;
+	spin_unlock(&vmlist_spinlock);
 	return area;
 }
 
@@ -182,14 +187,18 @@
 		printk("Trying to vfree() bad address (%p)\n", addr);
 		return;
 	}
+	spin_lock(&vmlist_spinlock);
 	for (p = &vmlist ; (tmp = *p) ; p = &tmp->next) {
 		if (tmp->addr == addr) {
 			*p = tmp->next;
-			vmfree_area_pages(VMALLOC_VMADDR(tmp->addr), tmp->size);
+			spin_unlock(&vmlist_spinlock);
+			vmfree_area_pages(VMALLOC_VMADDR(tmp->addr),
+					  tmp->size - PAGE_SIZE);
 			kfree(tmp);
 			return;
 		}
 	}
+	spin_unlock(&vmlist_spinlock);
 	printk("Trying to vfree() nonexistent vm area (%p)\n", addr);
 }
 
@@ -222,6 +231,7 @@
 	if ((unsigned long) addr + count < count)
 		count = -(unsigned long) addr;
 
+	spin_lock(&vmlist_spinlock);
 	for (tmp = vmlist; tmp; tmp = tmp->next) {
 		vaddr = (char *) tmp->addr;
 		if (addr >= vaddr + tmp->size - PAGE_SIZE)
@@ -245,5 +255,6 @@
 		} while (--n > 0);
 	}
 finished:
+	spin_unlock(&vmlist_spinlock);
 	return buf - buf_start;
 }

Index: linux/mm/vmscan.c

mm/vmscan.c renamed from mm/vmscan.c:1.1.1.12 +79 -68

282 lines not on this page · raw message

Index: linux/kernel/fork.c

kernel/fork.c renamed from kernel/fork.c:1.1.1.6 +5 -1
diff -u linux/kernel/fork.c:1.1.1.6 linux/kernel/fork.c:1.1.1.1.2.10
@@ -209,16 +209,19 @@
 		tmp->vm_next = NULL;
 		file = tmp->vm_file;
 		if (file) {
+			struct semaphore * s = &file->f_dentry->d_inode->i_sem;
 			file->f_count++;
 			if (tmp->vm_flags & VM_DENYWRITE)
 				file->f_dentry->d_inode->i_writecount--;
-      
+
+			down(s);
 			/* insert tmp into the share list, just after mpnt */
 			if((tmp->vm_next_share = mpnt->vm_next_share) != NULL)
 				mpnt->vm_next_share->vm_pprev_share =
 					&tmp->vm_next_share;
 			mpnt->vm_next_share = tmp;
 			tmp->vm_pprev_share = &mpnt->vm_next_share;
+			up(s);
 		}
 
 		/* Copy the pages, but defer checking for errors */
@@ -511,6 +514,7 @@
 
 	p->did_exec = 0;
 	p->swappable = 0;
+	p->trashing = 0;
 	p->state = TASK_UNINTERRUPTIBLE;
 
 	copy_flags(clone_flags, p);

Index: linux/kernel/sysctl.c

kernel/sysctl.c renamed from kernel/sysctl.c:1.1.1.6 +4 -6
diff -u linux/kernel/sysctl.c:1.1.1.6 linux/kernel/sysctl.c:1.1.1.1.2.12
@@ -32,7 +32,7 @@
 
 /* External variables not in a header file. */
 extern int panic_timeout;
-extern int console_loglevel, C_A_D;
+extern int console_loglevel, C_A_D, swapout_interval;
 extern int bdf_prm[], bdflush_min[], bdflush_max[];
 extern char binfmt_java_interpreter[], binfmt_java_appletviewer[];
 extern int sysctl_overcommit_memory;
@@ -216,6 +216,8 @@
 };
 
 static ctl_table vm_table[] = {
+	{VM_SWAPOUT, "swapout_interval",
+	 &swapout_interval, sizeof(int), 0644, NULL, &proc_dointvec},
 	{VM_FREEPG, "freepages", 
 	 &freepages, sizeof(freepages_t), 0644, NULL, &proc_dointvec},
 	{VM_BDFLUSH, "bdflush", &bdf_prm, 9*sizeof(int), 0600, NULL,
@@ -223,11 +225,7 @@
 	 &bdflush_min, &bdflush_max},
 	{VM_OVERCOMMIT_MEMORY, "overcommit_memory", &sysctl_overcommit_memory,
 	 sizeof(sysctl_overcommit_memory), 0644, NULL, &proc_dointvec},
-	{VM_BUFFERMEM, "buffermem",
-	 &buffer_mem, sizeof(buffer_mem_t), 0644, NULL, &proc_dointvec},
-	{VM_PAGECACHE, "pagecache",
-	 &page_cache, sizeof(buffer_mem_t), 0644, NULL, &proc_dointvec},
-	{VM_PAGERDAEMON, "kswapd",
+	{VM_PAGERDAEMON, "pager",
 	 &pager_daemon, sizeof(pager_daemon_t), 0644, NULL, &proc_dointvec},
 	{VM_PGT_CACHE, "pagetable_cache", 
 	 &pgt_cache_water, 2*sizeof(int), 0600, NULL, &proc_dointvec},

Index: linux/include/linux/mm.h

include/linux/mm.h renamed from include/linux/mm.h:1.1.1.6 +5 -7
diff -u linux/include/linux/mm.h:1.1.1.6 linux/include/linux/mm.h:1.1.1.1.2.23
@@ -118,12 +118,10 @@
 	unsigned long offset;
 	struct page *next_hash;
 	atomic_t count;
-	unsigned int unused;
 	unsigned long flags;	/* atomic flags, some possibly updated asynchronously */
 	struct wait_queue *wait;
 	struct page **pprev_hash;
 	struct buffer_head * buffers;
-	unsigned long map_nr;	/* page->map_nr == page - mem_map */
 } mem_map_t;
 
 /* Page flag bit values */
@@ -165,6 +163,7 @@
 
 #define PageClearSlab(page)	(clear_bit(PG_Slab, &(page)->flags))
 #define PageClearSwapCache(page)(clear_bit(PG_swap_cache, &(page)->flags))
+#define PageClearDirty(page)	(clear_bit(PG_dirty, &(page)->flags))
 
 #define PageTestandClearDirty(page) \
 			(test_and_clear_bit(PG_dirty, &(page)->flags))
@@ -302,8 +301,7 @@
 
 /* filemap.c */
 extern void remove_inode_page(struct page *);
-extern unsigned long page_unuse(struct page *);
-extern int shrink_mmap(int, int);
+extern int FASTCALL(shrink_mmap(int, int));
 extern void truncate_inode_pages(struct inode *, unsigned long);
 extern unsigned long get_cached_page(struct inode *, unsigned long, int);
 extern void put_cached_page(unsigned long);
@@ -387,9 +385,9 @@
 }
 
 #define buffer_under_min()	((buffermem >> PAGE_SHIFT) * 100 < \
-				buffer_mem.min_percent * num_physpages)
-#define pgcache_under_min()	(page_cache_size * 100 < \
-				page_cache.min_percent * num_physpages)
+				pager_daemon.buffer_min_percent * num_physpages)
+#define pgcache_under_min()	((page_cache_size-swapper_inode.i_nrpages) * 100 < \
+				pager_daemon.cache_min_percent * num_physpages)
 
 #endif /* __KERNEL__ */
 

Index: linux/include/linux/pagemap.h

include/linux/pagemap.h renamed from include/linux/pagemap.h:1.1.1.1 +1 -1
diff -u linux/include/linux/pagemap.h:1.1.1.1 linux/include/linux/pagemap.h:1.1.1.1.2.3
@@ -14,7 +14,7 @@
 
 static inline unsigned long page_address(struct page * page)
 {
-	return PAGE_OFFSET + PAGE_SIZE * page->map_nr;
+	return PAGE_OFFSET + ((page - mem_map) << PAGE_SHIFT);
 }
 
 #define PAGE_HASH_BITS 11

Index: linux/include/linux/sched.h

include/linux/sched.h renamed from include/linux/sched.h:1.1.1.6 +8 -6
diff -u linux/include/linux/sched.h:1.1.1.6 linux/include/linux/sched.h:1.1.1.1.2.13
@@ -169,6 +174,7 @@
 	unsigned long rss, total_vm, locked_vm;
 	unsigned long def_flags;
 	unsigned long cpu_vm_mask;
+	unsigned long swap_cnt, swap_address;
 	/*
 	 * This is an architecture-specific pointer: the portable
 	 * part of Linux does not know about any segments.
@@ -177,15 +183,17 @@
 };
 
 #define INIT_MM {					\
-		&init_mmap, NULL, swapper_pg_dir, 	\
+		&init_mmap, NULL, swapper_pg_dir,	\
 		ATOMIC_INIT(1), 1,			\
 		MUTEX,					\
 		0,					\
 		0, 0, 0, 0,				\
-		0, 0, 0, 				\
+		0, 0, 0,				\
 		0, 0, 0, 0,				\
 		0, 0, 0,				\
-		0, 0, NULL }
+		0, 0,					\
+		0, 0,					\
+		NULL }
 
 struct signal_struct {
 	atomic_t		count;
@@ -270,8 +278,7 @@
 /* mm fault and swap info: this can arguably be seen as either mm-specific or thread-specific */
 	unsigned long min_flt, maj_flt, nswap, cmin_flt, cmaj_flt, cnswap;
 	int swappable:1;
-	unsigned long swap_address;
-	unsigned long swap_cnt;		/* number of pages to swap on next pass */
+	int trashing:1;
 /* process credentials */
 	uid_t uid,euid,suid,fsuid;
 	gid_t gid,egid,sgid,fsgid;
@@ -355,7 +362,7 @@
 /* utime */	{0,0,0,0},0, \
 /* per CPU times */ {0, }, {0, }, \
 /* flt */	0,0,0,0,0,0, \
-/* swp */	0,0,0, \
+/* swp */	0,0, \
 /* process credentials */					\
 /* uid etc */	0,0,0,0,0,0,0,0,				\
 /* suppl grps*/ 0, {0,},					\

Index: linux/include/linux/swap.h

include/linux/swap.h renamed from include/linux/swap.h:1.1.1.6 +2 -9
diff -u linux/include/linux/swap.h:1.1.1.6 linux/include/linux/swap.h:1.1.1.1.2.19
@@ -33,7 +33,7 @@
 #define SWP_USED	1
 #define SWP_WRITEOK	3
 
-#define SWAP_CLUSTER_MAX 32
+#define SWAP_CLUSTER	(pager_daemon.swap_cluster)
 
 #define SWAP_MAP_MAX	0x7fff
 #define SWAP_MAP_BAD	0x8000
@@ -76,7 +76,7 @@
 extern int try_to_free_pages(unsigned int gfp_mask);
 
 /* linux/mm/page_io.c */
-extern void rw_swap_page(int, unsigned long, char *, int);
+extern void rw_swap_page(int, unsigned long, struct page *, int);
 extern void rw_swap_page_nocache(int, unsigned long, char *);
 extern void rw_swap_page_nolock(int, unsigned long, char *, int);
 extern void swap_after_unlock_page (unsigned long entry);
@@ -134,13 +134,6 @@
 extern unsigned long swap_cache_find_total;
 extern unsigned long swap_cache_find_success;
 #endif
-
-extern inline unsigned long in_swap_cache(struct page *page)
-{
-	if (PageSwapCache(page))
-		return page->offset;
-	return 0;
-}
 
 /*
  * Work out if there are any other processes sharing this page, ignoring

Index: linux/include/linux/swapctl.h

include/linux/swapctl.h renamed from include/linux/swapctl.h:1.1.1.4 +9 -18
diff -u linux/include/linux/swapctl.h:1.1.1.4 linux/include/linux/swapctl.h:1.1.1.1.2.9
@@ -4,32 +4,23 @@
 #include <asm/page.h>
 #include <linux/fs.h>
 
-typedef struct buffer_mem_v1
+typedef struct freepages_s
 {
-	unsigned int	min_percent;
-	unsigned int	borrow_percent;
-	unsigned int	max_percent;
-} buffer_mem_v1;
-typedef buffer_mem_v1 buffer_mem_t;
-extern buffer_mem_t buffer_mem;
-extern buffer_mem_t page_cache;
-
-typedef struct freepages_v1
-{
 	unsigned int	min;
 	unsigned int	low;
 	unsigned int	high;
-} freepages_v1;
-typedef freepages_v1 freepages_t;
+} freepages_t;
 extern freepages_t freepages;
 
-typedef struct pager_daemon_v1
+typedef struct pager_daemon_s
 {
-	unsigned int	tries_base;
-	unsigned int	tries_min;
+	unsigned int	priority;
+	unsigned int	buffer_min_percent;
+	unsigned int	cache_min_percent;
+	unsigned int	tries;
 	unsigned int	swap_cluster;
-} pager_daemon_v1;
-typedef pager_daemon_v1 pager_daemon_t;
+	unsigned int	max_async_pages;
+} pager_daemon_t;
 extern pager_daemon_t pager_daemon;
 
 #endif /* _LINUX_SWAPCTL_H */

--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#88 lore raw

Re: [patch] NEW: arca-vm-21, swapout via shrink_mmap using PG_dirty

In my new PG_dirty implementation I did a grave bug that was causing sometimes under eavily swapping a corrupted swap entry (note, the kernel memory was always safe, so no risk to bad fs corruption). Sometimes happened that a swapin was swapping in a random swap data, instead of the (not) swapped out page of the process. This because when GFP_IO was not set (and so I was not going to sync the page to disk) I didn't re-set the Dirty bit to tell to the MM that the page is still dirty.

I noticed the bug one hour ago and I fixed it now.

mm/filemap.c line 178

Quoted 3 lines
mm/filemap.c renamed from mm/filemap.c:1.1.1.9 +3 -0
+		if (PageSwapCache(page)) {
+			unsigned long entry = page->offset;
+			if (PageTestandClearDirty(page) &&
			    ^^^^^^^^^^^^^^^^^^^^^^^^^^^

mm/filemap.c line 182

Quoted 4 lines
mm/filemap.c renamed from mm/filemap.c:1.1.1.9 +4 -0
+			    swap_count(entry) > 1)
+			{
+				if (!(gfp_mask & __GFP_IO))
+					continue;
					^^^^^^^^^

mm/filemap.c line 192

Quoted 10 lines
mm/filemap.c renamed from mm/filemap.c:1.1.1.9 +10 -0
+				entry = page->offset;
+				set_bit(PG_locked, &page->flags);
+				atomic_inc(&page->count);
+				rw_swap_page(WRITE, entry, page, 0);
+				atomic_dec(&page->count);
+			}
+			delete_from_swap_cache(page);
+			return 1;
+		}
+

With the bug fixed it seems really rock solid. It would be interesting making performance comparison with kernels that are swapping out in swap_out() (e.g. clean pre7). I am not sure it's a win (but I'm sure it's more fun ;). The swapout performances are a bit decreased even if sometimes (in the second pass) my benchmark give me super results with this my new code (43 sec, that's been the record of every other kernel tried).

The only thing I don't like is that the kernel seems to stall a bit every some seconds in the grow_freeabe() path (the old swap_out()), also the profiling report try_to_swap_out() as the function where the kernel is passing most of the time (20 timer interrupt against 10 of shrink_mmap). Maybe because now I'm recalling grow_freeable() many more times than I was used to do... Maybe I should reinsert something like the smart swapout weight code to allow grow_freeable() to scale greatly... It's just quite good though.

The fixed patch (arca-vm-22) can be downloaded from here:

ftp://e-mind.com/pub/linux/kernel-patches/2.2.0-pre7-arca-VM-22.gz

(if it's too slow drop me a line and I'll post privately it via email, I am not posting it here again to not spam too much ;)

Andrea Arcangeli

--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#89 lore raw

Re: [patch] NEW: arca-vm-21, swapout via shrink_mmap using PG_dirty

Quoted 3 lines · Andrea Arcangeli

With the bug fixed it seems really rock solid. It would be interesting making performance comparison with kernels that are swapping out in swap_out() (e.g. clean pre7). I am not sure it's a win (but I'm sure it's

Even if rock solid my PG_dirty implementation is been a lose. This because swapping out from shrink_mmap() was causing not ordered write to disk. So even if the process userspace was ordered in the swap, it was async written not-ordered. This was harming a _lot_ swapout performances... There's also the point that shrink_mmap() is so highly/default used that stalling in it many times (if unlucky due many consecutive dirty swap cache pages to sync to disk) was not the best. So I dropped the shrink_mmap()-swapout idea completly.

But I had new ideas that here has improved things a _lot_.

Steve could you try the image test over this new patch against pre7 clean?

Also you Kelle, could you try my new arca-vm-24 on your 16Mbyte machine? I think that you'll be very happy ;).

Note, arca-vm-24 is tunable:

/proc/sys/vm/pager has 5 entry:

6 10 32 32 2048

The first is the lower priority that try_to_free_pages() uses. The most this value is high, the lower will be the starting priority, and this will result in more swapping. 6 is a rasonable value. If the system swap too much even if not low on memory you could decrease this value to 4 for example.

The second value is the max percentage of cache in the system that we take even if we are very low on memory (the system should autobalance close to that percentage after some time). The `cache' is intended as cache+buffers.

The third is the number of pages we free every time a process try to reclaim memory but when the system is low on memory. 32 pages at time is a safe value. Incresing this value will cause the process that get stuck in the freeing memory path to stall for more time (so it could harm iteractive performances).

The fourth is the cluster size on the swap space. pre7 set it to 512 pages, but I checked that it's a _lose_. 32 is/was a good value.

The fifth number is the number of pages that we allow to run async at the same time (when the limit is reached we'll wait for I/O completation). pre7 set this value to 32 but that value is a _bottleneck_ for some rasonable fast system. Increasing too much this value could cause the system to have too much page in fly to disk at one time and so it could risk to go out of memory (if the freepages.min is too low, note I never tried arca-mv-24 on verylow memory and I don't know if it's reproducible). That never happens here and 2048 is something like infinite. But I am running with freepages.min = 255 because I have 128Mbyte of RAM. So if arca-vm-24 will kill random processes on your system (search for Out of memory messages in dmesg) the first thing you should try is:

echo 6 10 32 32 32 >/proc/sys/vm/pager

this way you'll return to clean pre7 from this point of view.

begin 664 2.2.0-pre7-arca-VM-24.gz M'XL("+MOHC8"S(N,BXP+7!R93<M87)C82U632TR-"D/&MWV[:2G^E?@?J> MFRM9E"U2#\MRXZUK.XVW=NSC1],]:0X/14$2:XE4^?#C9KV_?6<&(F0E.WT M)JTDIC!8#"8%X8Y#2;\<<06?I^[DSCG7$ZG?)HV]N8^-,I:Z?5GI&UC7]W MU_98V_:V96VTV^WUP,:UF[#_=@/&]IAEC_J#4:?+K+V]O8U6JU4%RX=;V;M MCJSAJ-\3PW_ZB;5WN[OF@+7P:Y?]]-,&,^/6Z6)LW!C^(C2QGC>W*?V\;Q] M,':FBS2>)_Z2L_>L0QW/&RW#2,+4FSMBTAPDXDD:!6P\QZ?G#2:F[/=HRGX_ MFU(@AKD<Q&N\9W\"WT>[^=]<>(F_#U-YP<QCQ+'#Y+0^2OE*8_%=*U:$E0* MX'%G:^-4W34_\!;IA.]D7-N>ES:O.J"TAVL'T%9VE:U<C\[email protected]=T8] M>V19Y1VM0M=LK%ULK+4[1"Y;NWOF'G'Y'Q,^]0/.?O[H7/&_#*,+S&=YD]9 M,N=,<(W-W9B-.0^8']R["W\"7)^PK1T-^C(*$^Y!AS%%%8)A1^S53:"0#=:
M&;`8X:S<&<?],8S&DB^=I;MB+79^>.E\[email protected]>6^-F"?.V$\:
ME[\X$8=&'GA\8K)WI3G:!].%.XL!TP:#S6=LB]U$3X".W7&^(KJ789PP+UPN MPV#QQ-(8R;A6TQB8*+_6"VX,QS/1@)O.<Q:U@#PC-^2GC<1%3^$E9\S]F* M1],P6KIRC9C-W-@11A->0X6#P/T\4$F$N[8_<MT]IC+1L.P4<BFI@%,L M3.4TKJLX!RC8>)C:L*V$'+,5Q'W:*O:[(&S21C\*Q'KXK:<E]R+C'B"$&Z MP1,L/^+;^$0MGSES/*3488G@4[I"*2!.(5,+/";L9P+M;D*0DY#'.&_,^1+A M(NXN@)]CSA["*)DS/V'<!RS1-CN=$IG^Q"1(Z'D@YBS"\([%X9(G<V39PK_# M>?UXE)%G_'U)4J'_8V%JHV"WUZ*;A.P;>V8/<Q]$I]&!\7"Y%F/XH3O/)7 MW)G&CK\]/ZCV+OW?US?S1\3.^]]0:$MEZ\H-!P@M=#@M0&HT.SA6H6FHC+. M0Z'00(_9]LCNCOJ[+RLTA"Z@AJS3&5F@"?<4A68-P5ZT\$N>F#2(_5G46Y M6L+I%+81=7Z<1*F7"&G="H!7#J@U,D%N$BY]S\'CG@8PMEW@'O"T@!/_WX% M->WZ/BH[@4TF"2J;!7&L3]&S;$2ZM*-GP)O'H5!F,;0C"HP(^G!]1-AM-@6 M_JY0N[6"HWPOZ:55=SNF;<.R[3W3[FB*'(1U$7IWH(<-UM&:>12%$;1:6FLA MV=!E%^(+71,_2IZ@M:NUIJLDQ"5!1T_KF$:<.^XTX3A)7\?$O2CO&FA=\8.[ M<M(:98CV*XVX/C\$)V/H=9XO7#'V+I7Q45*V3"LCMYUYZ\``+RH5OU:NEJ' MMI:>UJ6MI:]UU:QEHV0:]G5&K.U#*NXY%I@F:V:M71*&PD>T#UN8]="KP;D M\MP%50EZ%*0G27S0]J"T9*0VG;'8)RVM[<U0WX)\G9&XM-T6L:C=SRY((% M&E!T9HJOJ<.?H)Q)<!V>)/U\*M<(.M(T!1Q&4];Q7.,TEM+!LGU:V3<2M&H M(R(3F]=P?``I.D0YJ$-2B-AK:(Y!XM:B*<2Q!@WIBO[0M-#GZ?"LG5=:.O M>8("F*%6;!XVOT8:0H.@'J&<UJ[email protected];Y?-[H-Y@1G7G_@!MG&T?]#H* M\C=M8X&U3.<?%+W48GZ%;&V"HP5W(Y6#'C9\#P\%!ITZ'<O?8",A51C)RHS4 M)O@>5M:16V'F]Y"/0MKMV.80'-^]+/HC_34%3PF\MVV/=!28;ZN\'WH3\"- M7(+V@GOG'#AB&D&$WSAMARNVVSL=LB@KP5DQ_/P3N_<Y8P>0.>36S$8%(9 M\N'P^N;H\.RL43L6G7&57I@K0%]<H3C.**FMF7JI"H8]"7,0$Z)F1-MX?58 M,LHU8C".5S&4YZ4-&0Y,J\-:70@8][10Y'[I9I%&R>].P>6,''!2&W,&J(1 M''!V<,N#W\Y<:X_GGZX:8)K;W4Z[$<ID88$AH';.I;.)QX.\6"]*ELYH_ MQ<0L1;FO9D2\/AUMK&B/_7_S\B1%]\N39&;6X."GS>8"I($&9/V"P#[3GS\P MX8$/K1(QV9(/*B-Q82Q"$ASL"TQNX"(\4J::AW>!N.YX,Q_GUY.K3R9GC MB&#Z!6\_QHU^Q>&78U[T^?4QK^0Q2@C+GG^O)CE5B\"XF:<"L(=9K9X]Z@\5 MYW^P)[(9O2QGI!^5*9W/D3=^'<+TTFW!?X6?7E8=<=X<]7NKQ5"B`01<9W MF$[2.X5JPU-/O]S)!-PP0H)I!0/S"ACOPW^P!C?RYCZ&[FG$V_&*>_X4HH95 M"$>41R,12T-0[(X77,"NW"B!"(:=(4LHE&9!"#%\$#Z@^P9Q-H;J,9\M09CC M;9GAV36M/C!EV#4MP97G?=5HG7XZO7'.S]DW%$%A7]]!7)F0!C/9I]NS,[&:
M%<:X,[0-)C-(9%\=)^S`X<W%^>F1@Q,UK*;)+),F@I[SVYN3WTTY,3QWM-\L M^R\G+&\3+:VB93T8*P_*\2#)[#G'8NA(BT<Y#G@F=2ON.,B0?/JFA(R&(6-& M2M_L=LB([0ZE.,)!72[9U$T7N%,3XA8HY&DXH@0&\T@H9JD[%BF1&'-L;BPS M(@!;2$D(SOL\XNZD:*(04A='U&W3!4CCTOU3_AP3I-Y>8^7=WG4)Y*GB=A) M%+V1I47A9CGPMU><PCV#0R&06V-@7@06U)<&'/0ND$#8-0-K7&,M+=HVB2" MH-8/9C@K\FL5A1Y,PKR(3T"H?7<1RX7Z$XC0X=/D^!'CQQ0_<0$SZIQA)W[$ M,^J<82<9,THJM[H#N]B8E)+56SO&MXY)?Y_AS0S$0'T'UW>,AR"TS,8PY[- M[$L,AXBN(2FOVAMH"=^6!4]J.SUMFR2VI5FYP$I!%/-$Z\\"?XM!L7I:K5@ MLV@5YD=(O$Y$^67C+LR&LV@8:\;!+4(601]M9;!`U=C4'HOV(0"-[X$/D" MKL]L:]3;U>Q!MTO;W)6[G&F\Z\^7SNWUR;%AZ6V?KTYO3BY^-;JJ+W/]^?#2 M.3J[O;XYN7+.#W]G7;L(OM5.X7/DUEL<@D4:@R[7@@2".:?_?S<ZC[O3Z;2F M\^?#8^@<=CH=<1LRP)70)ZY$\3N3Z,E)0A$]"C=22U;-IBLR5<U]Z4-GB;0= M<DK\4#C3;<V9?A`N.CF#Y,*6?$AO[D;H6NI>\-M@-3>[UAU543A!*%RN]62\
MHY&_@V+T%(]88Q=):](7)UQYC!(8V>FED"KF=:7;"RW9[,.];ZZD7DX\!V M@XY"7V3_C8/CU/.$,R'\OHVV$J/@I4,)'C1\@4(/;RCFVFA_]4-_F.#(G<] M@FNBF90>/C:T#[+,:3MK[L#O9R%5=-/Q.8SN&#HAXJ8GXF#+.'DD(9DOJ>! M@\;>DS=D]%#[++LR#$MM>4E)<LWJ"G:)34+;TWC2)MU7E16VE(_Y["(A3:
MC5R?;N1V"YW5,[LV:_4PG4LZ*\_IN[$XL[6I?KSI.T"UE3RMP'Q,LV-6!%/. MO;71*O6BTB"=X<0;[%LISVTH@5$Y!VZ,PR@*']9V+]U'I>]9)V._H%)K5Y^2 M(OY66Y6'-0.*4&L?S\?:!0,WVM]4?TFN>+_<M@@?*FUS?S:G=:GXE&6IS<H# M+*KUK#]G)U]I+'[OUVRH:F/JME3KK]O5)/)AEK$;\_WZ+F)"2^]913Z<SN2I MTJ'%J)5>0ECAGFH9B8NE-2F,+/7HSTEE/A0[NE=Q)/]:SQ60C.-ZN_:X7XJM MSTX_W?[NH&D^NCES/J*]U+34'>#CBYTIZ+]*68?65W*>ZOHJ>J@6057[V)52 M``VP!(#5(,JE6=^R,&[N6[T\VV:LV@<3\*+Y(_>R$@YHRJ,"T=;"MLQE5X?A M!30\WQQ>_^K<?CK]!/[1U>WES>G/9R>BQ,(+5T\BPFYX8*VX(R_+5F!0ZY@; M/\6H/->P-^NM9W"IEUAL5UE<1E+#9'L-DS-0XS-((H%TT1VUNZ.NZH[:Y([:
M:DKSA*317;![,(G(6!'2^Q#WL3F$=VW,>NYK68\T:];N0'&FQ"0@,75DY5> M&,3A@CN+<+;@]WQALB/GT#G6TY5K!HD('EZE(2X5[T3!!M/ILXJ6G[Y:N)/ MK/%!?:$]NH]?OA9Y&6-(<9=)LZ?[KTK\.(%%(\(3.D"T5KPY-[G#]BG3RPX M[(3W8%7"Y1+3#G!4HR<9:5L#%&#\&BHI#A1#"(P1D+(H['XI?GSY"L+Y#<3W MVV_G=+O;F],MEE>^Z8)0]B[<C,PR?\W#Z?H5C9-UAGT>EG^XQTZ.<X$4SCW MW'LV0=)QB@]7)R>7O\,N6[?-/$4L'=Y0XY4,05O0_[S\0>(0#X"=KD'FUB3 M(#;*9'M;)6([,O-A"L[971/DNV7;>9T56=;:RI/[F,^Y\5O)U='%^?GF#HZ M.;^X^A^8O;(W2,>Z?4-$V8K7C7EM^6VQ_-L/'TZN@ID0):2W<3>O#(#&G+V MJM["VR;U.[1X=''$Y@`-X9LGIR@<#?^PPFNC@^!CY]@BCL4MPF)7K63S-0F M,>^=:K+RV76S]C8!NOSEQE$72$?$D<L48KJ:R2L"Y\&EJT5[K5A59]'T.42> M^35.29FK75()[ZWO0C7>5PM-ZL#S?#';Q7PQZ.1NQ4U7X?(:.VN7@?:VA[G. MIRC/MDRKAV46?3PT>%IJ;H=8YBV9>@2^09E"J9-*.64,,H7]+"?3%CX<".C2 MLO^5BA#Z0F"AVRD%6<Y-4S-@:FBHV(\_,JO)=E@C([ME4;*@;>0@@8Q\." M%=Y@&\T]$O">%955M!BD!0N<@I9X$388+-^@&4VB15$;'&!+QP#3!E2COP! M')>8@6U"R"2X5C2@'<AX51<-M_Y*S:&\YC&HE[.ZNU2\4\O+_XQC(RU(H@% M"IT@DO6H\(%1KB1,EJ)FU`!(_>VE5G$@L(J[2TE_%E"K91/RYGW0,;M[0!]\
MVUD=+0Z7V6-,YS8D2B*JB<RRFF(=89"N'*Q-7B=)^P\:<Q5G2X0@XHL8J_ M_@NKY^+0QJZ!Q?31*$</XG"%4+O/B)[@:)!S@:6-9D2HYCKX1XP%^"3$A MO70C6).R9]O;8M.?JU+)50(KH5_KY[)S,<N-*&FF/(EDTW=<6Z\7'"P4, M9S$*EVIR@^81(V1R@I+6QK-!(EJ:NLI0(789*V4II.C)9L)@2!1=,;JHJK7 MG17:F1SZ@YJNDZ@R$6%5D&(Q0F#Q-N(%+K=>Y5!+0]JBJFRY>E\1I+:H9*WG M-TLJ^NON8"M94#UDEY25;-4B-V-O#92**(#T!M(\W-Q]]R1-\]E"[-<8UZ6 MJG&PU[17KC(K@)1U_A3>,SC%EC6R]D96!ZW$4+<J2VE2]'3/WJC3*4S*@!*[ M@RRQ:Z!@L-9[5KHRWE>Z@DC)]I8Z\LPG7<M01_L]:ZRY[FZQ-9?M+68WMS0S ML6-U.OLH?QK.^KOJ>M!\TPC#<O(K][email protected]^HGU/3BCG;[^H[6 M(2G=+G?MFH+4$JCJ,'38=@=V0/58>B10;*SK+!0J*L393GR7(<T(;2"DRX M1T8'K8]N#3*KN2YCRZBP>)"UMC$4C-?)I%9<9HWA994S!9[]Y[]7\-"ZZX9 M-W$L"T%SPKN&:D--.HWYVQOBU0UAA"UAA#NY$59LG+XZ0%5:7,WJ8%"F'5]9 M72R79Q#>-RROM+YL952.K^DEJ95$K&F+HGRK8UI#N4(PD],THC1W,L=*D61; M-.>Z\X>&ET8P=Y(3QBX_8/!T>'9V<90;2>D>JE>A^1LTY"\AQ9FK1(@U=0#G M*H\?\41G:#/C(S`V1;T)M>54%9W$:F,6@LT/[]!:D:R#WR^H>&761?B0SVKH M:Z!9C<J,Q0)?FI7\-3*";1VQ,&2U:(4U,4J<_]_W*NL+02"?KW*=IMZ@57&A M>&G(*-$SH"/0[0]-U<T3W@T[>$]R.^'W>)8>!;_'X/S=[4M3?$RO9HS)<PT# M=KISP:8AOIOA3MHN9H44ATOS'6%7E/QG$Z=ZX5*R]3<PE%*L:XE';.BWC^$+ M2!^G\9.\_U>.1,X&[email protected]?!HJ_->HNMY5KS%VE2Y\:KK0$.S6V$5VKA) M.3OF'K/W6?BQ;V176?<<[CR%?10L^\DJU"$)[E"V:232CC#^!<A^!:!\A M3#K+LD1ZL6BZ\%&7;(L-?WVW7M[N[X6OVVQ\(4&>+S^X"?EQQPL8_F">?NO M,B77[5+!('X/LR*+0Q;[RQ6X=\1U0E!B")>"G-C#@HT\!(?Y#U[1RC(PGJ M@-J\$OHDA%?)$*N%:%.S&:()$*M2\@*H_#@@#C:F^FH:%T)RQN=+.;87"- M1"/*P;N?2>2RGVKBHST8V6$%D7+]Y.BJ:(LTL..'H,ZN,/<B.P^DIXZ+A; MF<&\B7S!2V*."T%?T):C<[]5-[:0])=]NY>)K+J+.5)]O-^J=S>B_4KK]'X M@:>[,?2*C'QIC6&<HB50FD+4-48CDR5;A<-J,HM"@76C!+\ICV$4CD>)C,K2 MRBMKU368_VR@J)ZE!KM)-I+%Q/E=GIIJJ<K)AVPYC*B5^.:"J#R*U*]44^] M8>Z8]I"U>KG[\IS5AGP$723T$)VK28CI_F"GZC9$M("DKR#%_U)../H\U", MV!;7$AAH"(T#'.WM(]IC+DK>[MU%BB]2H]\NK$3"00FU3N>ZL&1U_#@7I+ MF,"N+<GD]QQ)%.5;<B6?D6X7S"<JA'(%FC3A5&.'VK;T*I80\,D&5N;"*DVA MI$#MY"]-JBRYN;A0>49%FE8;4]0D[]+IJM:6)=:%=D1&;<U5]UT5]$V;!,/ M#K[SMTR7+O59+*"#@UXI#A$7,[7CAAT"(?[N[',UV;K[E2?Y$0$@PQ3!#3 MKR.F/&JWKQ*44_#2]:RDHF\).LAVR"U&+\ES%UZZ"^:"DS4W:?K:#%MN:I+ M6]';(292"-!#W&60AL3*.8P1>DYUC8.:#QX]Q$1EJ50Q21EEU.<A6P[!;>R M.G#)2#(:.*@KN%"FF605G4=Y.M;-(<'?OA"[TQO*+5,F)='.3DX;#X$\#B)S M.Y5O.&::1K[ACW=V@[[9DSYRZ>#;J([YG:7`@X]:<T:#5``6$</>E!\-4MU M^,T:G%V,#Q%G%@5KR@J3$75Z7;Q0O4Z[9[WU.K[42\FE&DU?1O+&5(0*^O+= M1=?NB-OG3AZ3B%@K30JQ$$Z=\N93_H9?P!\<W0"6;/35R>%Q;G\;LC2/96!4 M+&P*[Z=BN#70#"(?S/[A3[$6Y/CDY]M?Z+(6#3<X#,E=8_.8C]/9;^<CL@N* MN1:Z%FMIZ67;3;S$$G\V:1[VS\YP\8B:^I^K/X)-LW;;Z>)]S::+/KE;W1?Z M<,,'U?W6X;_#N@M`M=``+#S^I_QS'3;5O<+G0!8:9'7KF:/NE!N^@$8CWGXX M/3NY_KI?KH#%YDS[,;L_4&[79>TA781YKJPY1$]NW:1;L4\>,$FE")1SF03% M(EYU^)P['MD!51S^\1.3R0&IY)<"*.9_I:)T&O2-="^V&;MO?G_W7/,S"P M[FT$J"Q-EJC3_9,+TC@/'U"!TCU*Q.,PHIN45@;[G7!$Y-2/XJ1-2=!L$71_ MFYD&%X]MFKY#T3(US\BO)M)8I;&TF\&X$3^PQ$%=SZPKMTTKS(CDB^/B+' MP#1RRL*OB?@DQ8LU$/PB1_?X=L'=Z+D7;B-=+?6&Q3_@SI#_C(5(?(T3QC M:..#ERU6X2H6\N,1AU0.Z@8PRTYHT\KL#A$"S+5UWWY9O\[$?1@R5YLNO_ M>[O:YB9R)/S9]RM$BB)VQDX<V\F%A%5%A92L,L54+=5?'%-XL%XX[?SC!-R M\..OGW[1:%Y,<K!W*2K$,Y)&([5:K>[G:3N[%T6!QQ2%JFZ&8B"HK2N9Y#H M.A5@=VR1]S;?8D!720-4JM]35B]DH'??7S<ZP=>YRZSH+J(56.J:.K=/VDW MITD_=@_/1\?.VFE?N_U=#H@?[75[>]0(/9R."W0^2&FEOOBR=_E#.W6OA; M!/G%9K%.:=(X-"J$N%V^=38EX4\#8P"&-DYXPD03I-1$DLYF&A#0]7<)'!Q MD#T"1LPJF;+"3C.R0*7P9*[&)^X7:7B64@5T)PX2BY7#TTQ-6[=^62QO5WB( M:_[2XF%R[FP^HKW!G:UH',;)=(*">XB%E9&UZ32^J(7<"O2+-]_:^T)0>"H* MF6>D=Z2>DJL=\R0"X'P1L:^"2%')/^O/IZ$Z6G4T<&VEGE.4F=1-,5@TV%& M0..?UJ02U8&R(O62IT_A$PZ&EK0K652/ZR:&&GLSC-M,542*%YC<%3/KO,' M_RK%MAZO@*5XHKP?FV5U*S%ZD)TBM@ZL=)W1D*#B!KTM\:63_H@\H>'7K> M7Q@@--\)U;RED_]8ZHF+VH?1/ZSB>?I)E>96S(.6C+8<]GK6LMLH^4SP>IE MXK\:3Q=DG\N[(>AG07'J"(RII:8-D'=I.W1E=K68CJ0K'+/8E%S&!BI&13> MSB?,.CQL]P]<]/=>NZ]Q%T$'^)0\\11&TJVA*7(WF0<+T.6YU+M)F(SV)VEG M00PLUF%N(&0SHGUC@E@'%5@N,_U<!^?^LZ='L[]4]<+SO9HL,)@N#>H\UE ME_=?V83?Z<NT0763C#_L&KW,UKR1RU9)#2-7D%11#)G)K69-XMZ:-N<>LY;C MGNVI%%0#9T..+TGTW.L:"QV(L7CJ\EG($\@(D'FT7DXG,"F:Q@?9,.E#OB*% M4K#BDO'J']BSM/P2J==9ZNTE31*(*[RZ878B=3(7IE8=U)+-^Z5P&0#(/( M&F8C7UV-QC"W]_,!.GX'A*IT0_Z"!T0<U][Z6+('QF<T4+D&*:X^H,DW$! MR^*2K0I/8B7CC2>*BD/_33L.HZ!-=3Y+(B>U)IDNRHS$3[+Q5=F98GAM?B. MV+B"V2KXF9"]LZ?VED#&GDGA8@;M.4-&"W20ZI.:O7S)LF3.KGX184F1!RE M/\_BE$2'.JMOP,W,XJN$QU53!B7LU5BSKAFI#<DIA?!>C)*R;G]:@TF,3UL% MC^I6<0FP#AU)*H@LJ1']7(`4H>*^?0LNJN-7HT>^WJ-'[D%Q>VZ%<!.)\.'1 M[&$-EH8L&38F;4T$T>3](R%6]7P*-*@95A3+1>:M_72*1&8J.Q[2)*6]2L!\
MS"?,0F/7YFPRSCY+8].IM9RN9S@ML/QLC_*=,E19O[_]\"+_]4``:Z$LP#*- MI2R/-.\CD[D?11&D7+UF)FKT\KMD1TUY0ND0/9(9OM&T<'!)K2$5"[#60[[ M]X'->JXSIIZL)B-VTM"H,'^<C"8:]UE:EO308MEBLD,/HKE3*I>[>DETVOI M-P*FZ57GZ=*8M?L'@L[\(DBZYP)-7N:G/W>OF[#%14[>'JP-J^67>SFF2) M>5YW74VD@"F<53>$.!2Z5==#L7P^.UWMTP9=Z0*XDJ51Q&M[IK=ZHFN.R&J; M#I>SD9V0LSB]\H=C#*B/'M'PQ[3,\YO8NB=J3)-PY3\8O6EFX/U:#4J(Q& MC?Z"5LH%=@1DRHS7KV+'X0E.EW3),*3'4XLZ@H\?<[B0_^\9"841I!XHFJZG M3#5KL,R%''1L@?I7I"[\X\O6$=Q66RK]RG/IA4>DR,!_&&"YR7<@MF.:[LB M/D"0AFBB%<+:K/.J-!]T.CM^I"I*TG?MM-0W>EX4L6XT9)P5?8*Y:1D9@CU] MP*EHOH>[1''\,Z(X_DM$<?P_%T41=DA=C2B.U'L];MMX'OZ/0-YP]""KO/% M7,.$LQ,*ISLMKN]<9.A3(#?<^4!NHI]NI.W?]K^1PGO(X&DN8[12?GO.PM@" M>(G^_NWL_6L1S-GH/H(Y$,$<#&H%,Y!(>MT?E\@-\E,6N7L4NU.F1&KIO\GJ MI.8\;)U,.",:SUD7GMLNDU$RG99%:O:T?NNF(T+$C+F%?0#@G;_9OY/HO;R M^?F[7-CX4RYNZ)\*7!4,W*F3*"6?UTO5LB(=/]M$FU\3\8;O2U"M$;>DJ*, M[TBR+<DMHS"-H]QU+A;LRQP-HSW>E@,-C5ERF=$!R,R^3C#TR^(&B8DKW"SO MH">%@^"O$Q)FH6@L"FYGG70;064]%B='OF-O1'.N2T]G\KKI$=OR<G'F-> M*[+0$<ORCER4]1^IV5:4(DU>0<XK@EXCZ76B7I1U'/2#ET8"G(<0)>U;474 M\?@][B.G:]3O]MN#;@E%]H=WER!%!(Z[XM7[M%C9?'!2&9YMF^-+9O4PUVA9 ML8N,U>LGW)<N7B[4J*S!J&ANE(A(->[?D#=%X<C:?TZJ_*:+*&7]A(F/H*! MG/CC$6I/)\A13Q]9*FAHA@D=4(>XU5QBEKYZ-152G&7^\NBEM%!6.'=066J MEO(=BOS2L4O"7]>2FZ1FCYR1[/IF_+T[3V(S].(+@'/N'WR120*LP[FF3_ MG$KXJE/RL0'SP*F9VVLCUUNY??=9[MRH/6//4!.TY]W@4*:)].7^JW8U1/ MRI0=]I2JESEQ"-:L'+.+'>FCC-.BZVH$QD"';&1"RF=L.=35J-]B6IM-%+M0 M<8^1H0+'-TSF_:HK0Z]>O].OBR3-"BP[.)_B%"TCQ]87SGJE'FVY7!57+>:W M47_X]8%/>(<SOE8Q#<+SI#%T<4<X\CS"YG!&XR2+]3XQ:VFSNSUV&/2/^A9 MID9).S>_PMD_EX.4IGTK_1R/%C?(C+?%7EN7)=,I1QC)%+GT6XCW"BN93'84 MB$XSEJ/1&H:K\9()\PASE:^S>B;.J:HH.MIA6\HX%8K^$3I7WG%_7*1I[ZM M4DF[C)'/K];IG&=50NNX[S#XZL4^=3JO"9<35D,TH$^[![#K/_C,+#WT" M259AXGWQ;?4/.7F0;(W:BR4#.CF_'MX&%UB9<*)R7GY$B6UY<J\.5?17$]4 M<[D-.JV&B[8'3STMI_2SER'CA@FPF%]?B5_%K29O_B0GC04EGMJB\,2!?/"" M<DH@J&Y.8?M1H_!*]<^(*L\(RRKAP"9L>6+,Z.],7+U3_JEX+AG(O!>98" MQYW+YB,W&U@J'H=_5\FV>V261:M"F:,G4M5CZ9YD"QMTS0&@/^(-6R77$X2" M3[<>OM,_CSD*_'"+=!Q90CL2A-.?$*))LZ=7L>OH#[K>A!UNO+R\ZII[;?= M]O%V"\PF7Q0_S20O2@_;?DAE6H42_-0H(LT&-#%II?1$<:N''.4;T,%<7<%H M9WF;,VN0/B"GT'N_HCA%7R70]Y_8HWNQ&-VR+F.W^A5B&OJS86$C<:TH66[ M3JH)4/^2/>YK=A^CRBPF0XZ#K'0A55PH7+7BAMUC$,08ZY?&;C*_;C[RG;PP M/R@5P+PVWY^_?'W^YHT$NF?3Q6:J!]8XA:F9+6Y6"WXC:VD6#+;>E]A9,L M-$'CFSU*#GAK])@/#V^R,,:S,8\!)+T%-B>U)_E8SCU6B*J\TT2=S6<(AL MPR&*<*NUZ\=;&Y/)ZAUR7HG!@/,&\VS=1</)S[_[=N9EX8GVU1JA,VU,DS5 M3NX$O)Q"[IERYAE:-.LYZT_Y@@4ROOXU1$!2@[#(,KN>)I98I?GJHYPD[M5Z M9!$[Z7+J^\JW*FV78_PMST161ID,JYLP&8)IV;-$MU_^VI;U4DP\L_HEH\=` M=Y4!*:G>0<Y/X[RR8/FR])*%D2)8Q.+!X>#;-$MF^?>S9/&M$=L6P!VM)">- M?5]+/#(A2FD@DW\GGN_6J2.(/0D(8H#J>*6WN1C8:ZSFJMC5E[_^8_@::*'G MK3PHN?$$DM5"5KYK17Y5&XY986VV).?Y\<*X8F'X)6\J/((JY^:!U/CVK39" M9JT7[=6-#08L6FZ2JY=.G\DGCS#4RWF^"7974#TD8);Q?,U66O</KZ?A^$Q M7!6YA$U7"/0W1XDAMC9:&)KL&L*#R-QZP^#CD"#L%R8]PW/:68WN&D%.SL M$CH,&R&D7G!%V87;._K5Z!T609R>A9G-=10#S-/)U9M;L9.;>OSE[)F%@ M6,.\_%CB20>F.-U(4J;&%6#R@CJEU;$L$9QQ#:H]ZD[]%DQ:)&HJKM#B$*> M_8-.1R+Z8B-)Q)3."9+J@"GSG#U##G=!X(_#Q4BZF/A5*VM,>65Y7R1GP,]V MI&$]H4%KVV%3$E0UP5+I?)H.^;]W*.C<+@+,Q^FL$M);=+9IBG?DV4.`$U7 MTK@$H:![S$:B]JY.@6SH:,ZL]3V-&J6N1@W].KR&2:UP6/G)^_+D'YC(H,-W MS>2/];*KR4=49D<B]-*1>H45)''H=/S4X&BE'KK[-X5D%=]KBY0^^GW,7M7* +XOX/]0H@'H9Q````
`
end

Comments?

Andrea Arcangeli

--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#90 lore raw

Re: [patch] NEW: arca-vm-21, swapout via shrink_mmap using PG_dirty

Quoted 5 lines · Andrea Arcangeli

Even if rock solid my PG_dirty implementation is been a lose. This because swapping out from shrink_mmap() was causing not ordered write to disk. So even if the process userspace was ordered in the swap, it was async written not-ordered. This was harming a _lot_ swapout performances...

Indeed.

Note that what I really wanted to use PG_dirty for was not for normal page-outs, but for shared mappings of files.

For normal page-out activity, the PG_dirty thing isn't a win, simply because (a) it doesn't actually buy us anything (we might as well do it from the page tables directly) and (b) as you noticed, it increases fragmentation.

The reason PG_dirty should be a win for shared mappings is: (a) it gets rid of the file write semaphore problem in a very clean way and (b) it reduces the number of IO requests for mappings that are writable for multiple contexts (right now we will actually do multiple page-outs, one for each shared mapping that has dirtied the page).

I know you worked on patches to reduce (b) by walking multiple page tables, but quite frankly that was always so ugly as to never stand a chance in h*ll of ever getting included in a standard kernel.

I looked at the problem, and PG_dirty for shared mappings should be reasonably simple. However, I don't think I can do it for 2.2 simply because it involves some VFS interface changes (it requires that you can use the pame_map[] information and nothing else to page out: we have the inode and the offset which actually is enough data to do it, but we don't have a good enough "inode->i_op->writepage()" setup yet).

Linus

--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#91 lore raw

Re: [patch] NEW: arca-vm-21, swapout via shrink_mmap using PG_dirty

Quoted 2 lines · Linus Torvalds

Note that what I really wanted to use PG_dirty for was not for normal page-outs, but for shared mappings of files.

Ah, Ok ;). I was using it in a completly different manner. I was using it to indicate that the swap cache page was not uptodate on the swap space. But as just said this cause not ordered write to disk from shrink_mmap(). Other than that it _was_ fine.

Quoted 2 lines

The reason PG_dirty should be a win for shared mappings is: (a) it gets rid of the file write semaphore problem in a very clean way and (b) it

I can't understand this. I think to know _where_ to mark the page dirty (in the `if (vm_op->swapout)' path) but I don't understand _where_ to write the page out to disk avoiding the fs deadlock. Writing them in shrink_mmap() would not fix the deadlock (obviously if shrink_mmap() is still recalled as now by try_to_free_pages() etc...).

Quoted 2 lines

I know you worked on patches to reduce (b) by walking multiple page tables, but quite frankly that was always so ugly as to never stand a

OK, agreed ;). I am taking it here in the meantime only because it should be at least safe.

Quoted 6 lines

I looked at the problem, and PG_dirty for shared mappings should be reasonably simple. However, I don't think I can do it for 2.2 simply because it involves some VFS interface changes (it requires that you can use the pame_map[] information and nothing else to page out: we have the inode and the offset which actually is enough data to do it, but we don't have a good enough "inode->i_op->writepage()" setup yet).

I still don't understand from _where_ doing the writepage. If we would do it from shrink_mmap() I can't see how we could clear the pte of the process (or better processes) before starting the writepage(). Probably I am missing something of important (maybe because these nights I had not a lot of time to sleep ;)...

Andrea Arcangeli

--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#92 lore raw

Re: [patch] NEW: arca-vm-21, swapout via shrink_mmap using PG_dirty

Quoted 6 lines · Andrea Arcangeli

I can't understand this. I think to know _where_ to mark the page dirty (in the `if (vm_op->swapout)' path) but I don't understand _where_ to write the page out to disk avoiding the fs deadlock. Writing them in shrink_mmap() would not fix the deadlock (obviously if shrink_mmap() is still recalled as now by try_to_free_pages() etc...).

You'd write them out only from a separate deamon that only needs to scan the physical page map. That separate deamon might actually be kswapd, but that's just an implementation detail rather than a conceptual issue.

Linus

--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#93 lore raw

Re: [patch] NEW: arca-vm-21, swapout via shrink_mmap using PG_dirty

In reply to Linus Torvalds
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"LT" == Linus Torvalds <[email protected]> writes:

LT> Note that what I really wanted to use PG_dirty for was not for normal LT> page-outs, but for shared mappings of files.

LT> For normal page-out activity, the PG_dirty thing isn't a win, simply LT> because (a) it doesn't actually buy us anything (we might as well do it LT> from the page tables directly)

If we combine it with early scanning of the page tables, it should allow us to perform I/O before we need the memory. While not bogging down processes.

LT> and (b) as you noticed, it increases fragmentation.

This is only because he didn't implement any kind of request queue. A fifo queue of pages to write would have keep performance up at current levels.

LT> The reason PG_dirty should be a win for shared mappings is: (a) it gets LT> rid of the file write semaphore problem in a very clean way and

Nope. Because we can still have some try to write to file X. That write needs memory, and we try to swapout a mapping of file X. Unless you believe it implies the write outs then must use a seperate process.

LT> (b) it
LT> reduces the number of IO requests for mappings that are writable for LT> multiple contexts (right now we will actually do multiple page-outs, one LT> for each shared mapping that has dirtied the page).

With a reasonable proximity in time even that isn't necessary because of the buffer cache. This is only a real issue for filesystems that don't implement good write cachine on their own. In which case the primary thing to fix is caching for those filesystems. We can use PG_dirty for that case too, but the emphasis is different.

LT> I looked at the problem, and PG_dirty for shared mappings should be LT> reasonably simple. However, I don't think I can do it for 2.2 simply LT> because it involves some VFS interface changes (it requires that you can LT> use the pame_map[] information and nothing else to page out: we have the LT> inode and the offset which actually is enough data to do it, but we don't LT> have a good enough "inode->i_op->writepage()" setup yet).

At least in part because for NFS you need who is doing the write, which we currently store with a struct file. To get it correct we really need a two level setup. Level 1 per pte to enter in the write request. Level 2 per page to acutally write it out.

If there are conflicts, (not the same user, etc) Level 1 can handle them.

If I have any luck I should have a draft of a complete set of changes to do all of this for 2.3 in about a month. I have been working on this in the backgroud for quite a while.

Eric

--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#94 lore raw

Re: [patch] NEW: arca-vm-21, swapout via shrink_mmap using PG_dirty

Quoted 5 lines · Eric W. Biederman

LT> and (b) as you noticed, it increases fragmentation.

This is only because he didn't implement any kind of request queue. A fifo queue of pages to write would have keep performance up at current levels.

Infact I didn't wanted having to alloc more memory in order to free memory (it's something I like to avoid). But the point is that I think that swapping out from shrink_mmap() even if doing ordered I/O is not a win. Try, benchmark and let me know your results, maybe I am wrong. And with a FIFO also shrink_mmap() would change in order to do what swap_out() is doing right now. And btw I think that the fifo could be approssimated to a browse in the swap cache.

Quoted 6 lines

LT> The reason PG_dirty should be a win for shared mappings is: (a) it gets LT> rid of the file write semaphore problem in a very clean way and

Nope. Because we can still have some try to write to file X. That write needs memory, and we try to swapout a mapping of file X. Unless you believe it implies the write outs then must use a seperate process.

Agreed. I just pointed this out, but maybe I did not understood _where_ we should do the write to disk to reclaim memory.

Andrea Arcangeli

--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#95 lore raw

Re: [patch] NEW: arca-vm-21, swapout via shrink_mmap using PG_dirty

In reply to Andrea Arcangeli
Quoted 4 lines · Andrea Arcangeli

Also you Kelle, could you try my new arca-vm-24 on your 16Mbyte machine? I think that you'll be very happy ;).

Note, arca-vm-24 is tunable:

Ehmmm, ohoh, I did a little mistake in arca-vm-24 that was causing a lockup under heavy swapping ;) (I was still decrementing counter in the grow_freeable() while loop...)

So I diffed a fixed arca-vm-25 that rocks here. It's against pre-8.gz in testing. This new one should be really safe (and pre8 is also fixing also the swapout deadlock making the semaphores recursive). Give me comments if you'll try it. arca-vm-24/25 still seems far better than anything tried before here. I don't think I could do something better than it for 2.2.

ftp://e-mind.com/pub/linux/kernel-patches/2.2.0-pre8testing-arca-VM-25.gz

Andrea Arcangeli

--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#96 lore raw

Re: Results: pre6 vs pre6+zlatko's_patch vs pre5 vs arcavm13

In reply to Linus Torvalds
Quoted 12 lines · Linus Torvalds
Quoted 8 lines · Steve Bergman

The change seems to have hurt it in both cases. What I am seeing on pre6 and it's derivitives is a *lot* of *swapin* activity. Pre5 almost exclusively swaps *out* during the image test, averaging about 1.25MB/sec (spends a lot of time at around 2000k/sec) with very little swapping in. All the pre6 derivitives swap *in* quite heavily during the test. The 'so' number sometimes drops to 0 for seconds at a time. It also looks like pre6 swaps out slightly more overall (~165MB vs 160MB).

Quoted 3 lines

This is interesting - the only thing that changed between pre5 and pre6 (apart from the line that I asked you to revert and that made things worse) was actually the deadlock code. And the only thing _that_ changes,

I just given my explaination of why pre6 is completly unbalanced (even if I have never run pre6 myself, but I just tried doing what pre6 does some time before pre6 was out). I quote myself:

I think there are problems with 2.2.0-pre6 VM (even if I have not tried it yet really). Latest time I tried on previous kernel to use in __get_free_pages() a try_to_free_pages weight > than MAX_SWAP_CLUSTER (aka freepages.high - nr_free_pages) I had bad impact of VM balance under swapping.

The problem is try_to_free_pages() implementation. Using a lower weight as in pre5 we was sure to return to shrink_mmap with more frequency and so getting more balance. Instead now we return to risk to only swapout without make real free memory space.

Your patch will not fix the problem. The problem is try_to_free_pages() implementation.

Andrea Arcangeli

--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#97 lore raw

Re: Results: pre6 vs pre6+zlatko's_patch vs pre5 vs arcavm13

In reply to Steve Bergman
Quoted 1 line · Steve Bergman

'Image test' in 128MB:

Steve, could you try the image test in 128Mbyte with this my new patch (arca-vm-14) applyed against clean 2.2.0-pre6?

Index: linux/mm/vmscan.c

mm/vmscan.c renamed from mm/vmscan.c:1.1.1.11 +75 -31
diff -u linux/mm/vmscan.c:1.1.1.11 linux/mm/vmscan.c:1.1.1.1.2.83
@@ -10,6 +10,11 @@
  *  Version: $Id: vmscan.c,v 1.5 1998/02/23 22:14:28 sct Exp $
  */
 
+/*
+ * free_user_and_cache() and always async swapout original idea.
+ * Copyright (C) 1999  Andrea Arcangeli
+ */
+
 #include <linux/slab.h>
 #include <linux/kernel_stat.h>
 #include <linux/swap.h>
@@ -20,6 +25,8 @@
 
 #include <asm/pgtable.h>
 
+int swapout_interval = HZ;
+
 /*
  * The swap-out functions return 1 if they successfully
  * threw something out, and we got a free page. It returns
@@ -199,11 +206,11 @@
 
 	do {
 		int result;
-		tsk->swap_address = address + PAGE_SIZE;
 		result = try_to_swap_out(tsk, vma, address, pte, gfp_mask);
+		address += PAGE_SIZE;
+		tsk->swap_address = address;
 		if (result)
 			return result;
-		address += PAGE_SIZE;
 		pte++;
 	} while (address < end);
 	return 0;
@@ -306,7 +313,8 @@
 static int swap_out(unsigned int priority, int gfp_mask)
 {
 	struct task_struct * p, * pbest;
-	int counter, assign, max_cnt;
+	int counter, assign;
+	unsigned long max_cnt;
 
 	/* 
 	 * We make one or two passes through the task list, indexed by 
@@ -325,7 +333,7 @@
 	counter = nr_tasks / (priority+1);
 	if (counter < 1)
 		counter = 1;
-	if (counter > nr_tasks)
+	else if (counter > nr_tasks)
 		counter = nr_tasks;
 
 	for (; counter >= 0; counter--) {
@@ -338,7 +346,7 @@
 		for (; p != &init_task; p = p->next_task) {
 			if (!p->swappable)
 				continue;
-	 		if (p->mm->rss <= 0)
+	 		if (p->mm->rss == 0)
 				continue;
 			/* Refresh swap_cnt? */
 			if (assign)
@@ -430,7 +438,7 @@
 			break;
 		current->state = TASK_INTERRUPTIBLE;
 		run_task_queue(&tq_disk);
-		schedule_timeout(HZ);
+		schedule_timeout(swapout_interval);
 
 		/*
 		 * kswapd isn't even meant to keep up with anything,
@@ -438,13 +446,50 @@
 		 * point is to make sure that the system doesn't stay
 		 * forever in a really bad memory squeeze.
 		 */
-		if (nr_free_pages < freepages.high)
-			try_to_free_pages(0, 16);
+		if (nr_free_pages < freepages.min)
+			try_to_free_pages(0, freepages.high - nr_free_pages);
 	}
 
 	return 0;
 }
 
+static int free_user_and_cache(int priority, int gfp_mask)
+{
+	static unsigned long grow_swap_cache = 0;
+
+	if (nr_free_pages < freepages.min)
+		grow_swap_cache = 0;
+
+	switch (grow_swap_cache)
+	{
+	case 0:
+		if (shrink_mmap(priority, gfp_mask))
+			goto success;
+		if (swap_out(priority, gfp_mask))
+		{
+			grow_swap_cache = 1;
+			goto success;
+		}
+		goto failed;
+	default:
+		if (swap_out(priority, gfp_mask))
+		{
+			shrink_mmap(priority, gfp_mask);
+			if (++grow_swap_cache == SWAP_CLUSTER_MAX)
+				grow_swap_cache = 0;
+			goto success;
+		}
+		grow_swap_cache = 0;
+		if (shrink_mmap(priority, gfp_mask))
+			goto success;
+		goto failed;
+	}
+ failed:
+	return 0;
+ success:
+	return 1;
+}
+
 /*
  * We need to make the locks finer granularity, but right
  * now we need this so that we can do page allocations
@@ -457,33 +502,32 @@
 int try_to_free_pages(unsigned int gfp_mask, int count)
 {
 	int priority;
+	static int state = 0;
 
 	lock_kernel();
-
-	/* Always trim SLAB caches when memory gets low. */
-	kmem_cache_reap(gfp_mask);
-
-	priority = 6;
-	do {
-		while (shrink_mmap(priority, gfp_mask)) {
-			if (!--count)
-				goto done;
-		}
 
-		/* Try to get rid of some shared memory pages.. */
-		while (shm_swap(priority, gfp_mask)) {
-			if (!--count)
-				goto done;
-		}
-	
-		/* Then, try to page stuff out.. */
-		while (swap_out(priority, gfp_mask)) {
-			if (!--count)
-				goto done;
-		}
+	priority = 8;
+	switch (state)
+	{
+		do {
+		case 0:
+			while (free_user_and_cache(priority, gfp_mask)) {
+				if (!--count)
+					goto done;
+			}
+			state = 1;
+		case 1:
+			/* Try to get rid of some shared memory pages.. */
+			while (shm_swap(priority, gfp_mask)) {
+				if (!--count)
+					goto done;
+			}
+			state = 0;
 
-		shrink_dcache_memory(priority, gfp_mask);
-	} while (--priority >= 0);
+			kmem_cache_reap(gfp_mask);
+			shrink_dcache_memory(priority, gfp_mask);
+		} while (--priority >= 0);
+	}
 done:
 	unlock_kernel();
 

Andrea Arcangeli

--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#98 lore raw

Re: Results: pre6 vs pre6+zlatko's_patch vs pre5 vs arcavm13

Quoted 3 lines · Andrea Arcangeli

Steve, could you try the image test in 128Mbyte with this my new patch (arca-vm-14) applyed against clean 2.2.0-pre6?

Please don't do this.

mm/vmscan.c line 211

Quoted 6 lines
mm/vmscan.c renamed from mm/vmscan.c:1.1.1.11 +2 -1
 	do {
 		int result;
-		tsk->swap_address = address + PAGE_SIZE;
 		result = try_to_swap_out(tsk, vma, address, pte, gfp_mask);
+		address += PAGE_SIZE;
+		tsk->swap_address = address;

The above is horribly broken, and should be killed on sight.

"swap_address" _must_ be set before try_to_swap_out(), because otherwise when try-to_swap_out() sleeps any other processes trying to free will start from the wrong address - unfairly penalizing the process in question, as the accessed bits have been cleared.

If the above help, it only does so because it is unfair - which _can_ help simply because other processes run faster.

It looks like you tried to optimize away one add, at the expense of getting the whole algorithm wrong.

Linus

--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#99 lore raw

Re: Results: pre6 vs pre6+zlatko's_patch vs pre5 vs arcavm13

Quoted 1 line · Linus Torvalds

The above is horribly broken, and should be killed on sight.

Woops thanks and excuse me. I did not thought at the sleep case...

Here it is arca-vm-15 with at least this bug removed... excuse me again...

Index: linux/mm/vmscan.c

mm/vmscan.c renamed from mm/vmscan.c:1.1.1.11 +73 -29
diff -u linux/mm/vmscan.c:1.1.1.11 linux/mm/vmscan.c:1.1.1.1.2.83
@@ -10,6 +10,11 @@
  *  Version: $Id: vmscan.c,v 1.5 1998/02/23 22:14:28 sct Exp $
  */
 
+/*
+ * free_user_and_cache() and always async swapout original idea.
+ * Copyright (C) 1999  Andrea Arcangeli
+ */
+
 #include <linux/slab.h>
 #include <linux/kernel_stat.h>
 #include <linux/swap.h>
@@ -20,6 +25,8 @@
 
 #include <asm/pgtable.h>
 
+int swapout_interval = HZ;
+
 /*
  * The swap-out functions return 1 if they successfully
  * threw something out, and we got a free page. It returns
@@ -306,7 +313,8 @@
 static int swap_out(unsigned int priority, int gfp_mask)
 {
 	struct task_struct * p, * pbest;
-	int counter, assign, max_cnt;
+	int counter, assign;
+	unsigned long max_cnt;
 
 	/* 
 	 * We make one or two passes through the task list, indexed by 
@@ -325,7 +333,7 @@
 	counter = nr_tasks / (priority+1);
 	if (counter < 1)
 		counter = 1;
-	if (counter > nr_tasks)
+	else if (counter > nr_tasks)
 		counter = nr_tasks;
 
 	for (; counter >= 0; counter--) {
@@ -338,7 +346,7 @@
 		for (; p != &init_task; p = p->next_task) {
 			if (!p->swappable)
 				continue;
-	 		if (p->mm->rss <= 0)
+	 		if (p->mm->rss == 0)
 				continue;
 			/* Refresh swap_cnt? */
 			if (assign)
@@ -430,7 +438,7 @@
 			break;
 		current->state = TASK_INTERRUPTIBLE;
 		run_task_queue(&tq_disk);
-		schedule_timeout(HZ);
+		schedule_timeout(swapout_interval);
 
 		/*
 		 * kswapd isn't even meant to keep up with anything,
@@ -438,13 +446,50 @@
 		 * point is to make sure that the system doesn't stay
 		 * forever in a really bad memory squeeze.
 		 */
-		if (nr_free_pages < freepages.high)
-			try_to_free_pages(0, 16);
+		if (nr_free_pages < freepages.min)
+			try_to_free_pages(0, freepages.high - nr_free_pages);
 	}
 
 	return 0;
 }
 
+static int free_user_and_cache(int priority, int gfp_mask)
+{
+	static unsigned long grow_swap_cache = 0;
+
+	if (nr_free_pages < freepages.min)
+		grow_swap_cache = 0;
+
+	switch (grow_swap_cache)
+	{
+	case 0:
+		if (shrink_mmap(priority, gfp_mask))
+			goto success;
+		if (swap_out(priority, gfp_mask))
+		{
+			grow_swap_cache = 1;
+			goto success;
+		}
+		goto failed;
+	default:
+		if (swap_out(priority, gfp_mask))
+		{
+			shrink_mmap(priority, gfp_mask);
+			if (++grow_swap_cache == SWAP_CLUSTER_MAX)
+				grow_swap_cache = 0;
+			goto success;
+		}
+		grow_swap_cache = 0;
+		if (shrink_mmap(priority, gfp_mask))
+			goto success;
+		goto failed;
+	}
+ failed:
+	return 0;
+ success:
+	return 1;
+}
+
 /*
  * We need to make the locks finer granularity, but right
  * now we need this so that we can do page allocations
@@ -457,33 +502,32 @@
 int try_to_free_pages(unsigned int gfp_mask, int count)
 {
 	int priority;
+	static int state = 0;
 
 	lock_kernel();
-
-	/* Always trim SLAB caches when memory gets low. */
-	kmem_cache_reap(gfp_mask);
-
-	priority = 6;
-	do {
-		while (shrink_mmap(priority, gfp_mask)) {
-			if (!--count)
-				goto done;
-		}
 
-		/* Try to get rid of some shared memory pages.. */
-		while (shm_swap(priority, gfp_mask)) {
-			if (!--count)
-				goto done;
-		}
-	
-		/* Then, try to page stuff out.. */
-		while (swap_out(priority, gfp_mask)) {
-			if (!--count)
-				goto done;
-		}
+	priority = 8;
+	switch (state)
+	{
+		do {
+		case 0:
+			while (free_user_and_cache(priority, gfp_mask)) {
+				if (!--count)
+					goto done;
+			}
+			state = 1;
+		case 1:
+			/* Try to get rid of some shared memory pages.. */
+			while (shm_swap(priority, gfp_mask)) {
+				if (!--count)
+					goto done;
+			}
+			state = 0;
 
-		shrink_dcache_memory(priority, gfp_mask);
-	} while (--priority >= 0);
+			kmem_cache_reap(gfp_mask);
+			shrink_dcache_memory(priority, gfp_mask);
+		} while (--priority >= 0);
+	}
 done:
 	unlock_kernel();
 

I think you could try it now...

Andrea Arcangeli

--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#100 lore raw

Re: Results: pre6 vs pre6+zlatko's_patch vs pre5 vs arcavm13

Quoted 3 lines · Andrea Arcangeli

Here it is arca-vm-15 with at least this bug removed...

In the image test, it looks very good:

arcavm15 1:59
pre6 2:27

The best run for arcavm15 was 1:53 which which is a record for any kernel that I've tried so far.

I'll try the low memory compile and see how it looks.

-Steve
--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#101 lore raw

Results: arcavm15, et. al.

For the image load test:

pre6+zlatko's_patch             2:35
and with requested change       3:09
pre6                            2:27
pre5                            1:58
arcavm13                        9:13

arcavm15 1:59

For the kernel compile test:

In 12MB:

                                Elapsed Maj.    Min.    Swaps
                                -----   ------  ------  -----
pre6+zlatko_patch               22:14   383206  204482  57823
and with requested change       22:23   378662  198194  51445
pre6                            20:54   352934  191210  48678
pre5                            19:35   334680  183732  93427 
arcavm13                        19:45   344452  180243  38977

arcavm15 20:07 N/A N/A N/A

Arcavm15 looks very good. pre5 and arcavm13 look a bit better but of the kernels with the anti-deadlock code it looks the best so far. ( I assume that being based upon pre6 it's safe.)
The battery in my palmtop died so I don't have the page fault and swaps results available for arcavm15. I'll grab the pre-7.gz patch and see how it does.

-Steve
--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#102 lore raw

Re: Results: arcavm15, et. al.

Here are the results of pre-7:

116 Image test in 128MB:

pre6+zlatko's_patch             2:35
and with requested change       3:09
pre6                            2:27
pre5                            1:58
arcavm13                        9:13
arcavm15                        1:59

pre-7 2:41

For the kernel compile test in 12MB:

                                Elapsed Maj.    Min.    Swaps
                                -----   ------  ------  -----
pre6+zlatko_patch               22:14   383206  204482  57823
and with requested change       22:23   378662  198194  51445
pre6                            20:54   352934  191210  48678
pre5                            19:35   334680  183732  93427
arcavm13                        19:45   344452  180243  38977
arcavm15                        20:07   N/A     N/A     N/A

pre-7 21:14 356386 192835 50912

-Steve
--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#103 lore raw

Re: Results: arcavm15, et. al.

In reply to Steve Bergman
Quoted 4 lines · Steve Bergman

For the image load test:

pre6+zlatko's_patch 2:35
arcavm15 1:59

Steve, could you give a try to this new arca-vm-16?

arca-vm-16 is still against 2.2.0-pre6 because last night I can't find pre7 on the ftp site.

Index: linux/mm/vmscan.c

mm/vmscan.c renamed from mm/vmscan.c:1.1.1.11 +58 -28
diff -u linux/mm/vmscan.c:1.1.1.11 linux/mm/vmscan.c:1.1.1.1.2.86
@@ -10,6 +10,11 @@
  *  Version: $Id: vmscan.c,v 1.5 1998/02/23 22:14:28 sct Exp $
  */
 
+/*
+ * free_user_and_cache() and always async swapout original idea.
+ * Copyright (C) 1999  Andrea Arcangeli
+ */
+
 #include <linux/slab.h>
 #include <linux/kernel_stat.h>
 #include <linux/swap.h>
@@ -20,6 +25,8 @@
 
 #include <asm/pgtable.h>
 
+int swapout_interval = HZ;
+
 /*
  * The swap-out functions return 1 if they successfully
  * threw something out, and we got a free page. It returns
@@ -306,7 +313,8 @@
 static int swap_out(unsigned int priority, int gfp_mask)
 {
 	struct task_struct * p, * pbest;
-	int counter, assign, max_cnt;
+	int counter, assign;
+	unsigned long max_cnt;
 
 	/* 
 	 * We make one or two passes through the task list, indexed by 
@@ -325,7 +333,7 @@
 	counter = nr_tasks / (priority+1);
 	if (counter < 1)
 		counter = 1;
-	if (counter > nr_tasks)
+	else if (counter > nr_tasks)
 		counter = nr_tasks;
 
 	for (; counter >= 0; counter--) {
@@ -338,7 +346,7 @@
 		for (; p != &init_task; p = p->next_task) {
 			if (!p->swappable)
 				continue;
-	 		if (p->mm->rss <= 0)
+	 		if (p->mm->rss == 0)
 				continue;
 			/* Refresh swap_cnt? */
 			if (assign)
@@ -430,7 +438,7 @@
 			break;
 		current->state = TASK_INTERRUPTIBLE;
 		run_task_queue(&tq_disk);
-		schedule_timeout(HZ);
+		schedule_timeout(swapout_interval);
 
 		/*
 		 * kswapd isn't even meant to keep up with anything,
@@ -438,13 +446,36 @@
 		 * point is to make sure that the system doesn't stay
 		 * forever in a really bad memory squeeze.
 		 */
-		if (nr_free_pages < freepages.high)
-			try_to_free_pages(0, 16);
+		if (nr_free_pages < freepages.min)
+			try_to_free_pages(0, freepages.high - nr_free_pages);
 	}
 
 	return 0;
 }
 
+static int free_user_and_cache(int priority, int gfp_mask)
+{
+	static unsigned long grow_swap_cache = 0;
+
+	if (!shrink_mmap(priority, gfp_mask))
+		grow_swap_cache = 1;
+
+	switch (grow_swap_cache)
+	{
+	case 0:
+		return 1;
+	default:
+		if (grow_swap_cache++ >= freepages.high)
+			grow_swap_cache = 0;
+	}
+
+	if (swap_out(priority, gfp_mask))
+		return 1;
+
+	grow_swap_cache = 0;
+	return 0;
+}
+
 /*
  * We need to make the locks finer granularity, but right
  * now we need this so that we can do page allocations
@@ -457,33 +488,32 @@
 int try_to_free_pages(unsigned int gfp_mask, int count)
 {
 	int priority;
+	static int state = 0;
 
 	lock_kernel();
 
-	/* Always trim SLAB caches when memory gets low. */
-	kmem_cache_reap(gfp_mask);
-
 	priority = 6;
-	do {
-		while (shrink_mmap(priority, gfp_mask)) {
-			if (!--count)
-				goto done;
-		}
-
-		/* Try to get rid of some shared memory pages.. */
-		while (shm_swap(priority, gfp_mask)) {
-			if (!--count)
-				goto done;
-		}
-	
-		/* Then, try to page stuff out.. */
-		while (swap_out(priority, gfp_mask)) {
-			if (!--count)
-				goto done;
-		}
+	switch (state)
+	{
+		do {
+		case 0:
+			while (free_user_and_cache(priority, gfp_mask)) {
+				if (!--count)
+					goto done;
+			}
+			state = 1;
+		case 1:
+			/* Try to get rid of some shared memory pages.. */
+			while (shm_swap(priority, gfp_mask)) {
+				if (!--count)
+					goto done;
+			}
+			state = 0;
 
-		shrink_dcache_memory(priority, gfp_mask);
-	} while (--priority >= 0);
+			kmem_cache_reap(gfp_mask);
+			shrink_dcache_memory(priority, gfp_mask);
+		} while (--priority >= 0);
+	}
 done:
 	unlock_kernel();
 

Andrea Arcangeli

--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#104 lore raw

Re: Results: pre6 vs pre6+zlatko's_patch vs pre5 vs arcavm13

In reply to Steve Bergman
Quoted 6 lines · Steve Bergman

pre6+zlatko_patch 5:29 192527 149728 3554
pre6 5:27 192002 149694 4257
pre5 5:28 188566 148674 5646
arcavm13 5:32 188560 148234 1594

From what I've seen, arcavm and the zlatko_patch do differnt things. Would

it be possible to do arcavm+zlatko? or am I wrong?

--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#105 lore raw

Re: arca-vm-8 [Re: [patch] arca-vm-6, killed kswapd [Re: [patch] new-vm , improvement , [Re: 2.2.0 Bug summary]]]

In reply to Andrea Arcangeli

Oh, well.. Based on what the arca-[678] patches did, there's now a pre-5 out there. Not very similar, but it should incorporate the basic idea:
namely much more aggressively asynchronous swap-outs from a process context.

Comment away,

Linus

--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#106 lore raw

Re: arca-vm-8 [Re: [patch] arca-vm-6, killed kswapd [Re: [patch] new-vm , improvement , [Re: 2.2.0 Bug summary]]]

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"LT" == Linus Torvalds <[email protected]> writes:

LT> Oh, well.. Based on what the arca-[678] patches did, there's now a pre-5 LT> out there. Not very similar, but it should incorporate the basic idea:
LT> namely much more aggressively asynchronous swap-outs from a process LT> context.

LT> Comment away,

1) With your comments on PG_dirty/(what shrink_mmap should do) you have worked out what needs to happen for the mapped in memory case, and I haven't quite gotten there. Thank You.

2) I have tested using PG_dirty from shrink_mmap and it is a performance problem because it loses all locality of reference, and because it forces shrink_mmap into a dual role, of freeing and writing pages, which need seperate tuning.

Linus is this a case you feel is important to tune for 2.2? If so I would be happy to play with it.

Eric
--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#107 lore raw

Re: arca-vm-8 [Re: [patch] arca-vm-6, killed kswapd [Re: [patch] new-vm , improvement , [Re: 2.2.0 Bug summary]]]

Quoted 4 lines · Eric W. Biederman

1) With your comments on PG_dirty/(what shrink_mmap should do) you have worked out what needs to happen for the mapped in memory case, and I haven't quite gotten there. Thank You.

Note that it is not finalized. That's why I didn't write the code (which should be fairly simple), because it has some fairly subtle issues and thus becomes a 2.3.x thing, I very much suspect.

Basically, my rule of thumb for the changes I did was: "it should have the same code paths as the old code". What that means is that I didn't actually do any changes that changed real code: I did only changes that changed _behaviour_.

That way I can be reasonably hopeful that there are no new bugs introduced even though performance is very different. I _do_ have some early data that seems to say that this _has_ uncovered a very old deadlock condition:
something that could happen before but was almost impossible to trigger.

The deadlock I suspect is:
- we're low on memory
- we allocate or look up a new block on the filesystem. This involves getting the ext2 superblock lock, and doing a "bread()" of the free block bitmap block.
- this causes us to try to allocate a new buffer, and we are so low on memory that we go into try_to_free_pages() to find some more memory.
- try_to_free_pages() finds a shared memory file to page out.
- trying to page that out, it looks up the buffers on the filesystem it needs, but deadlocks on the superblock lock.

Note that this could happen before too (I've not removed any of the codepaths that could lead to it), but it was dynamically _much_ less likely to happen.

I'm not even sure it really exists, but I have some really old reports that _could_ be due to this, and a few more recent ones (that I never could explain). And I have a few _really_ recent ones from here internally at transmeta that looks like it's triggering more easily these days.

(Note that this is not actually pre5-related: I've been chasing this on and off for some time, and it seems to have just gotten easier to trigger, which is why I finally have a theory on what is going on - just a theory though, and I may be completely off the mark).

The positive news is that if I'm right in my suspicions it can only happen with shared writable mappings or shared memory segments. The bad news is that the bug appears rather old, and no immediate solution presents itself.

Quoted 4 lines

2) I have tested using PG_dirty from shrink_mmap and it is a performance problem because it loses all locality of reference, and because it forces shrink_mmap into a dual role, of freeing and writing pages, which need seperate tuning.

Exactly. This is part of the complexity.

The right solution (I _think_) is to conceptually always mark it PG_dirty in vmscan, and basically leave all the nasty cases to the filemap physical page scan. But in the simple cases (ie a swap-cached page that is only mapped by one process and doesn't have any other users), you'd start the IO "early".

That would essentially mean that normal single mappings get the good locality, while the case we really suck at right now (multiple mappings which can all dirty the page) would not cause excessive page-outs.

Basically, I think that the stuff we handle now with the swap-cache we do well on already, and we'd only really want to handle the shared memory case with PG_dirty. But I think this is a 2.3 issue, and I only added the comment (and the PG_dirty define) for now.

Quoted 2 lines

Linus is this a case you feel is important to tune for 2.2? If so I would be happy to play with it.

It might be something good to test out, but I really don't want patches at this date (unless your patches also fix the above deadlock problem, which I can't see them doing ;)

Linus

--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#108 lore raw

Re: arca-vm-8 [Re: [patch] arca-vm-6, killed kswapd [Re: [patch] new-vm , improvement , [Re: 2.2.0 Bug summary]]]

Quoted 9 lines · Linus Torvalds
Quoted 4 lines · Eric W. Biederman

2) I have tested using PG_dirty from shrink_mmap and it is a performance problem because it loses all locality of reference, and because it forces shrink_mmap into a dual role, of freeing and writing pages, which need seperate tuning.

Exactly. This is part of the complexity.

It can be solved by having a 'laundry' list like the *BSD folks have and maybe a special worker thread to take care of the laundry (optimizing placement on disk, etc).

Quoted 9 lines

The right solution (I _think_) is to conceptually always mark it PG_dirty in vmscan, and basically leave all the nasty cases to the filemap physical page scan. But in the simple cases (ie a swap-cached page that is only mapped by one process and doesn't have any other users), you'd start the IO "early".

That would essentially mean that normal single mappings get the good locality, while the case we really suck at right now (multiple mappings which can all dirty the page) would not cause excessive page-outs.

We can already do that by simply not writing the page to disk if there are other users besides us (keeping in mind the swap cache and other system things).

One problem might be that we could end up with more on-disk fragmentation that way (and maybe less clusterable I/O).

Quoted 5 lines

Basically, I think that the stuff we handle now with the swap-cache we do well on already, and we'd only really want to handle the shared memory case with PG_dirty. But I think this is a 2.3 issue, and I only added the comment (and the PG_dirty define) for now.

It's quite definately 2.3. It's just a minor performance issue for most systems (an extra write is an order of magnitude cheaper than an extra read where a process is actually waiting).

Rik -- If a Microsoft product fails, who do you sue?

+-------------------------------------------------------------------+
| Linux memory management tour guide.        [email protected] |
| Scouting Vries cubscout leader.    http://humbolt.geo.uu.nl/~riel |
+-------------------------------------------------------------------+

--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#109 lore raw

Re: arca-vm-8 [Re: [patch] arca-vm-6, killed kswapd [Re: [patch]

Quoted 3 lines

It can be solved by having a 'laundry' list like the *BSD folks have and maybe a special worker thread to take care of the laundry (optimizing placement on disk, etc).

We actually have one - on the sparc anyway there is asyncd

Alan

--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#110 lore raw

Re: arca-vm-8 [Re: [patch] arca-vm-6, killed kswapd [Re: [patch] new-vm , improvement , [Re: 2.2.0 Bug summary]]]

In reply to Linus Torvalds

Linus Torvalds <[email protected]> writes:

[snip]

Quoted 17 lines

That way I can be reasonably hopeful that there are no new bugs introduced even though performance is very different. I _do_ have some early data that seems to say that this _has_ uncovered a very old deadlock condition:
something that could happen before but was almost impossible to trigger.

The deadlock I suspect is:
- we're low on memory
- we allocate or look up a new block on the filesystem. This involves getting the ext2 superblock lock, and doing a "bread()" of the free block bitmap block.
- this causes us to try to allocate a new buffer, and we are so low on memory that we go into try_to_free_pages() to find some more memory.
- try_to_free_pages() finds a shared memory file to page out.
- trying to page that out, it looks up the buffers on the filesystem it needs, but deadlocks on the superblock lock.

Quoted 3 lines

Note that this could happen before too (I've not removed any of the codepaths that could lead to it), but it was dynamically _much_ less likely to happen.

You could be very easily right. Look below.

Quoted 11 lines

I'm not even sure it really exists, but I have some really old reports that _could_ be due to this, and a few more recent ones (that I never could explain). And I have a few _really_ recent ones from here internally at transmeta that looks like it's triggering more easily these days.

(Note that this is not actually pre5-related: I've been chasing this on and off for some time, and it seems to have just gotten easier to trigger, which is why I finally have a theory on what is going on - just a theory though, and I may be completely off the mark).

Quoted 4 lines

The positive news is that if I'm right in my suspicions it can only happen with shared writable mappings or shared memory segments. The bad news is that the bug appears rather old, and no immediate solution presents itself.

Exactly. I was torture testing shared mapping when I got very weird deadlock. It happened only once, few days ago. Look at report and enjoy:

Jan  5 03:49:14 atlas kernel: SysRq: Show Memory 
Jan  5 03:49:14 atlas kernel: Mem-info: 
Jan  5 03:49:14 atlas kernel: Free pages:         512kB 
Jan  5 03:49:14 atlas kernel:  ( Free: 128 (128 256 384) 
Jan  5 03:49:14 atlas kernel: 0*4kB 0*8kB 0*16kB 0*32kB 0*64kB 4*128kB = 512kB) 
Jan  5 03:49:14 atlas kernel: Swap cache: add 131125/131125, delete 130652/13065
2, find 0/0 
Jan  5 03:49:14 atlas kernel: Free swap:       231632kB 
Jan  5 03:49:14 atlas kernel: 16384 pages of RAM 
Jan  5 03:49:14 atlas kernel: 956 reserved pages 
Jan  5 03:49:14 atlas kernel: 17996 pages shared 
Jan  5 03:49:14 atlas kernel: 473 pages swap cached 
Jan  5 03:49:14 atlas kernel: 13 pages in page table cache 
Jan  5 03:49:14 atlas kernel: Buffer memory:    14696kB 
Jan  5 03:49:14 atlas kernel: Buffer heads:     14732 
Jan  5 03:49:14 atlas kernel: Buffer blocks:    14696 
Jan  5 03:49:14 atlas kernel:    CLEAN: 144 buffers, 18 used (last=122), 0 locke

d, 0 protected, 0 dirty

This looks exactly like the problem you were describing, isn't it?

[snip]

Quoted 4 lines

Basically, I think that the stuff we handle now with the swap-cache we do well on already, and we'd only really want to handle the shared memory case with PG_dirty. But I think this is a 2.3 issue, and I only added the comment (and the PG_dirty define) for now.

Nice, thanks. That will make experimenting slightly easier and will give courage to people to actually experiment with PG_Dirty implementation. So far, only Eric did some work in this area.

Of course, this is all 2.3 work.

Quoted 8 lines
Quoted 3 lines

Linus is this a case you feel is important to tune for 2.2? If so I would be happy to play with it.

It might be something good to test out, but I really don't want patches at this date (unless your patches also fix the above deadlock problem, which I can't see them doing ;)

Sure!

Signature · 4 lines
Zlatko
--
This is a majordomo managed list.  To unsubscribe, send a message with
the body 'unsubscribe linux-mm me@address' to: [email protected]
#111 lore raw

Re: arca-vm-8 [Re: [patch] arca-vm-6, killed kswapd [Re: [patch] new-vm , improvement , [Re: 2.2.0 Bug summary]]]

In reply to Linus Torvalds
Quoted 11 lines · Linus Torvalds

The deadlock I suspect is:
- we're low on memory
- we allocate or look up a new block on the filesystem. This involves getting the ext2 superblock lock, and doing a "bread()" of the free block bitmap block.
- this causes us to try to allocate a new buffer, and we are so low on memory that we go into try_to_free_pages() to find some more memory.
- try_to_free_pages() finds a shared memory file to page out.
- trying to page that out, it looks up the buffers on the filesystem it needs, but deadlocks on the superblock lock.

Confirmed. Hpa was good enough to reproduce this, and my debugging code caught the (fairly deep) deadlock:

	system_call ->
	sys_write ->
	ext2_file_write ->
	ext2_getblk ->
	ext2_alloc_block ->	** gets superblock lock **
	ext2_new_block ->
	getblk ->
	refill_freelist ->
	grow_buffers ->
	__get_free_pages ->
	try_to_free_pages ->
	swap_out ->
	swap_out_process ->
	swap_out_vma ->
	try_to_swap_out ->
	filemap_swapout ->
	filemap_write_page ->
	ext2_file_write ->
	ext2_getblk ->
	ext2_alloc_block ->
	__wait_on_super		** BOOM - we want the superblock lock again **

and I suspect the fix is fairly simple: I'll just add back the __GFP_IO bit (we kind of used to have one that did something similar) which will make the swap-out code not write out shared pages when it allocates buffers.

The better fix would actually be to make sure that filesystems do not hold locks around these kinds of blocking operations, but that is harder to do at this late stage.

Linus

--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#112 lore raw

Re: arca-vm-8 [Re: [patch] arca-vm-6, killed kswapd [Re: [patch] new-vm , improvement , [Re: 2.2.0 Bug summary]]]

Quoted 5 lines · Linus Torvalds

and I suspect the fix is fairly simple: I'll just add back the __GFP_IO bit (we kind of used to have one that did something similar) which will make the swap-out code not write out shared pages when it allocates buffers.

Ok, here it is.. Stable.

Linus

-----

include/linux/mm.h renamed from linux/include/linux/mm.h +4 -3
diff -u --recursive --new-file v2.2.0-pre5/linux/include/linux/mm.h linux/include/linux/mm.h
@@ -315,14 +323,15 @@
 #define __GFP_LOW	0x02
 #define __GFP_MED	0x04
 #define __GFP_HIGH	0x08
+#define __GFP_IO	0x10
 
 #define __GFP_DMA	0x80
 
 #define GFP_BUFFER	(__GFP_LOW | __GFP_WAIT)
 #define GFP_ATOMIC	(__GFP_HIGH)
-#define GFP_USER	(__GFP_LOW | __GFP_WAIT)
-#define GFP_KERNEL	(__GFP_MED | __GFP_WAIT)
-#define GFP_NFS		(__GFP_HIGH | __GFP_WAIT)
+#define GFP_USER	(__GFP_LOW | __GFP_WAIT | __GFP_IO)
+#define GFP_KERNEL	(__GFP_MED | __GFP_WAIT | __GFP_IO)
+#define GFP_NFS		(__GFP_HIGH | __GFP_WAIT | __GFP_IO)
 
 /* Flag - indicates that the buffer will be suitable for DMA.  Ignored on some
    platforms, used as appropriate on others */
mm/vmscan.c renamed from linux/mm/vmscan.c +8 -1
diff -u --recursive --new-file v2.2.0-pre5/linux/mm/vmscan.c linux/mm/vmscan.c
@@ -76,7 +76,6 @@
 		set_pte(page_table, __pte(entry));
 drop_pte:
 		vma->vm_mm->rss--;
-		tsk->nswap++;
 		flush_tlb_page(vma, address);
 		__free_page(page_map);
 		return 0;
@@ -99,6 +98,14 @@
 		pte_clear(page_table);
 		goto drop_pte;
 	}
+
+	/*
+	 * Don't go down into the swap-out stuff if
+	 * we cannot do I/O! Avoid recursing on FS
+	 * locks etc.
+	 */
+	if (!(gfp_mask & __GFP_IO))
+		return 0;
 
 	/*
 	 * Ok, it's really dirty. That means that

--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#113 lore raw

Re: arca-vm-8 [Re: [patch] arca-vm-6, killed kswapd [Re: [patch] new-vm , improvement , [Re: 2.2.0 Bug summary]]]

Quoted 1 line · Linus Torvalds

Ok, here it is.. Stable.

Yesterday after your email I tried and I been able to reproduce the deadlock here too. It's trivial, simply alloc a shared mapping of 160Mbyte and start dirtifying it and msync it in loop. So I applyed your patch and the machine still deadlocked after some second. I thought "argg update_shared_mappings is faulting noooooo"!! So I removed updated_shared_mappings() and I tried again and it still deadlocked... I thought "oh, cool, I still have something to fix ;)".

So I developed this debugging code (that I post here because I guess it could be useful also to many others) to know which was the still pending bug:

Index: sched.c
===================================================================
RCS file: /var/cvs/linux/kernel/sched.c,v
retrieving revision 1.1.1.1.2.37

sched.c +19 -0
diff -u -r1.1.1.1.2.37 sched.c
@@ -22,6 +22,10 @@
  * current-task
  */
 
+/*
+ * Debug down() code. Copyright (C) 1999  Andrea Arcangeli
+ */
+
 #include <linux/mm.h>
 #include <linux/kernel_stat.h>
 #include <linux/fdreg.h>
@@ -893,12 +897,27 @@
 	tsk->state = TASK_RUNNING;		\
 	remove_wait_queue(&sem->wait, &wait);
 
+void generate_oops (struct semaphore *sem)
+{
+	sema_init(sem, 9876);
+	wake_up(&sem->wait);
+}
+
 void __down(struct semaphore * sem)
 {
 	DOWN_VAR
+	struct timer_list timer;
+	init_timer (&timer);
+	timer.expires = jiffies + HZ*20;
+	timer.data = (unsigned long) sem;
+	timer.function = (void (*)(unsigned long)) generate_oops;
+	add_timer(&timer);
 	DOWN_HEAD(TASK_UNINTERRUPTIBLE)
 	schedule();
+	if (atomic_read(&sem->count) == 9876)
+		*(int *) 0 = 0;
 	DOWN_TAIL(TASK_UNINTERRUPTIBLE)
+	del_timer(&timer);
 }
 
 int __down_interruptible(struct semaphore * sem)

Then recompiled, rebooted, return to run the deadlocking proggy, deadlocked again after some seconds and after 20 second I had a
nice Oops on the screen. SysRQ-K helped me to restore some functionality in another console. Then I run dmesg | ksymoops.... and I had this:

Using `/usr/src/linux/System.map' to map addresses to symbols.

Quoted 1 line
Quoted 1 line

EIP: c0111646 <__down+b2/160>

Trace: c0111574 <generate_oops>
Trace: c0189f58 <__down_failed+8/10>
Trace: c010ef1a <do_page_fault+56/340>
Trace: c0108c0d <error_code+2d/40>
Trace: c0111646 <__down+b2/160>
Trace: c0111574 <generate_oops>
Trace: c0189f58 <__down_failed+8/10>
Trace: c011dc59 <filemap_write_page+9d/138>
Trace: c011dd59 <filemap_swapout+65/7c>
Trace: c0121864 <try_to_swap_out+118/1c4>
Trace: c0121a18 <swap_out_vma+108/164>
Trace: c0121ad4 <swap_out_process+60/88>
Trace: c0121bdb <swap_out+df/fc>
Trace: c011cbb7 <shrink_mmap+11b/138>
Trace: c0121d1a <free_user_and_cache+1e/34>
Trace: c0121d76 <try_to_free_pages+46/a4>
Trace: c0122615 <__get_free_pages+d5/220>
Trace: c0126af2 <get_hash_table+52/64>
Trace: c0127bcf <grow_buffers+3b/ec>
Trace: c0126ca8 <refill_freelist+c/34>
Trace: c0126f3a <getblk+202/228>
Trace: c013af6c <ext2_alloc_block+68/13c>
Trace: c013b5c4 <block_getblk+15c/2b0>
Trace: c013b887 <ext2_getblk+16f/20c>
Trace: c0139d2b <ext2_file_write+40b/554>
Trace: c011dcc0 <filemap_write_page+104/138>
Trace: c011e0fe <filemap_sync+256/30c>
Trace: c011e297 <msync_interval+2f/7c>
Trace: c011e3d2 <sys_msync+ee/14c>
Trace: c0108ad4 <system_call+34/40>

Code: c0111646 <__down+b2/160> 
Code: c0111646 <__down+b2/160>  c7 05 00 00 00 	movl   $0x0,0x0
Code: c011164b <__down+b7/160>  00 00 00 00 00 
Code: c0111656 <__down+c2/160>  8b 75 d8       	movl   0xffffffd8(%ebp),%esi
Code: c0111659 <__down+c5/160>  c7 06 02 00 00 	movl   $0x2,(%esi)
Code: c011165f <__down+cb/160>  31 00          	xorl   %eax,(%eax)
Code: c0111667 <__down+d3/160>  90             	nop    
Code: c0111668 <__down+d4/160>  90             	nop    
Code: c0111669 <__down+d5/160>  90             	nop    

So I looked at buffer.c ;)

Index: buffer.c
===================================================================
RCS file: /var/cvs/linux/fs/buffer.c,v
retrieving revision 1.1.1.1.2.8

fs/buffer.c renamed from buffer.c +1 -1
diff -u -r1.1.1.1.2.8 buffer.c
@@ -689,7 +689,7 @@
  */
 static void refill_freelist(int size)
 {
-	if (!grow_buffers(GFP_KERNEL, size)) {
+	if (!grow_buffers(GFP_BUFFER, size)) {
 		wakeup_bdflush(1);
 		current->policy |= SCHED_YIELD;
 		schedule();

and now is really stable ;))

--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#114 lore raw

Re: arca-vm-8 [Re: [patch] arca-vm-6, killed kswapd [Re: [patch] new-vm , improvement , [Re: 2.2.0 Bug summary]]]

Quoted 2 lines · Andrea Arcangeli

So I looked at buffer.c ;)

Ehh, duh. I had it right in my tree, but the _patch_ I sent out only had my mm changes, but not my fs changes.

Embarrassing ;)

Linus

--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#115 lore raw

MM deadlock [was: Re: arca-vm-8...]

In reply to Linus Torvalds

Hi,

I've found an another deadlock.
Two processes were locked trying to grab an inode write semaphore. Their call traces are (in diff format):

Using `map-2.2.0pre5-1' to map addresses to symbols.

Trace: c010f038 <__down+58/90>
Trace: c018d080 <__down_failed+8/c>
Trace: c011abaa <filemap_write_page+a6/15c>
Trace: c011acad <filemap_swapout+4d/60>
Trace: c011e2ae <try_to_swap_out+10a/1ac>
Trace: c011e45a <swap_out_vma+10a/174>
Trace: c011e521 <swap_out_process+5d/8c>
Trace: c011e60b <swap_out+bb/e4>
Trace: c011e75b <try_to_free_pages+4b/70>
Trace: c011ef61 <__get_free_pages+b5/1dc>
-Trace: c0119cd7 <try_to_read_ahead+2f/124>
-Trace: c011a970 <filemap_nopage+170/304>
-Trace: c0118888 <do_no_page+54/e4>
-Trace: c01189e4 <handle_mm_fault+cc/168>
+Trace: c0118375 <do_wp_page+19/210>
+Trace: c0118a3a <handle_mm_fault+122/168>
Trace: c010ce9f <do_page_fault+143/364>

I suspect that one of the processes grabbed the semaphore and then deadlocked trying to do it again. Probably the process invoked write()
with the data having been swapped out. The page fault handler tried to free some memory and try_to_free_pages decided to write out dirty pages of a shared mapping. By accident the dirty pages happened to belong to the file the process had started to write to.

A simple solution will be to check if the inode semaphore is held before trying to write pages out and skip the mapping if it is. However it doesn't seem to be a very good solution because if the most memory is occupied by dirty pages of a shared mapping then writing the pages out is the most right thing to do.

Best wishes
Andrey V.
Savochkin

On Thu, Jan 07, 1999 at 02:57:34PM -0800, Linus Torvalds wrote:
[snip]

Quoted 16 lines

Confirmed. Hpa was good enough to reproduce this, and my debugging code caught the (fairly deep) deadlock:

	system_call ->
	sys_write ->
	ext2_file_write ->
	ext2_getblk ->
	ext2_alloc_block ->	** gets superblock lock **
	ext2_new_block ->
	getblk ->
	refill_freelist ->
	grow_buffers ->
	__get_free_pages ->
	try_to_free_pages ->
	swap_out ->
	swap_out_process ->
Quoted 8 lines
	swap_out_vma ->
	try_to_swap_out ->
	filemap_swapout ->
	filemap_write_page ->
	ext2_file_write ->
	ext2_getblk ->
	ext2_alloc_block ->
	__wait_on_super		** BOOM - we want the superblock lock again **

--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#116 lore raw

Re: MM deadlock [was: Re: arca-vm-8...]

Quoted 2 lines · Savochkin Andrey Vladimirovich

I've found an another deadlock.

Yes. This is a case I knew about, and that Alan already mentioned. Trying to write from a shared mapping has a path that can take the write semaphore twice.

This one is a whole lot harder to fix - the previous one needed only a simple extra flag, this one is truly nasty.

The cleanest solution I can think of is actually to allow semaphores to be recursive. I can do that with minimal overhead (just one extra instruction in the non-contention case), so it's not too bad, and I've wanted to do it for certain other things, but it's still a nasty piece of code to mess around with.

Oh, well. I don't think I have much choice. Making the swap-out routines refuse to touch an inode that is busy is a sure way to allow people to let bad users lock down infinite amounts of memory.

Linus

--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#117 lore raw

Re: MM deadlock [was: Re: arca-vm-8...]

Quoted 1 line · Linus Torvalds

refuse to touch an inode that is busy is a sure way to allow people to

What do you mean for busy? What about refusing filemap_write_page() in filemap_swapout() only if !atomic_count(&vma->vm_file->d_entry->d_inode->i_sem.count)?

That way other no-fs path could still put the dirty pages of the shared mapping on disk. Today I had a really little time to play with Linux due OFFTOPIC University studies (I should never play with Linux :() so I had not time to try out this my new idea, so maybe I am missing something...

Other my thoughts about the topic are: maybe do the inode sempahore recursive could be better anyway so better to do that now? I don't know what does it mean recursive ;), I guess like lock_kernel(). But that way we would be not sure to preserve data integrity if the same process would do crazy things, right now we would "only" deadlock in such case.

Andrea Arcangeli

--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#118 lore raw

Re: MM deadlock [was: Re: arca-vm-8...]

Hi,

Quoted 6 lines · Andrea Arcangeli
Quoted 1 line · Linus Torvalds

refuse to touch an inode that is busy is a sure way to allow people to

What do you mean for busy? What about refusing filemap_write_page() in filemap_swapout() only if !atomic_count(&vma->vm_file->d_entry->d_inode->i_sem.count)?

The problem with that is what happens if we have a large, active write-mapped file with lots of IO activity on it; we become essentially unable to swap that file out. That has really nasty VM death implications for things like databases.

--Stephen
--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#119 lore raw

Re: MM deadlock [was: Re: arca-vm-8...]

Quoted 5 lines · Stephen C. Tweedie

The problem with that is what happens if we have a large, active write-mapped file with lots of IO activity on it; we become essentially unable to swap that file out. That has really nasty VM death implications for things like databases.

Indeed. Maybe we really should use kswapd for this, especially now that kswapd doesn't really do much else..

Btw, pre-6 had a bug in kswapd that is relevant to this discussion - it used a 0 argument to try_to_free_pages(), even though kswapd very much is able to do IO. (So in pre-6, waking up kswapd is the wrong thing to try to do ;)

Linus

--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#120 lore raw

Re: MM deadlock [was: Re: arca-vm-8...]

In reply to Linus Torvalds
Quoted 8 lines · Linus Torvalds

The cleanest solution I can think of is actually to allow semaphores to be recursive. I can do that with minimal overhead (just one extra instruction in the non-contention case), so it's not too bad, and I've wanted to do it for certain other things, but it's still a nasty piece of code to mess around with.

Oh, well. I don't think I have much choice.

Does anybody know semaphores by heart? I've got code that may well work, but the race conditions for semaphores are nasty. As mentioned, this only adds a single instruction to the common non-contended case, and I really do believe it should be correct, but it is completely untested (so it might not work at all), and it would be good to have somebody with some theory go through this..

Basically, these simple changes should make it ok to do recursive semaphore grabs, so

	down(&sem);
	down(&sem);
	up(&sem);
	up(&sem);

should work and leave the semaphore unlocked.

Anybody? Semaphore theory used to be really popular at Universities, so there must be somebody who has some automated proving program somewhere..

Linus

-----

include/asm-i386/semaphore.h renamed from linux/include/asm-i386/semaphore.h +19 -5
diff -u --recursive --new-file penguin/linux/include/asm-i386/semaphore.h linux/include/asm-i386/semaphore.h
@@ -25,12 +25,23 @@
 
 struct semaphore {
 	atomic_t count;
+	unsigned long owner;
 	int waking;
 	struct wait_queue * wait;
 };
 
-#define MUTEX ((struct semaphore) { ATOMIC_INIT(1), 0, NULL })
-#define MUTEX_LOCKED ((struct semaphore) { ATOMIC_INIT(0), 0, NULL })
+/*
+ * Because we want the non-contention case to be
+ * fast, we save the stack pointer into the "owner"
+ * field, and to get the true task pointer we have
+ * to do the bit masking. That moves the masking
+ * operation into the slow path.
+ */
+#define semaphore_owner(sem) \
+	((struct task_struct *)((2*PAGE_MASK) & (sem)->owner))
+
+#define MUTEX ((struct semaphore) { ATOMIC_INIT(1), 0, 0, NULL })
+#define MUTEX_LOCKED ((struct semaphore) { ATOMIC_INIT(0), 0, 0, NULL })
 
 asmlinkage void __down_failed(void /* special register calling convention */);
 asmlinkage int  __down_failed_interruptible(void  /* params in registers */);
@@ -64,13 +75,14 @@
 	spin_unlock_irqrestore(&semaphore_wake_lock, flags);
 }
 
-static inline int waking_non_zero(struct semaphore *sem)
+static inline int waking_non_zero(struct semaphore *sem, struct task_struct *tsk)
 {
 	unsigned long flags;
 	int ret = 0;
 
 	spin_lock_irqsave(&semaphore_wake_lock, flags);
-	if (sem->waking > 0) {
+	if (sem->waking > 0 || semaphore_owner(sem) == tsk) {
+		sem->owner = (unsigned long) tsk;
 		sem->waking--;
 		ret = 1;
 	}
@@ -91,7 +103,8 @@
 		"lock ; "
 #endif
 		"decl 0(%0)\n\t"
-		"js 2f\n"
+		"js 2f\n\t"
+		"movl %%esp,4(%0)\n"
 		"1:\n"
 		".section .text.lock,\"ax\"\n"
 		"2:\tpushl $1b\n\t"
@@ -113,6 +126,7 @@
 #endif
 		"decl 0(%1)\n\t"
 		"js 2f\n\t"
+		"movl %%esp,4(%1)\n\t"
 		"xorl %0,%0\n"
 		"1:\n"
 		".section .text.lock,\"ax\"\n"
kernel/sched.c renamed from linux/kernel/sched.c +1 -1
diff -u --recursive --new-file penguin/linux/kernel/sched.c linux/kernel/sched.c
@@ -883,7 +883,7 @@
 	 * who gets to gate through and who has to wait some more.	 \
 	 */								 \
 	for (;;) {							 \
-		if (waking_non_zero(sem))	/* are we waking up?  */ \
+		if (waking_non_zero(sem, tsk))	/* are we waking up?  */ \
 			break;			/* yes, exit loop */
 
 #define DOWN_TAIL(task_state)			\

--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#121 lore raw

Re: MM deadlock [was: Re: arca-vm-8...]

Quoted 11 lines · Linus Torvalds
Quoted 8 lines · Linus Torvalds

The cleanest solution I can think of is actually to allow semaphores to be recursive. I can do that with minimal overhead (just one extra instruction in the non-contention case), so it's not too bad, and I've wanted to do it for certain other things, but it's still a nasty piece of code to mess around with.

Oh, well. I don't think I have much choice.

Well, doesn't semaphore recursion mean that the write atomicity is no more guaranteed by inode's i_sem semaphore?

Best wishes
Andrey V.
Savochkin
--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#122 lore raw

Re: MM deadlock [was: Re: arca-vm-8...]

Quoted 2 lines · Savochkin Andrey Vladimirovich

Well, doesn't semaphore recursion mean that the write atomicity is no more guaranteed by inode's i_sem semaphore?

Looking first Linus's patch I guessed right what does it mean recursion over a sempahore (not that there would be many other choices though ;). As I just pointed out the write atomicity is not more garanteed from the internal path of the same process (previously in such case we would deadlock but sure we had no ways to corrupt things). It's still garanteed that many processes working on a critical section protected by the same semaphore will not mess up things.

Andrea Arcangeli

--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#123 lore raw

Re: MM deadlock [was: Re: arca-vm-8...]

In reply to Savochkin Andrey Vladimirovich

Hi,

Quoted 2 lines · Savochkin Andrey Vladimirovich

Well, doesn't semaphore recursion mean that the write atomicity is no more guaranteed by inode's i_sem semaphore?

Yes. That's OK from one point of view --- there's nothing in the specs which requires us to make writes atomic. The question is whether any filesystems rely on it internally in their implementation.

--Stephen
--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#124 lore raw

Re: MM deadlock [was: Re: arca-vm-8...]

In reply to Linus Torvalds

Hi,

Quoted 7 lines · Linus Torvalds
Quoted 6 lines · Linus Torvalds

The cleanest solution I can think of is actually to allow semaphores to be recursive. I can do that with minimal overhead (just one extra instruction in the non-contention case), so it's not too bad, and I've wanted to do it for certain other things, but it's still a nasty piece of code to mess around with.

Ack. I've been having a closer look, and making the superblock lock recursive doesn't work: the ext2fs allocation code is definitely not reentrant. In particular, the bitmap buffers can get evicted out from under our feet if we reenter the block allocation code, leading to nasty filesystem and/or memory corruption. The allocation code can also get confused if the bitmap contents change between checking the group descriptor for a block group and reading in the bitmap itself, leading to potential ENOSPC errors turning up wrongly.

Preventing recursive VM access to the filesystem while we have the superblock lock seems the only easy way out short of making the allocation/truncate code fully reentrant.

On the other hand, it does look as if the inode deadlock is dealt with OK if we just make that semaphore recursive; I can't see anywhere that dies if we make that change. This does somewhat imply that we may need to make a distinction between reentrant and non-reentrant semaphores if we go down this route.

--Stephen.
--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#125 lore raw

Re: MM deadlock [was: Re: arca-vm-8...]

Quoted 3 lines · Stephen C. Tweedie

dies if we make that change. This does somewhat imply that we may need to make a distinction between reentrant and non-reentrant semaphores if we go down this route.

Agreed.

Andrea Arcangeli

--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#126 lore raw

Re: MM deadlock [was: Re: arca-vm-8...]

In reply to Stephen C. Tweedie
Quoted 3 lines · Stephen C. Tweedie

Ack. I've been having a closer look, and making the superblock lock recursive doesn't work

That's fine - the superblock lock doesn't need to be re-entrant, because __GFP_IO is quite sufficient for that one.

The thing I want to make re-entrant is just semaphore accesses: at the point where we would otherwise deadlock on the writer semaphore it's much better to just allow nested writes. I suspect all filesystems can already handle nested writes - they are a lot easier to handle than truly concurrent ones.

Linus

--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#127 lore raw

Re: MM deadlock [was: Re: arca-vm-8...]

Quoted 4 lines

point where we would otherwise deadlock on the writer semaphore it's much better to just allow nested writes. I suspect all filesystems can already handle nested writes - they are a lot easier to handle than truly concurrent ones.

Suspect makes me kind of nervous. Especially so close to 2.2 and given the normal results of making a bad file system error.

Alan

--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#128 lore raw

Re: MM deadlock [was: Re: arca-vm-8...]

Quoted 2 lines · Alan Cox

Suspect makes me kind of nervous. Especially so close to 2.2 and given the normal results of making a bad file system error.

Another way to fix the thing could be to left only to kswapd the work to sync shared-mmapped page out to disk when needed. We could wakeup kswapd from the inside of filemap_swapout... It's dirty but should work fine without the need of reentrant semaphores. BTW, before my always-async-swapout idea kswapd was hiding the bug pretty well ;).

Personally I like far more the clean solution but...

Andrea Arcangeli

--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#129 lore raw

Re: MM deadlock [was: Re: arca-vm-8...]

Hi,

Quoted 4 lines · Andrea Arcangeli

Another way to fix the thing could be to left only to kswapd the work to sync shared-mmapped page out to disk when needed. We could wakeup kswapd from the inside of filemap_swapout... It's dirty but should work fine without the need of reentrant semaphores.

Yep. I had this working for swap a long time ago via a separate kswiod thread for swap IO, but it didn't make a lot of difference at the time (we weren't swapping very intelligently in those days, though). It's something I have thought of resurrecting, mainly because I'm nervous that if kswapd spends too much time swapping asynchronously then we can be left starved of real free pages on the free lists for interrupts.

--Stephen

--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#130 lore raw

Re: MM deadlock [was: Re: arca-vm-8...]

In reply to Alan Cox
Quoted 3 lines · Alan Cox

Suspect makes me kind of nervous. Especially so close to 2.2 and given the normal results of making a bad file system error.

Umm.. The other choice is to leave in an old deadlock condition - that is now well documented and thus wellknown?

Linus

--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#131 lore raw

Re: MM deadlock [was: Re: arca-vm-8...]

Quoted 7 lines · Alan Cox
Quoted 3 lines

Suspect makes me kind of nervous. Especially so close to 2.2 and given the normal results of making a bad file system error.

Umm.. The other choice is to leave in an old deadlock condition - that is now well documented and thus wellknown?

Or to defer the I/O to the unlock

--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#132 lore raw

Re: MM deadlock [was: Re: arca-vm-8...]

Quoted 2 lines · Alan Cox

Or to defer the I/O to the unlock

Hmm.. I don't generally like this idea because it is so easily fraught with various nasty usage issues - just looking at the file semaphore would probably make it fairly easy for somebody who knows how we work to come up with some programs that may not deadlock but would create some really pathological memory management behaviour.

I'll think about it, though - together with some kswapd help we might well be able to guarantee that nobody will be able to cause problems by keeping a file busy.

Linus

--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#133 lore raw

Re: MM deadlock [was: Re: arca-vm-8...]

In reply to Linus Torvalds

Hi,

Quoted 5 lines · Linus Torvalds

The thing I want to make re-entrant is just semaphore accesses: at the point where we would otherwise deadlock on the writer semaphore it's much better to just allow nested writes. I suspect all filesystems can already handle nested writes - they are a lot easier to handle than truly concurrent ones.

We used to do it anyway, before inodes were locked for write, if I remember correctly.

What I'm after is something like the patch below for a fix (don't apply
it: it should work and should fix the problem, but it's really just for illustration). It enforces an i_atomic_allocate semaphore to lock against truncate(). The write-page filemap code takes this semaphore, but does _not_ take i_sem at all.

Frankly, I really don't think we want to serialise writes so aggressively in the first place. In POSIX, O_APPEND is the only case where we need to do this (and since that modifies i_size, it's a natural case to do under the i_atomic_allocate semaphore in any case).

This patch should fix the problem in hand, but what I think we really want is a read/write semaphore for i_atomic_allocate: we want normal read and write IO to a file to guard against a concurrent truncate(), but _not_ against each other (in situations such as threaded/async IO to a database file, multiple outstanding IOs can be a big win). Basically, most writes should take out a read lock on the filesize so that the file won't disappear from under their feet; only extending or truncating the file should take out an i_atomic_allocate write lock (assuming the same sorts of semantics for r/w semaphores as we already have for r/w spinlocks).

Are there really any filesystems we know can't deal with concurrent/reentrant writes to an inode? We already have to deal with concurrent reads with a single write in progress, after all.

--Stephen

----------------------------------------------------------------

inode.c renamed from inode.c.~1~ +1 -0
@@ -132,6 +132,7 @@
 	INIT_LIST_HEAD(&inode->i_dentry);
 	sema_init(&inode->i_sem, 1);
 	sema_init(&inode->i_atomic_write, 1);
+	sema_init(&inode->i_atomic_allocate, 1);
 }
 
 static inline void write_inode(struct inode *inode)
open.c renamed from open.c~ +2 -0
@@ -70,6 +70,7 @@
 	int error;
 	struct iattr newattrs;
 
+	down(&inode->i_atomic_allocate);
 	down(&inode->i_sem);
 	newattrs.ia_size = length;
 	newattrs.ia_valid = ATTR_SIZE | ATTR_CTIME;
@@ -81,6 +82,7 @@
 			inode->i_op->truncate(inode);
 	}
 	up(&inode->i_sem);
+	up(&inode->i_atomic_allocate);
 	return error;
 }
 
linux/fs.h renamed from linux/fs.h.~1~ +1 -0
@@ -358,6 +358,7 @@
 	unsigned long		i_nrpages;
 	struct semaphore	i_sem;
 	struct semaphore	i_atomic_write;
+	struct semaphore	i_atomic_allocate;
 	struct inode_operations	*i_op;
 	struct super_block	*i_sb;
 	struct wait_queue	*i_wait;
filemap.c renamed from filemap.c~ +2 -2
@@ -1113,9 +1113,9 @@
 	 * and file could be released ... increment the count to be safe.
 	 */
 	file->f_count++;
-	down(&inode->i_sem);
+	down(&inode->i_atomic_allocate);
 	result = do_write_page(inode, file, (const char *) page, offset);
-	up(&inode->i_sem);
+	up(&inode->i_atomic_allocate);
 	fput(file);
 	return result;
 }

--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#134 lore raw

Re: MM deadlock [was: Re: arca-vm-8...]

In reply to Linus Torvalds

Hi,

Quoted 7 lines · Linus Torvalds
Quoted 3 lines · Stephen C. Tweedie

Ack. I've been having a closer look, and making the superblock lock recursive doesn't work

That's fine - the superblock lock doesn't need to be re-entrant, because __GFP_IO is quite sufficient for that one.

I'm no longer convinced about that. I think it's much much worse. A bread() on an ext2 bitmap buffer with the superblock held is only safe if the IO can complete without _ever_ relying on a GFP_IO allocation. That means that any interrupt allocations required in that space have to be satisfiable by kswapd without GFP_IO, or kswapd could deadlock on us. It means that if our superblock-locked IO has to stall waiting for an nbd server process or a raid daemon, then those daemons cannot safely do GFP_IO. It's really gross.

I think it's actually ugly enough that we cannot make it safe: we can really only be sure if we prevent all GFP_IO from any process which might be involved in our deadlock loop, or if we avoid doing any IO with the superblock lock held.

It really looks as if the right way around this is to prevent GFP_IO from deadlocking in the first place, by moving the asynchronous page writes out of kswapd/try_to_free_page and into a separate worker thread. That way we can continue to try to reclaim memory somewhere else without deadlocking. In that case the only thing we are left having to worry about is doing a synchronous swapout, where we end up blocking waiting for the IO thread to complete.

In fact, to make it really safe we'd need to avoid synchronous swapout
altogether: otherwise we can have

	    A			kswiod		nbd server process
	    lock_super();
	    bread(ndb device);
	    try_to_free_page();
	    rw_swap_page_async();
				filemap_write_page();
				lock_super();
	    wait_on_buffer();
						try_to_free_page();
						rw_swap_page_sync();
						Oops, kswiod is stalled.

Can we get away without synchronous swapout? Notice that in this case, kswiod may be blocked but kswapd itself will not be. As long as the nbd server does not try to do a synchronous swap, it won't deadlock on kswiod. In other words, it is safe to wait for avaibility of another free page, but it is not safe to wait for completion of any single, specific swap IO. If kswapd itself no longer performs the IO, then we can always free more memory, until we get to the complete death stage where there are absolutely no clean pages left in the system.

If we do this, then both the inode and the superblock deadlocks disappear.

--Stephen.
--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#135 lore raw

Re: MM deadlock [was: Re: arca-vm-8...]

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"ST" == Stephen C Tweedie <[email protected]> writes:

ST> Hi,
ST> On Sun, 10 Jan 1999 10:35:10 -0800 (PST), Linus Torvalds

Quoted 7 lines · ST> <[email protected]> said:
Quoted 7 lines · Stephen C. Tweedie
Quoted 3 lines

Ack. I've been having a closer look, and making the superblock lock recursive doesn't work

That's fine - the superblock lock doesn't need to be re-entrant, because __GFP_IO is quite sufficient for that one.

ST> I'm no longer convinced about that. I think it's much much worse. A ST> bread() on an ext2 bitmap buffer with the superblock held is only safe ST> if the IO can complete without _ever_ relying on a GFP_IO allocation. ST> That means that any interrupt allocations required in that space have to ST> be satisfiable by kswapd without GFP_IO, or kswapd could deadlock ST> on us.

Well interrupts use GFP_ATOMIC . . .

ST> It means that if our superblock-locked IO has to stall waiting for an ST> nbd server process or a raid daemon, then those daemons cannot safely do ST> GFP_IO. It's really gross.

Right. And the flag not to do I/O doesn't propogate across processes. This sounds like a variation of the priority inheritance problem.

I wonder if this is why there are some known deadlocks with raid?

ST> I think it's actually ugly enough that we cannot make it safe: we can ST> really only be sure if we prevent all GFP_IO from any process which ST> might be involved in our deadlock loop, or if we avoid doing any IO with ST> the superblock lock held.

ST> In fact, to make it really safe we'd need to avoid synchronous swapout ST> altogether: otherwise we can have

ST> Can we get away without synchronous swapout? Notice that in this case, ST> kswiod may be blocked but kswapd itself will not be. As long as the nbd ST> server does not try to do a synchronous swap, it won't deadlock on ST> kswiod. In other words, it is safe to wait for avaibility of another ST> free page, but it is not safe to wait for completion of any single, ST> specific swap IO. If kswapd itself no longer performs the IO, then we ST> can always free more memory, until we get to the complete death stage ST> where there are absolutely no clean pages left in the system.

ST> If we do this, then both the inode and the superblock deadlocks ST> disappear.

Sounds good.

I have a daemon just about ready to go, hopefully I can post it tommorrow for preliminary testing. It looks like my work for 2.3 in a small part can help deadlocks after all.

It walks the page tables and just writes out dirty pages, and marks them clean but it doesn't remove them from processes. So it can get an early jump on writing things out.

Then if we are hitting a low memory situation (because pages become dirty quickly), we can just wake it up, more often.

Currently we are doing totally asynchonous swapping but from the context of the process that needs memory, (so the locks are in different processes). Adding a second daemon will play havoc on our balancing but it shouldn't affect anything else.

Grr. I forgot about sysv shm. It is the only thing doing synchronous swapping right now.

Oh, and just as a side note we are currently unfairly penalizing threaded programs by doing for_each_task instead of for_each_mm in the swapout code...

Eric
--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#136 lore raw

Re: MM deadlock [was: Re: arca-vm-8...]

Hi,

Quoted 3 lines · On 11 Jan 1999 00:04:11 -0600, [email protected] (Eric W. Biederman) said:

Oh, and just as a side note we are currently unfairly penalizing threaded programs by doing for_each_task instead of for_each_mm in the swapout code...

I know, on my TODO list...

--Stephen
--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#137 lore raw

Re: MM deadlock [was: Re: arca-vm-8...]

Quoted 9 lines · Stephen C. Tweedie
Quoted 3 lines · On 11 Jan 1999 00:04:11 -0600, [email protected] (Eric W. Biederman) said:

Oh, and just as a side note we are currently unfairly penalizing threaded programs by doing for_each_task instead of for_each_mm in the swapout code...

I know, on my TODO list...

Actually, this one is _really_ easy to fix.

The truly trivial fix is to just move "swap_cnt" into the mm structure, and you're all done. You'd still walk the list with for_each_task(), but it no longer matters.

Linus

--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#138 lore raw

Re: MM deadlock [was: Re: arca-vm-8...]

Quoted 11 lines · Linus Torvalds
Quoted 9 lines · Stephen C. Tweedie
Quoted 3 lines · On 11 Jan 1999 00:04:11 -0600, [email protected] (Eric W. Biederman) said:

Oh, and just as a side note we are currently unfairly penalizing threaded programs by doing for_each_task instead of for_each_mm in the swapout code...

I know, on my TODO list...

Quoted 8 lines

Actually, this one is _really_ easy to fix.

The truly trivial fix is to just move "swap_cnt" into the mm structure, and you're all done. You'd still walk the list with for_each_task(), but it no longer matters.

Linus

Not related to this, but I (hopefully correctly) observed that SHM swap I/O is done synchronously.

Could somebody spare a minute to explain why is that so, and what needs to be done to make SHM swapping asynchronous?

Also, while we're at MM fixes, I'm appending below a small patch that will improve interactive feel.

After number of async pages gets bigger than pager_daemon.swap_cluster (= SWAP_CLUSTER_MAX), swapin readahead becomes synchronous, and that hurts performance. It is better to skip readahead in such situations, and that is also more fair to swapout. Andrea came to exactly the same conclusion, independent of me (on the same day :)).

mm/page_alloc.c +2 -0
diff -urN linux-pre-7/mm/page_alloc.c linux/mm/page_alloc.c
@@ -358,6 +358,8 @@
 	for (i = 1 << page_cluster; i > 0; i--) {
 	      if (offset >= swapdev->max)
 		      return;
+	      if (atomic_read(&nr_async_pages) > pager_daemon.swap_cluster)
+		      return;
 	      if (!swapdev->swap_map[offset] ||
 		  swapdev->swap_map[offset] == SWAP_MAP_BAD ||
 		  test_bit(offset, swapdev->swap_lockmap))

Regards,

Signature · 4 lines
Zlatko
--
This is a majordomo managed list.  To unsubscribe, send a message with
the body 'unsubscribe linux-mm me@address' to: [email protected]
#139 lore raw

Re: MM deadlock [was: Re: arca-vm-8...]

Quoted 2 lines · Zlatko Calusic

Could somebody spare a minute to explain why is that so, and what needs to be done to make SHM swapping asynchronous?

Maybe because nobody care about shm? I think shm can wait for 2.3 to be improved.

Quoted 2 lines

Also, while we're at MM fixes, I'm appending below a small patch that will improve interactive feel.

This is just in my latest arca patches as you have just noticed. Don't think that this thing make some difference though. But sometimes could improve performances and make tons of sense.

Andrea Arcangeli

--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#140 lore raw

Re: MM deadlock [was: Re: arca-vm-8...]

Hi,

Quoted 6 lines · Andrea Arcangeli
Quoted 2 lines · Zlatko Calusic

Could somebody spare a minute to explain why is that so, and what needs to be done to make SHM swapping asynchronous?

Maybe because nobody care about shm? I think shm can wait for 2.3 to be improved.

"Nobody"? Oracle uses large shared memory regions for starters.

--Stephen
--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#141 lore raw

2.2.0-pre6 ain't nice =(

Hello

I've been running 2.2.0-pre6 for about 5 days now (w/o reboot) and I'm sad to say that it seems to swap more and more for each day. Especially when something heavy I/O is running, but even when the system is not used at all it is much more sluggish then freshly rebooted...

I hope this problem will be fixed, we certainly don't want NT emulation =)

--
Med vanlig halsning
Kalle Andersson
[email protected]

--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#142 lore raw

Re: MM deadlock [was: Re: arca-vm-8...]

In reply to Stephen C. Tweedie
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

Could somebody spare a minute to explain why is that so, and what needs to be done to make SHM swapping asynchronous?

Maybe because nobody care about shm? I think shm can wait for 2.3 to be improved.

"Nobody"? Oracle uses large shared memory regions for starters.

All the big databases use large shared memory objects.

--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#143 lore raw

Re: MM deadlock [was: Re: arca-vm-8...]

Quoted 3 lines · Alan Cox
Quoted 1 line

"Nobody"? Oracle uses large shared memory regions for starters.

All the big databases use large shared memory objects.

which is _not_ expected to be swapped at all for a correctly set-up Oracle database installation.

-- mingo

--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#144 lore raw

Re: MM deadlock [was: Re: arca-vm-8...]

In reply to Alan Cox
Quoted 9 lines · Alan Cox
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

Could somebody spare a minute to explain why is that so, and what needs to be done to make SHM swapping asynchronous?

Maybe because nobody care about shm? I think shm can wait for 2.3 to be improved.

"Nobody"? Oracle uses large shared memory regions for starters.

All the big databases use large shared memory objects.

I was't aware of that. I noticed that also postgres (a big database) uses shm but it's _only_ something like 1 Mbyte (at least during trivial usage). With my current code such 1 Mbyte would not be touched unless there would be some really big memory squeezee (like something that cause a swapout of tons of memory and that would slowdown a bit the system anyway). This is obviously not true in clean pre7 (see try_to_free_pages()).

With my latest code, optimizing the shm swapout (as we do with normal userspace memory) would help only if the shm memory is going to be in size something like the total VM allocated in all processes' mm. Since I supposed that "normal" apps don't use huge amount of shm memory I told that we could not care until 2.3. I can't know how much shm memory uses Oracle SQL server because I can't have it. I am pretty sure instead that postgresql will be not stuck in shm swapout here even if the shm swapout code is gross.

Andrea Arcangeli

--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#145 lore raw

Re: MM deadlock [was: Re: arca-vm-8...]

Quoted 8 lines · Andrea Arcangeli

I was't aware of that. I noticed that also postgres (a big database) uses shm but it's _only_ something like 1 Mbyte (at least during trivial usage). With my current code such 1 Mbyte would not be touched unless there would be some really big memory squeezee (like something that cause a swapout of tons of memory and that would slowdown a bit the system anyway). This is obviously not true in clean pre7 (see try_to_free_pages()).

Quoted 8 lines

With my latest code, optimizing the shm swapout (as we do with normal userspace memory) would help only if the shm memory is going to be in size something like the total VM allocated in all processes' mm. Since I supposed that "normal" apps don't use huge amount of shm memory I told that we could not care until 2.3. I can't know how much shm memory uses Oracle SQL server because I can't have it. I am pretty sure instead that postgresql will be not stuck in shm swapout here even if the shm swapout code is gross.

Informix Dynamic Server is a free download from www.informix.com (but its fairly big, ~30MB). I think Oracle is downloadable too. With either the shm used is normally "large" with respect to available physical memory (i.e. everything that isn't needed by processes under your normal load) because the database engines use it to cache data (this is why they want raw IO - there's no point the OS caching the data as well).

Mike

Signature · 12 lines
    A train stops at a train station, a bus stops at a bus station.
    On my desk I have a work station...
.----------------------------------------------------------------------.
|  Mike Jagdis                  |  Internet:  mailto:[email protected]   |
|  Roan Technology Ltd.         |                                      |
|  54A Peach Street, Wokingham  |  Telephone:  +44 118 989 0403        |
|  RG40 1XG, ENGLAND            |  Fax:        +44 118 989 1195        |
`----------------------------------------------------------------------'

--
This is a majordomo managed list.  To unsubscribe, send a message with
the body 'unsubscribe linux-mm me@address' to: [email protected]
#146 lore raw

Re: MM deadlock [was: Re: arca-vm-8...]

Quoted 5 lines · Mike Jagdis

With either the shm used is normally "large" with respect to available physical memory (i.e. everything that isn't needed by processes under your normal load) because the database engines use it to cache data (this is why they want raw IO - there's no point the OS caching the data as well).

Ah but if what you say is true the db server shm issue raised by Stephen is completly pointless. If the shm memory is used as _cache_ for the data there's _no_ one point to swapout it out in first place. So when using the shm for caching purposes the db server _must_ set the SHM_LOCK flag on the shm memory using shmctl.

Andrea Arcangeli

--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#147 lore raw

Re: MM deadlock [was: Re: arca-vm-8...]

In reply to Andrea Arcangeli
Quoted 9 lines · Andrea Arcangeli
Quoted 6 lines · Alan Cox
Quoted 6 lines
Quoted 5 lines
Quoted 2 lines

Could somebody spare a minute to explain why is that so, and what needs to be done to make SHM swapping asynchronous?

Maybe because nobody care about shm? I think shm can wait for 2.3 to be improved.

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

"Nobody"? Oracle uses large shared memory regions for starters.

All the big databases use large shared memory objects.

I was't aware of that. I noticed that also postgres (a big database) uses shm but it's _only_ something like 1 Mbyte (at least during trivial usage). With my current code such 1 Mbyte would not be touched unless

Our current database size 1.6Gb, locks & buffers are using "large" SHM heavily. Due to Linux SHMMAX = 16M, allocation is divided into serveral 16M segments.

current database buffers = 130,000 * 1024 bytes
locks = 65536 * 18 bytes

Quick Spec:
Dual PPro 200MHz, 256Mb Ram
Kernel 2.2.0-pre6
Progress 7.3C08 via latest iBCS 2.1.x emulator

Signature · 12 lines
+---| Netscape Communicator 4.x |---| Powered by Linux 2.1.x |---+
|/v\ Agus Budy Wuysang                   MIS Department          |
| |  Phone:  +62-21-344-1316 ext 317     GSM: +62-816-1972-051   |
+--------| http://www.rad.net.id/users/personal/s/supes |--------+
-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GCS/IT dx s: a- C+++ UL++++$ P- L+++(++++) E--- W++ N+++ o? K? w-- O-
M- V-- PS+ PE Y-- PGP t+@ 5 X+ R- tv- b+ DI? D++(+) G e++ h* r+ y++
------END GEEK CODE BLOCK------
--
This is a majordomo managed list.  To unsubscribe, send a message with
the body 'unsubscribe linux-mm me@address' to: [email protected]
#148 lore raw

Re: MM deadlock [was: Re: arca-vm-8...]

In reply to Stephen C. Tweedie
Quoted 7 lines · Stephen C. Tweedie
Quoted 2 lines · Andrea Arcangeli

Maybe because nobody care about shm? I think shm can wait for 2.3 to be improved.

"Nobody"? Oracle uses large shared memory regions for starters.

Yeah, and so does Informix Dynamic Server. But, in general, you do not want this to be swapped heavily, if at all.

Mike

Signature · 12 lines
    A train stops at a train station, a bus stops at a bus station.
    On my desk I have a work station...
.----------------------------------------------------------------------.
|  Mike Jagdis                  |  Internet:  mailto:[email protected]   |
|  Roan Technology Ltd.         |                                      |
|  54A Peach Street, Wokingham  |  Telephone:  +44 118 989 0403        |
|  RG40 1XG, ENGLAND            |  Fax:        +44 118 989 1195        |
`----------------------------------------------------------------------'

--
This is a majordomo managed list.  To unsubscribe, send a message with
the body 'unsubscribe linux-mm me@address' to: [email protected]
#149 lore raw

Re: MM deadlock [was: Re: arca-vm-8...]

In reply to Zlatko Calusic
Quoted 6 lines · Zlatko Calusic

After number of async pages gets bigger than pager_daemon.swap_cluster (= SWAP_CLUSTER_MAX), swapin readahead becomes synchronous, and that hurts performance. It is better to skip readahead in such situations, and that is also more fair to swapout. Andrea came to exactly the same conclusion, independent of me (on the same day :)).

IIRC this facility was in the original swapin readahead implementation. That only leaves the question who removed it and why :))

cheers,

Rik -- If a Microsoft product fails, who do you sue?

+-------------------------------------------------------------------+
| Linux memory management tour guide.        [email protected] |
| Scouting Vries cubscout leader.    http://humbolt.geo.uu.nl/~riel |
+-------------------------------------------------------------------+

--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#150 lore raw

Re: MM deadlock [was: Re: arca-vm-8...]

Quoted 9 lines · Rik van Riel
Quoted 6 lines · Zlatko Calusic

After number of async pages gets bigger than pager_daemon.swap_cluster (= SWAP_CLUSTER_MAX), swapin readahead becomes synchronous, and that hurts performance. It is better to skip readahead in such situations, and that is also more fair to swapout. Andrea came to exactly the same conclusion, independent of me (on the same day :)).

Quoted 4 lines

IIRC this facility was in the original swapin readahead implementation. That only leaves the question who removed it and why :))

*I* did, because original test was too complicated and nobody understood what was it actual purpose.

Beside that, when MM code changed recently, nr_free_pages started hovering at lower values, and that was killing readahead at most cases (with old test in place), thus producing terrible results, especially when you had more than one thrashing task.

Signature · 4 lines
Zlatko
--
This is a majordomo managed list.  To unsubscribe, send a message with
the body 'unsubscribe linux-mm me@address' to: [email protected]
#151 lore raw

Re: MM deadlock [was: Re: arca-vm-8...]

In reply to Rik van Riel
Quoted 3 lines · Rik van Riel

IIRC this facility was in the original swapin readahead implementation. That only leaves the question who removed it and why :))

There's another thing I completly disagree and that I just removed here. It's the alignment of the offset field. I see no one point in going back instead of only doing real read_ahead_.

Maybe I am missing something?

Index: page_alloc.c
===================================================================
RCS file: /var/cvs/linux/mm/page_alloc.c,v
retrieving revision 1.1.1.8
retrieving revision 1.1.1.1.2.29

mm/page_alloc.c renamed from page_alloc.c +3 -3
diff -u -r1.1.1.8 -r1.1.1.1.2.29
@@ -353,10 +352,10 @@
 	unsigned long offset = SWP_OFFSET(entry);
 	struct swap_info_struct *swapdev = SWP_TYPE(entry) + swap_info;
 	
-	offset = (offset >> page_cluster) << page_cluster;
-	
 	for (i = 1 << page_cluster; i > 0; i--) {
-	      if (offset >= swapdev->max)
+	      if (offset >= swapdev->max ||
+		  /* don't block on I/O for doing readahead -arca */
+		  atomic_read(&nr_async_pages) > pager_daemon.max_async_pages)
 		      return;
 	      if (!swapdev->swap_map[offset] ||
 		  swapdev->swap_map[offset] == SWAP_MAP_BAD ||

Andrea Arcangeli

--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#152 lore raw

Re: MM deadlock [was: Re: arca-vm-8...]

Quoted 11 lines · Andrea Arcangeli
Quoted 3 lines · Rik van Riel

IIRC this facility was in the original swapin readahead implementation. That only leaves the question who removed it and why :))

There's another thing I completly disagree and that I just removed here. It's the alignment of the offset field. I see no one point in going back instead of only doing real read_ahead_.

Maybe I am missing something?

Yes. Imagine the paging in of big binary case. The page faults will occur all over the place, not in a nice sequential order. The page-in clusters stuff _doubled_ performance of paging in certain big static binaries.

Chris

--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#153 lore raw

Re: MM deadlock [was: Re: arca-vm-8...]

Quoted 3 lines · Chris Evans

Yes. Imagine the paging in of big binary case. The page faults will occur all over the place, not in a nice sequential order. The page-in clusters stuff _doubled_ performance of paging in certain big static binaries.

I think that if it helped it means that the swap cache got shrunk too much early due a not good free paging algorithm.

Andrea Arcangeli

--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#154 lore raw

Re: MM deadlock [was: Re: arca-vm-8...]

Hi,

Quoted 7 lines · Andrea Arcangeli
Quoted 3 lines · Chris Evans

Yes. Imagine the paging in of big binary case. The page faults will occur all over the place, not in a nice sequential order. The page-in clusters stuff _doubled_ performance of paging in certain big static binaries.

I think that if it helped it means that the swap cache got shrunk too much early due a not good free paging algorithm.

Not in the slightest. We're talking about the things like the performance of starting up a fresh new copy of netscape. Swapout has nothing to do with it in that case: we are starting from a ground state where the binary is completely uncached. The clustered pagein has a huge impact in that case.

--Stephen
--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#155 lore raw

Re: MM deadlock [was: Re: arca-vm-8...]

In reply to Andrea Arcangeli
Quoted 11 lines · Andrea Arcangeli
Quoted 3 lines · Rik van Riel

IIRC this facility was in the original swapin readahead implementation. That only leaves the question who removed it and why :))

There's another thing I completly disagree and that I just removed here. It's the alignment of the offset field. I see no one point in going back instead of only doing real read_ahead_.

Maybe I am missing something?

Yes, you are:

- aligned reads make sure you don't do smallish readaheads of only 1 block (because you've already got the rest)
- there are programs that move through the data backwards or tilewise
- in allocating swap space it just doesn't make sense to read into the next swap 'region'

Rik -- If a Microsoft product fails, who do you sue?

+-------------------------------------------------------------------+
| Linux memory management tour guide.             [email protected] |
| Scouting Vries cubscout leader.     http://www.nl.linux.org/~riel |
+-------------------------------------------------------------------+

--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#156 lore raw

Re: MM deadlock [was: Re: arca-vm-8...]

Quoted 2 lines · Rik van Riel

- in allocating swap space it just doesn't make sense to read into the next swap 'region'

The point is that I can't see a swap `region' looking at how scan_swap_map() works. The more atomic region I can see in the swap space is a block of bytes large PAGE_SIZE bytes (e.g. offset ;).

For the case of binaries the aging on the page cache should take care of it (even if there's no aging on the swap cache as pre[567] if I remeber well).

Andrea Arcangeli

--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#157 lore raw

Re: MM deadlock [was: Re: arca-vm-8...]

Hi,

Quoted 7 lines · Andrea Arcangeli
Quoted 2 lines · Rik van Riel

- in allocating swap space it just doesn't make sense to read into the next swap 'region'

The point is that I can't see a swap `region' looking at how scan_swap_map() works. The more atomic region I can see in the swap space is a block of bytes large PAGE_SIZE bytes (e.g. offset ;).

The whole point is that we try to swap adjacent virtual pages to adjacent swap entries, so there is a good chance that nearby swap entries are going to be useful when we page them back in again. Given that adjacent swap entries on a swap partition are guaranteed to be physically contiguous, it costs very little to swap in several nearby elements at the same time, and we get a good chance of reading in useful pages.

Quoted 3 lines

For the case of binaries the aging on the page cache should take care of it (even if there's no aging on the swap cache as pre[567] if I remeber well).

There is no aging on the page cache at all other than the PG_referenced bit.

--Stephen
--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#158 lore raw

Re: MM deadlock [was: Re: arca-vm-8...]

Quoted 6 lines
Quoted 3 lines

For the case of binaries the aging on the page cache should take care of it (even if there's no aging on the swap cache as pre[567] if I remeber well).

There is no aging on the page cache at all other than the PG_referenced bit.

I know that most of you do not like aging. Nevertheless, on high stressed systems with less than 128M you will see a critical point whereas the page cache and readahead does not avoid that swapin I/O time needed by a program increases to similar size of the average program time slice.

At this point the system performance breaks down dramatically even with 2.2.0pre[567] ...

What's about a simple aging of program page cluster or better of the page cache? Increasing the age could be done if and only if the pages or page clusters swapped in and the program wasn't able to use its time slice. Decreasing the age could be placed in shrink_mmap().

Werner

--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#159 lore raw

Re: MM deadlock [was: Re: arca-vm-8...]

Hi,

Quoted 7 lines · Dr. Werner Fink
Quoted 2 lines

There is no aging on the page cache at all other than the PG_referenced bit.

I know that most of you do not like aging. Nevertheless, on high stressed systems with less than 128M you will see a critical point whereas the page cache and readahead does not avoid that swapin I/O time needed by a program increases to similar size of the average program time slice.

There's no reason why timeslices should have anything to do with swapin IO time; we do not count time spent waiting for IO against the process's allocated timeslice.

Quoted 4 lines

What's about a simple aging of program page cluster or better of the page cache? Increasing the age could be done if and only if the pages or page clusters swapped in and the program wasn't able to use its time slice. Decreasing the age could be placed in shrink_mmap().

Page aging dramatically increases the amount of CPU time we spend looking for free pages. The selection of which pages to swap out really shouldn't have anything to do with scheduling of CPU-bound processes (which is the only time where timeslices actually count for anything).

--Stephen
--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#160 lore raw

Re: MM deadlock [was: Re: arca-vm-8...]

Quoted 8 lines · Stephen C. Tweedie
Quoted 4 lines

I know that most of you do not like aging. Nevertheless, on high stressed systems with less than 128M you will see a critical point whereas the page cache and readahead does not avoid that swapin I/O time needed by a program increases to similar size of the average program time slice.

There's no reason why timeslices should have anything to do with swapin IO time; we do not count time spent waiting for IO against the process's allocated timeslice.

Yes we do I/O async so while the I/O is in action we could be just back in userspace, but both shrink_mmap() and swap_out() are not something of really so light (at least with >128Mbyte of ram). When we are running in shrink_mmap() the current->counter is decreased as usual.

It's trivial conceptually make shrink_mmap() _fast_, adding two prev_freeable,next_freeable pointers in the mem_map struct and adding pages back and forth to the list (at the same time I now update nr_freeable_pages). Probably I'll do that soon.

I see instead not trivial to decrease the cost of swap_out()...

I agree that the timeslice has nothing to do with swapout/shrink_mmap issue. But the timeslice _must_ be decremented as now during the shrink_mmap/swapout passes, because otherwise we would risk to stall the not trashing process too much.

Andrea Arcangeli

--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#161 lore raw

Re: MM deadlock [was: Re: arca-vm-8...]

Hi,

Quoted 4 lines · Andrea Arcangeli

Yes we do I/O async so while the I/O is in action we could be just back in userspace, but both shrink_mmap() and swap_out() are not something of really so light (at least with >128Mbyte of ram). When we are running in shrink_mmap() the current->counter is decreased as usual.

If shrink_mmap() can exhaust the timeslice while we are swapping (ie. we are IO-bound), then something is *SERIOUSLY* wrong!

--Stephen
--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#162 lore raw

Re: MM deadlock [was: Re: arca-vm-8...]

Quoted 1 line · Stephen C. Tweedie

If shrink_mmap() can exhaust the timeslice while we are swapping (ie. we

When we are in shrink_mmap() we are _not_ swapping. We are instead looping in the mem_map pool.

If we instead block in I/O sync, the timeslice should be not touched.

Andrea Arcangeli

--
This is a majordomo managed list. To unsubscribe, send a message with the body 'unsubscribe linux-mm me@address' to: [email protected]

#163 lore raw

Re: MM deadlock [was: Re: arca-vm-8...]

In reply to Stephen C. Tweedie
Quoted 2 lines

Page aging dramatically increases the amount of CPU time we spend looking for free pages. The selection of which pages to swap out really

Thats a bug in our current vm structures, like the others - inability to throw out page tables, inability to find memory easily, inability to move blocks to allocate large areas in a target space, inability to handle large user spaces etc.

At least 2.3 will have plenty of fun things to do 8)

Alan

--
To unsubscribe, send a message with 'unsubscribe linux-mm my@address' in the body to [email protected]. For more info on Linux MM,
see: http://humbolt.geo.uu.nl/Linux-MM/

#164 lore raw

Re: MM deadlock [was: Re: arca-vm-8...]

Quoted 5 lines · Alan Cox

Thats a bug in our current vm structures, like the others - inability to throw out page tables, inability to find memory easily, inability to move blocks to allocate large areas in a target space, inability to handle large user spaces etc.

What? None of those are bugs, they are features.

Complexity is not a goal to be reached. Complexity is something to be avoided at all cost. If you don't believe me, look at NT.

Linus

--
To unsubscribe, send a message with 'unsubscribe linux-mm my@address' in the body to [email protected]. For more info on Linux MM,
see: http://humbolt.geo.uu.nl/Linux-MM/

#165 lore raw

Re: MM deadlock [was: Re: arca-vm-8...]

Quoted 7 lines · Linus Torvalds
Quoted 5 lines · Alan Cox

Thats a bug in our current vm structures, like the others - inability to throw out page tables, inability to find memory easily, inability to move blocks to allocate large areas in a target space, inability to handle large user spaces etc.

Quoted 6 lines

What? None of those are bugs, they are features.

Complexity is not a goal to be reached. Complexity is something to be avoided at all cost. If you don't believe me, look at NT.

Linus

Make things as simple as possible, but no simpler.

Do you really think "inability to handle large user spaces" or "inability to find memory easily" are features?

Perhaps all the current solutions have been overly complex, however, that doesn't mean there is no simple way to accomplish the same thing.

--
To unsubscribe, send a message with 'unsubscribe linux-mm my@address' in the body to [email protected]. For more info on Linux MM,
see: http://humbolt.geo.uu.nl/Linux-MM/

#166 lore raw

Re: MM deadlock [was: Re: arca-vm-8...]

Quoted 3 lines · Gregory Maxwell

Do you really think "inability to handle large user spaces" or "inability to find memory easily" are features?

Alan is just full of it on both accounts.

We handle large user space with no problem, and we find free memory no problem.

Linus

--
To unsubscribe, send a message with 'unsubscribe linux-mm my@address' in the body to [email protected]. For more info on Linux MM,
see: http://humbolt.geo.uu.nl/Linux-MM/

#167 lore raw

Re: MM deadlock [was: Re: arca-vm-8...]

Quoted 9 lines · Gregory Maxwell
Quoted 3 lines

Do you really think "inability to handle large user spaces" or "inability to find memory easily" are features?

Alan is just full of it on both accounts.

We handle large user space with no problem, and we find free memory no problem.

Oh good, whats the configuration setting for a 4Gig Xeon box. I've got people dying to know. So I'm not full of it.

Its not "inability to find memory easily" in my original comments either. In context its about the expense sometimes of finding which things to swap.

Note that I don't disagree with Linus. Every time Linus can say "but you don't need that because [sensible solution]" is a bigger win than adding a ton of special case code.

Right now

o I can't run 3Gig user processes on a 4Gig Xeon
o I can't support devices needing large physically linear blocks of
memory

#1 is happening today
#2 is happening a bit now - although its a lesser problem (unable to allocate ISA DMA buffer..) thats the visible part of a bigger issue. Some people don't bother with scatter gather DMA - real examples:
S3 Sonic Vibes - linux can't support its wavetable (wants 4Mb linear)
Zoran based capture chips - physically linear capture/masks Matrox Meteor frame grabber - physically linear grabbing

So 2.3 needs to be able to allocate large linear physical spaces - not neccessarily efficiently either. These are all occasional grabs of memory.

Alan

--
To unsubscribe, send a message with 'unsubscribe linux-mm my@address' in the body to [email protected]. For more info on Linux MM,
see: http://humbolt.geo.uu.nl/Linux-MM/

#168 lore raw

Re: MM deadlock [was: Re: arca-vm-8...]

Quoted 9 lines · Alan Cox

I can't support devices needing large physically linear blocks of memory ...

S3 Sonic Vibes - linux can't support its wavetable (wants 4Mb linear)
Zoran based capture chips - physically linear capture/masks Matrox Meteor frame grabber - physically linear grabbing

So 2.3 needs to be able to allocate large linear physical spaces - not neccessarily efficiently either. These are all occasional grabs of memory.

Yes---physical addressing for I/O is reality. Some devices may not implement scatter-gather, and some may do so and yet still be afflicted with high latencies for descriptor fetching and the like.

If allocations are rare, it doesn't seem that unreasonable to actually do physical copies, push stuff bodily out of the way to construct a new contiguous region. Or else a separate allocator, like the present-day bigphysarea.

Cheers,
Peter Monta [email protected]
Imedia Corp.
--
To unsubscribe, send a message with 'unsubscribe linux-mm my@address' in the body to [email protected]. For more info on Linux MM,
see: http://humbolt.geo.uu.nl/Linux-MM/

#169 lore raw

Re: MM deadlock [was: Re: arca-vm-8...]

In reply to Alan Cox
Quoted 3 lines · Alan Cox

Oh good, whats the configuration setting for a 4Gig Xeon box. I've got people dying to know. So I'm not full of it.

Oh, the answer is very simple: it's not going to happen.

EVER.

You need more that 32 bits of address space to handle that kind of memory. This is not something I'm going to discuss further. If people want to use more than 2GB of memory, they have exactly two options with Linux:

- get a machine with reasonable address spaces. Right now that's either alpha or sparc64, in the not too distant future it will be merced.
- use the extra memory as a ram-disk (possibly memory-mappable, but even that I consider unlikely)

This is not negotiable.

Linus

--
To unsubscribe, send a message with 'unsubscribe linux-mm my@address' in the body to [email protected]. For more info on Linux MM,
see: http://humbolt.geo.uu.nl/Linux-MM/

#170 lore raw

Re: MM deadlock [was: Re: arca-vm-8...]

In reply to Linus Torvalds
Quoted 11 lines · Alan Cox
Quoted 5 lines

Thats a bug in our current vm structures, like the others - inability to throw out page tables, inability to find memory easily, inability to move blocks to allocate large areas in a target space, inability to handle large user spaces etc.

What? None of those are bugs, they are features.

Complexity is not a goal to be reached. Complexity is something to be avoided at all cost. If you don't believe me, look at NT.

A feature becomes a bug at the point it becomes a problem. Right now there is a continual background DMA rumbling. That one at least needs solving.

Being able to throw out page tables is something that is going to be needed too. As far as I can see that does not mean complexity. The Linux VM is very clean in its page handling, there is almost nothing in the page tables that cannot be flushed or dumped to disk if need be.

There are real cases where grab large linear block is needed. Sadly the fact that NT and 98 support it will make this more not less common. The current PCI soundcards like the S3 SonicVibes aren't easily supportable in Linux because they require a 4Mb linear block. The Zoran video capture chipset (Trust, Iomega, and others) needs large linear blocks. Even I2O wants 32/64K linear chunks and thats designed to be "OS independant"

Its on my "please for 2.3" list not because the linear block problem is an elegance issue but because people are baning their heads on it. The large physical memory problem is there because people are already hitting it.

Alan

--
To unsubscribe, send a message with 'unsubscribe linux-mm my@address' in the body to [email protected]. For more info on Linux MM,
see: http://humbolt.geo.uu.nl/Linux-MM/

#171 lore raw

Re: MM deadlock [was: Re: arca-vm-8...]

Quoted 5 lines · Alan Cox

Being able to throw out page tables is something that is going to be needed too. As far as I can see that does not mean complexity. The Linux VM is very clean in its page handling, there is almost nothing in the page tables that cannot be flushed or dumped to disk if need be.

There _is_ a major problem: being able to swap out page tables means that the thing that swaps them out _has_ to own the mm semaphore.

That's the right thing to do anyway, but it means, for example, that the _only_ process that can page stuff out would be kswapd.

Who knows? Maybe I should just bite the bullet and make that the rule, then we could forget about all the extra recursive semaphore crap too. And it has other advantages - it can speed up the page fault handler (which right now has to get the kernel lock for certain situations).

Once that is done, paging out page tables is not really a problem.

Quoted 1 line

There are real cases where grab large linear block is needed.

Nobody has so far shown a reasonable implementation where this would be possible.

Linus

--
To unsubscribe, send a message with 'unsubscribe linux-mm my@address' in the body to [email protected]. For more info on Linux MM,
see: http://humbolt.geo.uu.nl/Linux-MM/

#172 lore raw

Re: MM deadlock [was: Re: arca-vm-8...]

Quoted 4 lines
Quoted 1 line

There are real cases where grab large linear block is needed.

Nobody has so far shown a reasonable implementation where this would be possible.

Thats as maybe. However someone needs to find a way to do it. Right now I can run a matrox meteor on netbsd,freebsd,openbsd,windows95, nt but not Linux

Thats not meant as a flippant remark - its something to be stuck on the 2.3 problem chart. Its just a question of who out there is sitting on the solution

--
To unsubscribe, send a message with 'unsubscribe linux-mm my@address' in the body to [email protected]. For more info on Linux MM,
see: http://humbolt.geo.uu.nl/Linux-MM/

#173 lore raw

Re: MM deadlock [was: Re: arca-vm-8...]

Quoted 2 lines · Alan Cox

Thats as maybe. However someone needs to find a way to do it. Right now I can run a matrox meteor on netbsd,freebsd,openbsd,windows95, nt but not Linux

If I understand well the problem is get more than 1<<maxorder contiguos phys pages in RAM. I think it should not too difficult to do a dirty hack to have such contiguos RAM without wait for 2.[34]. I could implement a alternate __get_big_pages that does some try to get many mem-areas of the maximal order contigous. Maybe it will not able to give you such contiguos memory (due mem fragmentation) but if it's possible it will give back it to you (_slowly_). Then you should use an aware free_big_pages() to give back the memory. That way the codebase (for people that doesn't need __get_big_pages in their device drivers) will be untouched (so no codebase stability issues).

Andrea Arcangeli

--
To unsubscribe, send a message with 'unsubscribe linux-mm my@address' in the body to [email protected]. For more info on Linux MM,
see: http://humbolt.geo.uu.nl/Linux-MM/

#174 lore raw

Re: MM deadlock [was: Re: arca-vm-8...]

Quoted 2 lines

If I understand well the problem is get more than 1<<maxorder contiguos phys pages in RAM. I think it should not too difficult to do a dirty hack

Yep. We are talking about 2->4Mb sized chunks. We are also talking about chunks that are allocated rarely - for example when you load wave data into the sound card, while you are capturing etc. So its blocks that can be slow to allocate, slow to free, so long as they are normal speed to access. That may make the problem a lot easier

Quoted 7 lines

alternate __get_big_pages that does some try to get many mem-areas of the maximal order contigous. Maybe it will not able to give you such contiguos memory (due mem fragmentation) but if it's possible it will give back it to you (_slowly_). Then you should use an aware free_big_pages() to give back the memory. That way the codebase (for people that doesn't need __get_big_pages in their device drivers) will be untouched (so no codebase stability issues).

That fact we effectively "poison" the various blocks of memory with locked down kernel objects is what makes this so tricky. It really needs some back pressure applied so that kernel allocations come from a limited number of maxorder blocks, at least except under exceptional circumstances.

I think its too tricky for 2.2 even as a later retrofit

--
To unsubscribe, send a message with 'unsubscribe linux-mm my@address' in the body to [email protected]. For more info on Linux MM,
see: http://humbolt.geo.uu.nl/Linux-MM/

#175 lore raw

Re: MM deadlock [was: Re: arca-vm-8...]

Quoted 9 lines · Alan Cox
Quoted 3 lines

If I understand well the problem is get more than 1<<maxorder contiguos phys pages in RAM. I think it should not too difficult to do a dirty hack

Yep. We are talking about 2->4Mb sized chunks. We are also talking about chunks that are allocated rarely - for example when you load wave data into the sound card, while you are capturing etc. So its blocks that can be slow to allocate, slow to free, so long as they are normal speed to access. That may make the problem a lot easier

How much of this problem can be solved with a ramfs that takes what you give it at boot time?

Signature · 5 lines
Garst
--
To unsubscribe, send a message with 'unsubscribe linux-mm my@address'
in the body to [email protected].  For more info on Linux MM,
see: http://humbolt.geo.uu.nl/Linux-MM/
#176 lore raw

Re: MM deadlock [was: Re: arca-vm-8...]

Quoted 2 lines

How much of this problem can be solved with a ramfs that takes what you give it at boot time?

Grabbing 4Mb for wave tables, and 4Mb for a matrox meteor at boot "just in case" is at the "you might as well run another OS" level of "supported" IMHO anyway. Its the right answer for any 2.2 retrofits

Alan

--
To unsubscribe, send a message with 'unsubscribe linux-mm my@address' in the body to [email protected]. For more info on Linux MM,
see: http://humbolt.geo.uu.nl/Linux-MM/

#177 lore raw

Re: MM deadlock [was: Re: arca-vm-8...]

In reply to Alan Cox
Quoted 11 lines · Alan Cox
Quoted 2 lines

If I understand well the problem is get more than 1<<maxorder contiguos phys pages in RAM. I think it should not too difficult to do a dirty hack

Yep. We are talking about 2->4Mb sized chunks. We are also talking about chunks that are allocated rarely

Quoted 4 lines

alternate __get_big_pages that does some try to get many mem-areas of the maximal order contigous. Maybe it will not able to give you such contiguos memory (due mem fragmentation) but if it's possible it will give back it to you (_slowly_).

Quoted 5 lines

That fact we effectively "poison" the various blocks of memory with locked down kernel objects is what makes this so tricky. It really needs some back pressure applied so that kernel allocations come from a limited number of maxorder blocks, at least except under exceptional circumstances.

We need a different memory allocator for that. Maybe it's time to dig up my zone allocator proposal (on my home page) and adapt it to something working.

Unfortunately I don't have the time to do that, so I'll leave the job to Alan or Stephen (who should have the time since they're with Red Hat)...

Quoted 1 line

I think its too tricky for 2.2 even as a later retrofit

Once the allocator is ready and stabilized, we might be able to retrofit it to 2.2. It's just a single module we need to touch...

cheers,

Rik -- If a Microsoft product fails, who do you sue?

+-------------------------------------------------------------------+
| Linux memory management tour guide.             [email protected] |
| Scouting Vries cubscout leader.     http://www.nl.linux.org/~riel |
+-------------------------------------------------------------------+

--
To unsubscribe, send a message with 'unsubscribe linux-mm my@address' in the body to [email protected]. For more info on Linux MM,
see: http://humbolt.geo.uu.nl/Linux-MM/

#178 lore raw

Re: MM deadlock [was: Re: arca-vm-8...]

In reply to Alan Cox
Quoted 7 lines · Alan Cox
Quoted 4 lines
Quoted 1 line

There are real cases where grab large linear block is needed.

Nobody has so far shown a reasonable implementation where this would be possible.

Thats as maybe. However someone needs to find a way to do it. Right now I can run a matrox meteor on netbsd,freebsd,openbsd,windows95, nt but not Linux

I donnot know of all these systems, but, AFAIR, FreeBSD does not guarantee the malloc_contig() function will succeed every time, after the system has been started (obviously for allocation > PAGE_SIZE).

If you tell me that some system XXX is able to quickly free Mega-Bytes of physical contiguous memory at any time when it is asked for such a brain-deaded allocation, then for sure, I will never use system XXX, because this magic behaviour seems not to be possible without some paranoid VM policy that may affect badly performances for normal stuff.

Now, I agree that it is theorically possible to free a large contiguous physical memory on most systems at any time, by flushing caches and moving virtual pages that are only virtually referenced and this move will not changes their virtual reference(s).

Quoted 3 lines

Thats not meant as a flippant remark - its something to be stuck on the 2.3 problem chart. Its just a question of who out there is sitting on the solution.

Anything that requires more that 1 PAGE of physical memory at a time on running systems is a very bad thing in my opinion. The PAGE is the only required granularity of physical memory you should need on a virtual memory system. If you ever need more, then you break simplicity and go straight-away to complexity and cross-fingered behaviours. The only exception is at system start-up, where it is still time for pooling every-thing that needs so. I am not going to change my mind on this topic and I donnot care of crappy 'Designed for Windows' things.

Regards,
Gerard.

--
To unsubscribe, send a message with 'unsubscribe linux-mm my@address' in the body to [email protected]. For more info on Linux MM,
see: http://humbolt.geo.uu.nl/Linux-MM/

#179 lore raw

Re: MM deadlock [was: Re: arca-vm-8...]

Quoted 2 lines · Gerard Roudier

If you tell me that some system XXX is able to quickly free Mega-Bytes of physical contiguous memory at any time when it is asked for such a

Noone said it has to happen quickly, it's entirely useful even if the calling process (and possibly others) will sleep for 10secs. These allocations are very uncommon, but nevertheless sometimes necessary for some device (drivers).

Quoted 3 lines

brain-deaded allocation, then for sure, I will never use system XXX, because this magic behaviour seems not to be possible without some paranoid VM policy that may affect badly performances for normal stuff.

You may well call the devices that need this broken, the problem is that they are in rather widespread use.

If we don't find an algorithm that doesn't affect preformance for the normal stuff, (why would something like selecting
a memory region and forcing everything that's currently in the way to be swapped out not work?), then we should probably have a special pool for these "perverse" mappings.

But I think there's a rather generic problem: how are you going to support 32bit PCI busmasters in machines with more than 4Gig main memory? It's conceptually the same as how are you going to support ISA DMA with more than 16Meg main memory.

32bit only PCI busmasters are very common these days, I don't know a single PCI soundcard that can do 64bit master (or even slave) cycles. Also, all PCI soundcards I know which have a hardware wavetable synth (without sample ROM) require ridiculously large contiguous allocations (>= 1M) for the synth to work.

Quoted 2 lines

Anything that requires more that 1 PAGE of physical memory at a time on running systems is a very bad thing in my opinion. The PAGE is the only

Ok, then remove any soundcard from your system. That might be acceptable for you, but probably not for 90% of the Linux users.

Tom
--
To unsubscribe, send a message with 'unsubscribe linux-mm my@address' in the body to [email protected]. For more info on Linux MM,
see: http://humbolt.geo.uu.nl/Linux-MM/

#180 lore raw

Re: MM deadlock [was: Re: arca-vm-8...]

Quoted 9 lines · Thomas Sailer
Quoted 2 lines · Gerard Roudier

If you tell me that some system XXX is able to quickly free Mega-Bytes of physical contiguous memory at any time when it is asked for such a

Noone said it has to happen quickly, it's entirely useful even if the calling process (and possibly others) will sleep for 10secs. These allocations are very uncommon, but nevertheless sometimes necessary for some device (drivers).

I suggest to allow some application program to decide what stuff to victimize and to be able to tell the kernel about, but not to ask the kernel for doing the bad work for you and then critisize it.

Quoted 6 lines
Quoted 3 lines

brain-deaded allocation, then for sure, I will never use system XXX, because this magic behaviour seems not to be possible without some paranoid VM policy that may affect badly performances for normal stuff.

You may well call the devices that need this broken, the problem is that they are in rather widespread use.

There are bunches of things that are widespread used nowadays and that should have disappeard since years if people were a bit more concerned by technical and progress considerations.

For example, it seems that 32 bits systems are not enough to provide a flat virtual addressing space far larger than the physical address space needed for applications (that was the primary goal of virtual memory invention). If we were powered a bit more by technical considerations, we should drop support of 32 bits systems immediately since as you know 64 bits systems are available since years and Linux supports them quite well.

Each time we add support or maintain support of crap, we just encourage crap and allow the mediocrity to last longer that it really deserves.

A device that requires more contiguous space than 1 PAGE for its support is crap. Because designers spared peanuts by not implementing address translation tables, we just have to complete their work by complexifying O/Ses. The win is 0.02 euro of silicium for them but lots of time wasted by O/Ses guys to support the crap.

Quoted 10 lines

If we don't find an algorithm that doesn't affect preformance for the normal stuff, (why would something like selecting
a memory region and forcing everything that's currently in the way to be swapped out not work?), then we should probably have a special pool for these "perverse" mappings.

But I think there's a rather generic problem: how are you going to support 32bit PCI busmasters in machines with more than 4Gig main memory? It's conceptually the same as how are you going to support ISA DMA with more than 16Meg main memory.

What the ratio of machines that need 4 GB of more for doing their work?
How much does they cost?
What can we do, if some people that have such machines want to use IO controllers that are not able to DMA the whole physical space? We just may suggest them to learn or to get help from a psychiatric, but we should not accept to waste time trying to make the crap work less worse.

Quoted 5 lines

32bit only PCI busmasters are very common these days, I don't know a single PCI soundcard that can do 64bit master (or even slave) cycles. Also, all PCI soundcards I know which have a hardware wavetable synth (without sample ROM) require ridiculously large contiguous allocations (>= 1M) for the synth to work.

Are you sure a soundcard is really required for systems that run with GBs of memory?

Quoted 5 lines
Quoted 2 lines

Anything that requires more that 1 PAGE of physical memory at a time on running systems is a very bad thing in my opinion. The PAGE is the only

Ok, then remove any soundcard from your system. That might be acceptable for you, but probably not for 90% of the Linux users.

A real Linux user is able to make a custom kernel that incorporates some driver at boot-up, and can live with that. The ones that are whining about their PinkSocket O/S having problem to load the sound driver module at run-time is another busyness in my opinion.

Regards,
Gerard.

--
To unsubscribe, send a message with 'unsubscribe linux-mm my@address' in the body to [email protected]. For more info on Linux MM,
see: http://humbolt.geo.uu.nl/Linux-MM/

#181 lore raw

Re: MM deadlock [was: Re: arca-vm-8...]

Quoted 2 lines · Gerard Roudier

What can we do, if some people that have such machines want to use IO controllers that are not able to DMA the whole physical space?

Does it matter for a soundcard that just needs its 64k buffer allocated on driver open and then be happy for the rest of its life?

Fact is that soundcard design was broken since its inception and I've given up hope that someone in that business sees some light 8-)

Quoted 2 lines

Are you sure a soundcard is really required for systems that run with GBs of memory?

Have you seen a PC without one lately?
Allmost all Linux guys I know want to listen to MP3 files 8-)

Tom
--
To unsubscribe, send a message with 'unsubscribe linux-mm my@address' in the body to [email protected]. For more info on Linux MM,
see: http://humbolt.geo.uu.nl/Linux-MM/

#182 lore raw

Re: MM deadlock [was: Re: arca-vm-8...]

In reply to Gerard Roudier

-----BEGIN PGP SIGNED MESSAGE-----

why don'y you spin off your own verion of Linux that only supports that hardware that you consider "good enough" and let the rest of us go back to making the system work in the real world where lots of things are not "good enough" by someones definition.

David Lang

"If users are made to understand that the system administrator's job is to make computers run, and not to make them happy, they can, in fact, be made happy most of the time. If users are allowed to believe that the system administrator's job is to make them happy, they can, in fact, never be made happy."
- -Paul Evans (as quoted by Barb Dijker in "Managing Support Staff", LISA '97)

Quoted 91 lines · Gerard Roudier

Date: Tue, 26 Jan 1999 21:48:59 +0100 (MET)
From: Gerard Roudier <[email protected]>
To: Thomas Sailer <[email protected]>
Cc: [email protected], [email protected]
Subject: Re: MM deadlock [was: Re: arca-vm-8...]

Quoted 9 lines · Thomas Sailer
Quoted 2 lines · Gerard Roudier

If you tell me that some system XXX is able to quickly free Mega-Bytes of physical contiguous memory at any time when it is asked for such a

Noone said it has to happen quickly, it's entirely useful even if the calling process (and possibly others) will sleep for 10secs. These allocations are very uncommon, but nevertheless sometimes necessary for some device (drivers).

I suggest to allow some application program to decide what stuff to victimize and to be able to tell the kernel about, but not to ask the kernel for doing the bad work for you and then critisize it.

Quoted 6 lines
Quoted 3 lines

brain-deaded allocation, then for sure, I will never use system XXX, because this magic behaviour seems not to be possible without some paranoid VM policy that may affect badly performances for normal stuff.

You may well call the devices that need this broken, the problem is that they are in rather widespread use.

There are bunches of things that are widespread used nowadays and that should have disappeard since years if people were a bit more concerned by technical and progress considerations.

For example, it seems that 32 bits systems are not enough to provide a flat virtual addressing space far larger than the physical address space needed for applications (that was the primary goal of virtual memory invention). If we were powered a bit more by technical considerations, we should drop support of 32 bits systems immediately since as you know 64 bits systems are available since years and Linux supports them quite well.

Each time we add support or maintain support of crap, we just encourage crap and allow the mediocrity to last longer that it really deserves.

A device that requires more contiguous space than 1 PAGE for its support is crap. Because designers spared peanuts by not implementing address translation tables, we just have to complete their work by complexifying O/Ses. The win is 0.02 euro of silicium for them but lots of time wasted by O/Ses guys to support the crap.

Quoted 10 lines

If we don't find an algorithm that doesn't affect preformance for the normal stuff, (why would something like selecting
a memory region and forcing everything that's currently in the way to be swapped out not work?), then we should probably have a special pool for these "perverse" mappings.

But I think there's a rather generic problem: how are you going to support 32bit PCI busmasters in machines with more than 4Gig main memory? It's conceptually the same as how are you going to support ISA DMA with more than 16Meg main memory.

What the ratio of machines that need 4 GB of more for doing their work?
How much does they cost?
What can we do, if some people that have such machines want to use IO controllers that are not able to DMA the whole physical space? We just may suggest them to learn or to get help from a psychiatric, but we should not accept to waste time trying to make the crap work less worse.

Quoted 5 lines

32bit only PCI busmasters are very common these days, I don't know a single PCI soundcard that can do 64bit master (or even slave) cycles. Also, all PCI soundcards I know which have a hardware wavetable synth (without sample ROM) require ridiculously large contiguous allocations (>= 1M) for the synth to work.

Are you sure a soundcard is really required for systems that run with GBs of memory?

Quoted 5 lines
Quoted 2 lines

Anything that requires more that 1 PAGE of physical memory at a time on running systems is a very bad thing in my opinion. The PAGE is the only

Ok, then remove any soundcard from your system. That might be acceptable for you, but probably not for 90% of the Linux users.

A real Linux user is able to make a custom kernel that incorporates some driver at boot-up, and can live with that. The ones that are whining about their PinkSocket O/S having problem to load the sound driver module at run-time is another busyness in my opinion.

Quoted 9 lines

Regards,
Gerard.

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
Please read the FAQ at http://www.tux.org/lkml/

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQEVAwUBNq5c+T7msCGEppcbAQGiwQf9FwZmLH7ZItRrlqz/uijqbH8xDdyZW8QG bQ/t57UMRhsfnBprs1AT3Iy+3MEZ7oUiUkeDnH5vYm1HvKwYGBW9Derf3Fk4GMZk S86V1q/kYS3JKN+kXtRz4IOjqgZXzajPCKF8IQhGmD+mBO1gFMomFSqb62161HJj reHwBt6bbHrP/P7RzKh4SjvZ7vMZy2aZdSCzEWunn5oj9Bazj98fAsluCEwzbgcj hgfR4DJLUgbqDMM1ewWjnBAqwQrf9hcjblZQrEMGwvtt/ZAQ/Xjba0Akx9NoxIU8 ZYqy2j7AgiYpT/cVArhoLyJIoes1FqtOrcqjKVHgLSRZPgzQUpzBCQ== =eN9Y
-----END PGP SIGNATURE-----

--
To unsubscribe, send a message with 'unsubscribe linux-mm my@address' in the body to [email protected]. For more info on Linux MM,
see: http://humbolt.geo.uu.nl/Linux-MM/

#183 lore raw

Re: MM deadlock [was: Re: arca-vm-8...]

In reply to Gerard Roudier

Hi,

Quoted 2 lines · Gerard Roudier

I suggest to allow some application program to decide what stuff to victimize and to be able to tell the kernel about,

Yep, there is already a madvise() fuction in most modern unixen: it is especially useful for giving cache hints.

Quoted 3 lines

There are bunches of things that are widespread used nowadays and that should have disappeard since years if people were a bit more concerned by technical and progress considerations.

Yes. I see what you mean. We should immediately remove Linux support for FAT filesystems, the ISA bus and 8086 virtual mode.

Not.

Quoted 4 lines

For example, it seems that 32 bits systems are not enough to provide a flat virtual addressing space far larger than the physical address space needed for applications (that was the primary goal of virtual memory invention).

*One* of the primary goals. The other was protected multitasking. The x86 architecture today is perfectly well capable of supporting mutliple 32-bit address spaces within a 36 bit (64GB) physical address space, and large multiuser environments would benefit enormously from such an environment.

Quoted 2 lines

A device that requires more contiguous space than 1 PAGE for its support is crap.

So? IDE is crap because it doesn't support multiple outstanding commands. If you honestly believe that this means we should remove IDE support from the kernel, then you are living on another planet where getting real work done by real users doesn't matter. Fact is, we _can_ support this stuff, and users want us to.

--Stephen
--
To unsubscribe, send a message with 'unsubscribe linux-mm my@address' in the body to [email protected]. For more info on Linux MM,
see: http://humbolt.geo.uu.nl/Linux-MM/

#184 lore raw

Re: MM deadlock [was: Re: arca-vm-8...]

Quoted 5 lines · Stephen C. Tweedie

Hi,

On Tue, 26 Jan 1999 21:48:59 +0100 (MET), Gerard Roudier <[email protected]> said:

[ ... ]

Quoted 8 lines
Quoted 3 lines

There are bunches of things that are widespread used nowadays and that should have disappeard since years if people were a bit more concerned by technical and progress considerations.

Yes. I see what you mean. We should immediately remove Linux support for FAT filesystems, the ISA bus and 8086 virtual mode.

Not.

AFAIK, it is what M$$ is intending to do. If the Linux strategy is to be the greatest O/S for obsolete hardware, we can support that stuff years after M$$ has dropped the support of it.

Quoted 10 lines
Quoted 4 lines

For example, it seems that 32 bits systems are not enough to provide a flat virtual addressing space far larger than the physical address space needed for applications (that was the primary goal of virtual memory invention).

*One* of the primary goals. The other was protected multitasking. The x86 architecture today is perfectly well capable of supporting mutliple 32-bit address spaces within a 36 bit (64GB) physical address space, and large multiuser environments would benefit enormously from such an environment.

64 GB of memory needs 36 address lines. It is obvious to handle that on 64 bit machines that exists since _years_, but very painfull on 32 bit addressing machines. Implementing complex algorithms for handling this stupidity is stupidity by itself. 32 bit VM architecture is a 25 years old technology. The fact that it still exists nowadays is because the market place was more concerned by $$ than by real progress. If the PC market had started in 1980, then it might have happen that modern PCs would use rather Z80s type processors at something like 1 GHZ that 32 bit PII at 400 MHz.

Just thinking of the ridiculous price fast 32 bits processors are sold today is the proof, in my opinion, that 32 bit is definitely _dead_. People that still want to make efforts for that stuff are just stupid, in my opinion.

Quoted 4 lines
Quoted 2 lines

A device that requires more contiguous space than 1 PAGE for its support is crap.

So? IDE is crap because it doesn't support multiple outstanding

Indeed.

Quoted 4 lines

commands. If you honestly believe that this means we should remove IDE support from the kernel, then you are living on another planet where getting real work done by real users doesn't matter. Fact is, we _can_ support this stuff, and users want us to.

I live on the euro-planet and yours is just a satellit. :-))

Regards,
Gerard.

--
To unsubscribe, send a message with 'unsubscribe linux-mm my@address' in the body to [email protected]. For more info on Linux MM,
see: http://humbolt.geo.uu.nl/Linux-MM/

#185 lore raw

Re: MM deadlock [was: Re: arca-vm-8...]

In reply to Gerard Roudier

Hi,

Quoted 5 lines · Gerard Roudier

If you tell me that some system XXX is able to quickly free Mega-Bytes of physical contiguous memory at any time when it is asked for such a brain-deaded allocation, then for sure, I will never use system XXX, because this magic behaviour seems not to be possible without some paranoid VM policy that may affect badly performances for normal stuff.

It is really not hard to reserve a certain amount of memory (up to some fraction, say 25% or 50% of physical memory) for use only by pagable allocations. Most desktop boxes will _not_ require more than 50% of memory for locked kernel pages. Recovering any given range of contiguous pages from that pagable region may be expensive but will _always_ be possible, and given that it will usually be a one-off expense during driver setup, there is no reason why we cannot support it.

--Stephen
--
To unsubscribe, send a message with 'unsubscribe linux-mm my@address' in the body to [email protected]. For more info on Linux MM,
see: http://humbolt.geo.uu.nl/Linux-MM/

#186 lore raw

Re: MM deadlock [was: Re: arca-vm-8...]

Quoted 2 lines

It is really not hard to reserve a certain amount of memory (up to some fraction, say 25% or 50% of physical memory) for use only by pagable

I was guessing 25%.

Quoted 6 lines

allocations. Most desktop boxes will _not_ require more than 50% of memory for locked kernel pages. Recovering any given range of contiguous pages from that pagable region may be expensive but will _always_ be possible, and given that it will usually be a one-off expense during driver setup, there is no reason why we cannot support it.

Something like

Chop memory into 4Mb sized chunks that hold the perfectly normal and existing pages and buddy memory allocator. Set a flag on 25-33% of them to a max of say 10 and for <12Mb boxes simply say "tough".

The performance impact of that on free page requests seems to be pretty minimal. In actual fact it wil help performance in some cases since the machine can't easily be killed by going out of non kernel space allocations - the 25% is also a "can do work" sanity check.

Alan

--
To unsubscribe, send a message with 'unsubscribe linux-mm my@address' in the body to [email protected]. For more info on Linux MM,
see: http://humbolt.geo.uu.nl/Linux-MM/

#187 lore raw

Re: MM deadlock [was: Re: arca-vm-8...]

Quoted 4 lines · Alan Cox

Chop memory into 4Mb sized chunks that hold the perfectly normal and existing pages and buddy memory allocator. Set a flag on 25-33% of them to a max of say 10 and for <12Mb boxes simply say "tough".

We might also want to flag non-cached and dma areas too. That way we can hand cached, non-dma memory to the kernel, use non-cached stuff for buffer memory and page tables, keeping dma-able memory relatively clean and keeping the kernel (and critical pages) fast.

Maybe the execute bit should also have some influence on placement. Having executable text in uncached memory may well give a larger performance penalty than putting user data there...

In my zone allocator design I have outlined 5 or 7 (depending on how you look at it) different memory usages for the Linux kernel. You might want to check that out to see if you've overlooked something:

http://www.nl.linux.org/~riel/zone-alloc.html

Quoted 5 lines

The performance impact of that on free page requests seems to be pretty minimal. In actual fact it wil help performance in some cases since the machine can't easily be killed by going out of non kernel space allocations - the 25% is also a "can do work" sanity check.

It's very well possible to keep separate free memory stats and free memory from the different area's as needed.

cheers,

Rik -- If a Microsoft product fails, who do you sue?

+-------------------------------------------------------------------+
| Linux memory management tour guide.             [email protected] |
| Scouting Vries cubscout leader.     http://www.nl.linux.org/~riel |
+-------------------------------------------------------------------+

--
To unsubscribe, send a message with 'unsubscribe linux-mm my@address' in the body to [email protected]. For more info on Linux MM,
see: http://humbolt.geo.uu.nl/Linux-MM/

#188 lore raw

Re: MM deadlock [was: Re: arca-vm-8...]

In reply to Alan Cox
Quoted 5 lines · Alan Cox

Something like

Chop memory into 4Mb sized chunks that hold the perfectly normal and existing pages and buddy memory allocator. Set a flag on 25-33% of them to a max of say 10 and for <12Mb boxes simply say "tough".

this is conceptually 'boot-time allocation of big buffers' by splitting all available memory into two pieces:

size_kernel: generic memory
size_user: only swappable

(size_kernel+size_user = ca. size_allmemory)

This still doesnt solve the 'what if we need more big buffers than size_user' and 'what if we need kernel memory more than size_kernel' questions, and both are valid.

another (2.3 issue) approach could be to make two garantees for 'pinned-down kernel allocations':

1) either they will be deallocated after some definit timeout
2) or they can be explicitly deallocated via special mechanizms

this enables us to implement a 100% algorithm of 'moving' kernel-space objects, without having to do kernel-space paging or other runtime costs. Most 'pinned down' objects already have a specific timeout (buffer heads, used dentries) or can already be 'flushed'. (eg specific unused dentry-cache members, and other cached but freeable kernel-space objects).

the mechanizm is to 'ban' kernel-allocations from certain pages either passively (by waiting on the objects in question), or by actively moving them. The 'flushing' part is easy and we mainly already use it to reclaim memory.

the toughest part is the 'moving' stuff, which is not yet present and hard/impossible to implement in a clean and maintainable way. We need this eg. for sockets, files, (not inodes fortunately), task structures, vmas, mms, signal structures, etc. It really feels like a rewrite that needs a very good architecture to be successful, ie. we _have to_ guarantee 'correctness' automatically somehow to not let this develop into a mess. Also, it must have only very limited 'subsystem-side' complexity to not hinder development. Eg. in the debugging version we could have a per-allocation timer that warns us if we havent 'unused' that particular object within a given timeout. Dont know. It's tough.

but iff this mechanizm is present, we could 'ban' allocations from whatever physical page in the system (this isnt much different from all-VM solutions, they have to wait for swapouts too anyway, but is a heck better and faster wrt. mappings issues). This is very generic and does not presume any 'split' between usage types. This is not at all limited to 4m sections or whatever, and certainly works on any Linux system even 4M RAM boxes, and it's still possible to use up all memory for kernel allocations eg. for dedicated router boxes.

yes it restricts and complicates the way kernel subsystems can allocate buffers, but we _have_ to do that iff we want to solve the problem 100%.

-- mingo

--
To unsubscribe, send a message with 'unsubscribe linux-mm my@address' in the body to [email protected]. For more info on Linux MM,
see: http://humbolt.geo.uu.nl/Linux-MM/

#189 lore raw

Re: MM deadlock [was: Re: arca-vm-8...]

Quoted 12 lines · Alan Cox
Quoted 6 lines

Something like

Chop memory into 4Mb sized chunks that hold the perfectly normal and existing pages and buddy memory allocator. Set a flag on 25-33% of them to a max of say 10 and for <12Mb boxes simply say "tough".

this is conceptually 'boot-time allocation of big buffers' by splitting all available memory into two pieces:

Quoted 8 lines

size_kernel: generic memory
size_user: only swappable

(size_kernel+size_user = ca. size_allmemory)

This still doesnt solve the 'what if we need more big buffers than size_user' and 'what if we need kernel memory more than size_kernel' questions, and both are valid.

Solved by reboot.

Quoted 3 lines

the toughest part is the 'moving' stuff, which is not yet present and hard/impossible to implement in a clean and maintainable way. We need this eg. for sockets, files, (not inodes fortunately), task structures, vmas,

What's the benefit? If you need big chunks of physical memory, then you obviously are willing to sacrifice efficient use of every last byte.

Quoted 2 lines

yes it restricts and complicates the way kernel subsystems can allocate buffers, but we _have_ to do that iff we want to solve the problem 100%.

So for that last 10% of "solve" we introduce a lot of complexity into every subsystem?

--
To unsubscribe, send a message with 'unsubscribe linux-mm my@address' in the body to [email protected]. For more info on Linux MM,
see: http://humbolt.geo.uu.nl/Linux-MM/

#190 lore raw

Re: MM deadlock [was: Re: arca-vm-8...]

Quoted 4 lines
Quoted 3 lines

the toughest part is the 'moving' stuff, which is not yet present and hard/impossible to implement in a clean and maintainable way. We need this eg. for sockets, files, (not inodes fortunately), task structures, vmas,

Quoted 8 lines

What's the benefit? If you need big chunks of physical memory, then you obviously are willing to sacrifice efficient use of every last byte.

Quoted 2 lines

yes it restricts and complicates the way kernel subsystems can allocate buffers, but we _have_ to do that iff we want to solve the problem 100%.

So for that last 10% of "solve" we introduce a lot of complexity into every subsystem?

We don't need to solve the 100% case. Simply being sure we can (slowly) allocate up to 25% of RAM in huge chunks is going to be enough. Good point Ingo on one thing I'd missed - the big chunks themselves need some kind of handles since the moment we hand out 512K chunks we may not be able to shuffle and get a 4Mb block

--
To unsubscribe, send a message with 'unsubscribe linux-mm my@address' in the body to [email protected]. For more info on Linux MM,
see: http://humbolt.geo.uu.nl/Linux-MM/

#191 lore raw

Re: MM deadlock [was: Re: arca-vm-8...]

Hi,

Quoted 5 lines · On Tue, 26 Jan 1999 15:46:23 +0000 (GMT), [email protected] (Alan Cox)…

We don't need to solve the 100% case. Simply being sure we can (slowly) allocate up to 25% of RAM in huge chunks is going to be enough. Good point Ingo on one thing I'd missed - the big chunks themselves need some kind of handles since the moment we hand out 512K chunks we may not be able to shuffle and get a 4Mb block

The idea was to decide what region to hand out, _then_ to clear it. Standard best-fit algorithms apply when carving up the region.

--Stephen
--
To unsubscribe, send a message with 'unsubscribe linux-mm my@address' in the body to [email protected]. For more info on Linux MM,
see: http://humbolt.geo.uu.nl/Linux-MM/

#192 lore raw

Re: MM deadlock [was: Re: arca-vm-8...]

Quoted 5 lines

Hi,

On Tue, 26 Jan 1999 15:46:23 +0000 (GMT), [email protected] (Alan Cox) said:

Quoted 8 lines
Quoted 5 lines

We don't need to solve the 100% case. Simply being sure we can (slowly) allocate up to 25% of RAM in huge chunks is going to be enough. Good point Ingo on one thing I'd missed - the big chunks themselves need some kind of handles since the moment we hand out 512K chunks we may not be able to shuffle and get a 4Mb block

The idea was to decide what region to hand out, _then_ to clear it. Standard best-fit algorithms apply when carving up the region.

If clearing involves remapping kernel address space, then its a rather complex process.
kmalloc
give virt_to_bus to device
...
remap

--
To unsubscribe, send a message with 'unsubscribe linux-mm my@address' in the body to [email protected]. For more info on Linux MM,
see: http://humbolt.geo.uu.nl/Linux-MM/

#193 lore raw

Re: MM deadlock [was: Re: arca-vm-8...]

Hi,

Quoted 5 lines · On Sat, 30 Jan 1999 00:01:00 -0700 (MST), [email protected] said:
Quoted 2 lines

The idea was to decide what region to hand out, _then_ to clear it. Standard best-fit algorithms apply when carving up the region.

If clearing involves remapping kernel address space, then its a rather complex process.

No, that is the whole point behind restricting such allocations to a zone containing only swappable objects. There will be no non-relocatable objects there, and we can simply swap out each page in the selected contiguous zone.

_If_ we expect to do this often then we will want to keep the relocated pages in memory, but for solving the current problem --- driver initialisation --- that is not so important and we can rely on the existing page swap code to just get rid of the data which is in the way.

--Stephen
--
To unsubscribe, send a message with 'unsubscribe linux-mm my@address' in the body to [email protected]. For more info on Linux MM,
see: http://humbolt.geo.uu.nl/Linux-MM/

#194 lore raw

Re: MM deadlock [was: Re: arca-vm-8...]

In reply to [email protected]
Quoted 2 lines · On Tue, 26 Jan 1999 [email protected] wrote:

What's the benefit? If you need big chunks of physical memory, then you obviously are willing to sacrifice efficient use of every last byte.

no, what i want to have is support for on-demand shared-physical-memory hardware. Resource management. Alan has listed a few examples, and the list is not expected to get smaller. You are right, if we want to have big chunks of physical memory then we'll allocate it on reboot.

i dont think it's correct to say: 'anything that cannot be segmented in the physical memory space with page granularity, is considered to be broken in this regard and is not guaranteed to be 100% supported by the Linux architecture'.

Quoted 5 lines
Quoted 2 lines

yes it restricts and complicates the way kernel subsystems can allocate buffers, but we _have_ to do that iff we want to solve the problem 100%.

So for that last 10% of "solve" we introduce a lot of complexity into every subsystem?

no, as i pointed it out:

Quoted 2 lines

Also, it must have only very limited 'subsystem-side' complexity to not hinder development. [...]

plus, i'd like to point out that if we do something, we preferredly want to do it 100% correct, especially if the 'packet loss' is visible by user-space as well. But i'm not at all requesting it:

Quoted 2 lines

the toughest part is the 'moving' stuff, which is not yet present and hard/impossible to implement in a clean and maintainable way.

       ^^^^^^^^^^---(this might as well be the case)

-- mingo

--
To unsubscribe, send a message with 'unsubscribe linux-mm my@address' in the body to [email protected]. For more info on Linux MM,
see: http://humbolt.geo.uu.nl/Linux-MM/

#195 lore raw

Re: MM deadlock [was: Re: arca-vm-8...]

Quoted 4 lines

i dont think it's correct to say: 'anything that cannot be segmented in the physical memory space with page granularity, is considered to be broken in this regard and is not guaranteed to be 100% supported by the Linux architecture'.

Sure. But let's keep in mind that paging is designed to avoid memory fragmentation, and big chunks mean you don't care about some minor loss of usable memory. If you have a 4G phys memory and need big linear pieces, it is far better to waste 3.9 meg by aligning end of data, then to complicate all memory allocation techniques in kernel so you don't waste it. In fact you'd probably want a simplified slab
kmalloc:
if size is 4meg allocate a 4meg chunk from 4meg list else if size< 4 meg
either allocate a new 4 meg chunk and take space from it or find partially used 4 meg chunk with enough space in it.

so you might have a list of partially used 4meg chunks lying about wasting some space, but ...

--
To unsubscribe, send a message with 'unsubscribe linux-mm my@address' in the body to [email protected]. For more info on Linux MM,
see: http://humbolt.geo.uu.nl/Linux-MM/

#196 lore raw

Re: MM deadlock [was: Re: arca-vm-8...]

In reply to MOLNAR Ingo

Hi,

Quoted 5 lines · MOLNAR Ingo

this is conceptually 'boot-time allocation of big buffers' by splitting all available memory into two pieces:

size_kernel: generic memory
size_user: only swappable

which is something we already need to do if we want to support 4G physical memory cleanly (ie. add support for anonymous and cache pages to be mapped on demand into the kernel's VA, rather than having the whole of physical memory virtually mapped at all times).

Quoted 2 lines

the toughest part is the 'moving' stuff, which is not yet present and hard/impossible to implement in a clean and maintainable way.

Not at all. We only need to be able to free swappable pages: only the swappable region will be usable for large contiguous allocations. We don't even need to move them: they can be paged back in afterwards. Obviously this is expensive if we expect to do it often, but in reality it is probably something we only need to do at driver setup time (or occasionally on driver open).

--Stephen
--
To unsubscribe, send a message with 'unsubscribe linux-mm my@address' in the body to [email protected]. For more info on Linux MM,
see: http://humbolt.geo.uu.nl/Linux-MM/

#197 lore raw

Re: MM deadlock [was: Re: arca-vm-8...]

In reply to MOLNAR Ingo
Quoted 9 lines
Quoted 5 lines

Something like

Chop memory into 4Mb sized chunks that hold the perfectly normal and existing pages and buddy memory allocator. Set a flag on 25-33% of them to a max of say 10 and for <12Mb boxes simply say "tough".

this is conceptually 'boot-time allocation of big buffers' by splitting all available memory into two pieces:

Quoted 8 lines

size_kernel: generic memory
size_user: only swappable

(size_kernel+size_user = ca. size_allmemory)

This still doesnt solve the 'what if we need more big buffers than size_user' and 'what if we need kernel memory more than size_kernel' questions, and both are valid.

It does not have to look like that.
I guess we need some size_user memory on some ports anyway (i386 above 1GB physical, sun4d above 2GB physical, sparc64 memory hotplug mem_map), but the rest should be general memory.
I bet forcing every single driver in the kernel which ever does some kmalloc to write hooks for relocating that buffer is utopic - it would add too much complexity everywhere. You often don't keep track where all you put pointers to the kmalloced area. So we'll have to live with some unmovable objects. But for the rest, the memory allocator can behave like this:
either have some chunks in which non-swappable memory is being allocated, or have some rule, e.g. that non-swappable memory grows from the lowest physical pages up.
Now, for a swappable get_free_pages you can allocate it from anywhere, but it would be good to give precedence to the memory outside of the current non-swappable region(s).
For non-swappable get_free_pages, you first try hard to allocate it from the current non-swappable region(s) (first looking if there are free pages, then look if there are swappable pages (and in the latter case either swap them off, or just move them to swappable regions)). If all non-swappable region(s) are full of non-swappable allocations, then you allocate another non-swappable region and swap-off/move some pages from there.
As long as we keep most of the objects swappable/movable, this will work well. If there are too many unmovable objects, it will lead to deadly fragmentation and this won't work.
But most of the objects are swappable/movable: everything referenced in user pages only, vmalloc regions, or can be easily flushed.

Cheers,
Jakub
___________________________________________________________________
Jakub Jelinek | [email protected] | http://sunsite.mff.cuni.cz
Administrator of SunSITE Czech Republic, MFF, Charles University
___________________________________________________________________
UltraLinux | http://ultra.linux.cz/ | http://ultra.penguin.cz/
Linux version 2.2.0 on a sparc64 machine (3958.37 BogoMips)
___________________________________________________________________
--
To unsubscribe, send a message with 'unsubscribe linux-mm my@address' in the body to [email protected]. For more info on Linux MM,
see: http://humbolt.geo.uu.nl/Linux-MM/