Skip to content

Commit ed00c2f

Browse files
trondmyJ. Bruce Fields
authored andcommitted
knfsd: Further simplify the cache lookup
Order the structure so that the key can be compared using memcmp(). Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com> Signed-off-by: J. Bruce Fields <bfields@redhat.com>
1 parent 76ecec2 commit ed00c2f

File tree

2 files changed

+27
-37
lines changed

2 files changed

+27
-37
lines changed

fs/nfsd/cache.h

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,21 @@
1919
* is much larger than a sockaddr_in6.
2020
*/
2121
struct svc_cacherep {
22-
struct list_head c_lru;
22+
struct {
23+
/* Keep often-read xid, csum in the same cache line: */
24+
__be32 k_xid;
25+
__wsum k_csum;
26+
u32 k_proc;
27+
u32 k_prot;
28+
u32 k_vers;
29+
unsigned int k_len;
30+
struct sockaddr_in6 k_addr;
31+
} c_key;
2332

33+
struct list_head c_lru;
2434
unsigned char c_state, /* unused, inprog, done */
2535
c_type, /* status, buffer */
2636
c_secure : 1; /* req came from port < 1024 */
27-
struct sockaddr_in6 c_addr;
28-
__be32 c_xid;
29-
u32 c_prot;
30-
u32 c_proc;
31-
u32 c_vers;
32-
unsigned int c_len;
33-
__wsum c_csum;
3437
unsigned long c_timestamp;
3538
union {
3639
struct kvec u_vec;

fs/nfsd/nfscache.c

Lines changed: 16 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -131,15 +131,15 @@ nfsd_reply_cache_alloc(struct svc_rqst *rqstp, __wsum csum)
131131
rp->c_type = RC_NOCACHE;
132132
INIT_LIST_HEAD(&rp->c_lru);
133133

134-
rp->c_xid = rqstp->rq_xid;
135-
rp->c_proc = rqstp->rq_proc;
136-
memset(&rp->c_addr, 0, sizeof(rp->c_addr));
137-
rpc_copy_addr((struct sockaddr *)&rp->c_addr, svc_addr(rqstp));
138-
rpc_set_port((struct sockaddr *)&rp->c_addr, rpc_get_port(svc_addr(rqstp)));
139-
rp->c_prot = rqstp->rq_prot;
140-
rp->c_vers = rqstp->rq_vers;
141-
rp->c_len = rqstp->rq_arg.len;
142-
rp->c_csum = csum;
134+
memset(&rp->c_key, 0, sizeof(rp->c_key));
135+
rp->c_key.k_xid = rqstp->rq_xid;
136+
rp->c_key.k_proc = rqstp->rq_proc;
137+
rpc_copy_addr((struct sockaddr *)&rp->c_key.k_addr, svc_addr(rqstp));
138+
rpc_set_port((struct sockaddr *)&rp->c_key.k_addr, rpc_get_port(svc_addr(rqstp)));
139+
rp->c_key.k_prot = rqstp->rq_prot;
140+
rp->c_key.k_vers = rqstp->rq_vers;
141+
rp->c_key.k_len = rqstp->rq_arg.len;
142+
rp->c_key.k_csum = csum;
143143
}
144144
return rp;
145145
}
@@ -330,27 +330,14 @@ nfsd_cache_csum(struct svc_rqst *rqstp)
330330
return csum;
331331
}
332332

333-
static bool
334-
nfsd_cache_match(const struct svc_cacherep *key, const struct svc_cacherep *rp)
333+
static int
334+
nfsd_cache_key_cmp(const struct svc_cacherep *key, const struct svc_cacherep *rp)
335335
{
336-
/* Check RPC XID first */
337-
if (key->c_xid != rp->c_xid)
338-
return false;
339-
/* compare checksum of NFS data */
340-
if (key->c_csum != rp->c_csum) {
336+
if (key->c_key.k_xid == rp->c_key.k_xid &&
337+
key->c_key.k_csum != rp->c_key.k_csum)
341338
++payload_misses;
342-
return false;
343-
}
344-
345-
/* Other discriminators */
346-
if (key->c_proc != rp->c_proc ||
347-
key->c_prot != rp->c_prot ||
348-
key->c_vers != rp->c_vers ||
349-
key->c_len != rp->c_len ||
350-
memcmp(&key->c_addr, &rp->c_addr, sizeof(key->c_addr)) != 0)
351-
return false;
352339

353-
return true;
340+
return memcmp(&key->c_key, &rp->c_key, sizeof(key->c_key));
354341
}
355342

356343
/*
@@ -367,7 +354,7 @@ nfsd_cache_insert(struct nfsd_drc_bucket *b, struct svc_cacherep *key)
367354

368355
list_for_each_entry(rp, rh, c_lru) {
369356
++entries;
370-
if (nfsd_cache_match(key, rp)) {
357+
if (nfsd_cache_key_cmp(key, rp) == 0) {
371358
ret = rp;
372359
break;
373360
}
@@ -510,7 +497,7 @@ nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, __be32 *statp)
510497
if (!rp)
511498
return;
512499

513-
hash = nfsd_cache_hash(rp->c_xid);
500+
hash = nfsd_cache_hash(rp->c_key.k_xid);
514501
b = &drc_hashtbl[hash];
515502

516503
len = resv->iov_len - ((char*)statp - (char*)resv->iov_base);

0 commit comments

Comments
 (0)