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.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2011, 2015, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
30 * Lustre is a trademark of Sun Microsystems, Inc.
33 #include <linux/module.h>
34 #include <linux/sysctl.h>
35 #include <linux/sched.h>
37 #include <linux/sysctl.h>
38 #include <linux/version.h>
39 #include <linux/proc_fs.h>
40 #include <linux/slab.h>
41 #include <linux/stat.h>
42 #include <linux/ctype.h>
43 #include <asm/bitops.h>
44 #include <asm/uaccess.h>
45 #include <linux/utsname.h>
47 #define DEBUG_SUBSYSTEM S_CLASS
49 #include <obd_support.h>
50 #include <lprocfs_status.h>
51 #include <obd_class.h>
54 static struct ctl_table_header *obd_table_header;
58 proc_set_timeout(struct ctl_table *table, int write, void __user *buffer,
59 size_t *lenp, loff_t *ppos)
63 rc = proc_dointvec(table, write, buffer, lenp, ppos);
64 if (ldlm_timeout >= obd_timeout)
65 ldlm_timeout = max(obd_timeout / 3, 1U);
70 proc_memory_alloc(struct ctl_table *table, int write, void __user *buffer,
71 size_t *lenp, loff_t *ppos)
76 if (!*lenp || (*ppos && !write)) {
83 len = snprintf(buf, sizeof(buf), "%llu\n", obd_memory_sum());
87 if (copy_to_user(buffer, buf, len))
95 proc_mem_max(struct ctl_table *table, int write, void __user *buffer,
96 size_t *lenp, loff_t *ppos)
101 if (!*lenp || (*ppos && !write)) {
108 len = snprintf(buf, sizeof(buf), "%llu\n", obd_memory_max());
112 if (copy_to_user(buffer, buf, len))
120 proc_max_dirty_pages_in_mb(struct ctl_table *table, int write,
121 void __user *buffer, size_t *lenp, loff_t *ppos)
126 if (!table->data || !table->maxlen || !*lenp || (*ppos && !write)) {
131 rc = lprocfs_str_with_units_to_s64(buffer, *lenp, &val, 'M');
140 /* Don't allow them to let dirty pages exceed 90% of system
141 * memory and set a hard minimum of 4MB. */
142 if (val > ((totalram_pages / 10) * 9)) {
143 CERROR("Refusing to set max dirty pages to %lld, "
144 "which is more than 90%% of available RAM; "
145 "setting to %lu\n", val,
146 ((totalram_pages / 10) * 9));
147 obd_max_dirty_pages = ((totalram_pages / 10) * 9);
148 } else if (val < 4 << (20 - PAGE_SHIFT)) {
149 obd_max_dirty_pages = 4 << (20 - PAGE_SHIFT);
151 obd_max_dirty_pages = val;
157 len = lprocfs_read_frac_helper(buf, sizeof(buf),
158 *(unsigned long *)table->data,
159 1 << (20 - PAGE_SHIFT));
163 if (copy_to_user(buffer, buf, len))
172 static struct ctl_table obd_table[] = {
175 .procname = "timeout",
176 .data = &obd_timeout,
177 .maxlen = sizeof(int),
179 .proc_handler = &proc_set_timeout
183 .procname = "debug_peer_on_timeout",
184 .data = &obd_debug_peer_on_timeout,
185 .maxlen = sizeof(int),
187 .proc_handler = &proc_dointvec
191 .procname = "dump_on_timeout",
192 .data = &obd_dump_on_timeout,
193 .maxlen = sizeof(int),
195 .proc_handler = &proc_dointvec
199 .procname = "dump_on_eviction",
200 .data = &obd_dump_on_eviction,
201 .maxlen = sizeof(int),
203 .proc_handler = &proc_dointvec
207 .procname = "memused",
211 .proc_handler = &proc_memory_alloc
215 .procname = "memused_max",
219 .proc_handler = &proc_mem_max
223 .procname = "ldlm_timeout",
224 .data = &ldlm_timeout,
225 .maxlen = sizeof(int),
227 .proc_handler = &proc_set_timeout
231 .procname = "max_dirty_mb",
232 .data = &obd_max_dirty_pages,
233 .maxlen = sizeof(unsigned long),
235 .proc_handler = &proc_max_dirty_pages_in_mb
239 .procname = "bulk_timeout",
240 .data = &bulk_timeout,
241 .maxlen = sizeof(int),
243 .proc_handler = &proc_dointvec
247 .procname = "at_min",
249 .maxlen = sizeof(int),
251 .proc_handler = &proc_dointvec
255 .procname = "at_max",
257 .maxlen = sizeof(int),
259 .proc_handler = &proc_dointvec
263 .procname = "at_extra",
265 .maxlen = sizeof(int),
267 .proc_handler = &proc_dointvec
271 .procname = "at_early_margin",
272 .data = &at_early_margin,
273 .maxlen = sizeof(int),
275 .proc_handler = &proc_dointvec
279 .procname = "at_history",
281 .maxlen = sizeof(int),
283 .proc_handler = &proc_dointvec
288 static struct ctl_table parent_table[] = {
291 .procname = "lustre",
301 void obd_sysctl_init (void)
304 if ( !obd_table_header )
305 obd_table_header = register_sysctl_table(parent_table);
309 void obd_sysctl_clean (void)
312 if ( obd_table_header )
313 unregister_sysctl_table(obd_table_header);
314 obd_table_header = NULL;