Skip to content

Commit 92e4a67

Browse files
jtlaytonchucklever
authored andcommitted
nfsd: simplify the delayed disposal list code
When queueing a dispose list to the appropriate "freeme" lists, it pointlessly queues the objects one at a time to an intermediate list. Remove a few helpers and just open code a list_move to make it more clear and efficient. Better document the resulting functions with kerneldoc comments. Signed-off-by: Jeff Layton <jlayton@kernel.org> Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
1 parent 55fcc7d commit 92e4a67

1 file changed

Lines changed: 22 additions & 42 deletions

File tree

fs/nfsd/filecache.c

Lines changed: 22 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -402,49 +402,26 @@ nfsd_file_dispose_list(struct list_head *dispose)
402402
}
403403
}
404404

405-
static void
406-
nfsd_file_list_remove_disposal(struct list_head *dst,
407-
struct nfsd_fcache_disposal *l)
408-
{
409-
spin_lock(&l->lock);
410-
list_splice_init(&l->freeme, dst);
411-
spin_unlock(&l->lock);
412-
}
413-
414-
static void
415-
nfsd_file_list_add_disposal(struct list_head *files, struct net *net)
416-
{
417-
struct nfsd_net *nn = net_generic(net, nfsd_net_id);
418-
struct nfsd_fcache_disposal *l = nn->fcache_disposal;
419-
420-
spin_lock(&l->lock);
421-
list_splice_tail_init(files, &l->freeme);
422-
spin_unlock(&l->lock);
423-
queue_work(nfsd_filecache_wq, &l->work);
424-
}
425-
426-
static void
427-
nfsd_file_list_add_pernet(struct list_head *dst, struct list_head *src,
428-
struct net *net)
429-
{
430-
struct nfsd_file *nf, *tmp;
431-
432-
list_for_each_entry_safe(nf, tmp, src, nf_lru) {
433-
if (nf->nf_net == net)
434-
list_move_tail(&nf->nf_lru, dst);
435-
}
436-
}
437-
405+
/**
406+
* nfsd_file_dispose_list_delayed - move list of dead files to net's freeme list
407+
* @dispose: list of nfsd_files to be disposed
408+
*
409+
* Transfers each file to the "freeme" list for its nfsd_net, to eventually
410+
* be disposed of by the per-net garbage collector.
411+
*/
438412
static void
439413
nfsd_file_dispose_list_delayed(struct list_head *dispose)
440414
{
441-
LIST_HEAD(list);
442-
struct nfsd_file *nf;
443-
444415
while(!list_empty(dispose)) {
445-
nf = list_first_entry(dispose, struct nfsd_file, nf_lru);
446-
nfsd_file_list_add_pernet(&list, dispose, nf->nf_net);
447-
nfsd_file_list_add_disposal(&list, nf->nf_net);
416+
struct nfsd_file *nf = list_first_entry(dispose,
417+
struct nfsd_file, nf_lru);
418+
struct nfsd_net *nn = net_generic(nf->nf_net, nfsd_net_id);
419+
struct nfsd_fcache_disposal *l = nn->fcache_disposal;
420+
421+
spin_lock(&l->lock);
422+
list_move_tail(&nf->nf_lru, &l->freeme);
423+
spin_unlock(&l->lock);
424+
queue_work(nfsd_filecache_wq, &l->work);
448425
}
449426
}
450427

@@ -665,8 +642,8 @@ nfsd_file_close_inode_sync(struct inode *inode)
665642
* nfsd_file_delayed_close - close unused nfsd_files
666643
* @work: dummy
667644
*
668-
* Walk the LRU list and destroy any entries that have not been used since
669-
* the last scan.
645+
* Scrape the freeme list for this nfsd_net, and then dispose of them
646+
* all.
670647
*/
671648
static void
672649
nfsd_file_delayed_close(struct work_struct *work)
@@ -675,7 +652,10 @@ nfsd_file_delayed_close(struct work_struct *work)
675652
struct nfsd_fcache_disposal *l = container_of(work,
676653
struct nfsd_fcache_disposal, work);
677654

678-
nfsd_file_list_remove_disposal(&head, l);
655+
spin_lock(&l->lock);
656+
list_splice_init(&l->freeme, &head);
657+
spin_unlock(&l->lock);
658+
679659
nfsd_file_dispose_list(&head);
680660
}
681661

0 commit comments

Comments
 (0)