Subject: afs/fs/cachefs main.c,1.13,1.14 interface.c,1.3,1.4 cachefs-int.h,1.28,1.29

From: [email-masked]
Date: Thu, 24 Apr 2003 16:14:13 +0100

Update of /home/cvs/afs/fs/cachefs
In directory phoenix.infradead.org:/tmp/cvs-serv1701/fs/cachefs

Modified Files:
	main.c interface.c cachefs-int.h 
Log Message:
allocate cookies on their own slab

Index: main.c
===================================================================
RCS file: /home/cvs/afs/fs/cachefs/main.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- main.c	17 Apr 2003 11:59:04 -0000	1.13
+++ main.c	24 Apr 2003 15:14:10 -0000	1.14
@@ -42,12 +42,27 @@
 	if (ret<0)
 		goto error;
 
+	/* create ourselves a cookie jar */
+	ret = -ENOMEM;
+	cachefs_cookie_jar = kmem_cache_create("cachefs_cookie_jar",
+					       sizeof(struct cachefs_cookie),
+					       0,
+					       SLAB_HWCACHE_ALIGN,
+					       cachefs_cookie_init_once,
+					       NULL);
+	if (!cachefs_cookie_jar) {
+		printk(KERN_NOTICE "CacheFS: Failed to allocate a cookie jar\n");
+		goto error_jnld;
+	}
+
 	ret = cachefs_fs_init();
 	if (ret<0)
-		goto error_jnld;
+		goto error_cookie_jar;
 
 	return ret;
 
+ error_cookie_jar:
+	kmem_cache_destroy(cachefs_cookie_jar);
  error_jnld:
 	kcachefs_jnld_stop();	
  error:
@@ -65,6 +80,7 @@
 
 	cachefs_fs_exit();
 	kcachefs_jnld_stop();	
+	kmem_cache_destroy(cachefs_cookie_jar);
 
 } /* end cachefs_exit() */

Index: interface.c
===================================================================
RCS file: /home/cvs/afs/fs/cachefs/interface.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- interface.c	24 Apr 2003 14:42:24 -0000	1.3
+++ interface.c	24 Apr 2003 15:14:10 -0000	1.4
@@ -16,6 +16,8 @@
 LIST_HEAD(cachefs_cache_list);
 DECLARE_RWSEM(cachefs_addremove_sem);
 
+kmem_cache_t *cachefs_cookie_jar;
+
 static cachefs_match_val_t cachefs_fsdef_index_match(void *target, const void *entry);
 
 static void cachefs_fsdef_index_update(void *source, void *entry);
@@ -66,7 +68,7 @@
 
 	INIT_LIST_HEAD(&netfs->link);
 
-	netfs->primary_index = kmalloc(sizeof(*netfs->primary_index),GFP_KERNEL);
+	netfs->primary_index = kmem_cache_alloc(cachefs_cookie_jar,SLAB_KERNEL);
 	if (!netfs->primary_index) {
 		kleave(" = -ENOMEM");
 		return -ENOMEM;
@@ -141,10 +143,6 @@
 	kenter("");
 
 	/* prepare an active-inode record for the FSDEF index of this cache */
-	printk("###\n");
-	printk("### PREALLOC ACTIVE %p{%x}\n",active,atomic_read(&active->usage));
-	printk("###\n");
-
 	memset(active,0,sizeof(*active));
 
 	atomic_set(&active->usage,2);
@@ -173,10 +171,6 @@
 	down_write(&cachefs_fsdef_index.sem);
 	list_add_tail(&active->link,&cachefs_fsdef_index.active_inodes);
 
-	printk("###\n");
-	printk("### LISTADD ACTIVE %p{%x}\n",active,atomic_read(&active->usage));
-	printk("###\n");
-
 	atomic_inc(&cachefs_fsdef_index.usage);
 	up_write(&cachefs_fsdef_index.sem);
 
@@ -270,10 +264,6 @@
 		return -ENOMEM;
 	}
 
-	printk("###\n");
-	printk("### ALLOC ACTIVE %p{%x}\n",active,atomic_read(&active->usage));
-	printk("###\n");
-
 	memset(active,0,sizeof(*active));
 
 	active->super	= super;
@@ -305,10 +295,6 @@
 			/* set a negative entry */
 			if (list_empty(&active->link)) {
 				list_add_tail(&active->link,&cookie->active_inodes);
-
-	printk("###\n");
-	printk("### LISTADD ACTIVE %p{%x}\n",active,atomic_read(&active->usage));
-	printk("###\n");
 				atomic_inc(&cookie->usage);
 			}
 		}
