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 #ifndef HAVE_SYSCTL_UNNUMBERED
62 #define OBD_SYSCTL 300
65 OBD_TIMEOUT = 3, /* RPC timeout before recovery/intr */
66 OBD_DUMP_ON_TIMEOUT, /* dump kernel debug log upon eviction */
67 OBD_MEMUSED, /* bytes currently OBD_ALLOCated */
68 OBD_PAGESUSED, /* pages currently OBD_PAGE_ALLOCated */
69 OBD_MAXMEMUSED, /* maximum bytes OBD_ALLOCated concurrently */
70 OBD_MAXPAGESUSED, /* maximum pages OBD_PAGE_ALLOCated concurrently */
71 OBD_SYNCFILTER, /* XXX temporary, as we play with sync osts.. */
72 OBD_LDLM_TIMEOUT, /* LDLM timeout for ASTs before client eviction */
73 OBD_DUMP_ON_EVICTION, /* dump kernel debug log upon eviction */
74 OBD_DEBUG_PEER_ON_TIMEOUT, /* dump peer debug when RPC times out */
75 OBD_ALLOC_FAIL_RATE, /* memory allocation random failure rate */
76 OBD_MAX_DIRTY_PAGES, /* maximum dirty pages */
77 OBD_AT_MIN, /* Adaptive timeouts params */
86 #define OBD_SYSCTL CTL_UNNUMBERED
88 #define OBD_FAIL_LOC CTL_UNNUMBERED
89 #define OBD_FAIL_VAL CTL_UNNUMBERED
90 #define OBD_TIMEOUT CTL_UNNUMBERED
91 #define OBD_DUMP_ON_TIMEOUT CTL_UNNUMBERED
92 #define OBD_MEMUSED CTL_UNNUMBERED
93 #define OBD_PAGESUSED CTL_UNNUMBERED
94 #define OBD_MAXMEMUSED CTL_UNNUMBERED
95 #define OBD_MAXPAGESUSED CTL_UNNUMBERED
96 #define OBD_SYNCFILTER CTL_UNNUMBERED
97 #define OBD_LDLM_TIMEOUT CTL_UNNUMBERED
98 #define OBD_DUMP_ON_EVICTION CTL_UNNUMBERED
99 #define OBD_DEBUG_PEER_ON_TIMEOUT CTL_UNNUMBERED
100 #define OBD_ALLOC_FAIL_RATE CTL_UNNUMBERED
101 #define OBD_MAX_DIRTY_PAGES CTL_UNNUMBERED
102 #define OBD_AT_MIN CTL_UNNUMBERED
103 #define OBD_AT_MAX CTL_UNNUMBERED
104 #define OBD_AT_EXTRA CTL_UNNUMBERED
105 #define OBD_AT_EARLY_MARGIN CTL_UNNUMBERED
106 #define OBD_AT_HISTORY CTL_UNNUMBERED
110 int LL_PROC_PROTO(proc_set_timeout)
114 rc = proc_dointvec(table, write, buffer, lenp, ppos);
115 if (ldlm_timeout >= obd_timeout)
116 ldlm_timeout = max(obd_timeout / 3, 1U);
120 int LL_PROC_PROTO(proc_memory_alloc)
125 if (!*lenp || (*ppos && !write)) {
132 len = snprintf(buf, sizeof(buf), LPU64"\n", obd_memory_sum());
136 if (copy_to_user(buffer, buf, len))
143 int LL_PROC_PROTO(proc_pages_alloc)
148 if (!*lenp || (*ppos && !write)) {
155 len = snprintf(buf, sizeof(buf), LPU64"\n", obd_pages_sum());
159 if (copy_to_user(buffer, buf, len))
166 int LL_PROC_PROTO(proc_mem_max)
171 if (!*lenp || (*ppos && !write)) {
178 len = snprintf(buf, sizeof(buf), LPU64"\n", obd_memory_max());
182 if (copy_to_user(buffer, buf, len))
189 int LL_PROC_PROTO(proc_pages_max)
194 if (!*lenp || (*ppos && !write)) {
201 len = snprintf(buf, sizeof(buf), LPU64"\n", obd_pages_max());
205 if (copy_to_user(buffer, buf, len))
212 int LL_PROC_PROTO(proc_max_dirty_pages_in_mb)
216 if (!table->data || !table->maxlen || !*lenp || (*ppos && !write)) {
221 rc = lprocfs_write_frac_helper(buffer, *lenp,
222 (unsigned int *)table->data,
223 1 << (20 - PAGE_CACHE_SHIFT));
224 /* Don't allow them to let dirty pages exceed 90% of system
225 * memory and set a hard minimum of 4MB. */
226 if (obd_max_dirty_pages > ((totalram_pages / 10) * 9)) {
227 CERROR("Refusing to set max dirty pages to %u, which "
228 "is more than 90%% of available RAM; setting "
229 "to %lu\n", obd_max_dirty_pages,
230 ((totalram_pages / 10) * 9));
231 obd_max_dirty_pages = ((totalram_pages / 10) * 9);
232 } else if (obd_max_dirty_pages < 4 << (20 - PAGE_CACHE_SHIFT)) {
233 obd_max_dirty_pages = 4 << (20 - PAGE_CACHE_SHIFT);
239 len = lprocfs_read_frac_helper(buf, sizeof(buf),
240 *(unsigned int *)table->data,
241 1 << (20 - PAGE_CACHE_SHIFT));
245 if (copy_to_user(buffer, buf, len))
253 #ifdef RANDOM_FAIL_ALLOC
254 int proc_alloc_fail_rate(struct ctl_table *table, int write,
255 void __user *buffer, size_t *lenp, loff_t *ppos)
259 if (!table->data || !table->maxlen || !*lenp || (*ppos && !write)) {
264 rc = lprocfs_write_frac_helper(buffer, *lenp,
265 (unsigned int*)table->data,
266 OBD_ALLOC_FAIL_MULT);
271 len = lprocfs_read_frac_helper(buf, 21,
272 *(unsigned int*)table->data,
273 OBD_ALLOC_FAIL_MULT);
277 if (copy_to_user(buffer, buf, len))
286 int LL_PROC_PROTO(proc_at_min)
288 return proc_dointvec(table, write, buffer, lenp, ppos);
290 int LL_PROC_PROTO(proc_at_max)
292 return proc_dointvec(table, write, buffer, lenp, ppos);
294 int LL_PROC_PROTO(proc_at_extra)
296 return proc_dointvec(table, write, buffer, lenp, ppos);
298 int LL_PROC_PROTO(proc_at_early_margin)
300 return proc_dointvec(table, write, buffer, lenp, ppos);
302 int LL_PROC_PROTO(proc_at_history)
304 return proc_dointvec(table, write, buffer, lenp, ppos);
308 static struct ctl_table obd_table[] = {
310 INIT_CTL_NAME(OBD_TIMEOUT)
311 .procname = "timeout",
312 .data = &obd_timeout,
313 .maxlen = sizeof(int),
315 .proc_handler = &proc_set_timeout
318 INIT_CTL_NAME(OBD_DEBUG_PEER_ON_TIMEOUT)
319 .procname = "debug_peer_on_timeout",
320 .data = &obd_debug_peer_on_timeout,
321 .maxlen = sizeof(int),
323 .proc_handler = &proc_dointvec
326 INIT_CTL_NAME(OBD_DUMP_ON_TIMEOUT)
327 .procname = "dump_on_timeout",
328 .data = &obd_dump_on_timeout,
329 .maxlen = sizeof(int),
331 .proc_handler = &proc_dointvec
334 INIT_CTL_NAME(OBD_DUMP_ON_EVICTION)
335 .procname = "dump_on_eviction",
336 .data = &obd_dump_on_eviction,
337 .maxlen = sizeof(int),
339 .proc_handler = &proc_dointvec
342 INIT_CTL_NAME(OBD_MEMUSED)
343 .procname = "memused",
347 .proc_handler = &proc_memory_alloc
350 INIT_CTL_NAME(OBD_PAGESUSED)
351 .procname = "pagesused",
355 .proc_handler = &proc_pages_alloc
358 INIT_CTL_NAME(OBD_MAXMEMUSED)
359 .procname = "memused_max",
363 .proc_handler = &proc_mem_max
366 INIT_CTL_NAME(OBD_MAXPAGESUSED)
367 .procname = "pagesused_max",
371 .proc_handler = &proc_pages_max
374 INIT_CTL_NAME(OBD_LDLM_TIMEOUT)
375 .procname = "ldlm_timeout",
376 .data = &ldlm_timeout,
377 .maxlen = sizeof(int),
379 .proc_handler = &proc_set_timeout
381 #ifdef RANDOM_FAIL_ALLOC
383 INIT_CTL_NAME(OBD_ALLOC_FAIL_RATE)
384 .procname = "alloc_fail_rate",
385 .data = &obd_alloc_fail_rate,
386 .maxlen = sizeof(int),
388 .proc_handler = &proc_alloc_fail_rate
392 INIT_CTL_NAME(OBD_MAX_DIRTY_PAGES)
393 .procname = "max_dirty_mb",
394 .data = &obd_max_dirty_pages,
395 .maxlen = sizeof(int),
397 .proc_handler = &proc_max_dirty_pages_in_mb
400 INIT_CTL_NAME(OBD_AT_MIN)
401 .procname = "at_min",
403 .maxlen = sizeof(int),
405 .proc_handler = &proc_at_min
408 INIT_CTL_NAME(OBD_AT_MAX)
409 .procname = "at_max",
411 .maxlen = sizeof(int),
413 .proc_handler = &proc_at_max
416 INIT_CTL_NAME(OBD_AT_EXTRA)
417 .procname = "at_extra",
419 .maxlen = sizeof(int),
421 .proc_handler = &proc_at_extra
424 INIT_CTL_NAME(OBD_AT_EARLY_MARGIN)
425 .procname = "at_early_margin",
426 .data = &at_early_margin,
427 .maxlen = sizeof(int),
429 .proc_handler = &proc_at_early_margin
432 INIT_CTL_NAME(OBD_AT_HISTORY)
433 .procname = "at_history",
435 .maxlen = sizeof(int),
437 .proc_handler = &proc_at_history
442 static struct ctl_table parent_table[] = {
444 INIT_CTL_NAME(OBD_SYSCTL)
445 .procname = "lustre",
455 void obd_sysctl_init (void)
458 if ( !obd_table_header )
459 obd_table_header = register_sysctl_table(parent_table);
463 void obd_sysctl_clean (void)
466 if ( obd_table_header )
467 unregister_sysctl_table(obd_table_header);
468 obd_table_header = NULL;