4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2011, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
37 #include <linux/module.h>
38 #include <linux/sysctl.h>
39 #include <linux/sched.h>
41 #include <linux/sysctl.h>
42 #include <linux/version.h>
43 #include <linux/proc_fs.h>
44 #include <linux/slab.h>
45 #include <linux/stat.h>
46 #include <linux/ctype.h>
47 #include <asm/bitops.h>
48 #include <asm/uaccess.h>
49 #include <linux/utsname.h>
51 #define DEBUG_SUBSYSTEM S_CLASS
53 #include <obd_support.h>
54 #include <lprocfs_status.h>
57 struct ctl_table_header *obd_table_header = NULL;
61 proc_set_timeout(struct ctl_table *table, int write, void __user *buffer,
62 size_t *lenp, loff_t *ppos)
66 rc = proc_dointvec(table, write, buffer, lenp, ppos);
67 if (ldlm_timeout >= obd_timeout)
68 ldlm_timeout = max(obd_timeout / 3, 1U);
73 proc_memory_alloc(struct ctl_table *table, int write, void __user *buffer,
74 size_t *lenp, loff_t *ppos)
79 if (!*lenp || (*ppos && !write)) {
86 len = snprintf(buf, sizeof(buf), LPU64"\n", obd_memory_sum());
90 if (copy_to_user(buffer, buf, len))
98 proc_pages_alloc(struct ctl_table *table, int write, void __user *buffer,
99 size_t *lenp, loff_t *ppos)
104 if (!*lenp || (*ppos && !write)) {
111 len = snprintf(buf, sizeof(buf), LPU64"\n", obd_pages_sum());
115 if (copy_to_user(buffer, buf, len))
123 proc_mem_max(struct ctl_table *table, int write, void __user *buffer,
124 size_t *lenp, loff_t *ppos)
129 if (!*lenp || (*ppos && !write)) {
136 len = snprintf(buf, sizeof(buf), LPU64"\n", obd_memory_max());
140 if (copy_to_user(buffer, buf, len))
148 proc_pages_max(struct ctl_table *table, int write, void __user *buffer,
149 size_t *lenp, loff_t *ppos)
154 if (!*lenp || (*ppos && !write)) {
161 len = snprintf(buf, sizeof(buf), LPU64"\n", obd_pages_max());
165 if (copy_to_user(buffer, buf, len))
173 proc_max_dirty_pages_in_mb(struct ctl_table *table, int write,
174 void __user *buffer, size_t *lenp, loff_t *ppos)
178 if (!table->data || !table->maxlen || !*lenp || (*ppos && !write)) {
183 rc = lprocfs_write_frac_helper(buffer, *lenp,
184 (unsigned int *)table->data,
185 1 << (20 - PAGE_CACHE_SHIFT));
186 /* Don't allow them to let dirty pages exceed 90% of system
187 * memory and set a hard minimum of 4MB. */
188 if (obd_max_dirty_pages > ((totalram_pages / 10) * 9)) {
189 CERROR("Refusing to set max dirty pages to %u, which "
190 "is more than 90%% of available RAM; setting "
191 "to %lu\n", obd_max_dirty_pages,
192 ((totalram_pages / 10) * 9));
193 obd_max_dirty_pages = ((totalram_pages / 10) * 9);
194 } else if (obd_max_dirty_pages < 4 << (20 - PAGE_CACHE_SHIFT)) {
195 obd_max_dirty_pages = 4 << (20 - PAGE_CACHE_SHIFT);
201 len = lprocfs_read_frac_helper(buf, sizeof(buf),
202 *(unsigned int *)table->data,
203 1 << (20 - PAGE_CACHE_SHIFT));
207 if (copy_to_user(buffer, buf, len))
215 #ifdef RANDOM_FAIL_ALLOC
216 int proc_alloc_fail_rate(struct ctl_table *table, int write,
217 void __user *buffer, size_t *lenp, loff_t *ppos)
221 if (!table->data || !table->maxlen || !*lenp || (*ppos && !write)) {
226 rc = lprocfs_write_frac_helper(buffer, *lenp,
227 (unsigned int*)table->data,
228 OBD_ALLOC_FAIL_MULT);
233 len = lprocfs_read_frac_helper(buf, 21,
234 *(unsigned int*)table->data,
235 OBD_ALLOC_FAIL_MULT);
239 if (copy_to_user(buffer, buf, len))
249 static struct ctl_table obd_table[] = {
252 .procname = "timeout",
253 .data = &obd_timeout,
254 .maxlen = sizeof(int),
256 .proc_handler = &proc_set_timeout
260 .procname = "debug_peer_on_timeout",
261 .data = &obd_debug_peer_on_timeout,
262 .maxlen = sizeof(int),
264 .proc_handler = &proc_dointvec
268 .procname = "dump_on_timeout",
269 .data = &obd_dump_on_timeout,
270 .maxlen = sizeof(int),
272 .proc_handler = &proc_dointvec
276 .procname = "dump_on_eviction",
277 .data = &obd_dump_on_eviction,
278 .maxlen = sizeof(int),
280 .proc_handler = &proc_dointvec
284 .procname = "memused",
288 .proc_handler = &proc_memory_alloc
292 .procname = "pagesused",
296 .proc_handler = &proc_pages_alloc
300 .procname = "memused_max",
304 .proc_handler = &proc_mem_max
308 .procname = "pagesused_max",
312 .proc_handler = &proc_pages_max
316 .procname = "ldlm_timeout",
317 .data = &ldlm_timeout,
318 .maxlen = sizeof(int),
320 .proc_handler = &proc_set_timeout
322 #ifdef RANDOM_FAIL_ALLOC
325 .procname = "alloc_fail_rate",
326 .data = &obd_alloc_fail_rate,
327 .maxlen = sizeof(int),
329 .proc_handler = &proc_alloc_fail_rate
334 .procname = "max_dirty_mb",
335 .data = &obd_max_dirty_pages,
336 .maxlen = sizeof(int),
338 .proc_handler = &proc_max_dirty_pages_in_mb
342 .procname = "bulk_timeout",
343 .data = &bulk_timeout,
344 .maxlen = sizeof(int),
346 .proc_handler = &proc_dointvec
350 .procname = "at_min",
352 .maxlen = sizeof(int),
354 .proc_handler = &proc_dointvec
358 .procname = "at_max",
360 .maxlen = sizeof(int),
362 .proc_handler = &proc_dointvec
366 .procname = "at_extra",
368 .maxlen = sizeof(int),
370 .proc_handler = &proc_dointvec
374 .procname = "at_early_margin",
375 .data = &at_early_margin,
376 .maxlen = sizeof(int),
378 .proc_handler = &proc_dointvec
382 .procname = "at_history",
384 .maxlen = sizeof(int),
386 .proc_handler = &proc_dointvec
391 static struct ctl_table parent_table[] = {
394 .procname = "lustre",
404 void obd_sysctl_init (void)
407 if ( !obd_table_header )
408 obd_table_header = register_sysctl_table(parent_table);
412 void obd_sysctl_clean (void)
415 if ( obd_table_header )
416 unregister_sysctl_table(obd_table_header);
417 obd_table_header = NULL;