diff options
author | David Woodhouse <dwmw2@infradead.org> | 2006-05-26 16:19:05 -0400 |
---|---|---|
committer | David Woodhouse <dwmw2@infradead.org> | 2006-05-26 16:19:05 -0400 |
commit | 9bfeb691e75b21fdaa80ffae719083200b190381 (patch) | |
tree | 3c828820f1385249835f85e5073b4ffd10fcd09c /fs/jffs2/malloc.c | |
parent | f75e5097ef298c5a0aa106faa211d1afdc92dc3d (diff) |
[JFFS2] Switch to using an array of jffs2_raw_node_refs instead of a list.
This allows us to drop another pointer from the struct jffs2_raw_node_ref,
shrinking it to 8 bytes on 32-bit machines (if the TEST_TOTLEN) paranoia
check is turned off, which will be committed soon).
Signed-off-by: David Woodhouse <dwmw2@infradead.org>
Diffstat (limited to 'fs/jffs2/malloc.c')
-rw-r--r-- | fs/jffs2/malloc.c | 75 |
1 files changed, 51 insertions, 24 deletions
diff --git a/fs/jffs2/malloc.c b/fs/jffs2/malloc.c index 171483ef0e4d..4889d0700c0e 100644 --- a/fs/jffs2/malloc.c +++ b/fs/jffs2/malloc.c | |||
@@ -57,8 +57,8 @@ int __init jffs2_create_slab_caches(void) | |||
57 | if (!tmp_dnode_info_slab) | 57 | if (!tmp_dnode_info_slab) |
58 | goto err; | 58 | goto err; |
59 | 59 | ||
60 | raw_node_ref_slab = kmem_cache_create("jffs2_raw_node_ref", | 60 | raw_node_ref_slab = kmem_cache_create("jffs2_refblock", |
61 | sizeof(struct jffs2_raw_node_ref), | 61 | sizeof(struct jffs2_raw_node_ref) * (REFS_PER_BLOCK + 1), |
62 | 0, 0, NULL, NULL); | 62 | 0, 0, NULL, NULL); |
63 | if (!raw_node_ref_slab) | 63 | if (!raw_node_ref_slab) |
64 | goto err; | 64 | goto err; |
@@ -190,38 +190,65 @@ void jffs2_free_tmp_dnode_info(struct jffs2_tmp_dnode_info *x) | |||
190 | kmem_cache_free(tmp_dnode_info_slab, x); | 190 | kmem_cache_free(tmp_dnode_info_slab, x); |
191 | } | 191 | } |
192 | 192 | ||
193 | struct jffs2_raw_node_ref *jffs2_alloc_refblock(void) | ||
194 | { | ||
195 | struct jffs2_raw_node_ref *ret; | ||
196 | |||
197 | ret = kmem_cache_alloc(raw_node_ref_slab, GFP_KERNEL); | ||
198 | if (ret) { | ||
199 | int i = 0; | ||
200 | for (i=0; i < REFS_PER_BLOCK; i++) { | ||
201 | ret[i].flash_offset = REF_EMPTY_NODE; | ||
202 | ret[i].next_in_ino = NULL; | ||
203 | } | ||
204 | ret[i].flash_offset = REF_LINK_NODE; | ||
205 | ret[i].next_in_ino = NULL; | ||
206 | } | ||
207 | return ret; | ||
208 | } | ||
209 | |||
193 | int jffs2_prealloc_raw_node_refs(struct jffs2_sb_info *c, | 210 | int jffs2_prealloc_raw_node_refs(struct jffs2_sb_info *c, |
194 | struct jffs2_eraseblock *jeb, int nr) | 211 | struct jffs2_eraseblock *jeb, int nr) |
195 | { | 212 | { |
196 | struct jffs2_raw_node_ref *p = c->refs; | 213 | struct jffs2_raw_node_ref **p, *ref; |
214 | int i = nr; | ||
197 | 215 | ||
198 | dbg_memalloc("%d\n", nr); | 216 | dbg_memalloc("%d\n", nr); |
199 | 217 | ||
200 | while (nr && p) { | 218 | p = &jeb->last_node; |
201 | p = p->next_in_ino; | 219 | ref = *p; |
202 | nr--; | 220 | |
203 | } | 221 | dbg_memalloc("Reserving %d refs for block @0x%08x\n", nr, jeb->offset); |
204 | while (nr) { | 222 | |
205 | p = __jffs2_alloc_raw_node_ref(); | 223 | /* If jeb->last_node is really a valid node then skip over it */ |
206 | if (!p) | 224 | if (ref && ref->flash_offset != REF_EMPTY_NODE) |
207 | return -ENOMEM; | 225 | ref++; |
208 | p->next_in_ino = c->refs; | 226 | |
209 | c->refs = p; | 227 | while (i) { |
210 | nr--; | 228 | if (!ref) { |
229 | dbg_memalloc("Allocating new refblock linked from %p\n", p); | ||
230 | ref = *p = jffs2_alloc_refblock(); | ||
231 | if (!ref) | ||
232 | return -ENOMEM; | ||
233 | } | ||
234 | if (ref->flash_offset == REF_LINK_NODE) { | ||
235 | p = &ref->next_in_ino; | ||
236 | ref = *p; | ||
237 | continue; | ||
238 | } | ||
239 | i--; | ||
240 | ref++; | ||
211 | } | 241 | } |
212 | c->reserved_refs = nr; | 242 | jeb->allocated_refs = nr; |
213 | return 0; | ||
214 | } | ||
215 | 243 | ||
216 | struct jffs2_raw_node_ref *__jffs2_alloc_raw_node_ref(void) | 244 | dbg_memalloc("Reserved %d refs for block @0x%08x, last_node is %p (%08x,%p)\n", |
217 | { | 245 | nr, jeb->offset, jeb->last_node, jeb->last_node->flash_offset, |
218 | struct jffs2_raw_node_ref *ret; | 246 | jeb->last_node->next_in_ino); |
219 | ret = kmem_cache_alloc(raw_node_ref_slab, GFP_KERNEL); | 247 | |
220 | dbg_memalloc("%p\n", ret); | 248 | return 0; |
221 | return ret; | ||
222 | } | 249 | } |
223 | 250 | ||
224 | void __jffs2_free_raw_node_ref(struct jffs2_raw_node_ref *x) | 251 | void jffs2_free_refblock(struct jffs2_raw_node_ref *x) |
225 | { | 252 | { |
226 | dbg_memalloc("%p\n", x); | 253 | dbg_memalloc("%p\n", x); |
227 | kmem_cache_free(raw_node_ref_slab, x); | 254 | kmem_cache_free(raw_node_ref_slab, x); |