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 cfs_sysctl_table_header_t *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 = ll_proc_dointvec(table, write, filp, 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)
124 DECLARE_LL_PROC_PPOS_DECL;
126 if (!*lenp || (*ppos && !write)) {
133 len = snprintf(buf, sizeof(buf), LPU64"\n", obd_memory_sum());
137 if (copy_to_user(buffer, buf, len))
144 int LL_PROC_PROTO(proc_pages_alloc)
148 DECLARE_LL_PROC_PPOS_DECL;
150 if (!*lenp || (*ppos && !write)) {
157 len = snprintf(buf, sizeof(buf), LPU64"\n", obd_pages_sum());
161 if (copy_to_user(buffer, buf, len))
168 int LL_PROC_PROTO(proc_mem_max)
172 DECLARE_LL_PROC_PPOS_DECL;
174 if (!*lenp || (*ppos && !write)) {
181 len = snprintf(buf, sizeof(buf), LPU64"\n", obd_memory_max());
185 if (copy_to_user(buffer, buf, len))
192 int LL_PROC_PROTO(proc_pages_max)
196 DECLARE_LL_PROC_PPOS_DECL;
198 if (!*lenp || (*ppos && !write)) {
205 len = snprintf(buf, sizeof(buf), LPU64"\n", obd_pages_max());
209 if (copy_to_user(buffer, buf, len))
216 int LL_PROC_PROTO(proc_max_dirty_pages_in_mb)
219 DECLARE_LL_PROC_PPOS_DECL;
221 if (!table->data || !table->maxlen || !*lenp || (*ppos && !write)) {
226 rc = lprocfs_write_frac_helper(buffer, *lenp,
227 (unsigned int *)table->data,
228 1 << (20 - PAGE_CACHE_SHIFT));
229 /* Don't allow them to let dirty pages exceed 90% of system
230 * memory and set a hard minimum of 4MB. */
231 if (obd_max_dirty_pages > ((num_physpages / 10) * 9)) {
232 CERROR("Refusing to set max dirty pages to %u, which "
233 "is more than 90%% of available RAM; setting "
234 "to %lu\n", obd_max_dirty_pages,
235 ((num_physpages / 10) * 9));
236 obd_max_dirty_pages = ((num_physpages / 10) * 9);
237 } else if (obd_max_dirty_pages < 4 << (20 - PAGE_CACHE_SHIFT)) {
238 obd_max_dirty_pages = 4 << (20 - PAGE_CACHE_SHIFT);
244 len = lprocfs_read_frac_helper(buf, sizeof(buf),
245 *(unsigned int *)table->data,
246 1 << (20 - PAGE_CACHE_SHIFT));
250 if (copy_to_user(buffer, buf, len))
258 #ifdef RANDOM_FAIL_ALLOC
259 int LL_PROC_PROTO(proc_alloc_fail_rate)
262 DECLARE_LL_PROC_PPOS_DECL;
264 if (!table->data || !table->maxlen || !*lenp || (*ppos && !write)) {
269 rc = lprocfs_write_frac_helper(buffer, *lenp,
270 (unsigned int*)table->data,
271 OBD_ALLOC_FAIL_MULT);
276 len = lprocfs_read_frac_helper(buf, 21,
277 *(unsigned int*)table->data,
278 OBD_ALLOC_FAIL_MULT);
282 if (copy_to_user(buffer, buf, len))
291 int LL_PROC_PROTO(proc_at_min)
293 return ll_proc_dointvec(table, write, filp, buffer, lenp, ppos);
295 int LL_PROC_PROTO(proc_at_max)
297 return ll_proc_dointvec(table, write, filp, buffer, lenp, ppos);
299 int LL_PROC_PROTO(proc_at_extra)
301 return ll_proc_dointvec(table, write, filp, buffer, lenp, ppos);
303 int LL_PROC_PROTO(proc_at_early_margin)
305 return ll_proc_dointvec(table, write, filp, buffer, lenp, ppos);
307 int LL_PROC_PROTO(proc_at_history)
309 return ll_proc_dointvec(table, write, filp, buffer, lenp, ppos);
313 static cfs_sysctl_table_t obd_table[] = {
315 INIT_CTL_NAME(OBD_TIMEOUT)
316 .procname = "timeout",
317 .data = &obd_timeout,
318 .maxlen = sizeof(int),
320 .proc_handler = &proc_set_timeout
323 INIT_CTL_NAME(OBD_DEBUG_PEER_ON_TIMEOUT)
324 .procname = "debug_peer_on_timeout",
325 .data = &obd_debug_peer_on_timeout,
326 .maxlen = sizeof(int),
328 .proc_handler = &proc_dointvec
331 INIT_CTL_NAME(OBD_DUMP_ON_TIMEOUT)
332 .procname = "dump_on_timeout",
333 .data = &obd_dump_on_timeout,
334 .maxlen = sizeof(int),
336 .proc_handler = &proc_dointvec
339 INIT_CTL_NAME(OBD_DUMP_ON_EVICTION)
340 .procname = "dump_on_eviction",
341 .data = &obd_dump_on_eviction,
342 .maxlen = sizeof(int),
344 .proc_handler = &proc_dointvec
347 INIT_CTL_NAME(OBD_MEMUSED)
348 .procname = "memused",
352 .proc_handler = &proc_memory_alloc
355 INIT_CTL_NAME(OBD_PAGESUSED)
356 .procname = "pagesused",
360 .proc_handler = &proc_pages_alloc
363 INIT_CTL_NAME(OBD_MAXMEMUSED)
364 .procname = "memused_max",
368 .proc_handler = &proc_mem_max
371 INIT_CTL_NAME(OBD_MAXPAGESUSED)
372 .procname = "pagesused_max",
376 .proc_handler = &proc_pages_max
379 INIT_CTL_NAME(OBD_LDLM_TIMEOUT)
380 .procname = "ldlm_timeout",
381 .data = &ldlm_timeout,
382 .maxlen = sizeof(int),
384 .proc_handler = &proc_set_timeout
386 #ifdef RANDOM_FAIL_ALLOC
388 INIT_CTL_NAME(OBD_ALLOC_FAIL_RATE)
389 .procname = "alloc_fail_rate",
390 .data = &obd_alloc_fail_rate,
391 .maxlen = sizeof(int),
393 .proc_handler = &proc_alloc_fail_rate
397 INIT_CTL_NAME(OBD_MAX_DIRTY_PAGES)
398 .procname = "max_dirty_mb",
399 .data = &obd_max_dirty_pages,
400 .maxlen = sizeof(int),
402 .proc_handler = &proc_max_dirty_pages_in_mb
405 INIT_CTL_NAME(OBD_AT_MIN)
406 .procname = "at_min",
408 .maxlen = sizeof(int),
410 .proc_handler = &proc_at_min
413 INIT_CTL_NAME(OBD_AT_MAX)
414 .procname = "at_max",
416 .maxlen = sizeof(int),
418 .proc_handler = &proc_at_max
421 INIT_CTL_NAME(OBD_AT_EXTRA)
422 .procname = "at_extra",
424 .maxlen = sizeof(int),
426 .proc_handler = &proc_at_extra
429 INIT_CTL_NAME(OBD_AT_EARLY_MARGIN)
430 .procname = "at_early_margin",
431 .data = &at_early_margin,
432 .maxlen = sizeof(int),
434 .proc_handler = &proc_at_early_margin
437 INIT_CTL_NAME(OBD_AT_HISTORY)
438 .procname = "at_history",
440 .maxlen = sizeof(int),
442 .proc_handler = &proc_at_history
447 static cfs_sysctl_table_t parent_table[] = {
449 INIT_CTL_NAME(OBD_SYSCTL)
450 .procname = "lustre",
460 void obd_sysctl_init (void)
463 if ( !obd_table_header )
464 obd_table_header = cfs_register_sysctl_table(parent_table, 0);
468 void obd_sysctl_clean (void)
471 if ( obd_table_header )
472 cfs_unregister_sysctl_table(obd_table_header);
473 obd_table_header = NULL;