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, 2015, 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>
55 #include <obd_class.h>
58 static struct ctl_table_header *obd_table_header;
62 proc_set_timeout(struct ctl_table *table, int write, void __user *buffer,
63 size_t *lenp, loff_t *ppos)
67 rc = proc_dointvec(table, write, buffer, lenp, ppos);
68 if (ldlm_timeout >= obd_timeout)
69 ldlm_timeout = max(obd_timeout / 3, 1U);
74 proc_memory_alloc(struct ctl_table *table, int write, void __user *buffer,
75 size_t *lenp, loff_t *ppos)
80 if (!*lenp || (*ppos && !write)) {
87 len = snprintf(buf, sizeof(buf), LPU64"\n", obd_memory_sum());
91 if (copy_to_user(buffer, buf, len))
99 proc_mem_max(struct ctl_table *table, int write, void __user *buffer,
100 size_t *lenp, loff_t *ppos)
105 if (!*lenp || (*ppos && !write)) {
112 len = snprintf(buf, sizeof(buf), LPU64"\n", obd_memory_max());
116 if (copy_to_user(buffer, buf, len))
124 proc_max_dirty_pages_in_mb(struct ctl_table *table, int write,
125 void __user *buffer, size_t *lenp, loff_t *ppos)
130 if (!table->data || !table->maxlen || !*lenp || (*ppos && !write)) {
135 rc = lprocfs_write_frac_u64_helper(buffer, *lenp, &val,
136 1 << (20 - PAGE_CACHE_SHIFT));
138 /* Don't allow them to let dirty pages exceed 90% of system
139 * memory and set a hard minimum of 4MB. */
140 if (val > ((totalram_pages / 10) * 9)) {
141 CERROR("Refusing to set max dirty pages to "LPU64", "
142 "which is more than 90%% of available RAM; "
143 "setting to %lu\n", val,
144 ((totalram_pages / 10) * 9));
145 obd_max_dirty_pages = ((totalram_pages / 10) * 9);
146 } else if (val < 4 << (20 - PAGE_CACHE_SHIFT)) {
147 obd_max_dirty_pages = 4 << (20 - PAGE_CACHE_SHIFT);
149 obd_max_dirty_pages = val;
155 len = lprocfs_read_frac_helper(buf, sizeof(buf),
156 *(unsigned long *)table->data,
157 1 << (20 - PAGE_CACHE_SHIFT));
161 if (copy_to_user(buffer, buf, len))
170 static struct ctl_table obd_table[] = {
173 .procname = "timeout",
174 .data = &obd_timeout,
175 .maxlen = sizeof(int),
177 .proc_handler = &proc_set_timeout
181 .procname = "debug_peer_on_timeout",
182 .data = &obd_debug_peer_on_timeout,
183 .maxlen = sizeof(int),
185 .proc_handler = &proc_dointvec
189 .procname = "dump_on_timeout",
190 .data = &obd_dump_on_timeout,
191 .maxlen = sizeof(int),
193 .proc_handler = &proc_dointvec
197 .procname = "dump_on_eviction",
198 .data = &obd_dump_on_eviction,
199 .maxlen = sizeof(int),
201 .proc_handler = &proc_dointvec
205 .procname = "memused",
209 .proc_handler = &proc_memory_alloc
213 .procname = "memused_max",
217 .proc_handler = &proc_mem_max
221 .procname = "ldlm_timeout",
222 .data = &ldlm_timeout,
223 .maxlen = sizeof(int),
225 .proc_handler = &proc_set_timeout
229 .procname = "max_dirty_mb",
230 .data = &obd_max_dirty_pages,
231 .maxlen = sizeof(unsigned long),
233 .proc_handler = &proc_max_dirty_pages_in_mb
237 .procname = "bulk_timeout",
238 .data = &bulk_timeout,
239 .maxlen = sizeof(int),
241 .proc_handler = &proc_dointvec
245 .procname = "at_min",
247 .maxlen = sizeof(int),
249 .proc_handler = &proc_dointvec
253 .procname = "at_max",
255 .maxlen = sizeof(int),
257 .proc_handler = &proc_dointvec
261 .procname = "at_extra",
263 .maxlen = sizeof(int),
265 .proc_handler = &proc_dointvec
269 .procname = "at_early_margin",
270 .data = &at_early_margin,
271 .maxlen = sizeof(int),
273 .proc_handler = &proc_dointvec
277 .procname = "at_history",
279 .maxlen = sizeof(int),
281 .proc_handler = &proc_dointvec
286 static struct ctl_table parent_table[] = {
289 .procname = "lustre",
299 void obd_sysctl_init (void)
302 if ( !obd_table_header )
303 obd_table_header = register_sysctl_table(parent_table);
307 void obd_sysctl_clean (void)
310 if ( obd_table_header )
311 unregister_sysctl_table(obd_table_header);
312 obd_table_header = NULL;