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;
60 int LL_PROC_PROTO(proc_set_timeout)
64 rc = proc_dointvec(table, write, buffer, lenp, ppos);
65 if (ldlm_timeout >= obd_timeout)
66 ldlm_timeout = max(obd_timeout / 3, 1U);
70 int LL_PROC_PROTO(proc_memory_alloc)
75 if (!*lenp || (*ppos && !write)) {
82 len = snprintf(buf, sizeof(buf), LPU64"\n", obd_memory_sum());
86 if (copy_to_user(buffer, buf, len))
93 int LL_PROC_PROTO(proc_pages_alloc)
98 if (!*lenp || (*ppos && !write)) {
105 len = snprintf(buf, sizeof(buf), LPU64"\n", obd_pages_sum());
109 if (copy_to_user(buffer, buf, len))
116 int LL_PROC_PROTO(proc_mem_max)
121 if (!*lenp || (*ppos && !write)) {
128 len = snprintf(buf, sizeof(buf), LPU64"\n", obd_memory_max());
132 if (copy_to_user(buffer, buf, len))
139 int LL_PROC_PROTO(proc_pages_max)
144 if (!*lenp || (*ppos && !write)) {
151 len = snprintf(buf, sizeof(buf), LPU64"\n", obd_pages_max());
155 if (copy_to_user(buffer, buf, len))
162 int LL_PROC_PROTO(proc_max_dirty_pages_in_mb)
166 if (!table->data || !table->maxlen || !*lenp || (*ppos && !write)) {
171 rc = lprocfs_write_frac_helper(buffer, *lenp,
172 (unsigned int *)table->data,
173 1 << (20 - PAGE_CACHE_SHIFT));
174 /* Don't allow them to let dirty pages exceed 90% of system
175 * memory and set a hard minimum of 4MB. */
176 if (obd_max_dirty_pages > ((totalram_pages / 10) * 9)) {
177 CERROR("Refusing to set max dirty pages to %u, which "
178 "is more than 90%% of available RAM; setting "
179 "to %lu\n", obd_max_dirty_pages,
180 ((totalram_pages / 10) * 9));
181 obd_max_dirty_pages = ((totalram_pages / 10) * 9);
182 } else if (obd_max_dirty_pages < 4 << (20 - PAGE_CACHE_SHIFT)) {
183 obd_max_dirty_pages = 4 << (20 - PAGE_CACHE_SHIFT);
189 len = lprocfs_read_frac_helper(buf, sizeof(buf),
190 *(unsigned int *)table->data,
191 1 << (20 - PAGE_CACHE_SHIFT));
195 if (copy_to_user(buffer, buf, len))
203 #ifdef RANDOM_FAIL_ALLOC
204 int proc_alloc_fail_rate(struct ctl_table *table, int write,
205 void __user *buffer, size_t *lenp, loff_t *ppos)
209 if (!table->data || !table->maxlen || !*lenp || (*ppos && !write)) {
214 rc = lprocfs_write_frac_helper(buffer, *lenp,
215 (unsigned int*)table->data,
216 OBD_ALLOC_FAIL_MULT);
221 len = lprocfs_read_frac_helper(buf, 21,
222 *(unsigned int*)table->data,
223 OBD_ALLOC_FAIL_MULT);
227 if (copy_to_user(buffer, buf, len))
236 int LL_PROC_PROTO(proc_at_min)
238 return proc_dointvec(table, write, buffer, lenp, ppos);
240 int LL_PROC_PROTO(proc_at_max)
242 return proc_dointvec(table, write, buffer, lenp, ppos);
244 int LL_PROC_PROTO(proc_at_extra)
246 return proc_dointvec(table, write, buffer, lenp, ppos);
248 int LL_PROC_PROTO(proc_at_early_margin)
250 return proc_dointvec(table, write, buffer, lenp, ppos);
252 int LL_PROC_PROTO(proc_at_history)
254 return proc_dointvec(table, write, buffer, lenp, ppos);
258 static struct ctl_table obd_table[] = {
261 .procname = "timeout",
262 .data = &obd_timeout,
263 .maxlen = sizeof(int),
265 .proc_handler = &proc_set_timeout
269 .procname = "debug_peer_on_timeout",
270 .data = &obd_debug_peer_on_timeout,
271 .maxlen = sizeof(int),
273 .proc_handler = &proc_dointvec
277 .procname = "dump_on_timeout",
278 .data = &obd_dump_on_timeout,
279 .maxlen = sizeof(int),
281 .proc_handler = &proc_dointvec
285 .procname = "dump_on_eviction",
286 .data = &obd_dump_on_eviction,
287 .maxlen = sizeof(int),
289 .proc_handler = &proc_dointvec
293 .procname = "memused",
297 .proc_handler = &proc_memory_alloc
301 .procname = "pagesused",
305 .proc_handler = &proc_pages_alloc
309 .procname = "memused_max",
313 .proc_handler = &proc_mem_max
317 .procname = "pagesused_max",
321 .proc_handler = &proc_pages_max
325 .procname = "ldlm_timeout",
326 .data = &ldlm_timeout,
327 .maxlen = sizeof(int),
329 .proc_handler = &proc_set_timeout
331 #ifdef RANDOM_FAIL_ALLOC
334 .procname = "alloc_fail_rate",
335 .data = &obd_alloc_fail_rate,
336 .maxlen = sizeof(int),
338 .proc_handler = &proc_alloc_fail_rate
343 .procname = "max_dirty_mb",
344 .data = &obd_max_dirty_pages,
345 .maxlen = sizeof(int),
347 .proc_handler = &proc_max_dirty_pages_in_mb
351 .procname = "at_min",
353 .maxlen = sizeof(int),
355 .proc_handler = &proc_at_min
359 .procname = "at_max",
361 .maxlen = sizeof(int),
363 .proc_handler = &proc_at_max
367 .procname = "at_extra",
369 .maxlen = sizeof(int),
371 .proc_handler = &proc_at_extra
375 .procname = "at_early_margin",
376 .data = &at_early_margin,
377 .maxlen = sizeof(int),
379 .proc_handler = &proc_at_early_margin
383 .procname = "at_history",
385 .maxlen = sizeof(int),
387 .proc_handler = &proc_at_history
392 static struct ctl_table parent_table[] = {
395 .procname = "lustre",
405 void obd_sysctl_init (void)
408 if ( !obd_table_header )
409 obd_table_header = register_sysctl_table(parent_table);
413 void obd_sysctl_clean (void)
416 if ( obd_table_header )
417 unregister_sysctl_table(obd_table_header);
418 obd_table_header = NULL;