[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] 2.4.9 si_swapinfo() speedup



the attached patch makes si_swapinfo() use the swapfile.c global page
accounting rather than walking the swapfiles to find the total and
free numbers.  Some folks have seen si_swapinfo() take an absurd amount
of time..

Rik hints at rumours of the global accounting being questionable in some
cases, perhaps more use of it would motivate that to be fixed :)

compiles, but totally untested.

- z

--- linux-2.4.9/mm/swapfile.c.swapinfo	Mon Sep 10 11:06:05 2001
+++ linux-2.4.9/mm/swapfile.c	Mon Sep 10 11:40:22 2001
@@ -877,27 +877,12 @@
 
 void si_swapinfo(struct sysinfo *val)
 {
-	unsigned int i;
-	unsigned long freeswap = 0;
-	unsigned long totalswap = 0;
+	swap_list_lock();
 
-	for (i = 0; i < nr_swapfiles; i++) {
-		unsigned int j;
-		if ((swap_info[i].flags & SWP_WRITEOK) != SWP_WRITEOK)
-			continue;
-		for (j = 0; j < swap_info[i].max; ++j) {
-			switch (swap_info[i].swap_map[j]) {
-				case SWAP_MAP_BAD:
-					continue;
-				case 0:
-					freeswap++;
-				default:
-					totalswap++;
-			}
-		}
-	}
-	val->freeswap = freeswap;
-	val->totalswap = totalswap;
+	val->totalswap = total_swap_pages;
+	val->freeswap = nr_swap_pages;
+
+	swap_list_unlock();
 	return;
 }
 
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/