nfsd: move nfs4_client allocation to dedicated slabcache

On x86_64, it's 1152 bytes, so we can avoid wasting 896 bytes each.

Signed-off-by: Jeff Layton <jlayton@redhat.com>
Signed-off-by: J. Bruce Fields <bfields@redhat.com>
This commit is contained in:
Jeff Layton 2018-03-16 09:47:22 -04:00 committed by J. Bruce Fields
parent 9d7ed1355d
commit 9258a2d5cd

View File

@ -98,6 +98,7 @@ enum nfsd4_st_mutex_lock_subclass {
*/ */
static DECLARE_WAIT_QUEUE_HEAD(close_wq); static DECLARE_WAIT_QUEUE_HEAD(close_wq);
static struct kmem_cache *client_slab;
static struct kmem_cache *openowner_slab; static struct kmem_cache *openowner_slab;
static struct kmem_cache *lockowner_slab; static struct kmem_cache *lockowner_slab;
static struct kmem_cache *file_slab; static struct kmem_cache *file_slab;
@ -1794,7 +1795,7 @@ static struct nfs4_client *alloc_client(struct xdr_netobj name)
struct nfs4_client *clp; struct nfs4_client *clp;
int i; int i;
clp = kzalloc(sizeof(struct nfs4_client), GFP_KERNEL); clp = kmem_cache_zalloc(client_slab, GFP_KERNEL);
if (clp == NULL) if (clp == NULL)
return NULL; return NULL;
clp->cl_name.data = kmemdup(name.data, name.len, GFP_KERNEL); clp->cl_name.data = kmemdup(name.data, name.len, GFP_KERNEL);
@ -1825,7 +1826,7 @@ static struct nfs4_client *alloc_client(struct xdr_netobj name)
err_no_hashtbl: err_no_hashtbl:
kfree(clp->cl_name.data); kfree(clp->cl_name.data);
err_no_name: err_no_name:
kfree(clp); kmem_cache_free(client_slab, clp);
return NULL; return NULL;
} }
@ -1845,7 +1846,7 @@ free_client(struct nfs4_client *clp)
kfree(clp->cl_ownerstr_hashtbl); kfree(clp->cl_ownerstr_hashtbl);
kfree(clp->cl_name.data); kfree(clp->cl_name.data);
idr_destroy(&clp->cl_stateids); idr_destroy(&clp->cl_stateids);
kfree(clp); kmem_cache_free(client_slab, clp);
} }
/* must be called under the client_lock */ /* must be called under the client_lock */
@ -3471,21 +3472,26 @@ static void nfsd4_init_file(struct knfsd_fh *fh, unsigned int hashval,
void void
nfsd4_free_slabs(void) nfsd4_free_slabs(void)
{ {
kmem_cache_destroy(odstate_slab); kmem_cache_destroy(client_slab);
kmem_cache_destroy(openowner_slab); kmem_cache_destroy(openowner_slab);
kmem_cache_destroy(lockowner_slab); kmem_cache_destroy(lockowner_slab);
kmem_cache_destroy(file_slab); kmem_cache_destroy(file_slab);
kmem_cache_destroy(stateid_slab); kmem_cache_destroy(stateid_slab);
kmem_cache_destroy(deleg_slab); kmem_cache_destroy(deleg_slab);
kmem_cache_destroy(odstate_slab);
} }
int int
nfsd4_init_slabs(void) nfsd4_init_slabs(void)
{ {
client_slab = kmem_cache_create("nfsd4_clients",
sizeof(struct nfs4_client), 0, 0, NULL);
if (client_slab == NULL)
goto out;
openowner_slab = kmem_cache_create("nfsd4_openowners", openowner_slab = kmem_cache_create("nfsd4_openowners",
sizeof(struct nfs4_openowner), 0, 0, NULL); sizeof(struct nfs4_openowner), 0, 0, NULL);
if (openowner_slab == NULL) if (openowner_slab == NULL)
goto out; goto out_free_client_slab;
lockowner_slab = kmem_cache_create("nfsd4_lockowners", lockowner_slab = kmem_cache_create("nfsd4_lockowners",
sizeof(struct nfs4_lockowner), 0, 0, NULL); sizeof(struct nfs4_lockowner), 0, 0, NULL);
if (lockowner_slab == NULL) if (lockowner_slab == NULL)
@ -3518,6 +3524,8 @@ out_free_lockowner_slab:
kmem_cache_destroy(lockowner_slab); kmem_cache_destroy(lockowner_slab);
out_free_openowner_slab: out_free_openowner_slab:
kmem_cache_destroy(openowner_slab); kmem_cache_destroy(openowner_slab);
out_free_client_slab:
kmem_cache_destroy(client_slab);
out: out:
dprintk("nfsd4: out of memory while initializing nfsv4\n"); dprintk("nfsd4: out of memory while initializing nfsv4\n");
return -ENOMEM; return -ENOMEM;