From patchwork Sun Dec 12 21:00:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Weinberger X-Patchwork-Id: 12672641 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B8AA5C433EF for ; Sun, 12 Dec 2021 21:00:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229536AbhLLVA7 (ORCPT ); Sun, 12 Dec 2021 16:00:59 -0500 Received: from lithops.sigma-star.at ([195.201.40.130]:35118 "EHLO lithops.sigma-star.at" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229528AbhLLVA6 (ORCPT ); Sun, 12 Dec 2021 16:00:58 -0500 Received: from localhost (localhost [127.0.0.1]) by lithops.sigma-star.at (Postfix) with ESMTP id AD89A614E2ED; Sun, 12 Dec 2021 22:00:51 +0100 (CET) Received: from lithops.sigma-star.at ([127.0.0.1]) by localhost (lithops.sigma-star.at [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id xBu7Mhxd4hUg; Sun, 12 Dec 2021 22:00:51 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by lithops.sigma-star.at (Postfix) with ESMTP id 38727614E2F0; Sun, 12 Dec 2021 22:00:51 +0100 (CET) Received: from lithops.sigma-star.at ([127.0.0.1]) by localhost (lithops.sigma-star.at [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id Hm8rnARabn_U; Sun, 12 Dec 2021 22:00:51 +0100 (CET) Received: from blindfold.corp.sigma-star.at (213-47-184-186.cable.dynamic.surfer.at [213.47.184.186]) by lithops.sigma-star.at (Postfix) with ESMTPSA id D0559614E2ED; Sun, 12 Dec 2021 22:00:50 +0100 (CET) From: Richard Weinberger To: linux-nfs@vger.kernel.org Cc: linux-kernel@vger.kernel.org, anna.schumaker@netapp.com, trond.myklebust@hammerspace.com, david@sigma-star.at, Richard Weinberger Subject: [RFC PATCH] NFS: Save 4 bytes when re-exporting Date: Sun, 12 Dec 2021 22:00:44 +0100 Message-Id: <20211212210044.16238-1-richard@nod.at> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org When re-exporting, the whole struct nfs_fh is embedded in the new fhandle. But we need only nfs_fh->data[], nfs_fh->size is not needed. So skip fs_fh->size and save a full word (4 bytes). The downside is the extra memcpy() in nfs_fh_to_dentry(). Signed-off-by: Richard Weinberger --- While investigating into improving NFS re-export I noticed that we can already save 4 bytes of overhead. I don't think we need to embedd the full struct nfs_fh and can skip ->size. Thanks, //richard --- fs/nfs/export.c | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/fs/nfs/export.c b/fs/nfs/export.c index 5f6e1b715545..5579c87106a1 100644 --- a/fs/nfs/export.c +++ b/fs/nfs/export.c @@ -22,9 +22,9 @@ enum { }; -static struct nfs_fh *nfs_exp_embedfh(__u32 *p) +static unsigned char *nfs_exp_embedfh(__u32 *p) { - return (struct nfs_fh *)(p + EMBED_FH_OFF); + return (unsigned char *)(p + EMBED_FH_OFF); } /* @@ -35,8 +35,8 @@ static int nfs_encode_fh(struct inode *inode, __u32 *p, int *max_len, struct inode *parent) { struct nfs_fh *server_fh = NFS_FH(inode); - struct nfs_fh *clnt_fh = nfs_exp_embedfh(p); - size_t fh_size = offsetof(struct nfs_fh, data) + server_fh->size; + unsigned char *raw_fh = nfs_exp_embedfh(p); + size_t fh_size = server_fh->size; int len = EMBED_FH_OFF + XDR_QUADLEN(fh_size); dprintk("%s: max fh len %d inode %p parent %p", @@ -58,7 +58,9 @@ nfs_encode_fh(struct inode *inode, __u32 *p, int *max_len, struct inode *parent) p[FILEID_LOW_OFF] = NFS_FILEID(inode); p[FILE_I_TYPE_OFF] = inode->i_mode & S_IFMT; p[len - 1] = 0; /* Padding */ - nfs_copy_fh(clnt_fh, server_fh); + + memcpy(raw_fh, server_fh->data, server_fh->size); + *max_len = len; dprintk("%s: result fh fileid %llu mode %u size %d\n", __func__, NFS_FILEID(inode), inode->i_mode, *max_len); @@ -70,18 +72,22 @@ nfs_fh_to_dentry(struct super_block *sb, struct fid *fid, int fh_len, int fh_type) { struct nfs_fattr *fattr = NULL; - struct nfs_fh *server_fh = nfs_exp_embedfh(fid->raw); - size_t fh_size = offsetof(struct nfs_fh, data) + server_fh->size; + unsigned char *raw_server_fh = nfs_exp_embedfh(fid->raw); const struct nfs_rpc_ops *rpc_ops; struct dentry *dentry; struct inode *inode; - int len = EMBED_FH_OFF + XDR_QUADLEN(fh_size); u32 *p = fid->raw; + struct nfs_fh server_fh = { 0 }; int ret; - /* NULL translates to ESTALE */ - if (fh_len < len || fh_type != len) + server_fh.size = (fh_len * XDR_UNIT) - (EMBED_FH_OFF * XDR_UNIT); + if (server_fh.size < 1) { + WARN_ON_ONCE(1); + /* NULL translates to ESTALE */ return NULL; + } + + memcpy(server_fh.data, raw_server_fh, server_fh.size); fattr = nfs_alloc_fattr_with_label(NFS_SB(sb)); if (fattr == NULL) { @@ -95,20 +101,20 @@ nfs_fh_to_dentry(struct super_block *sb, struct fid *fid, dprintk("%s: fileid %llu mode %d\n", __func__, fattr->fileid, fattr->mode); - inode = nfs_ilookup(sb, fattr, server_fh); + inode = nfs_ilookup(sb, fattr, &server_fh); if (inode) goto out_found; rpc_ops = NFS_SB(sb)->nfs_client->rpc_ops; - ret = rpc_ops->getattr(NFS_SB(sb), server_fh, fattr, NULL); + ret = rpc_ops->getattr(NFS_SB(sb), &server_fh, fattr, NULL); if (ret) { dprintk("%s: getattr failed %d\n", __func__, ret); - trace_nfs_fh_to_dentry(sb, server_fh, fattr->fileid, ret); + trace_nfs_fh_to_dentry(sb, &server_fh, fattr->fileid, ret); dentry = ERR_PTR(ret); goto out_free_fattr; } - inode = nfs_fhget(sb, server_fh, fattr); + inode = nfs_fhget(sb, &server_fh, fattr); out_found: dentry = d_obtain_alias(inode);