slabify the sunrpc layer
Subsystems (3)
PATCH 1/1 slabify the sunrpc layer
In order to better cope with low memory conditions, add slabs for struct rpc_task and 'small' RPC buffers of <= 2k. Protect these using mempools.
The only case where we appear to use buffers of > 2k is when symlinking, and is due to the fact that the path can be up to 4k in length. For the moment, we just use kmalloc(), but it may be worth it some time in the near future to convert nfs_symlink() to use pages.
Cheers,
Trond
include/linux/sunrpc/sched.h +5 -8
@@ -48,6 +48,7 @@*/ struct rpc_message tk_msg;/* RPC call info */ __u32 * tk_buffer;/* XDR buffer */ +size_t tk_bufsize;__u8 tk_garb_retry, tk_cred_retry, tk_suid_retry;
@@ -184,20 +185,16 @@struct rpc_task *rpc_wake_up_next (struct rpc_wait_queue *);void rpc_wake_up_status (struct rpc_wait_queue *,int );void rpc_delay (struct rpc_task *,unsigned long ); -void *rpc_allocate (unsigned int flags,unsigned int ); -void rpc_free (void *); +void *rpc_malloc (struct rpc_task *,size_t ); +void rpc_free (struct rpc_task *);int rpciod_up (void );void rpciod_down (void );void rpciod_wake_up (void );#ifdef RPC_DEBUG void rpc_show_tasks (void );#endif - -static __inline__void * -rpc_malloc (struct rpc_task *task,unsigned int size) -{ -return rpc_allocate (task->tk_flags, size); -} +int rpc_init_mempool (void ); +void rpc_destroy_mempool (void );static __inline__void rpc_exit (struct rpc_task *task,int status)
net/sunrpc/auth_null.c +4 -4
@@ -25,7 +25,7 @@struct rpc_auth *auth;dprintk ("RPC: creating NULL authenticator for client %p\n" , clnt); -if (!(auth = (struct rpc_auth *)rpc_allocate (0 ,sizeof (*auth)))) +if (!(auth = (struct rpc_auth *)kmalloc (sizeof (*auth),GFP_KERNEL )))return NULL ; auth->au_cslack =4 ; auth->au_rslack =2 ;
@@ -41,7 +41,7 @@ {dprintk ("RPC: destroying NULL authenticator %p\n" , auth);rpcauth_free_credcache (auth); -rpc_free (auth); +kfree (auth); }/*
@@ -52,7 +52,7 @@ {struct rpc_cred *cred; -if (!(cred = (struct rpc_cred *)rpc_allocate (flags,sizeof (*cred)))) +if (!(cred = (struct rpc_cred *)kmalloc (sizeof (*cred),GFP_KERNEL )))return NULL ;atomic_set (&cred->cr_count,0 ); cred->cr_flags =RPCAUTH_CRED_UPTODATE ;
@@ -68,7 +68,7 @@static void nul_destroy_cred (struct rpc_cred *cred) { -rpc_free (cred); +kfree (cred); }/*
net/sunrpc/auth_unix.c +4 -26
@@ -41,7 +41,7 @@struct rpc_auth *auth;dprintk ("RPC: creating UNIX authenticator for client %p\n" , clnt); -if (!(auth = (struct rpc_auth *)rpc_allocate (0 ,sizeof (*auth)))) +if (!(auth = (struct rpc_auth *)kmalloc (sizeof (*auth),GFP_KERNEL )))return NULL ; auth->au_cslack =UNX_WRITESLACK ; auth->au_rslack =2 ;/* assume AUTH_NULL verf */
@@ -58,7 +58,7 @@ {dprintk ("RPC: destroying UNIX authenticator %p\n" , auth);rpcauth_free_credcache (auth); -rpc_free (auth); +kfree (auth); } static struct rpc_cred *
@@ -70,7 +70,7 @@dprintk ("RPC: allocating UNIX cred for uid %d gid %d\n" , current->uid, current->gid); -if (!(cred = (struct unx_cred *)rpc_allocate (flags,sizeof (*cred)))) +if (!(cred = (struct unx_cred *)kmalloc (sizeof (*cred),GFP_KERNEL )))return NULL ;atomic_set (&cred->uc_count,0 );
@@ -98,32 +98,10 @@return (struct rpc_cred *) cred; } -struct rpc_cred * -authunix_fake_cred (struct rpc_task *task,uid_t uid,gid_t gid) -{ -struct unx_cred *cred; - -dprintk ("RPC: allocating fake UNIX cred for uid %d gid %d\n" , - uid, gid); - -if (!(cred = (struct unx_cred *)rpc_malloc (task,sizeof (*cred)))) -return NULL ; - -atomic_set (&cred->uc_count,1 ); - cred->uc_flags =RPCAUTH_CRED_DEAD |RPCAUTH_CRED_UPTODATE ; - cred->uc_uid = uid; - cred->uc_gid = gid; - cred->uc_fsuid = uid; - cred->uc_fsgid = gid; - cred->uc_gids[0 ] = (gid_t )NOGROUP ; - -return task->tk_msg.rpc_cred = (struct rpc_cred *) cred; -} -static void unx_destroy_cred (struct rpc_cred *cred) { -rpc_free (cred); +kfree (cred); }/*
net/sunrpc/clnt.c +5 -5
@@ -85,7 +85,7 @@if (vers >= program->nrvers || !(version = program->version[vers])) goto out; - clnt = (struct rpc_clnt *)rpc_allocate (0 ,sizeof (*clnt)); + clnt = (struct rpc_clnt *)kmalloc (sizeof (*clnt),GFP_KERNEL );if (!clnt) goto out_no_clnt;memset (clnt,0 ,sizeof (*clnt));
@@ -125,7 +125,7 @@ out_no_auth:printk (KERN_INFO "RPC: Couldn't create auth handle (flavor %u)\n" , flavor); -rpc_free (clnt); +kfree (clnt); clnt =NULL ; goto out; }
@@ -180,7 +180,7 @@xprt_destroy (clnt->cl_xprt); clnt->cl_xprt =NULL ; } -rpc_free (clnt); +kfree (clnt);return 0 ; }
@@ -487,7 +487,7 @@* auth->au_wslack */ bufsiz =rpcproc_bufsiz (clnt, task->tk_msg.rpc_proc) +RPC_SLACK_SPACE ; -if ((task->tk_buffer =rpc_malloc (task, bufsiz <<1 )) !=NULL ) +if (rpc_malloc (task, bufsiz <<1 ) !=NULL )return ;printk (KERN_INFO "RPC: buffer allocation failed for task %p\n" , task);
@@ -522,7 +522,7 @@ task->tk_action = call_bind;/* Default buffer setup */ - bufsiz =rpcproc_bufsiz (clnt, task->tk_msg.rpc_proc)+RPC_SLACK_SPACE ; + bufsiz = task->tk_bufsize >>1 ; sndbuf->head[0 ].iov_base = (void *)task->tk_buffer; sndbuf->head[0 ].iov_len = bufsiz; sndbuf->tail[0 ].iov_len =0 ;
net/sunrpc/sched.c +91 -73
234 lines not on this page · raw message
net/sunrpc/sunrpc_syms.c +3 -2
@@ -25,8 +25,6 @@/* RPC scheduler */ -EXPORT_SYMBOL (rpc_allocate); -EXPORT_SYMBOL (rpc_free);EXPORT_SYMBOL (rpc_execute);EXPORT_SYMBOL (rpc_init_task);EXPORT_SYMBOL (rpc_sleep_on);
@@ -134,6 +132,8 @@static int __init init_sunrpc (void ) { +if (rpc_init_mempool () !=0 ) +return -ENOMEM ;#ifdef RPC_DEBUG rpc_register_sysctl ();#endif
@@ -148,6 +148,7 @@ static void __exitcleanup_sunrpc (void ) { +rpc_destroy_mempool ();cache_unregister (&auth_domain_cache);cache_unregister (&ip_map_cache);#ifdef RPC_DEBUG
net/sunrpc/xprt.c +2 -2
@@ -1547,7 +1547,7 @@ out_bad:dprintk ("RPC: xprt_create_proto failed\n" );if (xprt) -rpc_free (xprt); +kfree (xprt);return NULL ; }
@@ -1586,7 +1586,7 @@dprintk ("RPC: destroying transport %p\n" , xprt);xprt_shutdown (xprt);xprt_close (xprt); -rpc_free (xprt); +kfree (xprt);return 0 ; }