2016-11-10 21:41:14

by Trond Myklebust

[permalink] [raw]
Subject: [PATCH 0/5] Optimisations for state management

The following patches constitute a grab bag of minor optimisations when
the NFS client is managing its state.

Trond Myklebust (5):
NFSv4: Don't check file access when reclaiming state
NFSv4: Don't ask for the change attribute when reclaiming state
NFSv4: Don't request a GETATTR on open_downgrade.
NFSv4: Don't request close-to-open attribute when holding a delegation
NFSv4: Optimise away forced revalidation when we know the attributes
are OK

fs/nfs/delegation.c | 4 ----
fs/nfs/inode.c | 2 +-
fs/nfs/nfs4proc.c | 23 +++++++++++++++++------
fs/nfs/nfs4xdr.c | 7 ++-----
4 files changed, 20 insertions(+), 16 deletions(-)

--
2.7.4



2016-11-10 21:41:15

by Trond Myklebust

[permalink] [raw]
Subject: [PATCH 2/5] NFSv4: Don't ask for the change attribute when reclaiming state

We don't need to ask for the change attribute when returning a delegation
or recovering from a server reboot, and it could actually cause us to
obtain an incorrect value if we're using a pNFS flavour that requires
LAYOUTCOMMIT.

Signed-off-by: Trond Myklebust <[email protected]>
---
fs/nfs/nfs4proc.c | 1 -
1 file changed, 1 deletion(-)

diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c
index 4eead738da8e..1e7e0754a96d 100644
--- a/fs/nfs/nfs4proc.c
+++ b/fs/nfs/nfs4proc.c
@@ -226,7 +226,6 @@ static const u32 nfs4_pnfs_open_bitmap[3] = {

static const u32 nfs4_open_noattr_bitmap[3] = {
FATTR4_WORD0_TYPE
- | FATTR4_WORD0_CHANGE
| FATTR4_WORD0_FILEID,
};

--
2.7.4


2016-11-10 21:41:14

by Trond Myklebust

[permalink] [raw]
Subject: [PATCH 1/5] NFSv4: Don't check file access when reclaiming state

If we're reclaiming state after a reboot, or as part of returning a
delegation, we don't need to check access modes again.

Signed-off-by: Trond Myklebust <[email protected]>
---
fs/nfs/nfs4proc.c | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c
index 6a1d650e0419..4eead738da8e 100644
--- a/fs/nfs/nfs4proc.c
+++ b/fs/nfs/nfs4proc.c
@@ -1221,6 +1221,7 @@ static struct nfs4_opendata *nfs4_opendata_alloc(struct dentry *dentry,
atomic_inc(&sp->so_count);
p->o_arg.open_flags = flags;
p->o_arg.fmode = fmode & (FMODE_READ|FMODE_WRITE);
+ p->o_arg.claim = nfs4_map_atomic_open_claim(server, claim);
p->o_arg.share_access = nfs4_map_atomic_open_share(server,
fmode, flags);
/* don't put an ACCESS op in OPEN compound if O_EXCL, because ACCESS
@@ -1228,8 +1229,14 @@ static struct nfs4_opendata *nfs4_opendata_alloc(struct dentry *dentry,
if (!(flags & O_EXCL)) {
/* ask server to check for all possible rights as results
* are cached */
- p->o_arg.access = NFS4_ACCESS_READ | NFS4_ACCESS_MODIFY |
- NFS4_ACCESS_EXTEND | NFS4_ACCESS_EXECUTE;
+ switch (p->o_arg.claim) {
+ case NFS4_OPEN_CLAIM_NULL:
+ case NFS4_OPEN_CLAIM_FH:
+ p->o_arg.access = NFS4_ACCESS_READ |
+ NFS4_ACCESS_MODIFY |
+ NFS4_ACCESS_EXTEND |
+ NFS4_ACCESS_EXECUTE;
+ }
}
p->o_arg.clientid = server->nfs_client->cl_clientid;
p->o_arg.id.create_time = ktime_to_ns(sp->so_seqid.create_time);
@@ -1239,7 +1246,6 @@ static struct nfs4_opendata *nfs4_opendata_alloc(struct dentry *dentry,
p->o_arg.bitmask = nfs4_bitmask(server, label);
p->o_arg.open_bitmap = &nfs4_fattr_bitmap[0];
p->o_arg.label = nfs4_label_copy(p->a_label, label);
- p->o_arg.claim = nfs4_map_atomic_open_claim(server, claim);
switch (p->o_arg.claim) {
case NFS4_OPEN_CLAIM_NULL:
case NFS4_OPEN_CLAIM_DELEGATE_CUR:
--
2.7.4


2016-11-10 21:41:17

by Trond Myklebust

[permalink] [raw]
Subject: [PATCH 3/5] NFSv4: Don't request a GETATTR on open_downgrade.

If we're not closing the file completely, there is no need to request
close-to-open attributes.

Signed-off-by: Trond Myklebust <[email protected]>
---
fs/nfs/nfs4xdr.c | 4 ----
1 file changed, 4 deletions(-)

diff --git a/fs/nfs/nfs4xdr.c b/fs/nfs/nfs4xdr.c
index fc89e5ed07ee..43cc989b5c06 100644
--- a/fs/nfs/nfs4xdr.c
+++ b/fs/nfs/nfs4xdr.c
@@ -2328,7 +2328,6 @@ static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req,
encode_sequence(xdr, &args->seq_args, &hdr);
encode_putfh(xdr, args->fh, &hdr);
encode_open_downgrade(xdr, args, &hdr);
- encode_getfattr(xdr, args->bitmask, &hdr);
encode_nops(&hdr);
}

@@ -6115,9 +6114,6 @@ static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp,
if (status)
goto out;
status = decode_open_downgrade(xdr, res);
- if (status != 0)
- goto out;
- decode_getfattr(xdr, res->fattr, res->server);
out:
return status;
}
--
2.7.4


2016-11-10 21:41:18

by Trond Myklebust

[permalink] [raw]
Subject: [PATCH 4/5] NFSv4: Don't request close-to-open attribute when holding a delegation

If holding a delegation, we do not need to ask the server to return
close-to-open cache consistency attributes as part of the CLOSE
compound.

Signed-off-by: Trond Myklebust <[email protected]>
---
fs/nfs/nfs4proc.c | 10 ++++++++--
fs/nfs/nfs4xdr.c | 3 ++-
2 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c
index 1e7e0754a96d..ded8854bc32f 100644
--- a/fs/nfs/nfs4proc.c
+++ b/fs/nfs/nfs4proc.c
@@ -3141,8 +3141,15 @@ static void nfs4_close_prepare(struct rpc_task *task, void *data)
goto out_wait;
}

