[PATCH]enhanced 1:1 mapping(revision 1)

Jörn Engel joern at wohnheim.fh-wedel.de
Tue Sep 27 07:55:31 EDT 2005


On Tue, 27 September 2005 15:59:41 +0800, zhao forrest wrote:
> 
> I revised the patch according to Joern's comments.
> Now the basic data structure is:
> vmalloc()/kmalloc + pointer array + slab cache.
> Also I did some code re-constructure to make it more clean.


> @@ -205,3 +215,57 @@ void jffs2_free_inode_cache(struct jffs2
>  	dbg_memalloc("%p\n", x);
>  	kmem_cache_free(inode_cache_slab, x);
>  }
> +
> +int jffs2_alloc_eraseblocks(struct jffs2_sb_info *c)
> +{
> +	uint32_t i;
> +#ifndef __ECOS
> +	if (jffs2_blocks_use_vmalloc(c))
> +		c->blocks = vmalloc(sizeof(uint8_t *) * c->nr_blocks);
> +	else
> +#endif
> +		c->blocks = kmalloc(sizeof(uint8_t *) * c->nr_blocks, GFP_KERNEL);
> +	if (!c->blocks)
> +		return -ENOMEM;
> +	memset(c->blocks, 0, sizeof(uint8_t *) * c->nr_blocks);

sizeof(uint8_t *) is rather odd.  Either this should be
sizeof(struct jffs2_eraseblock*), which is correct but admittedly
quite long, or a simple sizeof(void*).  uint8_t puts people on the
wrong track.

> +
> +	for (i=0; i<c->nr_blocks; i++) {
> +		c->blocks[i] = kmem_cache_alloc(eraseblock_slab, GFP_KERNEL);
> +		dbg_memalloc("%p\n", ret);
                                     ^^^
That should be c->blocks[i], I assume.

> +		if (!c->blocks[i]) {
> +			jffs2_free_eraseblocks(c);
> +			return -ENOMEM;
> +		}
> +		memset(c->blocks[i], 0, sizeof(struct jffs2_eraseblock));
> +	}
> +
> +	
> +	for (i=0; i<c->nr_blocks; i++) {
> +		INIT_LIST_HEAD(&c->blocks[i]->list);
> +		c->blocks[i]->offset = i * c->sector_size;
> +		c->blocks[i]->free_size = c->sector_size;
> +		c->blocks[i]->first_node = NULL;
> +		c->blocks[i]->last_node = NULL;
> +	}
> +
> +	return 0;
> +}
> +
> +void jffs2_free_eraseblocks(struct jffs2_sb_info *c)
> +{
> +	uint32_t i;
> +
> +	for (i=0; i<c->nr_blocks; i++) {
> +		if (c->blocks[i]) {
> +			dbg_memalloc("%p\n", c->blocks[i]);
> +			kmem_cache_free(eraseblock_slab, c->blocks[i]);
> +		}
> +	}
> +#ifndef __ECOS
> +	if (jffs2_blocks_use_vmalloc(c))
> +		vfree(c->blocks);
> +	else
> +#endif
> +	kfree(c->blocks);
        ^
another indentation level?  Not sure.
> +}
> +
 
It appears as if jffs2_blocks_use_vmalloc(c) was unchanged.  Maybe I
missed it, but that function should get adjusted by this patch.
Maybe we can move it into malloc.c, as that file contains the only two
remaining users, now.

Looks quite nice, thanks.

Jörn

-- 
The story so far:
In the beginning the Universe was created.  This has made a lot
of people very angry and been widely regarded as a bad move.
-- Douglas Adams




More information about the linux-mtd mailing list