aboutsummaryrefslogtreecommitdiffstats
path: root/fs/jffs2/malloc.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/jffs2/malloc.c')
-rw-r--r--fs/jffs2/malloc.c205
1 files changed, 205 insertions, 0 deletions
diff --git a/fs/jffs2/malloc.c b/fs/jffs2/malloc.c
new file mode 100644
index 000000000000..5abb431c2a00
--- /dev/null
+++ b/fs/jffs2/malloc.c
@@ -0,0 +1,205 @@
1/*
2 * JFFS2 -- Journalling Flash File System, Version 2.
3 *
4 * Copyright (C) 2001-2003 Red Hat, Inc.
5 *
6 * Created by David Woodhouse <dwmw2@infradead.org>
7 *
8 * For licensing information, see the file 'LICENCE' in this directory.
9 *
10 * $Id: malloc.c,v 1.28 2004/11/16 20:36:11 dwmw2 Exp $
11 *
12 */
13
14#include <linux/kernel.h>
15#include <linux/slab.h>
16#include <linux/init.h>
17#include <linux/jffs2.h>
18#include "nodelist.h"
19
20#if 0
21#define JFFS2_SLAB_POISON SLAB_POISON
22#else
23#define JFFS2_SLAB_POISON 0
24#endif
25
26// replace this by #define D3 (x) x for cache debugging
27#define D3(x)
28
29/* These are initialised to NULL in the kernel startup code.
30 If you're porting to other operating systems, beware */
31static kmem_cache_t *full_dnode_slab;
32static kmem_cache_t *raw_dirent_slab;
33static kmem_cache_t *raw_inode_slab;
34static kmem_cache_t *tmp_dnode_info_slab;
35static kmem_cache_t *raw_node_ref_slab;
36static kmem_cache_t *node_frag_slab;
37static kmem_cache_t *inode_cache_slab;
38
39int __init jffs2_create_slab_caches(void)
40{
41 full_dnode_slab = kmem_cache_create("jffs2_full_dnode",
42 sizeof(struct jffs2_full_dnode),
43 0, JFFS2_SLAB_POISON, NULL, NULL);
44 if (!full_dnode_slab)
45 goto err;
46
47 raw_dirent_slab = kmem_cache_create("jffs2_raw_dirent",
48 sizeof(struct jffs2_raw_dirent),
49 0, JFFS2_SLAB_POISON, NULL, NULL);
50 if (!raw_dirent_slab)
51 goto err;
52
53 raw_inode_slab = kmem_cache_create("jffs2_raw_inode",
54 sizeof(struct jffs2_raw_inode),
55 0, JFFS2_SLAB_POISON, NULL, NULL);
56 if (!raw_inode_slab)
57 goto err;
58
59 tmp_dnode_info_slab = kmem_cache_create("jffs2_tmp_dnode",
60 sizeof(struct jffs2_tmp_dnode_info),
61 0, JFFS2_SLAB_POISON, NULL, NULL);
62 if (!tmp_dnode_info_slab)
63 goto err;
64
65 raw_node_ref_slab = kmem_cache_create("jffs2_raw_node_ref",
66 sizeof(struct jffs2_raw_node_ref),
67 0, JFFS2_SLAB_POISON, NULL, NULL);
68 if (!raw_node_ref_slab)
69 goto err;
70
71 node_frag_slab = kmem_cache_create("jffs2_node_frag",
72 sizeof(struct jffs2_node_frag),
73 0, JFFS2_SLAB_POISON, NULL, NULL);
74 if (!node_frag_slab)
75 goto err;
76
77 inode_cache_slab = kmem_cache_create("jffs2_inode_cache",
78 sizeof(struct jffs2_inode_cache),
79 0, JFFS2_SLAB_POISON, NULL, NULL);
80 if (inode_cache_slab)
81 return 0;
82 err:
83 jffs2_destroy_slab_caches();
84 return -ENOMEM;
85}
86
87void jffs2_destroy_slab_caches(void)
88{
89 if(full_dnode_slab)
90 kmem_cache_destroy(full_dnode_slab);
91 if(raw_dirent_slab)
92 kmem_cache_destroy(raw_dirent_slab);
93 if(raw_inode_slab)
94 kmem_cache_destroy(raw_inode_slab);
95 if(tmp_dnode_info_slab)
96 kmem_cache_destroy(tmp_dnode_info_slab);
97 if(raw_node_ref_slab)
98 kmem_cache_destroy(raw_node_ref_slab);
99 if(node_frag_slab)
100 kmem_cache_destroy(node_frag_slab);
101 if(inode_cache_slab)
102 kmem_cache_destroy(inode_cache_slab);
103}
104
105struct jffs2_full_dirent *jffs2_alloc_full_dirent(int namesize)
106{
107 return kmalloc(sizeof(struct jffs2_full_dirent) + namesize, GFP_KERNEL);
108}
109
110void jffs2_free_full_dirent(struct jffs2_full_dirent *x)
111{
112 kfree(x);
113}
114
115struct jffs2_full_dnode *jffs2_alloc_full_dnode(void)
116{
117 struct jffs2_full_dnode *ret = kmem_cache_alloc(full_dnode_slab, GFP_KERNEL);
118 D3 (printk (KERN_DEBUG "alloc_full_dnode at %p\n", ret));
119 return ret;
120}
121
122void jffs2_free_full_dnode(struct jffs2_full_dnode *x)
123{
124 D3 (printk (KERN_DEBUG "free full_dnode at %p\n", x));
125 kmem_cache_free(full_dnode_slab, x);
126}
127
128struct jffs2_raw_dirent *jffs2_alloc_raw_dirent(void)
129{
130 struct jffs2_raw_dirent *ret = kmem_cache_alloc(raw_dirent_slab, GFP_KERNEL);
131 D3 (printk (KERN_DEBUG "alloc_raw_dirent\n", ret));
132 return ret;
133}
134
135void jffs2_free_raw_dirent(struct jffs2_raw_dirent *x)
136{
137 D3 (printk (KERN_DEBUG "free_raw_dirent at %p\n", x));
138 kmem_cache_free(raw_dirent_slab, x);
139}
140
141struct jffs2_raw_inode *jffs2_alloc_raw_inode(void)
142{
143 struct jffs2_raw_inode *ret = kmem_cache_alloc(raw_inode_slab, GFP_KERNEL);
144 D3 (printk (KERN_DEBUG "alloc_raw_inode at %p\n", ret));
145 return ret;
146}
147
148void jffs2_free_raw_inode(struct jffs2_raw_inode *x)
149{
150 D3 (printk (KERN_DEBUG "free_raw_inode at %p\n", x));
151 kmem_cache_free(raw_inode_slab, x);
152}
153
154struct jffs2_tmp_dnode_info *jffs2_alloc_tmp_dnode_info(void)
155{
156 struct jffs2_tmp_dnode_info *ret = kmem_cache_alloc(tmp_dnode_info_slab, GFP_KERNEL);
157 D3 (printk (KERN_DEBUG "alloc_tmp_dnode_info at %p\n", ret));
158 return ret;
159}
160
161void jffs2_free_tmp_dnode_info(struct jffs2_tmp_dnode_info *x)
162{
163 D3 (printk (KERN_DEBUG "free_tmp_dnode_info at %p\n", x));
164 kmem_cache_free(tmp_dnode_info_slab, x);
165}
166
167struct jffs2_raw_node_ref *jffs2_alloc_raw_node_ref(void)
168{
169 struct jffs2_raw_node_ref *ret = kmem_cache_alloc(raw_node_ref_slab, GFP_KERNEL);
170 D3 (printk (KERN_DEBUG "alloc_raw_node_ref at %p\n", ret));
171 return ret;
172}
173
174void jffs2_free_raw_node_ref(struct jffs2_raw_node_ref *x)
175{
176 D3 (printk (KERN_DEBUG "free_raw_node_ref at %p\n", x));
177 kmem_cache_free(raw_node_ref_slab, x);
178}
179
180struct jffs2_node_frag *jffs2_alloc_node_frag(void)
181{
182 struct jffs2_node_frag *ret = kmem_cache_alloc(node_frag_slab, GFP_KERNEL);
183 D3 (printk (KERN_DEBUG "alloc_node_frag at %p\n", ret));
184 return ret;
185}
186
187void jffs2_free_node_frag(struct jffs2_node_frag *x)
188{
189 D3 (printk (KERN_DEBUG "free_node_frag at %p\n", x));
190 kmem_cache_free(node_frag_slab, x);
191}
192
193struct jffs2_inode_cache *jffs2_alloc_inode_cache(void)
194{
195 struct jffs2_inode_cache *ret = kmem_cache_alloc(inode_cache_slab, GFP_KERNEL);
196 D3 (printk(KERN_DEBUG "Allocated inocache at %p\n", ret));
197 return ret;
198}
199
200void jffs2_free_inode_cache(struct jffs2_inode_cache *x)
201{
202 D3 (printk(KERN_DEBUG "Freeing inocache at %p\n", x));
203 kmem_cache_free(inode_cache_slab, x);
204}
205