Commit 50030d57 authored by Neil Brown's avatar Neil Brown Committed by Linus Torvalds

[PATCH] Use schedule_work to regular cache cleaning

Cleaning of the export caches is currently done by idle
nfsd threads which isn't very reliable.

This patch makes use of work_queues to do it all inside
cache.c
parent 6fc11138
......@@ -209,8 +209,8 @@ nfsd(struct svc_rqst *rqstp)
* recvfrom routine.
*/
while ((err = svc_recv(serv, rqstp,
5*60*HZ)) == -EAGAIN)
cache_clean();
60*60*HZ)) == -EAGAIN)
;
if (err < 0)
break;
update_thread_usage(atomic_read(&nfsd_busy));
......
......@@ -25,6 +25,7 @@
#include <linux/seq_file.h>
#include <linux/proc_fs.h>
#include <linux/net.h>
#include <linux/workqueue.h>
#include <asm/ioctls.h>
#include <linux/sunrpc/types.h>
#include <linux/sunrpc/cache.h>
......@@ -165,6 +166,9 @@ static struct file_operations cache_file_operations;
static struct file_operations content_file_operations;
static struct file_operations cache_flush_operations;
static void do_cache_clean(void *data);
static DECLARE_WORK(cache_cleaner, do_cache_clean, NULL);
void cache_register(struct cache_detail *cd)
{
cd->proc_ent = proc_mkdir(cd->name, proc_net_rpc);
......@@ -208,6 +212,9 @@ void cache_register(struct cache_detail *cd)
cd->last_close = 0;
list_add(&cd->others, &cache_list);
spin_unlock(&cache_list_lock);
/* start the cleaning process */
schedule_work(&cache_cleaner);
}
int cache_unregister(struct cache_detail *cd)
......@@ -229,6 +236,11 @@ int cache_unregister(struct cache_detail *cd)
cd->proc_ent = NULL;
remove_proc_entry(cd->name, proc_net_rpc);
}
if (list_empty(&cache_list)) {
/* module must be being unloaded so its safe to kill the worker */
cancel_delayed_work(&cache_cleaner);
flush_scheduled_work();
}
return 0;
}
......@@ -341,6 +353,23 @@ int cache_clean(void)
return rv;
}
/*
* We want to regularly clean the cache, so we need to schedule some work ...
*/
static void do_cache_clean(void *data)
{
int delay = 5;
if (cache_clean() == -1)
delay = 30*HZ;
if (list_empty(&cache_list))
delay = 0;
if (delay)
schedule_delayed_work(&cache_cleaner, delay);
}
/*
* Clean all caches promptly. This just calls cache_clean
* repeatedly until we are sure that every cache has had a chance to
......
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