- if (calldata->arg.fmode == 0)
+ if (calldata->arg.fmode == 0) {
task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE];
+
+ /* Close-to-open cache consistency revalidation */
+ if (!nfs4_have_delegation(inode, FMODE_READ))
+ calldata->arg.bitmask = NFS_SERVER(inode)->cache_consistency_bitmask;
+ else
+ calldata->arg.bitmask = NULL;
+ }
if (calldata->roc)
pnfs_roc_get_barrier(inode, &calldata->roc_barrier);

@@ -3225,7 +3232,6 @@ int nfs4_do_close(struct nfs4_state *state, gfp_t gfp_mask, int wait)
if (IS_ERR(calldata->arg.seqid))
goto out_free_calldata;
calldata->arg.fmode = 0;
- calldata->arg.bitmask = server->cache_consistency_bitmask;
calldata->res.fattr = &calldata->fattr;
calldata->res.seqid = calldata->arg.seqid;
calldata->res.server = server;
diff --git a/fs/nfs/nfs4xdr.c b/fs/nfs/nfs4xdr.c
index 43cc989b5c06..a8bebb52df78 100644
--- a/fs/nfs/nfs4xdr.c
+++ b/fs/nfs/nfs4xdr.c
@@ -2250,7 +2250,8 @@ static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr,
encode_sequence(xdr, &args->seq_args, &hdr);
encode_putfh(xdr, args->fh, &hdr);
encode_close(xdr, args, &hdr);
- encode_getfattr(xdr, args->bitmask, &hdr);
+ if (args->bitmask != NULL)
+ encode_getfattr(xdr, args->bitmask, &hdr);
encode_nops(&hdr);
}

--
2.7.4


2016-11-10 21:41:19

by Trond Myklebust

[permalink] [raw]
Subject: [PATCH 5/5] NFSv4: Optimise away forced revalidation when we know the attributes are OK

The NFS_INO_REVAL_FORCED flag needs to be set if we just got a delegation,
and we see that there might still be some ambiguity as to whether or not
our attribute or data cache are valid.
In practice, this means that a call to nfs_check_inode_attributes() will
have noticed a discrepancy between cached attributes and measured ones,
so let's move the setting of NFS_INO_REVAL_FORCED to there.

