2
* JFFS3 -- Journalling Flash File System, Version 3.
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
* JFFS2 Id: malloc.c,v 1.28 2004/11/16 20:36:11 dwmw2 Exp
11
* $Id: malloc.c,v 3.6 2005/01/05 16:19:00 dedekind Exp $
15
#include <linux/kernel.h>
16
#include <linux/slab.h>
17
#include <linux/init.h>
21
#define JFFS3_SLAB_POISON 0
23
/* These are initialised to NULL in the kernel startup code.
24
If you're porting to other operating systems, beware */
25
static kmem_cache_t *full_dnode_slab;
26
static kmem_cache_t *raw_dirent_slab;
27
static kmem_cache_t *raw_inode_slab;
28
static kmem_cache_t *tmp_dnode_info_slab;
29
static kmem_cache_t *raw_node_ref_slab;
30
static kmem_cache_t *node_frag_slab;
31
static kmem_cache_t *inode_cache_slab;
33
int __init jffs3_create_slab_caches(void)
35
full_dnode_slab = kmem_cache_create("jffs3_full_dnode",
36
sizeof(struct jffs3_full_dnode),
37
0, JFFS3_SLAB_POISON, NULL, NULL);
41
raw_dirent_slab = kmem_cache_create("jffs3_raw_dirent",
42
sizeof(struct jffs3_raw_dirent),
43
0, JFFS3_SLAB_POISON, NULL, NULL);
47
raw_inode_slab = kmem_cache_create("jffs3_raw_inode",
48
sizeof(struct jffs3_raw_inode),
49
0, JFFS3_SLAB_POISON, NULL, NULL);
53
tmp_dnode_info_slab = kmem_cache_create("jffs3_tmp_dnode",
54
sizeof(struct jffs3_tmp_dnode_info),
55
0, JFFS3_SLAB_POISON, NULL, NULL);
56
if (!tmp_dnode_info_slab)
59
raw_node_ref_slab = kmem_cache_create("jffs3_raw_node_ref",
60
sizeof(struct jffs3_raw_node_ref),
61
0, JFFS3_SLAB_POISON, NULL, NULL);
62
if (!raw_node_ref_slab)
65
node_frag_slab = kmem_cache_create("jffs3_node_frag",
66
sizeof(struct jffs3_node_frag),
67
0, JFFS3_SLAB_POISON, NULL, NULL);
71
inode_cache_slab = kmem_cache_create("jffs3_inode_cache",
72
sizeof(struct jffs3_inode_cache),
73
0, JFFS3_SLAB_POISON, NULL, NULL);
77
jffs3_destroy_slab_caches();
81
void jffs3_destroy_slab_caches(void)
84
kmem_cache_destroy(full_dnode_slab);
86
kmem_cache_destroy(raw_dirent_slab);
88
kmem_cache_destroy(raw_inode_slab);
89
if(tmp_dnode_info_slab)
90
kmem_cache_destroy(tmp_dnode_info_slab);
92
kmem_cache_destroy(raw_node_ref_slab);
94
kmem_cache_destroy(node_frag_slab);
96
kmem_cache_destroy(inode_cache_slab);
99
struct jffs3_full_dirent *jffs3_alloc_full_dirent(int namesize)
101
return kmalloc(sizeof(struct jffs3_full_dirent) + namesize, GFP_KERNEL);
104
void jffs3_free_full_dirent(struct jffs3_full_dirent *x)
109
struct jffs3_full_dnode *jffs3_alloc_full_dnode(void)
111
struct jffs3_full_dnode *ret = kmem_cache_alloc(full_dnode_slab, GFP_KERNEL);
112
DBG_SALLOC(1, "alloc_full_dnode at %p\n", ret);
116
void jffs3_free_full_dnode(struct jffs3_full_dnode *x)
118
DBG_SALLOC(1, "free full_dnode at %p\n", x);
119
kmem_cache_free(full_dnode_slab, x);
122
struct jffs3_raw_dirent *jffs3_alloc_raw_dirent(void)
124
struct jffs3_raw_dirent *ret = kmem_cache_alloc(raw_dirent_slab, GFP_KERNEL);
125
DBG_SALLOC(1, "alloc_raw_dirent %p\n", ret);
129
void jffs3_free_raw_dirent(struct jffs3_raw_dirent *x)
131
DBG_SALLOC(1, "free_raw_dirent at %p\n", x);
132
kmem_cache_free(raw_dirent_slab, x);
135
struct jffs3_raw_inode *jffs3_alloc_raw_inode(void)
137
struct jffs3_raw_inode *ret = kmem_cache_alloc(raw_inode_slab, GFP_KERNEL);
138
DBG_SALLOC(1, "alloc_raw_inode at %p\n", ret);
142
void jffs3_free_raw_inode(struct jffs3_raw_inode *x)
144
DBG_SALLOC(1, "free_raw_inode at %p\n", x);
145
kmem_cache_free(raw_inode_slab, x);
148
struct jffs3_tmp_dnode_info *jffs3_alloc_tmp_dnode_info(void)
150
struct jffs3_tmp_dnode_info *ret = kmem_cache_alloc(tmp_dnode_info_slab, GFP_KERNEL);
151
DBG_SALLOC(1, "alloc_tmp_dnode_info at %p\n", ret);
155
void jffs3_free_tmp_dnode_info(struct jffs3_tmp_dnode_info *x)
157
DBG_SALLOC(1, "free_tmp_dnode_info at %p\n", x);
158
kmem_cache_free(tmp_dnode_info_slab, x);
161
struct jffs3_raw_node_ref *jffs3_alloc_raw_node_ref(void)
163
struct jffs3_raw_node_ref *ret = kmem_cache_alloc(raw_node_ref_slab, GFP_KERNEL);
164
DBG_SALLOC(1, "alloc_raw_node_ref at %p\n", ret);
168
void jffs3_free_raw_node_ref(struct jffs3_raw_node_ref *x)
170
DBG_SALLOC(1, "free_raw_node_ref at %p\n", x);
171
kmem_cache_free(raw_node_ref_slab, x);
174
struct jffs3_node_frag *jffs3_alloc_node_frag(void)
176
struct jffs3_node_frag *ret = kmem_cache_alloc(node_frag_slab, GFP_KERNEL);
177
DBG_SALLOC(1, "alloc_node_frag at %p\n", ret);
181
void jffs3_free_node_frag(struct jffs3_node_frag *x)
183
DBG_SALLOC(1, "free_node_frag at %p\n", x);
184
kmem_cache_free(node_frag_slab, x);
187
struct jffs3_inode_cache *jffs3_alloc_inode_cache(void)
189
struct jffs3_inode_cache *ret = kmem_cache_alloc(inode_cache_slab, GFP_KERNEL);
190
DBG_SALLOC(1, "Allocated inocache at %p\n", ret);
194
void jffs3_free_inode_cache(struct jffs3_inode_cache *x)
196
DBG_SALLOC(1, "Freeing inocache at %p\n", x);
197
kmem_cache_free(inode_cache_slab, x);