Most of the init code in alloc_spu_context() is static and can happen in slab's constructor. Parts of the init code in spu_init_csa() could also be moved but it is probably ugly. Signed-off-by: Sebastian Siewior --- a/arch/powerpc/platforms/cell/spufs/context.c +++ b/arch/powerpc/platforms/cell/spufs/context.c @@ -31,17 +31,11 @@ atomic_t nr_spu_contexts = ATOMIC_INIT(0); -struct spu_context *alloc_spu_context(struct spu_gang *gang) +void spuctx_init_once(void *p, struct kmem_cache * cachep, unsigned long flags) { - struct spu_context *ctx; - ctx = kmem_cache_zalloc(spufs_ctx_cache, GFP_KERNEL); - if (!ctx) - goto out; - /* Binding to physical processor deferred - * until spu_activate(). - */ - if (spu_init_csa(&ctx->csa)) - goto out_free; + struct spu_context *ctx = p; + + memset(ctx, 0, sizeof *ctx); spin_lock_init(&ctx->mmio_lock); mutex_init(&ctx->mapping_lock); kref_init(&ctx->kref); @@ -53,9 +47,22 @@ struct spu_context *alloc_spu_context(st init_waitqueue_head(&ctx->mfc_wq); ctx->state = SPU_STATE_SAVED; ctx->ops = &spu_backing_ops; - ctx->owner = get_task_mm(current); INIT_LIST_HEAD(&ctx->rq); INIT_LIST_HEAD(&ctx->aff_list); +} + +struct spu_context *alloc_spu_context(struct spu_gang *gang) +{ + struct spu_context *ctx; + ctx = kmem_cache_alloc(spufs_ctx_cache, GFP_KERNEL); + if (!ctx) + goto out; + /* Binding to physical processor deferred + * until spu_activate(). + */ + if (spu_init_csa(&ctx->csa)) + goto out_free; + ctx->owner = get_task_mm(current); if (gang) spu_gang_add_ctx(gang, ctx); --- a/arch/powerpc/platforms/cell/spufs/inode.c +++ b/arch/powerpc/platforms/cell/spufs/inode.c @@ -780,7 +780,7 @@ static int __init spufs_init(void) if (!spufs_inode_cache) goto out; spufs_ctx_cache = kmem_cache_create("spufs_spu_ctx", - sizeof(struct spu_context), 0, 0, NULL); + sizeof(struct spu_context), 0, 0, spuctx_init_once); if (!spufs_ctx_cache) goto out_cache; --- a/arch/powerpc/platforms/cell/spufs/spufs.h +++ b/arch/powerpc/platforms/cell/spufs/spufs.h @@ -231,6 +231,7 @@ static inline void spu_release(struct sp mutex_unlock(&ctx->state_mutex); } +void spuctx_init_once(void *p, struct kmem_cache * cachep, unsigned long flags); struct spu_context * alloc_spu_context(struct spu_gang *gang); void destroy_spu_context(struct kref *kref); struct spu_context * get_spu_context(struct spu_context *ctx); --