@@ -340,10 +326,6 @@
 	case 0:
 		if (list_empty(&active->link)) {
 			list_add_tail(&active->link,&cookie->active_inodes);
-
-	printk("###\n");
-	printk("### LISTADD ACTIVE %p{%x}\n",active,atomic_read(&active->usage));
-	printk("###\n");
 			atomic_inc(&cookie->usage);
 		}
 		goto add_to_active_tree;
@@ -352,10 +334,6 @@
 		/* we can at least set a valid negative entry */
 		if (list_empty(&active->link)) {
 			list_add_tail(&active->link,&cookie->active_inodes);
-
-	printk("###\n");
-	printk("### LISTADD ACTIVE %p{%x}\n",active,atomic_read(&active->usage));
-	printk("###\n");
 			atomic_inc(&cookie->usage);
 		}
 
@@ -481,15 +459,13 @@
 	}
 
 	/* allocate a cookie first and pass it back */
-	cookie = kmalloc(sizeof(*cookie),GFP_KERNEL);
+	cookie = kmem_cache_alloc(cachefs_cookie_jar,SLAB_KERNEL);
 	if (!cookie) {
 		*_cookie = NULL;
 		kleave(" [ENOMEM]");
 		return;
 	}
 
-	memset(cookie,0,sizeof(*cookie));
-
 	atomic_set(&cookie->usage,1);
 	atomic_set(&cookie->children,0);
 
@@ -500,9 +476,6 @@
 	cookie->iparent		= iparent;
 	cookie->netfs_data	= netfs_data;
 
-	INIT_LIST_HEAD(&cookie->active_inodes);
-	init_rwsem(&cookie->sem);
-
 	*_cookie = cookie;
 
 	/* now we need to see whether the backing objects for this cookie yet exist */
@@ -614,11 +587,6 @@
 	while (!list_empty(&cookie->active_inodes)) {
 		active = list_entry(cookie->active_inodes.next, struct cachefs_active_inode,link);
 
-
-		printk("###\n");
-		printk("### RELINQ ACTIVE %p{%x}\n",active,atomic_read(&active->usage));
-		printk("###\n");
-
 		/* detach the cache inode from the cached object cookie */
 		set_bit(CACHEFS_ACTIVE_INODE_RELEASING,&active->flags);
 
@@ -753,7 +721,7 @@
 	if (cookie->iparent)
 		cachefs_cookie_put(cookie->iparent);
 
-	kfree(cookie);
+	kmem_cache_free(cachefs_cookie_jar,cookie);
 
 	kleave("");
 } /* end __cachefs_cookie_put() */
@@ -769,10 +737,6 @@
 
 	kenter("");
 
-	printk("###\n");
-	printk("### PUT ACTIVE %p{%x}\n",active,atomic_read(&active->usage));
-	printk("###\n");
-
 	/* remove from the cache's inode tree */
 	super = active->super;
 
@@ -790,3 +754,19 @@
 
 	kleave("");
 } /* end __cachefs_put_active_inode() */
+
+/*****************************************************************************/
+/*
+ * initialise an cookie jar slab element prior to any use
+ */
+void cachefs_cookie_init_once(void *_cookie, kmem_cache_t *cachep, unsigned long flags)
+{
+	struct cachefs_cookie *cookie = _cookie;
+
+	if ((flags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) == SLAB_CTOR_CONSTRUCTOR) {
+		memset(cookie,0,sizeof(*cookie));
+		INIT_LIST_HEAD(&cookie->active_inodes);
+		init_rwsem(&cookie->sem);
+	}
+
+} /* end cachefs_cookie_init_once() */

Index: cachefs-int.h
===================================================================
RCS file: /home/cvs/afs/fs/cachefs/cachefs-int.h,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -r1.28 -r1.29
--- cachefs-int.h	24 Apr 2003 14:42:24 -0000	1.28
+++ cachefs-int.h	24 Apr 2003 15:14:10 -0000	1.29
@@ -201,6 +201,10 @@
 	void				*netfs_data;	/* back pointer to netfs */
 };
 
+extern kmem_cache_t *cachefs_cookie_jar;
+
+extern void cachefs_cookie_init_once(void *_cookie, kmem_cache_t *cachep, unsigned long flags);
+
 /*****************************************************************************/
 /*
  * cache file and directory management