Skip to content

Commit e95f3f7

Browse files
Paulo AlcantaraSteve French
authored andcommitted
smb: client: make laundromat a delayed worker
By having laundromat kthread processing cached directories on every second turned out to be overkill, especially when having multiple SMB mounts. Relax it by using a delayed worker instead that gets scheduled on every @dir_cache_timeout (default=30) seconds per tcon. This also fixes the 1s delay when tearing down tcon. Signed-off-by: Paulo Alcantara (SUSE) <pc@manguebit.com> Reviewed-by: Shyam Prasad N <sprasad@microsoft.com> Signed-off-by: Steve French <stfrench@microsoft.com>
1 parent 94f6f05 commit e95f3f7

File tree

2 files changed

+36
-55
lines changed

2 files changed

+36
-55
lines changed

fs/smb/client/cached_dir.c

Lines changed: 35 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
static struct cached_fid *init_cached_dir(const char *path);
1616
static void free_cached_dir(struct cached_fid *cfid);
1717
static void smb2_close_cached_fid(struct kref *ref);
18+
static void cfids_laundromat_worker(struct work_struct *work);
1819

1920
static struct cached_fid *find_or_create_cached_dir(struct cached_fids *cfids,
2021
const char *path,
@@ -572,53 +573,46 @@ static void free_cached_dir(struct cached_fid *cfid)
572573
kfree(cfid);
573574
}
574575

575-
static int
576-
cifs_cfids_laundromat_thread(void *p)
576+
static void cfids_laundromat_worker(struct work_struct *work)
577577
{
578-
struct cached_fids *cfids = p;
578+
struct cached_fids *cfids;
579579
struct cached_fid *cfid, *q;
580-
struct list_head entry;
580+
LIST_HEAD(entry);
581581

582-
while (!kthread_should_stop()) {
583-
ssleep(1);
584-
INIT_LIST_HEAD(&entry);
585-
if (kthread_should_stop())
586-
return 0;
587-
spin_lock(&cfids->cfid_list_lock);
588-
list_for_each_entry_safe(cfid, q, &cfids->entries, entry) {
589-
if (time_after(jiffies, cfid->time + HZ * dir_cache_timeout)) {
590-
list_del(&cfid->entry);
591-
list_add(&cfid->entry, &entry);
592-
cfids->num_entries--;
593-
}
582+
cfids = container_of(work, struct cached_fids, laundromat_work.work);
583+
584+
spin_lock(&cfids->cfid_list_lock);
585+
list_for_each_entry_safe(cfid, q, &cfids->entries, entry) {
586+
if (time_after(jiffies, cfid->time + HZ * dir_cache_timeout)) {
587+
list_move(&cfid->entry, &entry);
588+
cfids->num_entries--;
594589
}
595-
spin_unlock(&cfids->cfid_list_lock);
590+
}
591+
spin_unlock(&cfids->cfid_list_lock);
596592

597-
list_for_each_entry_safe(cfid, q, &entry, entry) {
598-
cfid->on_list = false;
599-
list_del(&cfid->entry);
593+
list_for_each_entry_safe(cfid, q, &entry, entry) {
594+
cfid->on_list = false;
595+
list_del(&cfid->entry);
596+
/*
597+
* Cancel and wait for the work to finish in case we are racing
598+
* with it.
599+
*/
600+
cancel_work_sync(&cfid->lease_break);
601+
if (cfid->has_lease) {
600602
/*
601-
* Cancel, and wait for the work to finish in
602-
* case we are racing with it.
603+
* Our lease has not yet been cancelled from the server
604+
* so we need to drop the reference.
603605
*/
604-
cancel_work_sync(&cfid->lease_break);
605-
if (cfid->has_lease) {
606-
/*
607-
* We lease has not yet been cancelled from
608-
* the server so we need to drop the reference.
609-
*/
610-
spin_lock(&cfids->cfid_list_lock);
611-
cfid->has_lease = false;
612-
spin_unlock(&cfids->cfid_list_lock);
613-
kref_put(&cfid->refcount, smb2_close_cached_fid);
614-
}
606+
spin_lock(&cfids->cfid_list_lock);
607+
cfid->has_lease = false;
608+
spin_unlock(&cfids->cfid_list_lock);
609+
kref_put(&cfid->refcount, smb2_close_cached_fid);
615610
}
616611
}
617-
618-
return 0;
612+
queue_delayed_work(cifsiod_wq, &cfids->laundromat_work,
613+
dir_cache_timeout * HZ);
619614
}
620615

621-
622616
struct cached_fids *init_cached_dirs(void)
623617
{
624618
struct cached_fids *cfids;
@@ -629,19 +623,10 @@ struct cached_fids *init_cached_dirs(void)
629623
spin_lock_init(&cfids->cfid_list_lock);
630624
INIT_LIST_HEAD(&cfids->entries);
631625

632-
/*
633-
* since we're in a cifs function already, we know that
634-
* this will succeed. No need for try_module_get().
635-
*/
636-
__module_get(THIS_MODULE);
637-
cfids->laundromat = kthread_run(cifs_cfids_laundromat_thread,
638-
cfids, "cifsd-cfid-laundromat");
639-
if (IS_ERR(cfids->laundromat)) {
640-
cifs_dbg(VFS, "Failed to start cfids laundromat thread.\n");
641-
kfree(cfids);
642-
module_put(THIS_MODULE);
643-
return NULL;
644-
}
626+
INIT_DELAYED_WORK(&cfids->laundromat_work, cfids_laundromat_worker);
627+
queue_delayed_work(cifsiod_wq, &cfids->laundromat_work,
628+
dir_cache_timeout * HZ);
629+
645630
return cfids;
646631
}
647632

@@ -657,11 +642,7 @@ void free_cached_dirs(struct cached_fids *cfids)
657642
if (cfids == NULL)
658643
return;
659644

660-
if (cfids->laundromat) {
661-
kthread_stop(cfids->laundromat);
662-
cfids->laundromat = NULL;
663-
module_put(THIS_MODULE);
664-
}
645+
cancel_delayed_work_sync(&cfids->laundromat_work);
665646

666647
spin_lock(&cfids->cfid_list_lock);
667648
list_for_each_entry_safe(cfid, q, &cfids->entries, entry) {

fs/smb/client/cached_dir.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ struct cached_fids {
5757
spinlock_t cfid_list_lock;
5858
int num_entries;
5959
struct list_head entries;
60-
struct task_struct *laundromat;
60+
struct delayed_work laundromat_work;
6161
};
6262

6363
extern struct cached_fids *init_cached_dirs(void);

0 commit comments

Comments
 (0)