1 /* General filesystem local caching manager
3 * Copyright (C) 2004-2007 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
12 #define FSCACHE_DEBUG_LEVEL CACHE
13 #include <linux/module.h>
14 #include <linux/init.h>
15 #include <linux/sched.h>
16 #include <linux/completion.h>
17 #include <linux/slab.h>
18 #include <linux/seq_file.h>
19 #define CREATE_TRACE_POINTS
22 MODULE_DESCRIPTION("FS Cache Manager");
23 MODULE_AUTHOR("Red Hat, Inc.");
24 MODULE_LICENSE("GPL");
26 unsigned fscache_defer_lookup
= 1;
27 module_param_named(defer_lookup
, fscache_defer_lookup
, uint
,
29 MODULE_PARM_DESC(fscache_defer_lookup
,
30 "Defer cookie lookup to background thread");
32 unsigned fscache_defer_create
= 1;
33 module_param_named(defer_create
, fscache_defer_create
, uint
,
35 MODULE_PARM_DESC(fscache_defer_create
,
36 "Defer cookie creation to background thread");
38 unsigned fscache_debug
;
39 module_param_named(debug
, fscache_debug
, uint
,
41 MODULE_PARM_DESC(fscache_debug
,
42 "FS-Cache debugging mask");
44 struct kobject
*fscache_root
;
45 struct workqueue_struct
*fscache_object_wq
;
46 struct workqueue_struct
*fscache_op_wq
;
48 DEFINE_PER_CPU(wait_queue_head_t
, fscache_object_cong_wait
);
50 /* these values serve as lower bounds, will be adjusted in fscache_init() */
51 static unsigned fscache_object_max_active
= 4;
52 static unsigned fscache_op_max_active
= 2;
55 static struct ctl_table_header
*fscache_sysctl_header
;
57 static int fscache_max_active_sysctl(struct ctl_table
*table
, int write
,
59 size_t *lenp
, loff_t
*ppos
)
61 struct workqueue_struct
**wqp
= table
->extra1
;
62 unsigned int *datap
= table
->data
;
65 ret
= proc_dointvec(table
, write
, buffer
, lenp
, ppos
);
67 workqueue_set_max_active(*wqp
, *datap
);
71 static struct ctl_table fscache_sysctls
[] = {
73 .procname
= "object_max_active",
74 .data
= &fscache_object_max_active
,
75 .maxlen
= sizeof(unsigned),
77 .proc_handler
= fscache_max_active_sysctl
,
78 .extra1
= &fscache_object_wq
,
81 .procname
= "operation_max_active",
82 .data
= &fscache_op_max_active
,
83 .maxlen
= sizeof(unsigned),
85 .proc_handler
= fscache_max_active_sysctl
,
86 .extra1
= &fscache_op_wq
,
91 static struct ctl_table fscache_sysctls_root
[] = {
93 .procname
= "fscache",
95 .child
= fscache_sysctls
,
102 * initialise the fs caching module
104 static int __init
fscache_init(void)
106 unsigned int nr_cpus
= num_possible_cpus();
110 fscache_object_max_active
=
112 fscache_object_max_active
, WQ_UNBOUND_MAX_ACTIVE
);
115 fscache_object_wq
= alloc_workqueue("fscache_object", WQ_UNBOUND
,
116 fscache_object_max_active
);
117 if (!fscache_object_wq
)
118 goto error_object_wq
;
120 fscache_op_max_active
=
121 clamp_val(fscache_object_max_active
/ 2,
122 fscache_op_max_active
, WQ_UNBOUND_MAX_ACTIVE
);
125 fscache_op_wq
= alloc_workqueue("fscache_operation", WQ_UNBOUND
,
126 fscache_op_max_active
);
130 for_each_possible_cpu(cpu
)
131 init_waitqueue_head(&per_cpu(fscache_object_cong_wait
, cpu
));
133 ret
= fscache_proc_init();
139 fscache_sysctl_header
= register_sysctl_table(fscache_sysctls_root
);
140 if (!fscache_sysctl_header
)
144 fscache_cookie_jar
= kmem_cache_create("fscache_cookie_jar",
145 sizeof(struct fscache_cookie
),
147 if (!fscache_cookie_jar
) {
148 pr_notice("Failed to allocate a cookie jar\n");
150 goto error_cookie_jar
;
153 fscache_root
= kobject_create_and_add("fscache", kernel_kobj
);
157 pr_notice("Loaded\n");
161 kmem_cache_destroy(fscache_cookie_jar
);
164 unregister_sysctl_table(fscache_sysctl_header
);
167 fscache_proc_cleanup();
169 destroy_workqueue(fscache_op_wq
);
171 destroy_workqueue(fscache_object_wq
);
176 fs_initcall(fscache_init
);
179 * clean up on module removal
181 static void __exit
fscache_exit(void)
185 kobject_put(fscache_root
);
186 kmem_cache_destroy(fscache_cookie_jar
);
188 unregister_sysctl_table(fscache_sysctl_header
);
190 fscache_proc_cleanup();
191 destroy_workqueue(fscache_op_wq
);
192 destroy_workqueue(fscache_object_wq
);
193 pr_notice("Unloaded\n");
196 module_exit(fscache_exit
);