Skip to content

Commit 8ea6ecc

Browse files
chuckleverTrond Myklebust
authored andcommitted
lockd: Create client-side nlm_host cache
NFS clients don't need the garbage collection processing that is performed on nlm_host structures. The client picks up an nlm_host at mount time and holds a reference to it until the file system is unmounted. Servers, on the other hand, don't have a precise way to tell when an nlm_host is no longer being used, so zero refcount nlm_host entries are left to expire in the cache after a time. Basically there's nothing holding a reference to an nlm_host between individual server-side NLM requests, but we can't afford the expense of recreating them for every new NLM request from a client. The nlm_host cache adds some lifetime hysteresis to entries in the cache so the next time a particular nlm_host is needed, it's likely to be discovered by a lookup rather than created from whole cloth. With the new implementation, client nlm_host cache items are no longer garbage collected, and are destroyed directly by a new release function specialized for client entries, nlmclnt_release_host(). They are cached in their own data structure, and have their own lookup logic, simplified and specialized for client nlm_host entries. However, the client nlm_host cache still shares reboot recovery logic with the server nlm_host cache. The NSM "peer rebooted" downcall for clients and servers still come through the same RPC call. This is a legacy formal API that would be difficult to alter, and besides, the user space NSM implementation can't tell the difference between peers that are clients or servers. For this reason, the client cache continues to share the nlm_host_mutex (and reboot recovery logic) with the server cache. Signed-off-by: Chuck Lever <chuck.lever@oracle.com> Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
1 parent 7db836d commit 8ea6ecc

4 files changed

Lines changed: 78 additions & 14 deletions

File tree

‎fs/lockd/clntlock.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ EXPORT_SYMBOL_GPL(nlmclnt_init);
7979
*/
8080
void nlmclnt_done(struct nlm_host *host)
8181
{
82-
nlm_release_host(host);
82+
nlmclnt_release_host(host);
8383
lockd_down();
8484
}
8585
EXPORT_SYMBOL_GPL(nlmclnt_done);
@@ -273,7 +273,7 @@ reclaimer(void *ptr)
273273
spin_unlock(&nlm_blocked_lock);
274274

275275
/* Release host handle after use */
276-
nlm_release_host(host);
276+
nlmclnt_release_host(host);
277277
lockd_down();
278278
return 0;
279279
}

‎fs/lockd/clntproc.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ static void nlm_put_lockowner(struct nlm_lockowner *lockowner)
5858
return;
5959
list_del(&lockowner->list);
6060
spin_unlock(&lockowner->host->h_lock);
61-
nlm_release_host(lockowner->host);
61+
nlmclnt_release_host(lockowner->host);
6262
kfree(lockowner);
6363
}
6464

@@ -207,15 +207,15 @@ struct nlm_rqst *nlm_alloc_call(struct nlm_host *host)
207207
printk("nlm_alloc_call: failed, waiting for memory\n");
208208
schedule_timeout_interruptible(5*HZ);
209209
}
210-
nlm_release_host(host);
210+
nlmclnt_release_host(host);
211211
return NULL;
212212
}
213213

214214
void nlmclnt_release_call(struct nlm_rqst *call)
215215
{
216216
if (!atomic_dec_and_test(&call->a_count))
217217
return;
218-
nlm_release_host(call->a_host);
218+
nlmclnt_release_host(call->a_host);
219219
nlmclnt_release_lockargs(call);
220220
kfree(call);
221221
}

‎fs/lockd/host.c‎

Lines changed: 72 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#define NLM_HOST_COLLECT (120 * HZ)
2727

2828
static struct hlist_head nlm_hosts[NLM_HOST_NRHASH];
29+
static struct hlist_head nlm_client_hosts[NLM_HOST_NRHASH];
2930

