Whamcloud - gitweb
LU-5556 target: limit bulk transfer time
[fs/lustre-release.git] / lustre / obdclass / linux / linux-sysctl.c
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
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.
9  *
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).
15  *
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
19  *
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
22  * have any questions.
23  *
24  * GPL HEADER END
25  */
26 /*
27  * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
28  * Use is subject to license terms.
29  *
30  * Copyright (c) 2011, Intel Corporation.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  */
36
37 #include <linux/module.h>
38 #include <linux/sysctl.h>
39 #include <linux/sched.h>
40 #include <linux/mm.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>
50
51 #define DEBUG_SUBSYSTEM S_CLASS
52
53 #include <obd_support.h>
54 #include <lprocfs_status.h>
55
56 #ifdef CONFIG_SYSCTL
57 struct ctl_table_header *obd_table_header = NULL;
58 #endif
59
60 #ifndef HAVE_SYSCTL_UNNUMBERED
61
62 #define OBD_SYSCTL 300
63
64 enum {
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 */
78         OBD_AT_MAX,
79         OBD_AT_EXTRA,
80         OBD_AT_EARLY_MARGIN,
81         OBD_AT_HISTORY,
82         OBD_BULK_TIMEOUT,       /* bulk transfer timeout */
83 };
84
85 #else
86
87 #define OBD_SYSCTL              CTL_UNNUMBERED
88
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
109
110 #endif
111
112 int LL_PROC_PROTO(proc_set_timeout)
113 {
114         int rc;
115
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);
119         return rc;
120 }
121
122 int LL_PROC_PROTO(proc_memory_alloc)
123 {
124         char buf[22];
125         int len;
126         DECLARE_LL_PROC_PPOS_DECL;
127
128         if (!*lenp || (*ppos && !write)) {
129                 *lenp = 0;
130                 return 0;
131         }
132         if (write)
133                 return -EINVAL;
134
135         len = snprintf(buf, sizeof(buf), LPU64"\n", obd_memory_sum());
136         if (len > *lenp)
137                 len = *lenp;
138         buf[len] = '\0';
139         if (copy_to_user(buffer, buf, len))
140                 return -EFAULT;
141         *lenp = len;
142         *ppos += *lenp;
143         return 0;
144 }
145
146 int LL_PROC_PROTO(proc_pages_alloc)
147 {
148         char buf[22];
149         int len;
150         DECLARE_LL_PROC_PPOS_DECL;
151
152         if (!*lenp || (*ppos && !write)) {
153                 *lenp = 0;
154                 return 0;
155         }
156         if (write)
157                 return -EINVAL;
158
159         len = snprintf(buf, sizeof(buf), LPU64"\n", obd_pages_sum());
160         if (len > *lenp)
161                 len = *lenp;
162         buf[len] = '\0';
163         if (copy_to_user(buffer, buf, len))
164                 return -EFAULT;
165         *lenp = len;
166         *ppos += *lenp;
167         return 0;
168 }
169
170 int LL_PROC_PROTO(proc_mem_max)
171 {
172         char buf[22];
173         int len;
174         DECLARE_LL_PROC_PPOS_DECL;
175
176         if (!*lenp || (*ppos && !write)) {
177                 *lenp = 0;
178                 return 0;
179         }
180         if (write)
181                 return -EINVAL;
182
183         len = snprintf(buf, sizeof(buf), LPU64"\n", obd_memory_max());
184         if (len > *lenp)
185                 len = *lenp;
186         buf[len] = '\0';
187         if (copy_to_user(buffer, buf, len))
188                 return -EFAULT;
189         *lenp = len;
190         *ppos += *lenp;
191         return 0;
192 }
193
194 int LL_PROC_PROTO(proc_pages_max)
195 {
196         char buf[22];
197         int len;
198         DECLARE_LL_PROC_PPOS_DECL;
199
200         if (!*lenp || (*ppos && !write)) {
201                 *lenp = 0;
202                 return 0;
203         }
204         if (write)
205                 return -EINVAL;
206
207         len = snprintf(buf, sizeof(buf), LPU64"\n", obd_pages_max());
208         if (len > *lenp)
209                 len = *lenp;
210         buf[len] = '\0';
211         if (copy_to_user(buffer, buf, len))
212                 return -EFAULT;
213         *lenp = len;
214         *ppos += *lenp;
215         return 0;
216 }
217
218 int LL_PROC_PROTO(proc_max_dirty_pages_in_mb)
219 {
220         int rc = 0;
221         DECLARE_LL_PROC_PPOS_DECL;
222
223         if (!table->data || !table->maxlen || !*lenp || (*ppos && !write)) {
224                 *lenp = 0;
225                 return 0;
226         }
227         if (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);
241                 }
242         } else {
243                 char buf[21];
244                 int len;
245
246                 len = lprocfs_read_frac_helper(buf, sizeof(buf),
247                                                *(unsigned int *)table->data,
248                                                1 << (20 - PAGE_CACHE_SHIFT));
249                 if (len > *lenp)
250                         len = *lenp;
251                 buf[len] = '\0';
252                 if (copy_to_user(buffer, buf, len))
253                         return -EFAULT;
254                 *lenp = len;
255         }
256         *ppos += *lenp;
257         return rc;
258 }
259
260 #ifdef RANDOM_FAIL_ALLOC
261 int LL_PROC_PROTO(proc_alloc_fail_rate)
262 {
263         int rc          = 0;
264         DECLARE_LL_PROC_PPOS_DECL;
265
266         if (!table->data || !table->maxlen || !*lenp || (*ppos && !write)) {
267                 *lenp = 0;
268                 return 0;
269         }
270         if (write) {
271                 rc = lprocfs_write_frac_helper(buffer, *lenp,
272                                                (unsigned int*)table->data,
273                                                OBD_ALLOC_FAIL_MULT);
274         } else {
275                 char buf[21];
276                 int  len;
277
278                 len = lprocfs_read_frac_helper(buf, 21,
279                                                *(unsigned int*)table->data,
280                                                OBD_ALLOC_FAIL_MULT);
281                 if (len > *lenp)
282                         len = *lenp;
283                 buf[len] = '\0';
284                 if (copy_to_user(buffer, buf, len))
285                         return -EFAULT;
286                 *lenp = len;
287         }
288         *ppos += *lenp;
289         return rc;
290 }
291 #endif
292
293 int LL_PROC_PROTO(proc_bulk_timeout)
294 {
295         return proc_dointvec(table, write, buffer, lenp, ppos);
296 }
297 int LL_PROC_PROTO(proc_at_min)
298 {
299         return ll_proc_dointvec(table, write, filp, buffer, lenp, ppos);
300 }
301 int LL_PROC_PROTO(proc_at_max)
302 {
303         return ll_proc_dointvec(table, write, filp, buffer, lenp, ppos);
304 }
305 int LL_PROC_PROTO(proc_at_extra)
306 {
307         return ll_proc_dointvec(table, write, filp, buffer, lenp, ppos);
308 }
309 int LL_PROC_PROTO(proc_at_early_margin)
310 {
311         return ll_proc_dointvec(table, write, filp, buffer, lenp, ppos);
312 }
313 int LL_PROC_PROTO(proc_at_history)
314 {
315         return ll_proc_dointvec(table, write, filp, buffer, lenp, ppos);
316 }
317
318 #ifdef CONFIG_SYSCTL
319 static struct ctl_table obd_table[] = {
320         {
321                 INIT_CTL_NAME(OBD_TIMEOUT)
322                 .procname = "timeout",
323                 .data     = &obd_timeout,
324                 .maxlen   = sizeof(int),
325                 .mode     = 0644,
326                 .proc_handler = &proc_set_timeout
327         },
328         {
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),
333                 .mode     = 0644,
334                 .proc_handler = &proc_dointvec
335         },
336         {
337                 INIT_CTL_NAME(OBD_DUMP_ON_TIMEOUT)
338                 .procname = "dump_on_timeout",
339                 .data     = &obd_dump_on_timeout,
340                 .maxlen   = sizeof(int),
341                 .mode     = 0644,
342                 .proc_handler = &proc_dointvec
343         },
344         {
345                 INIT_CTL_NAME(OBD_DUMP_ON_EVICTION)
346                 .procname = "dump_on_eviction",
347                 .data     = &obd_dump_on_eviction,
348                 .maxlen   = sizeof(int),
349                 .mode     = 0644,
350                 .proc_handler = &proc_dointvec
351         },
352         {
353                 INIT_CTL_NAME(OBD_MEMUSED)
354                 .procname = "memused",
355                 .data     = NULL,
356                 .maxlen   = 0,
357                 .mode     = 0444,
358                 .proc_handler = &proc_memory_alloc
359         },
360         {
361                 INIT_CTL_NAME(OBD_PAGESUSED)
362                 .procname = "pagesused",
363                 .data     = NULL,
364                 .maxlen   = 0,
365                 .mode     = 0444,
366                 .proc_handler = &proc_pages_alloc
367         },
368         {
369                 INIT_CTL_NAME(OBD_MAXMEMUSED)
370                 .procname = "memused_max",
371                 .data     = NULL,
372                 .maxlen   = 0,
373                 .mode     = 0444,
374                 .proc_handler = &proc_mem_max
375         },
376         {
377                 INIT_CTL_NAME(OBD_MAXPAGESUSED)
378                 .procname = "pagesused_max",
379                 .data     = NULL,
380                 .maxlen   = 0,
381                 .mode     = 0444,
382                 .proc_handler = &proc_pages_max
383         },
384         {
385                 INIT_CTL_NAME(OBD_LDLM_TIMEOUT)
386                 .procname = "ldlm_timeout",
387                 .data     = &ldlm_timeout,
388                 .maxlen   = sizeof(int),
389                 .mode     = 0644,
390                 .proc_handler = &proc_set_timeout
391         },
392 #ifdef RANDOM_FAIL_ALLOC
393         {
394                 INIT_CTL_NAME(OBD_ALLOC_FAIL_RATE)
395                 .procname = "alloc_fail_rate",
396                 .data     = &obd_alloc_fail_rate,
397                 .maxlen   = sizeof(int),
398                 .mode     = 0644,
399                 .proc_handler = &proc_alloc_fail_rate
400         },
401 #endif
402         {
403                 INIT_CTL_NAME(OBD_MAX_DIRTY_PAGES)
404                 .procname = "max_dirty_mb",
405                 .data     = &obd_max_dirty_pages,
406                 .maxlen   = sizeof(int),
407                 .mode     = 0644,
408                 .proc_handler = &proc_max_dirty_pages_in_mb
409         },
410         {
411                 INIT_CTL_NAME(OBD_BULK_TIMEOUT)
412                 .procname       = "bulk_timeout",
413                 .data           = &bulk_timeout,
414                 .maxlen         = sizeof(int),
415                 .mode           = 0644,
416                 .proc_handler   = &proc_bulk_timeout
417         },
418         {
419                 INIT_CTL_NAME(OBD_AT_MIN)
420                 .procname = "at_min",
421                 .data     = &at_min,
422                 .maxlen   = sizeof(int),
423                 .mode     = 0644,
424                 .proc_handler = &proc_at_min
425         },
426         {
427                 INIT_CTL_NAME(OBD_AT_MAX)
428                 .procname = "at_max",
429                 .data     = &at_max,
430                 .maxlen   = sizeof(int),
431                 .mode     = 0644,
432                 .proc_handler = &proc_at_max
433         },
434         {
435                 INIT_CTL_NAME(OBD_AT_EXTRA)
436                 .procname = "at_extra",
437                 .data     = &at_extra,
438                 .maxlen   = sizeof(int),
439                 .mode     = 0644,
440                 .proc_handler = &proc_at_extra
441         },
442         {
443                 INIT_CTL_NAME(OBD_AT_EARLY_MARGIN)
444                 .procname = "at_early_margin",
445                 .data     = &at_early_margin,
446                 .maxlen   = sizeof(int),
447                 .mode     = 0644,
448                 .proc_handler = &proc_at_early_margin
449         },
450         {
451                 INIT_CTL_NAME(OBD_AT_HISTORY)
452                 .procname = "at_history",
453                 .data     = &at_history,
454                 .maxlen   = sizeof(int),
455                 .mode     = 0644,
456                 .proc_handler = &proc_at_history
457         },
458         {       INIT_CTL_NAME(0)    }
459 };
460
461 static struct ctl_table parent_table[] = {
462         {
463                 INIT_CTL_NAME(OBD_SYSCTL)
464                 .procname = "lustre",
465                 .data     = NULL,
466                 .maxlen   = 0,
467                 .mode     = 0555,
468                 .child    = obd_table
469         },
470         {       INIT_CTL_NAME(0)   }
471 };
472 #endif
473
474 void obd_sysctl_init (void)
475 {
476 #ifdef CONFIG_SYSCTL
477         if ( !obd_table_header )
478                 obd_table_header = register_sysctl_table(parent_table);
479 #endif
480 }
481
482 void obd_sysctl_clean (void)
483 {
484 #ifdef CONFIG_SYSCTL
485         if ( obd_table_header )
486                 unregister_sysctl_table(obd_table_header);
487         obd_table_header = NULL;
488 #endif
489 }