[linux-mm-cc] [UTIL PATCH 1/2] proc entry to select algo (ver2)

IKEDA Munehiro m-ikeda at ds.jp.nec.com
Thu May 24 05:10:50 EDT 2007


This patch makes you be able to select compression algo by writing
  -1 : cyclic (same as without this patch)
   0 : WKdm
   1 : WK4x4
   2 : LZO
to /proc/sys/vm/cc_algorithm.

This patch is for patch-ccache-alpha-008-2.6.21 applied kernel.

---
 include/linux/ccache.h |   13 ++++++++++---
 include/linux/sysctl.h |    1 +
 kernel/sysctl.c        |   10 ++++++++++
 mm/ccache.c            |   21 ++++++++++++++++++---
 4 files changed, 39 insertions(+), 6 deletions(-)

diff --git a/include/linux/ccache.h b/include/linux/ccache.h
index 8aee787..bf57328 100644
--- a/include/linux/ccache.h
+++ b/include/linux/ccache.h
@@ -83,10 +83,15 @@ enum CH_FLAGS {
 
 /* compression algos */
 #define MAX_COMP_ALGOS  4
-#define WKdm_IDX  0
-#define WK4x4_IDX 1
-#define LZO_IDX   2
+enum {
+	WKdm_IDX = 0,
+	WK4x4_IDX,
+	LZO_IDX,
+	end_of_IDX
+};
 
+extern const int ccache_min_algo_idx, ccache_max_algo_idx;
+extern int ccache_selected_algo;
 extern unsigned long max_anon_cc_size, max_fs_backed_cc_size;
 
 /*
@@ -145,6 +150,8 @@ extern int should_add_to_ccache(struct page *page);
 extern int cc_writepage(struct page *page);
 extern struct page* handle_ccache_fault(struct chunk_head *ch,
 				struct address_space *mapping);
+extern int sysctl_cc_algorithm(ctl_table *table, int write,
+	struct file *file, void __user *buffer, size_t *length, loff_t *ppos);
 extern int sysctl_max_anon_cc_size(ctl_table *table, int write,
 	struct file *file, void __user *buffer, size_t *length, loff_t *ppos);
 extern int sysctl_max_fs_backed_cc_size(ctl_table *table, int write,
diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
index e189393..33d8f37 100644
--- a/include/linux/sysctl.h
+++ b/include/linux/sysctl.h
@@ -209,6 +209,7 @@ enum
 	VM_MIN_SLAB=35,		 /* Percent pages ignored by zone reclaim */
 	VM_MAX_ANON_CC_SIZE=36,	/* max size for compressed cache for anonymous pages */
 	VM_MAX_FS_CC_SIZE=37,	/* max size for compressed cache for fs-backed pages */
+	VM_CC_ALGO=38,		/* compressed cache algorithm */
 
 	/* s390 vm cmm sysctls */
 	VM_CMM_PAGES=1111,
diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index d9ae8ef..0469a0f 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -617,6 +617,16 @@ static int one_hundred = 100;
 
 static ctl_table vm_table[] = {
 	{
+		.ctl_name	= VM_CC_ALGO,
+		.procname	= "cc_algorithm",
+		.data		= &ccache_selected_algo,
+		.maxlen		= sizeof(int),
+		.mode		= 0644,
+		.proc_handler	= &sysctl_cc_algorithm,
+		.extra1		= (void *)&ccache_min_algo_idx,
+		.extra2		= (void *)&ccache_max_algo_idx,
+	},
+	{
 		.ctl_name	= VM_MAX_ANON_CC_SIZE,
 		.procname	= "max_anon_cc_size",
 		.data		= &max_anon_cc_size,
diff --git a/mm/ccache.c b/mm/ccache.c
index 2d20b2c..fcd205c 100644
--- a/mm/ccache.c
+++ b/mm/ccache.c
@@ -19,6 +19,8 @@ static int anon_cc_started = 0, fs_backed_cc_started = 0;
 unsigned long max_anon_cc_size = 0, max_fs_backed_cc_size = 0;
 static atomic_t anon_cc_size, fs_backed_cc_size;	/* current sizes */
 const unsigned long ccache_size_limit = MAX_SWAP_OFFSET - 1;
+const int ccache_min_algo_idx = -1;
+const int ccache_max_algo_idx = end_of_IDX - 1;
 
 static struct list_head pages_head, mcl_head, lru_head;
 static struct chunk *free_head = NULL;
@@ -26,6 +28,7 @@ static struct chunk *free_head = NULL;
 /* show ccache stats via /proc/ccache_stats */
 static struct proc_dir_entry *proc_ccache_stats;
 
+int ccache_selected_algo = -1;
 static unsigned int next_algo = 1;
 
 typedef int (*compress_t) (unsigned char *src, unsigned long src_len,
@@ -65,9 +68,15 @@ static int guess_algo(struct page *page)
 	 * (as suggested by John Moser)
 	 */
 
-	/* cyclically select algos */
-	next_algo++;
-	next_algo %= 3;
+	if (ccache_selected_algo < 0) {
+		/* cyclically select algos */
+		next_algo++;
+		if (next_algo == end_of_IDX)
+			next_algo = 0;
+	}
+	else 	/* algo is fixed */
+		next_algo = ccache_selected_algo;
+
 	return next_algo;
 }
 
@@ -442,6 +451,12 @@ int init_ccache(void)
 	return 0;
 }
 
+int sysctl_cc_algorithm(ctl_table *table, int write,
+	struct file *file, void __user *buffer, size_t *length, loff_t *ppos)
+{
+	return proc_dointvec_minmax(table, write, file, buffer, length, ppos);
+}
+
 int sysctl_max_anon_cc_size(ctl_table *table, int write,
 	struct file *file, void __user *buffer, size_t *length, loff_t *ppos)
 {
-- 
1.4.4.4




More information about the linux-mm-cc mailing list