3031
#define for_each_host(host, pos, chain, table) \
3132
for ((chain) = (table); \
@@ -288,12 +289,76 @@ struct nlm_host *nlmclnt_lookup_host(const struct sockaddr *sap,
288289
.hostname_len = strlen(hostname),
289290
.noresvport = noresvport,
290291
};
292+
struct hlist_head *chain;
293+
struct hlist_node *pos;
294+
struct nlm_host *host;
295+
struct nsm_handle *nsm = NULL;
291296

292297
dprintk("lockd: %s(host='%s', vers=%u, proto=%s)\n", __func__,
293298
(hostname ? hostname : "<none>"), version,
294299
(protocol == IPPROTO_UDP ? "udp" : "tcp"));
295300

296-
return nlm_lookup_host(&ni);
301+
mutex_lock(&nlm_host_mutex);
302+
303+
chain = &nlm_client_hosts[nlm_hash_address(sap)];
304+
hlist_for_each_entry(host, pos, chain, h_hash) {
305+
if (!rpc_cmp_addr(nlm_addr(host), sap))
306+
continue;
307+
308+
/* Same address. Share an NSM handle if we already have one */
309+
if (nsm == NULL)
310+
nsm = host->h_nsmhandle;
311+
312+
if (host->h_proto != protocol)
313+
continue;
314+
if (host->h_version != version)
315+
continue;
316+
317+
nlm_get_host(host);
318+
dprintk("lockd: %s found host %s (%s)\n", __func__,
319+
host->h_name, host->h_addrbuf);
320+
goto out;
321+
}
322+
323+
host = nlm_alloc_host(&ni, nsm);
324+
if (unlikely(host == NULL))
325+
goto out;
326+
327+
hlist_add_head(&host->h_hash, chain);
328+
nrhosts++;
329+
330+
dprintk("lockd: %s created host %s (%s)\n", __func__,
331+
host->h_name, host->h_addrbuf);
332+
333+
out:
334+
mutex_unlock(&nlm_host_mutex);
335+
return host;
336+
}
337+
338+
/**
339+
* nlmclnt_release_host - release client nlm_host
340+
* @host: nlm_host to release
341+
*
342+
*/
343+
void nlmclnt_release_host(struct nlm_host *host)
344+
{
345+
if (host == NULL)
346+
return;
347+
348+
dprintk("lockd: release client host %s\n", host->h_name);
349+
350+
BUG_ON(atomic_read(&host->h_count) < 0);
351+
BUG_ON(host->h_server);
352+
353+
if (atomic_dec_and_test(&host->h_count)) {
354+
BUG_ON(!list_empty(&host->h_lockowners));
355+
BUG_ON(!list_empty(&host->h_granted));
356+
BUG_ON(!list_empty(&host->h_reclaim));
357+
358+
mutex_lock(&nlm_host_mutex);
359+
nlm_destroy_host_locked(host);
360+
mutex_unlock(&nlm_host_mutex);
361+
}
297362
}
298363

299364
/**
@@ -515,16 +580,14 @@ void nlm_host_rebooted(const struct nlm_reboot *info)
515580
* To avoid processing a host several times, we match the nsmstate.
516581
*/
517582
while ((host = next_host_state(nlm_hosts, nsm, info)) != NULL) {
518-
if (host->h_server) {
519-
/* We're server for this guy, just ditch
520-
* all the locks he held. */
521-
nlmsvc_free_host_resources(host);
522-
} else {
523-
/* He's the server, initiate lock recovery. */
524-
nlmclnt_recovery(host);
525-
}
583+
nlmsvc_free_host_resources(host);
526584
nlm_release_host(host);
527585
}
586+
while ((host = next_host_state(nlm_client_hosts, nsm, info)) != NULL) {
587+
nlmclnt_recovery(host);
588+
nlmclnt_release_host(host);
589+
}
590+
528591
nsm_release(nsm);
529592
}
530593

‎include/linux/lockd/lockd.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ struct nlm_host *nlmclnt_lookup_host(const struct sockaddr *sap,
223223
const u32 version,
224224
const char *hostname,
225225
int noresvport);
226+
void nlmclnt_release_host(struct nlm_host *);
226227
struct nlm_host *nlmsvc_lookup_host(const struct svc_rqst *rqstp,
227228
const char *hostname,
228229
const size_t hostname_len);

0 commit comments

Comments
 (0)