]> bbs.cooldavid.org Git - net-next-2.6.git/blame - fs/fscache/main.c
xps: Transmit Packet Steering
[net-next-2.6.git] / fs / fscache / main.c
CommitLineData
06b3db1b
DH
1/* General filesystem local caching manager
2 *
3 * Copyright (C) 2004-2007 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
5 *
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.
10 */
11
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>
8b8edefa 18#include <linux/seq_file.h>
06b3db1b
DH
19#include "internal.h"
20
21MODULE_DESCRIPTION("FS Cache Manager");
22MODULE_AUTHOR("Red Hat, Inc.");
23MODULE_LICENSE("GPL");
24
25unsigned fscache_defer_lookup = 1;
26module_param_named(defer_lookup, fscache_defer_lookup, uint,
27 S_IWUSR | S_IRUGO);
28MODULE_PARM_DESC(fscache_defer_lookup,
29 "Defer cookie lookup to background thread");
30
31unsigned fscache_defer_create = 1;
32module_param_named(defer_create, fscache_defer_create, uint,
33 S_IWUSR | S_IRUGO);
34MODULE_PARM_DESC(fscache_defer_create,
35 "Defer cookie creation to background thread");
36
37unsigned fscache_debug;
38module_param_named(debug, fscache_debug, uint,
39 S_IWUSR | S_IRUGO);
40MODULE_PARM_DESC(fscache_debug,
41 "FS-Cache debugging mask");
42
43struct kobject *fscache_root;
8b8edefa 44struct workqueue_struct *fscache_object_wq;
8af7c124 45struct workqueue_struct *fscache_op_wq;
8b8edefa
TH
46
47DEFINE_PER_CPU(wait_queue_head_t, fscache_object_cong_wait);
48
49/* these values serve as lower bounds, will be adjusted in fscache_init() */
50static unsigned fscache_object_max_active = 4;
8af7c124 51static unsigned fscache_op_max_active = 2;
8b8edefa
TH
52
53#ifdef CONFIG_SYSCTL
54static struct ctl_table_header *fscache_sysctl_header;
55
56static int fscache_max_active_sysctl(struct ctl_table *table, int write,
57 void __user *buffer,
58 size_t *lenp, loff_t *ppos)
59{
60 struct workqueue_struct **wqp = table->extra1;
61 unsigned int *datap = table->data;
62 int ret;
63
64 ret = proc_dointvec(table, write, buffer, lenp, ppos);
65 if (ret == 0)
66 workqueue_set_max_active(*wqp, *datap);
67 return ret;
68}
69
70ctl_table fscache_sysctls[] = {
71 {
72 .procname = "object_max_active",
73 .data = &fscache_object_max_active,
74 .maxlen = sizeof(unsigned),
75 .mode = 0644,
76 .proc_handler = fscache_max_active_sysctl,
77 .extra1 = &fscache_object_wq,
78 },
8af7c124
TH
79 {
80 .procname = "operation_max_active",
81 .data = &fscache_op_max_active,
82 .maxlen = sizeof(unsigned),
83 .mode = 0644,
84 .proc_handler = fscache_max_active_sysctl,
85 .extra1 = &fscache_op_wq,
86 },
8b8edefa
TH
87 {}
88};
89
90ctl_table fscache_sysctls_root[] = {
91 {
92 .procname = "fscache",
93 .mode = 0555,
94 .child = fscache_sysctls,
95 },
96 {}
97};
98#endif
06b3db1b
DH
99
100/*
101 * initialise the fs caching module
102 */
103static int __init fscache_init(void)
104{
8b8edefa
TH
105 unsigned int nr_cpus = num_possible_cpus();
106 unsigned int cpu;
06b3db1b
DH
107 int ret;
108
8b8edefa
TH
109 fscache_object_max_active =
110 clamp_val(nr_cpus,
111 fscache_object_max_active, WQ_UNBOUND_MAX_ACTIVE);
112
113 ret = -ENOMEM;
114 fscache_object_wq = alloc_workqueue("fscache_object", WQ_UNBOUND,
115 fscache_object_max_active);
116 if (!fscache_object_wq)
117 goto error_object_wq;
118
8af7c124
TH
119 fscache_op_max_active =
120 clamp_val(fscache_object_max_active / 2,
121 fscache_op_max_active, WQ_UNBOUND_MAX_ACTIVE);
122
123 ret = -ENOMEM;
124 fscache_op_wq = alloc_workqueue("fscache_operation", WQ_UNBOUND,
125 fscache_op_max_active);
126 if (!fscache_op_wq)
127 goto error_op_wq;
128
8b8edefa
TH
129 for_each_possible_cpu(cpu)
130 init_waitqueue_head(&per_cpu(fscache_object_cong_wait, cpu));
131
7394daa8
DH
132 ret = fscache_proc_init();
133 if (ret < 0)
134 goto error_proc;
135
8b8edefa
TH
136#ifdef CONFIG_SYSCTL
137 ret = -ENOMEM;
138 fscache_sysctl_header = register_sysctl_table(fscache_sysctls_root);
139 if (!fscache_sysctl_header)
140 goto error_sysctl;
141#endif
142
955d0091
DH
143 fscache_cookie_jar = kmem_cache_create("fscache_cookie_jar",
144 sizeof(struct fscache_cookie),
145 0,
146 0,
147 fscache_cookie_init_once);
148 if (!fscache_cookie_jar) {
149 printk(KERN_NOTICE
150 "FS-Cache: Failed to allocate a cookie jar\n");
151 ret = -ENOMEM;
152 goto error_cookie_jar;
153 }
154
4c515dd4
DH
155 fscache_root = kobject_create_and_add("fscache", kernel_kobj);
156 if (!fscache_root)
157 goto error_kobj;
158
06b3db1b
DH
159 printk(KERN_NOTICE "FS-Cache: Loaded\n");
160 return 0;
161
4c515dd4 162error_kobj:
955d0091
DH
163 kmem_cache_destroy(fscache_cookie_jar);
164error_cookie_jar:
8b8edefa
TH
165#ifdef CONFIG_SYSCTL
166 unregister_sysctl_table(fscache_sysctl_header);
167error_sysctl:
168#endif
4c515dd4 169 fscache_proc_cleanup();
7394daa8 170error_proc:
8af7c124
TH
171 destroy_workqueue(fscache_op_wq);
172error_op_wq:
8b8edefa
TH
173 destroy_workqueue(fscache_object_wq);
174error_object_wq:
06b3db1b
DH
175 return ret;
176}
177
178fs_initcall(fscache_init);
179
180/*
181 * clean up on module removal
182 */
183static void __exit fscache_exit(void)
184{
185 _enter("");
186
4c515dd4 187 kobject_put(fscache_root);
955d0091 188 kmem_cache_destroy(fscache_cookie_jar);
40f2b6ff 189#ifdef CONFIG_SYSCTL
8b8edefa 190 unregister_sysctl_table(fscache_sysctl_header);
40f2b6ff 191#endif
7394daa8 192 fscache_proc_cleanup();
8af7c124 193 destroy_workqueue(fscache_op_wq);
8b8edefa 194 destroy_workqueue(fscache_object_wq);
06b3db1b
DH
195 printk(KERN_NOTICE "FS-Cache: Unloaded\n");
196}
197
198module_exit(fscache_exit);
2868cbea
DH
199
200/*
201 * wait_on_bit() sleep function for uninterruptible waiting
202 */
203int fscache_wait_bit(void *flags)
204{
205 schedule();
206 return 0;
207}
208EXPORT_SYMBOL(fscache_wait_bit);
209
210/*
211 * wait_on_bit() sleep function for interruptible waiting
212 */
213int fscache_wait_bit_interruptible(void *flags)
214{
215 schedule();
216 return signal_pending(current);
217}
218EXPORT_SYMBOL(fscache_wait_bit_interruptible);