2 * JFFS2 -- Journalling Flash File System, Version 2.
4 * Copyright (C) 2001-2003 Red Hat, Inc.
6 * Created by David Woodhouse <dwmw2@infradead.org>
8 * For licensing information, see the file 'LICENCE' in this directory.
10 * $Id: malloc.c,v 1.31 2005/11/07 11:14:40 gleixner Exp $
14 #include <linux/kernel.h>
15 #include <linux/slab.h>
16 #include <linux/init.h>
17 #include <linux/jffs2.h>
20 /* These are initialised to NULL in the kernel startup code.
21 If you're porting to other operating systems, beware */
22 static kmem_cache_t
*full_dnode_slab
;
23 static kmem_cache_t
*raw_dirent_slab
;
24 static kmem_cache_t
*raw_inode_slab
;
25 static kmem_cache_t
*tmp_dnode_info_slab
;
26 static kmem_cache_t
*raw_node_ref_slab
;
27 static kmem_cache_t
*node_frag_slab
;
28 static kmem_cache_t
*inode_cache_slab
;
29 #ifdef CONFIG_JFFS2_FS_XATTR
30 static kmem_cache_t
*xattr_datum_cache
;
31 static kmem_cache_t
*xattr_ref_cache
;
34 int __init
jffs2_create_slab_caches(void)
36 full_dnode_slab
= kmem_cache_create("jffs2_full_dnode",
37 sizeof(struct jffs2_full_dnode
),
42 raw_dirent_slab
= kmem_cache_create("jffs2_raw_dirent",
43 sizeof(struct jffs2_raw_dirent
),
48 raw_inode_slab
= kmem_cache_create("jffs2_raw_inode",
49 sizeof(struct jffs2_raw_inode
),
54 tmp_dnode_info_slab
= kmem_cache_create("jffs2_tmp_dnode",
55 sizeof(struct jffs2_tmp_dnode_info
),
57 if (!tmp_dnode_info_slab
)
60 raw_node_ref_slab
= kmem_cache_create("jffs2_raw_node_ref",
61 sizeof(struct jffs2_raw_node_ref
),
63 if (!raw_node_ref_slab
)
66 node_frag_slab
= kmem_cache_create("jffs2_node_frag",
67 sizeof(struct jffs2_node_frag
),
72 inode_cache_slab
= kmem_cache_create("jffs2_inode_cache",
73 sizeof(struct jffs2_inode_cache
),
75 if (!inode_cache_slab
)
78 #ifdef CONFIG_JFFS2_FS_XATTR
79 xattr_datum_cache
= kmem_cache_create("jffs2_xattr_datum",
80 sizeof(struct jffs2_xattr_datum
),
82 if (!xattr_datum_cache
)
85 xattr_ref_cache
= kmem_cache_create("jffs2_xattr_ref",
86 sizeof(struct jffs2_xattr_ref
),
94 jffs2_destroy_slab_caches();
98 void jffs2_destroy_slab_caches(void)
101 kmem_cache_destroy(full_dnode_slab
);
103 kmem_cache_destroy(raw_dirent_slab
);
105 kmem_cache_destroy(raw_inode_slab
);
106 if(tmp_dnode_info_slab
)
107 kmem_cache_destroy(tmp_dnode_info_slab
);
108 if(raw_node_ref_slab
)
109 kmem_cache_destroy(raw_node_ref_slab
);
111 kmem_cache_destroy(node_frag_slab
);
113 kmem_cache_destroy(inode_cache_slab
);
114 #ifdef CONFIG_JFFS2_FS_XATTR
115 if (xattr_datum_cache
)
116 kmem_cache_destroy(xattr_datum_cache
);
118 kmem_cache_destroy(xattr_ref_cache
);
122 struct jffs2_full_dirent
*jffs2_alloc_full_dirent(int namesize
)
124 struct jffs2_full_dirent
*ret
;
125 ret
= kmalloc(sizeof(struct jffs2_full_dirent
) + namesize
, GFP_KERNEL
);
126 dbg_memalloc("%p\n", ret
);
130 void jffs2_free_full_dirent(struct jffs2_full_dirent
*x
)
132 dbg_memalloc("%p\n", x
);
136 struct jffs2_full_dnode
*jffs2_alloc_full_dnode(void)
138 struct jffs2_full_dnode
*ret
;
139 ret
= kmem_cache_alloc(full_dnode_slab
, GFP_KERNEL
);
140 dbg_memalloc("%p\n", ret
);
144 void jffs2_free_full_dnode(struct jffs2_full_dnode
*x
)
146 dbg_memalloc("%p\n", x
);
147 kmem_cache_free(full_dnode_slab
, x
);
150 struct jffs2_raw_dirent
*jffs2_alloc_raw_dirent(void)
152 struct jffs2_raw_dirent
*ret
;
153 ret
= kmem_cache_alloc(raw_dirent_slab
, GFP_KERNEL
);
154 dbg_memalloc("%p\n", ret
);
158 void jffs2_free_raw_dirent(struct jffs2_raw_dirent
*x
)
160 dbg_memalloc("%p\n", x
);
161 kmem_cache_free(raw_dirent_slab
, x
);
164 struct jffs2_raw_inode
*jffs2_alloc_raw_inode(void)
166 struct jffs2_raw_inode
*ret
;
167 ret
= kmem_cache_alloc(raw_inode_slab
, GFP_KERNEL
);
168 dbg_memalloc("%p\n", ret
);
172 void jffs2_free_raw_inode(struct jffs2_raw_inode
*x
)
174 dbg_memalloc("%p\n", x
);
175 kmem_cache_free(raw_inode_slab
, x
);
178 struct jffs2_tmp_dnode_info
*jffs2_alloc_tmp_dnode_info(void)
180 struct jffs2_tmp_dnode_info
*ret
;
181 ret
= kmem_cache_alloc(tmp_dnode_info_slab
, GFP_KERNEL
);
187 void jffs2_free_tmp_dnode_info(struct jffs2_tmp_dnode_info
*x
)
189 dbg_memalloc("%p\n", x
);
190 kmem_cache_free(tmp_dnode_info_slab
, x
);
193 struct jffs2_raw_node_ref
*jffs2_alloc_raw_node_ref(void)
195 struct jffs2_raw_node_ref
*ret
;
196 ret
= kmem_cache_alloc(raw_node_ref_slab
, GFP_KERNEL
);
197 dbg_memalloc("%p\n", ret
);
201 void jffs2_free_raw_node_ref(struct jffs2_raw_node_ref
*x
)
203 dbg_memalloc("%p\n", x
);
204 kmem_cache_free(raw_node_ref_slab
, x
);
207 struct jffs2_node_frag
*jffs2_alloc_node_frag(void)
209 struct jffs2_node_frag
*ret
;
210 ret
= kmem_cache_alloc(node_frag_slab
, GFP_KERNEL
);
211 dbg_memalloc("%p\n", ret
);
215 void jffs2_free_node_frag(struct jffs2_node_frag
*x
)
217 dbg_memalloc("%p\n", x
);
218 kmem_cache_free(node_frag_slab
, x
);
221 struct jffs2_inode_cache
*jffs2_alloc_inode_cache(void)
223 struct jffs2_inode_cache
*ret
;
224 ret
= kmem_cache_alloc(inode_cache_slab
, GFP_KERNEL
);
225 dbg_memalloc("%p\n", ret
);
229 void jffs2_free_inode_cache(struct jffs2_inode_cache
*x
)
231 dbg_memalloc("%p\n", x
);
232 kmem_cache_free(inode_cache_slab
, x
);
235 #ifdef CONFIG_JFFS2_FS_XATTR
236 struct jffs2_xattr_datum
*jffs2_alloc_xattr_datum(void)
238 struct jffs2_xattr_datum
*xd
;
239 xd
= kmem_cache_alloc(xattr_datum_cache
, GFP_KERNEL
);
240 dbg_memalloc("%p\n", xd
);
242 memset(xd
, 0, sizeof(struct jffs2_xattr_datum
));
243 xd
->class = RAWNODE_CLASS_XATTR_DATUM
;
244 INIT_LIST_HEAD(&xd
->xindex
);
248 void jffs2_free_xattr_datum(struct jffs2_xattr_datum
*xd
)
250 dbg_memalloc("%p\n", xd
);
251 kmem_cache_free(xattr_datum_cache
, xd
);
254 struct jffs2_xattr_ref
*jffs2_alloc_xattr_ref(void)
256 struct jffs2_xattr_ref
*ref
;
257 ref
= kmem_cache_alloc(xattr_ref_cache
, GFP_KERNEL
);
258 dbg_memalloc("%p\n", ref
);
260 memset(ref
, 0, sizeof(struct jffs2_xattr_ref
));
261 ref
->class = RAWNODE_CLASS_XATTR_REF
;
265 void jffs2_free_xattr_ref(struct jffs2_xattr_ref
*ref
)
267 dbg_memalloc("%p\n", ref
);
268 kmem_cache_free(xattr_ref_cache
, ref
);