Commit e95f3f74 authored by Paulo Alcantara's avatar Paulo Alcantara Committed by Steve French

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: default avatarPaulo Alcantara (SUSE) <pc@manguebit.com>
Reviewed-by: default avatarShyam Prasad N <sprasad@microsoft.com>
Signed-off-by: default avatarSteve French <stfrench@microsoft.com>
parent 94f6f055
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
static struct cached_fid *init_cached_dir(const char *path); static struct cached_fid *init_cached_dir(const char *path);
static void free_cached_dir(struct cached_fid *cfid); static void free_cached_dir(struct cached_fid *cfid);
static void smb2_close_cached_fid(struct kref *ref); static void smb2_close_cached_fid(struct kref *ref);
static void cfids_laundromat_worker(struct work_struct *work);
static struct cached_fid *find_or_create_cached_dir(struct cached_fids *cfids, static struct cached_fid *find_or_create_cached_dir(struct cached_fids *cfids,
const char *path, const char *path,
...@@ -572,53 +573,46 @@ static void free_cached_dir(struct cached_fid *cfid) ...@@ -572,53 +573,46 @@ static void free_cached_dir(struct cached_fid *cfid)
kfree(cfid); kfree(cfid);
} }
static int static void cfids_laundromat_worker(struct work_struct *work)
cifs_cfids_laundromat_thread(void *p)
{ {
struct cached_fids *cfids = p; struct cached_fids *cfids;
struct cached_fid *cfid, *q; struct cached_fid *cfid, *q;
struct list_head entry; LIST_HEAD(entry);
while (!kthread_should_stop()) { cfids = container_of(work, struct cached_fids, laundromat_work.work);
ssleep(1);
INIT_LIST_HEAD(&entry); spin_lock(&cfids->cfid_list_lock);
if (kthread_should_stop()) list_for_each_entry_safe(cfid, q, &cfids->entries, entry) {
return 0; if (time_after(jiffies, cfid->time + HZ * dir_cache_timeout)) {
spin_lock(&cfids->cfid_list_lock); list_move(&cfid->entry, &entry);
list_for_each_entry_safe(cfid, q, &cfids->entries, entry) { cfids->num_entries--;
if (time_after(jiffies, cfid->time + HZ * dir_cache_timeout)) {
list_del(&cfid->entry);
list_add(&cfid->entry, &entry);
cfids->num_entries--;
}
} }
spin_unlock(&cfids->cfid_list_lock); }
spin_unlock(&cfids->cfid_list_lock);
list_for_each_entry_safe(cfid, q, &entry, entry) { list_for_each_entry_safe(cfid, q, &entry, entry) {
cfid->on_list = false; cfid->on_list = false;
list_del(&cfid->entry); list_del(&cfid->entry);
/*
* Cancel and wait for the work to finish in case we are racing
* with it.
*/
cancel_work_sync(&cfid->lease_break);
if (cfid->has_lease) {
/* /*
* Cancel, and wait for the work to finish in * Our lease has not yet been cancelled from the server
* case we are racing with it. * so we need to drop the reference.
*/ */
cancel_work_sync(&cfid->lease_break); spin_lock(&cfids->cfid_list_lock);
if (cfid->has_lease) { cfid->has_lease = false;
/* spin_unlock(&cfids->cfid_list_lock);
* We lease has not yet been cancelled from kref_put(&cfid->refcount, smb2_close_cached_fid);
* the server so we need to drop the reference.
*/
spin_lock(&cfids->cfid_list_lock);
cfid->has_lease = false;
spin_unlock(&cfids->cfid_list_lock);
kref_put(&cfid->refcount, smb2_close_cached_fid);
}
} }
} }
queue_delayed_work(cifsiod_wq, &cfids->laundromat_work,
return 0; dir_cache_timeout * HZ);
} }
struct cached_fids *init_cached_dirs(void) struct cached_fids *init_cached_dirs(void)
{ {
struct cached_fids *cfids; struct cached_fids *cfids;
...@@ -629,19 +623,10 @@ struct cached_fids *init_cached_dirs(void) ...@@ -629,19 +623,10 @@ struct cached_fids *init_cached_dirs(void)
spin_lock_init(&cfids->cfid_list_lock); spin_lock_init(&cfids->cfid_list_lock);
INIT_LIST_HEAD(&cfids->entries); INIT_LIST_HEAD(&cfids->entries);
/* INIT_DELAYED_WORK(&cfids->laundromat_work, cfids_laundromat_worker);
* since we're in a cifs function already, we know that queue_delayed_work(cifsiod_wq, &cfids->laundromat_work,
* this will succeed. No need for try_module_get(). dir_cache_timeout * HZ);
*/
__module_get(THIS_MODULE);
cfids->laundromat = kthread_run(cifs_cfids_laundromat_thread,
cfids, "cifsd-cfid-laundromat");
if (IS_ERR(cfids->laundromat)) {
cifs_dbg(VFS, "Failed to start cfids laundromat thread.\n");
kfree(cfids);
module_put(THIS_MODULE);
return NULL;
}
return cfids; return cfids;
} }
...@@ -657,11 +642,7 @@ void free_cached_dirs(struct cached_fids *cfids) ...@@ -657,11 +642,7 @@ void free_cached_dirs(struct cached_fids *cfids)
if (cfids == NULL) if (cfids == NULL)
return; return;
if (cfids->laundromat) { cancel_delayed_work_sync(&cfids->laundromat_work);
kthread_stop(cfids->laundromat);
cfids->laundromat = NULL;
module_put(THIS_MODULE);
}
spin_lock(&cfids->cfid_list_lock); spin_lock(&cfids->cfid_list_lock);
list_for_each_entry_safe(cfid, q, &cfids->entries, entry) { list_for_each_entry_safe(cfid, q, &cfids->entries, entry) {
......
...@@ -57,7 +57,7 @@ struct cached_fids { ...@@ -57,7 +57,7 @@ struct cached_fids {
spinlock_t cfid_list_lock; spinlock_t cfid_list_lock;
int num_entries; int num_entries;
struct list_head entries; struct list_head entries;
struct task_struct *laundromat; struct delayed_work laundromat_work;
}; };
extern struct cached_fids *init_cached_dirs(void); extern struct cached_fids *init_cached_dirs(void);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment