mtd/fs/jffs2/ecos/src fs-ecos.c,1.13,1.14 malloc-ecos.c,1.2,1.3 os-ecos.h,1.10,1.11

David Woodhouse dwmw2 at infradead.org
Mon Nov 24 08:54:20 EST 2003


Update of /home/cvs/mtd/fs/jffs2/ecos/src
In directory phoenix.infradead.org:/tmp/cvs-serv1234/src

Modified Files:
	fs-ecos.c malloc-ecos.c os-ecos.h 
Log Message:
Merge raw_node_ref pool patch

Index: fs-ecos.c
===================================================================
RCS file: /home/cvs/mtd/fs/jffs2/ecos/src/fs-ecos.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- fs-ecos.c	24 Nov 2003 13:49:38 -0000	1.13
+++ fs-ecos.c	24 Nov 2003 13:54:17 -0000	1.14
@@ -145,6 +145,7 @@
 
 static char read_write_buffer[PAGE_CACHE_SIZE];	//avoids malloc when user may be under memory pressure
 static char gc_buffer[PAGE_CACHE_SIZE];	//avoids malloc when user may be under memory pressure
+static unsigned char n_fs_mounted = 0;  // a counter to track the number of jffs2 instances mounted
 
 //==========================================================================
 // Directory operations
@@ -539,10 +540,15 @@
 			return ENOMEM;
 		}
 		memset(c->inocache_list, 0, sizeof(struct jffs2_inode_cache *) * INOCACHE_HASHSIZE);
+                if (n_fs_mounted++ == 0)
+                        jffs2_create_slab_caches(); // No error check, cannot fail
 
 		err = jffs2_read_super(jffs2_sb);
 
 		if (err) {
+                        if (--n_fs_mounted == 0)
+                                jffs2_destroy_slab_caches();
+                        
 			free(jffs2_sb);
 			free(c->inocache_list);
 			return err;
@@ -611,7 +617,8 @@
 	} else {
           jffs2_sb->s_mount_count--;
         }
-        
+        if (--n_fs_mounted == 0)
+                jffs2_destroy_slab_caches();        
 	return ENOERR;
 }
 

Index: malloc-ecos.c
===================================================================
RCS file: /home/cvs/mtd/fs/jffs2/ecos/src/malloc-ecos.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- malloc-ecos.c	9 Jan 2003 13:53:44 -0000	1.2
+++ malloc-ecos.c	24 Nov 2003 13:54:17 -0000	1.3
@@ -12,8 +12,13 @@
  */
 
 #include <linux/kernel.h>
+#include <cyg/hal/drv_api.h>
 #include "nodelist.h"
 
+#if !defined(CYGNUM_FS_JFFS2_RAW_NODE_REF_CACHE_POOL_SIZE)
+# define CYGNUM_FS_JFFS2_RAW_NODE_REF_CACHE_POOL_SIZE 0
+#endif
+
 struct jffs2_full_dirent *jffs2_alloc_full_dirent(int namesize)
 {
 	return malloc(sizeof(struct jffs2_full_dirent) + namesize);
@@ -64,6 +69,27 @@
 	free(x);
 }
 
+struct jffs2_node_frag *jffs2_alloc_node_frag(void)
+{
+	return malloc(sizeof(struct jffs2_node_frag));
+}
+
+void jffs2_free_node_frag(struct jffs2_node_frag *x)
+{
+	free(x);
+}
+
+#if CYGNUM_FS_JFFS2_RAW_NODE_REF_CACHE_POOL_SIZE == 0
+
+int jffs2_create_slab_caches(void)
+{
+	return 0;
+}
+
+void jffs2_destroy_slab_caches(void)
+{
+}
+
 struct jffs2_raw_node_ref *jffs2_alloc_raw_node_ref(void)
 {
 	return malloc(sizeof(struct jffs2_raw_node_ref));
@@ -74,15 +100,53 @@
 	free(x);
 }
 
-struct jffs2_node_frag *jffs2_alloc_node_frag(void)
+#else // CYGNUM_FS_JFFS2_RAW_NODE_REF_CACHE_POOL_SIZE == 0
+
+static struct jffs2_raw_node_ref
+	rnr_pool[CYGNUM_FS_JFFS2_RAW_NODE_REF_CACHE_POOL_SIZE] __attribute__ ((aligned (4))),
+	* first = NULL;
+static cyg_drv_mutex_t mutex;
+
+int jffs2_create_slab_caches(void)
+{
+	struct jffs2_raw_node_ref * p;
+	cyg_drv_mutex_init(&mutex);
+	for (
+		p = rnr_pool;
+		p < rnr_pool + CYGNUM_FS_JFFS2_RAW_NODE_REF_CACHE_POOL_SIZE - 1;
+		p++
+	)
+		p->next_phys = p + 1;
+	rnr_pool[CYGNUM_FS_JFFS2_RAW_NODE_REF_CACHE_POOL_SIZE - 1].next_phys = NULL;
+	first = &rnr_pool[0];
+	return 0;
+}
+
+void jffs2_destroy_slab_caches(void)
 {
-	return malloc(sizeof(struct jffs2_node_frag));
 }
 
-void jffs2_free_node_frag(struct jffs2_node_frag *x)
+struct jffs2_raw_node_ref *jffs2_alloc_raw_node_ref(void)
 {
-	free(x);
+	struct jffs2_raw_node_ref * p;
+	
+	cyg_drv_mutex_lock(&mutex);
+	p = first;
+	if (p != NULL)
+		first = p->next_phys;
+	cyg_drv_mutex_unlock(&mutex);
+	return p;
 }
+
+void jffs2_free_raw_node_ref(struct jffs2_raw_node_ref *x)
+{
+	cyg_drv_mutex_lock(&mutex);
+	x->next_phys = first;
+	first = x;
+	cyg_drv_mutex_unlock(&mutex);
+}
+
+#endif // CYGNUM_FS_JFFS2_RAW_NODE_REF_CACHE_POOL_SIZE == 0
 
 struct jffs2_inode_cache *jffs2_alloc_inode_cache(void)
 {

Index: os-ecos.h
===================================================================
RCS file: /home/cvs/mtd/fs/jffs2/ecos/src/os-ecos.h,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- os-ecos.h	24 Nov 2003 13:49:38 -0000	1.10
+++ os-ecos.h	24 Nov 2003 13:54:17 -0000	1.11
@@ -14,6 +14,7 @@
 #ifndef __JFFS2_OS_ECOS_H__
 #define __JFFS2_OS_ECOS_H__
 
+#include <pkgconf/fs_jffs2.h>
 #include <cyg/io/io.h>
 #include <sys/types.h>
 #include <asm/atomic.h>




More information about the linux-mtd-cvs mailing list