From mboxrd@z Thu Jan 1 00:00:00 1970 From: "J. Bruce Fields" Subject: [PATCH 2/2] nfsd4.1: common slot allocation size calculation Date: Tue, 27 Oct 2009 19:07:42 -0400 Message-ID: <1256684862-14390-3-git-send-email-bfields@citi.umich.edu> References: <1256684862-14390-1-git-send-email-bfields@citi.umich.edu> <1256684862-14390-2-git-send-email-bfields@citi.umich.edu> Cc: pnfs@linux-nfs.org, Andy Adamson , "J. Bruce Fields" To: linux-fsdevel@vger.kernel.org Return-path: Received: from fieldses.org ([174.143.236.118]:54764 "EHLO fieldses.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754784AbZJ0XGU (ORCPT ); Tue, 27 Oct 2009 19:06:20 -0400 In-Reply-To: <1256684862-14390-2-git-send-email-bfields@citi.umich.edu> Sender: linux-fsdevel-owner@vger.kernel.org List-ID: We do the same calculation in a couple places; use a helper function, and add a little documentation, in the hopes of preventing bugs like that fixed in the last patch. Signed-off-by: J. Bruce Fields --- fs/nfsd/nfs4state.c | 14 +++++++++++--- 1 files changed, 11 insertions(+), 3 deletions(-) diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c index c171371..42dab95 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -524,6 +524,15 @@ free_session_slots(struct nfsd4_session *ses) kfree(ses->se_slots[i]); } +/* + * We don't actually need to cache the rpc and session headers, so we + * can allocate a little less for each slot: + */ +static inline int slot_bytes(struct nfsd4_channel_attrs *ca) +{ + return ca->maxresp_cached - NFSD_MIN_HDR_SEQ_SZ; +} + static int alloc_init_session(struct svc_rqst *rqstp, struct nfs4_client *clp, struct nfsd4_create_session *cses) @@ -555,7 +564,7 @@ alloc_init_session(struct svc_rqst *rqstp, struct nfs4_client *clp, memcpy(new, &tmp, sizeof(*new)); /* allocate each struct nfsd4_slot and data cache in one piece */ - cachesize = new->se_fchannel.maxresp_cached - NFSD_MIN_HDR_SEQ_SZ; + cachesize = slot_bytes(&new->se_fchannel); for (i = 0; i < new->se_fchannel.maxreqs; i++) { sp = kzalloc(sizeof(*sp) + cachesize, GFP_KERNEL); if (!sp) @@ -633,8 +642,7 @@ free_session(struct kref *kref) ses = container_of(kref, struct nfsd4_session, se_ref); spin_lock(&nfsd_drc_lock); - mem = ses->se_fchannel.maxreqs - * (ses->se_fchannel.maxresp_cached - NFSD_MIN_HDR_SEQ_SZ); + mem = ses->se_fchannel.maxreqs * slot_bytes(&ses->se_fchannel); nfsd_drc_mem_used -= mem; spin_unlock(&nfsd_drc_lock); free_session_slots(ses); -- 1.6.3.3