[linux-mm-cc] [PATCH] module param size too big fix up

nai.xia at gmail.com nai.xia at gmail.com
Mon Apr 28 04:25:42 EDT 2008


hi, Nitin,

I notice that when initializing compcache, if the compcache_size_kbytes is given
a very big value, the module will be loaded abnormally -- the block device will
not appear and the module will refuse to unload. (I think you can easily
reproduce it youself)

This patch makes the user unable to use a value bigger than the system RAM, 
Otherwise, it is trimmed to 50% of the total. 



Best Regards,
Nai


diff --git a/compcache.c b/compcache.c
index 6330e93..fc16357 100644
--- a/compcache.c
+++ b/compcache.c
@@ -271,6 +271,10 @@ static int __init compcache_init(void)
 	int ret;
 	size_t num_pages;
 	struct sysinfo i;
+	unsigned long system_ram_kbytes;
+
+	si_meminfo(&i);
+	system_ram_kbytes = i.totalram << (PAGE_SHIFT - 10);
 
 	mutex_init(&compcache.lock);
 
@@ -279,9 +283,15 @@ static int __init compcache_init(void)
 			" Using default: (%u%% of Total RAM).\n"
 			"Use compcache_size_kbytes module param to specify"
 			" custom size\n", DEFAULT_COMPCACHE_PERCENT);
-		si_meminfo(&i);
-		compcache_size_kbytes = ((DEFAULT_COMPCACHE_PERCENT *
-				i.totalram) / 100) << (PAGE_SHIFT - 10);
+		compcache_size_kbytes = ((DEFAULT_COMPCACHE_PERCENT * 
+				system_ram_kbytes) / 100 ) ;
+	}
+	else if ( compcache_size_kbytes > system_ram_kbytes ) {
+		pr_info(C "compcache size is too big (bigger than RAM)."
+			" Using maximum default: (50%% of Total RAM).\n"
+			"Use a smaller compcache_size_kbytes module param" 
+			"to specify custom size\n");
+		compcache_size_kbytes = system_ram_kbytes / 2;
 	}
 	
 	CC_DEBUG2("compcache_size_kbytes=%lu\n", compcache_size_kbytes);


More information about the linux-mm-cc mailing list