Signed-off-by: Trond Myklebust <[email protected]>
---
fs/nfs/delegation.c | 4 ----
fs/nfs/inode.c | 2 +-
2 files changed, 1 insertion(+), 5 deletions(-)

diff --git a/fs/nfs/delegation.c b/fs/nfs/delegation.c
index dff600ae0d74..d7df5e67b0c1 100644
--- a/fs/nfs/delegation.c
+++ b/fs/nfs/delegation.c
@@ -391,10 +391,6 @@ int nfs_inode_set_delegation(struct inode *inode, struct rpc_cred *cred, struct
rcu_assign_pointer(nfsi->delegation, delegation);
delegation = NULL;

- /* Ensure we revalidate the attributes and page cache! */
- spin_lock(&inode->i_lock);
- nfsi->cache_validity |= NFS_INO_REVAL_FORCED;
- spin_unlock(&inode->i_lock);
trace_nfs4_set_delegation(inode, res->delegation_type);

out:
diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
index bf4ec5ecc97e..3575e3408bd7 100644
--- a/fs/nfs/inode.c
+++ b/fs/nfs/inode.c
@@ -1317,7 +1317,7 @@ static int nfs_check_inode_attributes(struct inode *inode, struct nfs_fattr *fat
invalid |= NFS_INO_INVALID_ATIME;

if (invalid != 0)
- nfs_set_cache_invalid(inode, invalid);
+ nfs_set_cache_invalid(inode, invalid | NFS_INO_REVAL_FORCED);

nfsi->read_cache_jiffies = fattr->time_start;
return 0;
--
2.7.4


2016-11-10 22:19:06

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH 1/5] NFSv4: Don't check file access when reclaiming state

Hi Trond,

[auto build test WARNING on nfs/linux-next]
[also build test WARNING on v4.9-rc4 next-20161110]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url: https://github.com/0day-ci/linux/commits/Trond-Myklebust/Optimisations-for-state-management/20161111-054856
base: git://git.linux-nfs.org/projects/trondmy/linux-nfs.git linux-next
config: x86_64-eywa-module (attached as .config)
compiler: gcc-6 (Debian 6.2.0-3) 6.2.0 20160901
reproduce:
# save the attached .config to linux build tree
make ARCH=x86_64

All warnings (new ones prefixed by >>):

fs/nfs/nfs4proc.c: In function 'nfs4_opendata_alloc':
>> fs/nfs/nfs4proc.c:1232:3: warning: enumeration value 'NFS4_OPEN_CLAIM_PREVIOUS' not handled in switch [-Wswitch]
switch (p->o_arg.claim) {
^~~~~~
>> fs/nfs/nfs4proc.c:1232:3: warning: enumeration value 'NFS4_OPEN_CLAIM_DELEGATE_CUR' not handled in switch [-Wswitch]
>> fs/nfs/nfs4proc.c:1232:3: warning: enumeration value 'NFS4_OPEN_CLAIM_DELEGATE_PREV' not handled in switch [-Wswitch]
>> fs/nfs/nfs4proc.c:1232:3: warning: enumeration value 'NFS4_OPEN_CLAIM_DELEG_CUR_FH' not handled in switch [-Wswitch]
>> fs/nfs/nfs4proc.c:1232:3: warning: enumeration value 'NFS4_OPEN_CLAIM_DELEG_PREV_FH' not handled in switch [-Wswitch]

vim +/NFS4_OPEN_CLAIM_PREVIOUS +1232 fs/nfs/nfs4proc.c

1216 goto err_free_label;
1217 nfs_sb_active(dentry->d_sb);
1218 p->dentry = dget(dentry);
1219 p->dir = parent;
1220 p->owner = sp;
1221 atomic_inc(&sp->so_count);
1222 p->o_arg.open_flags = flags;
1223 p->o_arg.fmode = fmode & (FMODE_READ|FMODE_WRITE);
1224 p->o_arg.claim = nfs4_map_atomic_open_claim(server, claim);
1225 p->o_arg.share_access = nfs4_map_atomic_open_share(server,
1226 fmode, flags);
1227 /* don't put an ACCESS op in OPEN compound if O_EXCL, because ACCESS
1228 * will return permission denied for all bits until close */
1229 if (!(flags & O_EXCL)) {
1230 /* ask server to check for all possible rights as results
1231 * are cached */
> 1232 switch (p->o_arg.claim) {
1233 case NFS4_OPEN_CLAIM_NULL:
1234 case NFS4_OPEN_CLAIM_FH:
1235 p->o_arg.access = NFS4_ACCESS_READ |
1236 NFS4_ACCESS_MODIFY |
1237 NFS4_ACCESS_EXTEND |
1238 NFS4_ACCESS_EXECUTE;
1239 }
1240 }

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation


Attachments:
(No filename) (2.47 kB)
.config.gz (24.92 kB)
Download all attachments

2016-11-14 20:45:14

by Anna Schumaker

[permalink] [raw]
Subject: Re: [PATCH 1/5] NFSv4: Don't check file access when reclaiming state

Hi Trond,

On 11/10/2016 04:41 PM, Trond Myklebust wrote:
> If we're reclaiming state after a reboot, or as part of returning a
> delegation, we don't need to check access modes again.
>
> Signed-off-by: Trond Myklebust <[email protected]>
> ---
> fs/nfs/nfs4proc.c | 12 +++++++++---
> 1 file changed, 9 insertions(+), 3 deletions(-)
>
> diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c
> index 6a1d650e0419..4eead738da8e 100644
> --- a/fs/nfs/nfs4proc.c
> +++ b/fs/nfs/nfs4proc.c
> @@ -1221,6 +1221,7 @@ static struct nfs4_opendata *nfs4_opendata_alloc(struct dentry *dentry,
> atomic_inc(&sp->so_count);
> p->o_arg.open_flags = flags;
> p->o_arg.fmode = fmode & (FMODE_READ|FMODE_WRITE);
> + p->o_arg.claim = nfs4_map_atomic_open_claim(server, claim);
> p->o_arg.share_access = nfs4_map_atomic_open_share(server,
> fmode, flags);
> /* don't put an ACCESS op in OPEN compound if O_EXCL, because ACCESS
> @@ -1228,8 +1229,14 @@ static struct nfs4_opendata *nfs4_opendata_alloc(struct dentry *dentry,
> if (!(flags & O_EXCL)) {
> /* ask server to check for all possible rights as results
> * are cached */
> - p->o_arg.access = NFS4_ACCESS_READ | NFS4_ACCESS_MODIFY |
> - NFS4_ACCESS_EXTEND | NFS4_ACCESS_EXECUTE;
> + switch (p->o_arg.claim) {
> + case NFS4_OPEN_CLAIM_NULL:
> + case NFS4_OPEN_CLAIM_FH:
> + p->o_arg.access = NFS4_ACCESS_READ |
> + NFS4_ACCESS_MODIFY |
> + NFS4_ACCESS_EXTEND |
> + NFS4_ACCESS_EXECUTE;
> + }

This adds these warnings when I compile:

fs/nfs/nfs4proc.c: In function 'nfs4_opendata_alloc':
fs/nfs/nfs4proc.c:1232:3: error: enumeration value 'NFS4_OPEN_CLAIM_PREVIOUS' not handled in switch [-Werror=switch]
switch (p->o_arg.claim) {
^~~~~~
fs/nfs/nfs4proc.c:1232:3: error: enumeration value 'NFS4_OPEN_CLAIM_DELEGATE_CUR' not handled in switch [-Werror=switch]
fs/nfs/nfs4proc.c:1232:3: error: enumeration value 'NFS4_OPEN_CLAIM_DELEGATE_PREV' not handled in switch [-Werror=switch]
fs/nfs/nfs4proc.c:1232:3: error: enumeration value 'NFS4_OPEN_CLAIM_DELEG_CUR_FH' not handled in switch [-Werror=switch]
fs/nfs/nfs4proc.c:1232:3: error: enumeration value 'NFS4_OPEN_CLAIM_DELEG_PREV_FH' not handled in switch [-Werror=switch]

Thanks,
Anna


> }
> p->o_arg.clientid = server->nfs_client->cl_clientid;
> p->o_arg.id.create_time = ktime_to_ns(sp->so_seqid.create_time);
> @@ -1239,7 +1246,6 @@ static struct nfs4_opendata *nfs4_opendata_alloc(struct dentry *dentry,
> p->o_arg.bitmask = nfs4_bitmask(server, label);
> p->o_arg.open_bitmap = &nfs4_fattr_bitmap[0];
> p->o_arg.label = nfs4_label_copy(p->a_label, label);
> - p->o_arg.claim = nfs4_map_atomic_open_claim(server, claim);
> switch (p->o_arg.claim) {
> case NFS4_OPEN_CLAIM_NULL:
> case NFS4_OPEN_CLAIM_DELEGATE_CUR:
>