patch-2.1.117 linux/mm/vmscan.c

Next file: linux/net/core/dev.c
Previous file: linux/mm/swapfile.c
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v2.1.116/linux/mm/vmscan.c linux/mm/vmscan.c
@@ -529,6 +529,20 @@
 				    namings for POSIX.4 realtime scheduling
 				    priorities.  */
 
+	/*
+	 * 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;
+
 	init_swap_timer();
 	add_wait_queue(&kswapd_wait, &wait);
 	while (1) {
@@ -592,7 +606,7 @@
 	int retval = 1;
 
 	lock_kernel();
-	if (current->flags & PF_MEMALLOC) {
+	if (!(current->flags & PF_MEMALLOC)) {
 		current->flags |= PF_MEMALLOC;
 		do {
 			retval = do_try_to_free_page(gfp_mask);
@@ -600,7 +614,7 @@
 				break;
 			count--;
 		} while (count > 0);
-		current->flags &= PF_MEMALLOC;
+		current->flags &= ~PF_MEMALLOC;
 	}
 	unlock_kernel();
 	return retval;

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen, slshen@lbl.gov