Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2bea90d4 authored by Chuck Lever's avatar Chuck Lever Committed by Trond Myklebust
Browse files

SUNRPC: RPC buffer size estimates are too large



The RPC buffer size estimation logic in net/sunrpc/clnt.c always
significantly overestimates the requirements for the buffer size.
A little instrumentation demonstrated that in fact rpc_malloc was never
allocating the buffer from the mempool, but almost always called kmalloc.

To compute the size of the RPC buffer more precisely, split p_bufsiz into
two fields; one for the argument size, and one for the result size.

Then, compute the sum of the exact call and reply header sizes, and split
the RPC buffer precisely between the two.  That should keep almost all RPC
buffers within the 2KiB buffer mempool limit.

And, we can finally be rid of RPC_SLACK_SPACE!

Signed-off-by: default avatarChuck Lever <chuck.lever@oracle.com>
Signed-off-by: default avatarTrond Myklebust <Trond.Myklebust@netapp.com>
parent 511d2e88
Loading
Loading
Loading
Loading
+4 −6
Original line number Diff line number Diff line
@@ -225,16 +225,13 @@ xdr_decode_stat(struct rpc_rqst *rqstp, __be32 *p, struct nsm_res *resp)
#define SM_monres_sz	2
#define SM_unmonres_sz	1

#ifndef MAX
# define MAX(a, b)	(((a) > (b))? (a) : (b))
#endif

static struct rpc_procinfo	nsm_procedures[] = {
[SM_MON] = {
		.p_proc		= SM_MON,
		.p_encode	= (kxdrproc_t) xdr_encode_mon,
		.p_decode	= (kxdrproc_t) xdr_decode_stat_res,
		.p_bufsiz	= MAX(SM_mon_sz, SM_monres_sz) << 2,
		.p_arglen	= SM_mon_sz,
		.p_replen	= SM_monres_sz,
		.p_statidx	= SM_MON,
		.p_name		= "MONITOR",
	},
@@ -242,7 +239,8 @@ static struct rpc_procinfo nsm_procedures[] = {
		.p_proc		= SM_UNMON,
		.p_encode	= (kxdrproc_t) xdr_encode_unmon,
		.p_decode	= (kxdrproc_t) xdr_decode_stat,
		.p_bufsiz	= MAX(SM_mon_id_sz, SM_unmonres_sz) << 2,
		.p_arglen	= SM_mon_id_sz,
		.p_replen	= SM_unmonres_sz,
		.p_statidx	= SM_UNMON,
		.p_name		= "UNMONITOR",
	},
+2 −5
Original line number Diff line number Diff line
@@ -534,10 +534,6 @@ nlmclt_decode_res(struct rpc_rqst *req, __be32 *p, struct nlm_res *resp)
#define NLM_res_sz		NLM_cookie_sz+1
#define NLM_norep_sz		0

#ifndef MAX
# define MAX(a, b)		(((a) > (b))? (a) : (b))
#endif

/*
 * For NLM, a void procedure really returns nothing
 */
@@ -548,7 +544,8 @@ nlmclt_decode_res(struct rpc_rqst *req, __be32 *p, struct nlm_res *resp)
	.p_proc      = NLMPROC_##proc,					\
	.p_encode    = (kxdrproc_t) nlmclt_encode_##argtype,		\
	.p_decode    = (kxdrproc_t) nlmclt_decode_##restype,		\
	.p_bufsiz    = MAX(NLM_##argtype##_sz, NLM_##restype##_sz) << 2,	\
	.p_arglen    = NLM_##argtype##_sz,				\
	.p_replen    = NLM_##restype##_sz,				\
	.p_statidx   = NLMPROC_##proc,					\
	.p_name      = #proc,						\
	}
+2 −5
Original line number Diff line number Diff line
@@ -544,10 +544,6 @@ nlm4clt_decode_res(struct rpc_rqst *req, __be32 *p, struct nlm_res *resp)
#define NLM4_res_sz		NLM4_cookie_sz+1
#define NLM4_norep_sz		0

#ifndef MAX
# define MAX(a,b)		(((a) > (b))? (a) : (b))
#endif

/*
 * For NLM, a void procedure really returns nothing
 */
@@ -558,7 +554,8 @@ nlm4clt_decode_res(struct rpc_rqst *req, __be32 *p, struct nlm_res *resp)
	.p_proc      = NLMPROC_##proc,					\
	.p_encode    = (kxdrproc_t) nlm4clt_encode_##argtype,		\
	.p_decode    = (kxdrproc_t) nlm4clt_decode_##restype,		\
	.p_bufsiz    = MAX(NLM4_##argtype##_sz, NLM4_##restype##_sz) << 2,	\
	.p_arglen    = NLM4_##argtype##_sz,				\
	.p_replen    = NLM4_##restype##_sz,				\
	.p_statidx   = NLMPROC_##proc,					\
	.p_name      = #proc,						\
	}
+5 −2
Original line number Diff line number Diff line
@@ -133,13 +133,15 @@ xdr_decode_fhstatus3(struct rpc_rqst *req, __be32 *p, struct mnt_fhstatus *res)

#define MNT_dirpath_sz		(1 + 256)
#define MNT_fhstatus_sz		(1 + 8)
#define MNT_fhstatus3_sz	(1 + 16)

static struct rpc_procinfo	mnt_procedures[] = {
[MNTPROC_MNT] = {
	  .p_proc		= MNTPROC_MNT,
	  .p_encode		= (kxdrproc_t) xdr_encode_dirpath,	
	  .p_decode		= (kxdrproc_t) xdr_decode_fhstatus,
	  .p_bufsiz		= MNT_dirpath_sz << 2,
	  .p_arglen		= MNT_dirpath_sz,
	  .p_replen		= MNT_fhstatus_sz,
	  .p_statidx		= MNTPROC_MNT,
	  .p_name		= "MOUNT",
	},
@@ -150,7 +152,8 @@ static struct rpc_procinfo mnt3_procedures[] = {
	  .p_proc		= MOUNTPROC3_MNT,
	  .p_encode		= (kxdrproc_t) xdr_encode_dirpath,
	  .p_decode		= (kxdrproc_t) xdr_decode_fhstatus3,
	  .p_bufsiz		= MNT_dirpath_sz << 2,
	  .p_arglen		= MNT_dirpath_sz,
	  .p_replen		= MNT_fhstatus3_sz,
	  .p_statidx		= MOUNTPROC3_MNT,
	  .p_name		= "MOUNT",
	},
+2 −5
Original line number Diff line number Diff line
@@ -687,16 +687,13 @@ nfs_stat_to_errno(int stat)
	return nfs_errtbl[i].errno;
}

#ifndef MAX
# define MAX(a, b)	(((a) > (b))? (a) : (b))
#endif

#define PROC(proc, argtype, restype, timer)				\
[NFSPROC_##proc] = {							\
	.p_proc	    =  NFSPROC_##proc,					\
	.p_encode   =  (kxdrproc_t) nfs_xdr_##argtype,			\
	.p_decode   =  (kxdrproc_t) nfs_xdr_##restype,			\
	.p_bufsiz   =  MAX(NFS_##argtype##_sz,NFS_##restype##_sz) << 2,	\
	.p_arglen   =  NFS_##argtype##_sz,				\
	.p_replen   =  NFS_##restype##_sz,				\
	.p_timer    =  timer,						\
	.p_statidx  =  NFSPROC_##proc,					\
	.p_name     =  #proc,						\
Loading