summaryrefslogtreecommitdiffstats
path: root/fs/jffs2/malloc.c
diff options
context:
space:
mode:
authorDavid Woodhouse <dwmw2@infradead.org>2006-05-26 21:19:05 +0100
committerDavid Woodhouse <dwmw2@infradead.org>2006-05-26 21:19:05 +0100
commit9bfeb691e75b21fdaa80ffae719083200b190381 (patch)
tree3c828820f1385249835f85e5073b4ffd10fcd09c /fs/jffs2/malloc.c
parentf75e5097ef298c5a0aa106faa211d1afdc92dc3d (diff)
downloadop-kernel-dev-9bfeb691e75b21fdaa80ffae719083200b190381.zip
op-kernel-dev-9bfeb691e75b21fdaa80ffae719083200b190381.tar.gz
[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.c75
1 files changed, 51 insertions, 24 deletions
diff --git a/fs/jffs2/malloc.c b/fs/jffs2/malloc.c
index 171483e..4889d07 100644
--- a/fs/jffs2/malloc.c
+++ b/fs/jffs2/malloc.c
@@ -57,8 +57,8 @@ int __init jffs2_create_slab_caches(void)
if (!tmp_dnode_info_slab)
goto err;
- raw_node_ref_slab = kmem_cache_create("jffs2_raw_node_ref",
- sizeof(struct jffs2_raw_node_ref),
+ raw_node_ref_slab = kmem_cache_create("jffs2_refblock",
+ sizeof(struct jffs2_raw_node_ref) * (REFS_PER_BLOCK + 1),
0, 0, NULL, NULL);
if (!raw_node_ref_slab)
goto err;
@@ -190,38 +190,65 @@ void jffs2_free_tmp_dnode_info(struct jffs2_tmp_dnode_info *x)
kmem_cache_free(tmp_dnode_info_slab, x);
}
+struct jffs2_raw_node_ref *jffs2_alloc_refblock(void)
+{
+ struct jffs2_raw_node_ref *ret;
+
+ ret = kmem_cache_alloc(raw_node_ref_slab, GFP_KERNEL);
+ if (ret) {
+ int i = 0;
+ for (i=0; i < REFS_PER_BLOCK; i++) {
+ ret[i].flash_offset = REF_EMPTY_NODE;
+ ret[i].next_in_ino = NULL;
+ }
+ ret[i].flash_offset = REF_LINK_NODE;
+ ret[i].next_in_ino = NULL;
+ }
+ return ret;
+}
+
int jffs2_prealloc_raw_node_refs(struct jffs2_sb_info *c,
struct jffs2_eraseblock *jeb, int nr)
{
- struct jffs2_raw_node_ref *p = c->refs;
+ struct jffs2_raw_node_ref **p, *ref;
+ int i = nr;
dbg_memalloc("%d\n", nr);
- while (nr && p) {
- p = p->next_in_ino;
- nr--;
- }
- while (nr) {
- p = __jffs2_alloc_raw_node_ref();
- if (!p)
- return -ENOMEM;
- p->next_in_ino = c->refs;
- c->refs = p;
- nr--;
+ p = &jeb->last_node;
+ ref = *p;
+
+ dbg_memalloc("Reserving %d refs for block @0x%08x\n", nr, jeb->offset);
+
+ /* If jeb->last_node is really a valid node then skip over it */
+ if (ref && ref->flash_offset != REF_EMPTY_NODE)
+ ref++;
+
+ while (i) {
+ if (!ref) {
+ dbg_memalloc("Allocating new refblock linked from %p\n", p);
+ ref = *p = jffs2_alloc_refblock();
+ if (!ref)
+ return -ENOMEM;
+ }
+ if (ref->flash_offset == REF_LINK_NODE) {
+ p = &ref->next_in_ino;
+ ref = *p;
+ continue;
+ }
+ i--;
+ ref++;
}
- c->reserved_refs = nr;
- return 0;
-}
+ jeb->allocated_refs = nr;
-struct jffs2_raw_node_ref *__jffs2_alloc_raw_node_ref(void)
-{
- struct jffs2_raw_node_ref *ret;
- ret = kmem_cache_alloc(raw_node_ref_slab, GFP_KERNEL);
- dbg_memalloc("%p\n", ret);
- return ret;
+ dbg_memalloc("Reserved %d refs for block @0x%08x, last_node is %p (%08x,%p)\n",
+ nr, jeb->offset, jeb->last_node, jeb->last_node->flash_offset,
+ jeb->last_node->next_in_ino);
+
+ return 0;
}
-void __jffs2_free_raw_node_ref(struct jffs2_raw_node_ref *x)
+void jffs2_free_refblock(struct jffs2_raw_node_ref *x)
{
dbg_memalloc("%p\n", x);
kmem_cache_free(raw_node_ref_slab, x);
OpenPOWER on IntegriCloud