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 */
82 OBD_BULK_TIMEOUT, /* bulk transfer timeout */
87 #define OBD_SYSCTL CTL_UNNUMBERED
89 #define OBD_FAIL_LOC CTL_UNNUMBERED
90 #define OBD_FAIL_VAL CTL_UNNUMBERED
91 #define OBD_TIMEOUT CTL_UNNUMBERED
92 #define OBD_DUMP_ON_TIMEOUT CTL_UNNUMBERED
93 #define OBD_MEMUSED CTL_UNNUMBERED
94 #define OBD_PAGESUSED CTL_UNNUMBERED
95 #define OBD_MAXMEMUSED CTL_UNNUMBERED
96 #define OBD_MAXPAGESUSED CTL_UNNUMBERED
97 #define OBD_SYNCFILTER CTL_UNNUMBERED
98 #define OBD_LDLM_TIMEOUT CTL_UNNUMBERED
99 #define OBD_DUMP_ON_EVICTION CTL_UNNUMBERED
100 #define OBD_DEBUG_PEER_ON_TIMEOUT CTL_UNNUMBERED
101 #define OBD_ALLOC_FAIL_RATE CTL_UNNUMBERED
102 #define OBD_MAX_DIRTY_PAGES CTL_UNNUMBERED
103 #define OBD_AT_MIN CTL_UNNUMBERED
104 #define OBD_AT_MAX CTL_UNNUMBERED
105 #define OBD_AT_EXTRA CTL_UNNUMBERED
106 #define OBD_AT_EARLY_MARGIN CTL_UNNUMBERED
107 #define OBD_AT_HISTORY CTL_UNNUMBERED
108 #define OBD_BULK_TIMEOUT CTL_UNNUMBERED
112 int LL_PROC_PROTO(proc_set_timeout)
116 rc = ll_proc_dointvec(table, write, filp, buffer, lenp, ppos);
117 if (ldlm_timeout >= obd_timeout)
118 ldlm_timeout = max(obd_timeout / 3, 1U);
122 int LL_PROC_PROTO(proc_memory_alloc)
126 DECLARE_LL_PROC_PPOS_DECL;
128 if (!*lenp || (*ppos && !write)) {
135 len = snprintf(buf, sizeof(buf), LPU64"\n", obd_memory_sum());
139 if (copy_to_user(buffer, buf, len))
146 int LL_PROC_PROTO(proc_pages_alloc)
150 DECLARE_LL_PROC_PPOS_DECL;
152 if (!*lenp || (*ppos && !write)) {
159 len = snprintf(buf, sizeof(buf), LPU64"\n", obd_pages_sum());
163 if (copy_to_user(buffer, buf, len))
170 int LL_PROC_PROTO(proc_mem_max)
174 DECLARE_LL_PROC_PPOS_DECL;
176 if (!*lenp || (*ppos && !write)) {
183 len = snprintf(buf, sizeof(buf), LPU64"\n", obd_memory_max());
187 if (copy_to_user(buffer, buf, len))
194 int LL_PROC_PROTO(proc_pages_max)
198 DECLARE_LL_PROC_PPOS_DECL;
200 if (!*lenp || (*ppos && !write)) {
207 len = snprintf(buf, sizeof(buf), LPU64"\n", obd_pages_max());
211 if (copy_to_user(buffer, buf, len))
218 int LL_PROC_PROTO(proc_max_dirty_pages_in_mb)
221 DECLARE_LL_PROC_PPOS_DECL;
223 if (!table->data || !table->maxlen || !*lenp || (*ppos && !write)) {
228 rc = lprocfs_write_frac_helper(buffer, *lenp,
229 (unsigned int *)table->data,
230 1 << (20 - PAGE_CACHE_SHIFT));
231 /* Don't allow them to let dirty pages exceed 90% of system
232 * memory and set a hard minimum of 4MB. */
233 if (obd_max_dirty_pages > ((totalram_pages / 10) * 9)) {
234 CERROR("Refusing to set max dirty pages to %u, which "
235 "is more than 90%% of available RAM; setting "
236 "to %lu\n", obd_max_dirty_pages,
237 ((totalram_pages / 10) * 9));
238 obd_max_dirty_pages = ((totalram_pages / 10) * 9);
239 } else if (obd_max_dirty_pages < 4 << (20 - PAGE_CACHE_SHIFT)) {
240 obd_max_dirty_pages = 4 << (20 - PAGE_CACHE_SHIFT);
246 len = lprocfs_read_frac_helper(buf, sizeof(buf),
247 *(unsigned int *)table->data,
248 1 << (20 - PAGE_CACHE_SHIFT));
252 if (copy_to_user(buffer, buf, len))
260 #ifdef RANDOM_FAIL_ALLOC
261 int LL_PROC_PROTO(proc_alloc_fail_rate)
264 DECLARE_LL_PROC_PPOS_DECL;
266 if (!table->data || !table->maxlen || !*lenp || (*ppos && !write)) {
271 rc = lprocfs_write_frac_helper(buffer, *lenp,
272 (unsigned int*)table->data,
273 OBD_ALLOC_FAIL_MULT);
278 len = lprocfs_read_frac_helper(buf, 21,
279 *(unsigned int*)table->data,
280 OBD_ALLOC_FAIL_MULT);
284 if (copy_to_user(buffer, buf, len))
293 int LL_PROC_PROTO(proc_bulk_timeout)
295 return proc_dointvec(table, write, buffer, lenp, ppos);
297 int LL_PROC_PROTO(proc_at_min)
299 return ll_proc_dointvec(table, write, filp, buffer, lenp, ppos);
301 int LL_PROC_PROTO(proc_at_max)
303 return ll_proc_dointvec(table, write, filp, buffer, lenp, ppos);
305 int LL_PROC_PROTO(proc_at_extra)
307 return ll_proc_dointvec(table, write, filp, buffer, lenp, ppos);
309 int LL_PROC_PROTO(proc_at_early_margin)
311 return ll_proc_dointvec(table, write, filp, buffer, lenp, ppos);
313 int LL_PROC_PROTO(proc_at_history)
315 return ll_proc_dointvec(table, write, filp, buffer, lenp, ppos);
319 static struct ctl_table obd_table[] = {
321 INIT_CTL_NAME(OBD_TIMEOUT)
322 .procname = "timeout",
323 .data = &obd_timeout,
324 .maxlen = sizeof(int),
326 .proc_handler = &proc_set_timeout
329 INIT_CTL_NAME(OBD_DEBUG_PEER_ON_TIMEOUT)
330 .procname = "debug_peer_on_timeout",
331 .data = &obd_debug_peer_on_timeout,
332 .maxlen = sizeof(int),
334 .proc_handler = &proc_dointvec
337 INIT_CTL_NAME(OBD_DUMP_ON_TIMEOUT)
338 .procname = "dump_on_timeout",
339 .data = &obd_dump_on_timeout,
340 .maxlen = sizeof(int),
342 .proc_handler = &proc_dointvec
345 INIT_CTL_NAME(OBD_DUMP_ON_EVICTION)
346 .procname = "dump_on_eviction",
347 .data = &obd_dump_on_eviction,
348 .maxlen = sizeof(int),
350 .proc_handler = &proc_dointvec
353 INIT_CTL_NAME(OBD_MEMUSED)
354 .procname = "memused",
358 .proc_handler = &proc_memory_alloc
361 INIT_CTL_NAME(OBD_PAGESUSED)
362 .procname = "pagesused",
366 .proc_handler = &proc_pages_alloc
369 INIT_CTL_NAME(OBD_MAXMEMUSED)
370 .procname = "memused_max",
374 .proc_handler = &proc_mem_max
377 INIT_CTL_NAME(OBD_MAXPAGESUSED)
378 .procname = "pagesused_max",
382 .proc_handler = &proc_pages_max
385 INIT_CTL_NAME(OBD_LDLM_TIMEOUT)
386 .procname = "ldlm_timeout",
387 .data = &ldlm_timeout,
388 .maxlen = sizeof(int),
390 .proc_handler = &proc_set_timeout
392 #ifdef RANDOM_FAIL_ALLOC
394 INIT_CTL_NAME(OBD_ALLOC_FAIL_RATE)
395 .procname = "alloc_fail_rate",
396 .data = &obd_alloc_fail_rate,
397 .maxlen = sizeof(int),
399 .proc_handler = &proc_alloc_fail_rate
403 INIT_CTL_NAME(OBD_MAX_DIRTY_PAGES)
404 .procname = "max_dirty_mb",
405 .data = &obd_max_dirty_pages,
406 .maxlen = sizeof(int),
408 .proc_handler = &proc_max_dirty_pages_in_mb
411 INIT_CTL_NAME(OBD_BULK_TIMEOUT)
412 .procname = "bulk_timeout",
413 .data = &bulk_timeout,
414 .maxlen = sizeof(int),
416 .proc_handler = &proc_bulk_timeout
419 INIT_CTL_NAME(OBD_AT_MIN)
420 .procname = "at_min",
422 .maxlen = sizeof(int),
424 .proc_handler = &proc_at_min
427 INIT_CTL_NAME(OBD_AT_MAX)
428 .procname = "at_max",
430 .maxlen = sizeof(int),
432 .proc_handler = &proc_at_max
435 INIT_CTL_NAME(OBD_AT_EXTRA)
436 .procname = "at_extra",
438 .maxlen = sizeof(int),
440 .proc_handler = &proc_at_extra
443 INIT_CTL_NAME(OBD_AT_EARLY_MARGIN)
444 .procname = "at_early_margin",
445 .data = &at_early_margin,
446 .maxlen = sizeof(int),
448 .proc_handler = &proc_at_early_margin
451 INIT_CTL_NAME(OBD_AT_HISTORY)
452 .procname = "at_history",
454 .maxlen = sizeof(int),
456 .proc_handler = &proc_at_history
461 static struct ctl_table parent_table[] = {
463 INIT_CTL_NAME(OBD_SYSCTL)
464 .procname = "lustre",
474 void obd_sysctl_init (void)
477 if ( !obd_table_header )
478 obd_table_header = register_sysctl_table(parent_table);
482 void obd_sysctl_clean (void)
485 if ( obd_table_header )
486 unregister_sysctl_table(obd_table_header);
487 obd_table_header = NULL;