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) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2011, 2017, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
30 * Lustre is a trademark of Sun Microsystems, Inc.
32 #define DEBUG_SUBSYSTEM S_CLASS
34 #include <linux/vfs.h>
35 #include <obd_class.h>
36 #include <lprocfs_status.h>
37 #include <lustre_osc.h>
38 #include <cl_object.h>
39 #include "mdc_internal.h"
41 static ssize_t active_show(struct kobject *kobj, struct attribute *attr,
44 struct obd_device *dev = container_of(kobj, struct obd_device,
48 LPROCFS_CLIMP_CHECK(dev);
49 len = sprintf(buf, "%d\n", !dev->u.cli.cl_import->imp_deactive);
50 LPROCFS_CLIMP_EXIT(dev);
54 static ssize_t active_store(struct kobject *kobj, struct attribute *attr,
55 const char *buffer, size_t count)
57 struct obd_device *dev = container_of(kobj, struct obd_device,
62 rc = kstrtobool(buffer, &val);
67 if (dev->u.cli.cl_import->imp_deactive == val)
68 rc = ptlrpc_set_import_active(dev->u.cli.cl_import, val);
70 CDEBUG(D_CONFIG, "activate %u: ignoring repeat request\n",
75 LUSTRE_RW_ATTR(active);
77 static ssize_t max_rpcs_in_flight_show(struct kobject *kobj,
78 struct attribute *attr,
81 struct obd_device *dev = container_of(kobj, struct obd_device,
86 max = obd_get_max_rpcs_in_flight(&dev->u.cli);
87 len = sprintf(buf, "%u\n", max);
92 static ssize_t max_rpcs_in_flight_store(struct kobject *kobj,
93 struct attribute *attr,
97 struct obd_device *dev = container_of(kobj, struct obd_device,
102 rc = kstrtouint(buffer, 10, &val);
106 rc = obd_set_max_rpcs_in_flight(&dev->u.cli, val);
112 LUSTRE_RW_ATTR(max_rpcs_in_flight);
114 static ssize_t max_mod_rpcs_in_flight_show(struct kobject *kobj,
115 struct attribute *attr,
118 struct obd_device *dev = container_of(kobj, struct obd_device,
122 max = obd_get_max_mod_rpcs_in_flight(&dev->u.cli);
123 return sprintf(buf, "%hu\n", max);
126 static ssize_t max_mod_rpcs_in_flight_store(struct kobject *kobj,
127 struct attribute *attr,
131 struct obd_device *dev = container_of(kobj, struct obd_device,
136 rc = kstrtou16(buffer, 10, &val);
140 rc = obd_set_max_mod_rpcs_in_flight(&dev->u.cli, val);
146 LUSTRE_RW_ATTR(max_mod_rpcs_in_flight);
148 static int mdc_max_dirty_mb_seq_show(struct seq_file *m, void *v)
150 struct obd_device *dev = m->private;
151 struct client_obd *cli = &dev->u.cli;
154 spin_lock(&cli->cl_loi_list_lock);
155 val = PAGES_TO_MiB(cli->cl_dirty_max_pages);
156 spin_unlock(&cli->cl_loi_list_lock);
158 seq_printf(m, "%lu\n", val);
162 static ssize_t mdc_max_dirty_mb_seq_write(struct file *file,
163 const char __user *buffer,
164 size_t count, loff_t *off)
166 struct seq_file *sfl = file->private_data;
167 struct obd_device *dev = sfl->private;
168 struct client_obd *cli = &dev->u.cli;
172 rc = lprocfs_str_with_units_to_s64(buffer, count, &pages_number, 'M');
177 pages_number = round_up(pages_number, 1024 * 1024) >> PAGE_SHIFT;
178 if (pages_number <= 0 ||
179 pages_number >= MiB_TO_PAGES(OSC_MAX_DIRTY_MB_MAX) ||
180 pages_number > cfs_totalram_pages() / 4) /* 1/4 of RAM */
183 spin_lock(&cli->cl_loi_list_lock);
184 cli->cl_dirty_max_pages = pages_number;
185 osc_wake_cache_waiters(cli);
186 spin_unlock(&cli->cl_loi_list_lock);
190 LPROC_SEQ_FOPS(mdc_max_dirty_mb);
192 static ssize_t contention_seconds_show(struct kobject *kobj,
193 struct attribute *attr,
196 struct obd_device *obd = container_of(kobj, struct obd_device,
198 struct osc_device *od = obd2osc_dev(obd);
200 return sprintf(buf, "%lld\n", od->od_contention_time);
203 static ssize_t contention_seconds_store(struct kobject *kobj,
204 struct attribute *attr,
208 struct obd_device *obd = container_of(kobj, struct obd_device,
210 struct osc_device *od = obd2osc_dev(obd);
214 rc = kstrtoll(buffer, 0, &val);
218 od->od_contention_time = val;
222 LUSTRE_RW_ATTR(contention_seconds);
224 LUSTRE_ATTR(mds_conn_uuid, 0444, conn_uuid_show, NULL);
225 LUSTRE_RO_ATTR(conn_uuid);
227 LUSTRE_RW_ATTR(ping);
229 static int mdc_cached_mb_seq_show(struct seq_file *m, void *v)
231 struct obd_device *dev = m->private;
232 struct client_obd *cli = &dev->u.cli;
233 int shift = 20 - PAGE_SHIFT;
235 seq_printf(m, "used_mb: %ld\n"
238 (atomic_long_read(&cli->cl_lru_in_list) +
239 atomic_long_read(&cli->cl_lru_busy)) >> shift,
240 atomic_long_read(&cli->cl_lru_busy),
241 cli->cl_lru_reclaim);
246 /* shrink the number of caching pages to a specific number */
248 mdc_cached_mb_seq_write(struct file *file, const char __user *buffer,
249 size_t count, loff_t *off)
251 struct seq_file *sfl = file->private_data;
252 struct obd_device *dev = sfl->private;
253 struct client_obd *cli = &dev->u.cli;
258 if (count >= sizeof(kernbuf))
261 if (copy_from_user(kernbuf, buffer, count))
265 buffer += lprocfs_find_named_value(kernbuf, "used_mb:", &count) -
267 rc = lprocfs_str_with_units_to_s64(buffer, count, &pages_number, 'M');
271 pages_number >>= PAGE_SHIFT;
273 if (pages_number < 0)
276 rc = atomic_long_read(&cli->cl_lru_in_list) - pages_number;
281 env = cl_env_get(&refcheck);
283 (void)osc_lru_shrink(env, cli, rc, true);
284 cl_env_put(env, &refcheck);
290 LPROC_SEQ_FOPS(mdc_cached_mb);
292 static int mdc_unstable_stats_seq_show(struct seq_file *m, void *v)
294 struct obd_device *dev = m->private;
295 struct client_obd *cli = &dev->u.cli;
299 pages = atomic_long_read(&cli->cl_unstable_count);
300 mb = (pages * PAGE_SIZE) >> 20;
302 seq_printf(m, "unstable_pages: %20ld\n"
303 "unstable_mb: %10d\n", pages, mb);
306 LPROC_SEQ_FOPS_RO(mdc_unstable_stats);
308 static ssize_t mdc_rpc_stats_seq_write(struct file *file,
309 const char __user *buf,
310 size_t len, loff_t *off)
312 struct seq_file *seq = file->private_data;
313 struct obd_device *dev = seq->private;
314 struct client_obd *cli = &dev->u.cli;
316 lprocfs_oh_clear(&cli->cl_mod_rpcs_hist);
318 lprocfs_oh_clear(&cli->cl_read_rpc_hist);
319 lprocfs_oh_clear(&cli->cl_write_rpc_hist);
320 lprocfs_oh_clear(&cli->cl_read_page_hist);
321 lprocfs_oh_clear(&cli->cl_write_page_hist);
322 lprocfs_oh_clear(&cli->cl_read_offset_hist);
323 lprocfs_oh_clear(&cli->cl_write_offset_hist);
328 static int mdc_rpc_stats_seq_show(struct seq_file *seq, void *v)
330 struct obd_device *dev = seq->private;
331 struct client_obd *cli = &dev->u.cli;
332 unsigned long read_tot = 0, write_tot = 0, read_cum, write_cum;
335 obd_mod_rpc_stats_seq_show(&dev->u.cli, seq);
337 spin_lock(&cli->cl_loi_list_lock);
339 seq_printf(seq, "\nread RPCs in flight: %d\n",
340 cli->cl_r_in_flight);
341 seq_printf(seq, "write RPCs in flight: %d\n",
342 cli->cl_w_in_flight);
343 seq_printf(seq, "pending write pages: %d\n",
344 atomic_read(&cli->cl_pending_w_pages));
345 seq_printf(seq, "pending read pages: %d\n",
346 atomic_read(&cli->cl_pending_r_pages));
348 seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
349 seq_printf(seq, "pages per rpc rpcs %% cum %% |");
350 seq_printf(seq, " rpcs %% cum %%\n");
352 read_tot = lprocfs_oh_sum(&cli->cl_read_page_hist);
353 write_tot = lprocfs_oh_sum(&cli->cl_write_page_hist);
357 for (i = 0; i < OBD_HIST_MAX; i++) {
358 unsigned long r = cli->cl_read_page_hist.oh_buckets[i];
359 unsigned long w = cli->cl_write_page_hist.oh_buckets[i];
363 seq_printf(seq, "%d:\t\t%10lu %3u %3u | %10lu %3u %3u\n",
364 1 << i, r, pct(r, read_tot),
365 pct(read_cum, read_tot), w,
367 pct(write_cum, write_tot));
368 if (read_cum == read_tot && write_cum == write_tot)
372 seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
373 seq_printf(seq, "rpcs in flight rpcs %% cum %% |");
374 seq_printf(seq, " rpcs %% cum %%\n");
376 read_tot = lprocfs_oh_sum(&cli->cl_read_rpc_hist);
377 write_tot = lprocfs_oh_sum(&cli->cl_write_rpc_hist);
381 for (i = 0; i < OBD_HIST_MAX; i++) {
382 unsigned long r = cli->cl_read_rpc_hist.oh_buckets[i];
383 unsigned long w = cli->cl_write_rpc_hist.oh_buckets[i];
387 seq_printf(seq, "%d:\t\t%10lu %3u %3u | %10lu %3u %3u\n",
388 i, r, pct(r, read_tot), pct(read_cum, read_tot), w,
389 pct(w, write_tot), pct(write_cum, write_tot));
390 if (read_cum == read_tot && write_cum == write_tot)
394 seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
395 seq_printf(seq, "offset rpcs %% cum %% |");
396 seq_printf(seq, " rpcs %% cum %%\n");
398 read_tot = lprocfs_oh_sum(&cli->cl_read_offset_hist);
399 write_tot = lprocfs_oh_sum(&cli->cl_write_offset_hist);
403 for (i = 0; i < OBD_HIST_MAX; i++) {
404 unsigned long r = cli->cl_read_offset_hist.oh_buckets[i];
405 unsigned long w = cli->cl_write_offset_hist.oh_buckets[i];
409 seq_printf(seq, "%d:\t\t%10lu %3u %3u | %10lu %3u %3u\n",
410 (i == 0) ? 0 : 1 << (i - 1),
411 r, pct(r, read_tot), pct(read_cum, read_tot),
412 w, pct(w, write_tot), pct(write_cum, write_tot));
413 if (read_cum == read_tot && write_cum == write_tot)
416 spin_unlock(&cli->cl_loi_list_lock);
420 LPROC_SEQ_FOPS(mdc_rpc_stats);
422 static int mdc_stats_seq_show(struct seq_file *seq, void *v)
424 struct timespec64 now;
425 struct obd_device *dev = seq->private;
426 struct osc_stats *stats = &obd2osc_dev(dev)->od_stats;
428 ktime_get_real_ts64(&now);
430 seq_printf(seq, "snapshot_time: %lld.%09lu (secs.nsecs)\n",
431 (s64)now.tv_sec, now.tv_nsec);
432 seq_printf(seq, "lockless_write_bytes\t\t%llu\n",
433 stats->os_lockless_writes);
434 seq_printf(seq, "lockless_read_bytes\t\t%llu\n",
435 stats->os_lockless_reads);
436 seq_printf(seq, "lockless_truncate\t\t%llu\n",
437 stats->os_lockless_truncates);
441 static ssize_t mdc_stats_seq_write(struct file *file,
442 const char __user *buf,
443 size_t len, loff_t *off)
445 struct seq_file *seq = file->private_data;
446 struct obd_device *dev = seq->private;
447 struct osc_stats *stats = &obd2osc_dev(dev)->od_stats;
449 memset(stats, 0, sizeof(*stats));
452 LPROC_SEQ_FOPS(mdc_stats);
454 static int mdc_dom_min_repsize_seq_show(struct seq_file *m, void *v)
456 struct obd_device *dev = m->private;
458 seq_printf(m, "%u\n", dev->u.cli.cl_dom_min_inline_repsize);
463 static ssize_t mdc_dom_min_repsize_seq_write(struct file *file,
464 const char __user *buffer,
465 size_t count, loff_t *off)
467 struct obd_device *dev;
471 dev = ((struct seq_file *)file->private_data)->private;
472 rc = kstrtouint_from_user(buffer, count, 0, &val);
476 if (val > MDC_DOM_MAX_INLINE_REPSIZE)
479 dev->u.cli.cl_dom_min_inline_repsize = val;
482 LPROC_SEQ_FOPS(mdc_dom_min_repsize);
484 LPROC_SEQ_FOPS_RO_TYPE(mdc, connect_flags);
485 LPROC_SEQ_FOPS_RO_TYPE(mdc, server_uuid);
486 LPROC_SEQ_FOPS_RO_TYPE(mdc, timeouts);
487 LPROC_SEQ_FOPS_RO_TYPE(mdc, state);
488 LPROC_SEQ_FOPS_RW_TYPE(mdc, obd_max_pages_per_rpc);
489 LPROC_SEQ_FOPS_RW_TYPE(mdc, import);
490 LPROC_SEQ_FOPS_RW_TYPE(mdc, pinger_recov);
492 struct lprocfs_vars lprocfs_mdc_obd_vars[] = {
493 { .name = "connect_flags",
494 .fops = &mdc_connect_flags_fops },
495 { .name = "mds_server_uuid",
496 .fops = &mdc_server_uuid_fops },
497 { .name = "max_pages_per_rpc",
498 .fops = &mdc_obd_max_pages_per_rpc_fops },
499 { .name = "max_dirty_mb",
500 .fops = &mdc_max_dirty_mb_fops },
501 { .name = "mdc_cached_mb",
502 .fops = &mdc_cached_mb_fops },
503 { .name = "timeouts",
504 .fops = &mdc_timeouts_fops },
506 .fops = &mdc_import_fops },
508 .fops = &mdc_state_fops },
509 { .name = "pinger_recov",
510 .fops = &mdc_pinger_recov_fops },
511 { .name = "rpc_stats",
512 .fops = &mdc_rpc_stats_fops },
513 { .name = "unstable_stats",
514 .fops = &mdc_unstable_stats_fops },
515 { .name = "mdc_stats",
516 .fops = &mdc_stats_fops },
517 { .name = "mdc_dom_min_repsize",
518 .fops = &mdc_dom_min_repsize_fops },
522 static struct attribute *mdc_attrs[] = {
523 &lustre_attr_active.attr,
524 &lustre_attr_max_rpcs_in_flight.attr,
525 &lustre_attr_max_mod_rpcs_in_flight.attr,
526 &lustre_attr_contention_seconds.attr,
527 &lustre_attr_mds_conn_uuid.attr,
528 &lustre_attr_conn_uuid.attr,
529 &lustre_attr_ping.attr,
533 int mdc_tunables_init(struct obd_device *obd)
537 obd->obd_ktype.default_attrs = mdc_attrs;
538 obd->obd_vars = lprocfs_mdc_obd_vars;
540 rc = lprocfs_obd_setup(obd, false);
543 #ifdef CONFIG_PROC_FS
544 rc = lprocfs_alloc_md_stats(obd, 0);
546 lprocfs_obd_cleanup(obd);
550 rc = sptlrpc_lprocfs_cliobd_attach(obd);
552 #ifdef CONFIG_PROC_FS
553 lprocfs_free_md_stats(obd);
555 lprocfs_obd_cleanup(obd);
558 ptlrpc_lprocfs_register_obd(obd);