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, 2015, 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/statfs.h>
35 #include <obd_cksum.h>
36 #include <obd_class.h>
37 #include <lprocfs_status.h>
38 #include <linux/seq_file.h>
39 #include "osc_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,
47 return sprintf(buf, "%d\n", !dev->u.cli.cl_import->imp_deactive);
50 static ssize_t active_store(struct kobject *kobj, struct attribute *attr,
54 struct obd_device *dev = container_of(kobj, struct obd_device,
59 rc = kstrtoul(buffer, 10, &val);
66 if (dev->u.cli.cl_import->imp_deactive == val)
67 rc = ptlrpc_set_import_active(dev->u.cli.cl_import, val);
69 CDEBUG(D_CONFIG, "activate %ld: ignoring repeat request\n",
74 LUSTRE_RW_ATTR(active);
76 static ssize_t max_rpcs_in_flight_show(struct kobject *kobj,
77 struct attribute *attr,
80 struct obd_device *dev = container_of(kobj, struct obd_device,
82 struct client_obd *cli = &dev->u.cli;
84 return sprintf(buf, "%u\n", cli->cl_max_rpcs_in_flight);
87 static ssize_t max_rpcs_in_flight_store(struct kobject *kobj,
88 struct attribute *attr,
92 struct obd_device *dev = container_of(kobj, struct obd_device,
94 struct client_obd *cli = &dev->u.cli;
97 int adding, added, req_count;
99 rc = kstrtoul(buffer, 10, &val);
103 if (val < 1 || val > OSC_MAX_RIF_MAX)
106 adding = val - cli->cl_max_rpcs_in_flight;
107 req_count = atomic_read(&osc_pool_req_count);
108 if (adding > 0 && req_count < osc_reqpool_maxreqcount) {
110 * There might be some race which will cause over-limit
111 * allocation, but it is fine.
113 if (req_count + adding > osc_reqpool_maxreqcount)
114 adding = osc_reqpool_maxreqcount - req_count;
116 added = osc_rq_pool->prp_populate(osc_rq_pool, adding);
117 atomic_add(added, &osc_pool_req_count);
120 spin_lock(&cli->cl_loi_list_lock);
121 cli->cl_max_rpcs_in_flight = val;
122 client_adjust_max_dirty(cli);
123 spin_unlock(&cli->cl_loi_list_lock);
127 LUSTRE_RW_ATTR(max_rpcs_in_flight);
129 static ssize_t max_dirty_mb_show(struct kobject *kobj,
130 struct attribute *attr,
133 struct obd_device *dev = container_of(kobj, struct obd_device,
135 struct client_obd *cli = &dev->u.cli;
139 spin_lock(&cli->cl_loi_list_lock);
140 val = cli->cl_dirty_max_pages;
141 spin_unlock(&cli->cl_loi_list_lock);
143 mult = 1 << (20 - PAGE_SHIFT);
144 return lprocfs_read_frac_helper(buf, PAGE_SIZE, val, mult);
147 static ssize_t max_dirty_mb_store(struct kobject *kobj,
148 struct attribute *attr,
152 struct obd_device *dev = container_of(kobj, struct obd_device,
154 struct client_obd *cli = &dev->u.cli;
156 unsigned long pages_number;
158 rc = kstrtoul(buffer, 10, &pages_number);
162 pages_number *= 1 << (20 - PAGE_SHIFT); /* MB -> pages */
164 if (pages_number <= 0 ||
165 pages_number >= OSC_MAX_DIRTY_MB_MAX << (20 - PAGE_SHIFT) ||
166 pages_number > totalram_pages / 4) /* 1/4 of RAM */
169 spin_lock(&cli->cl_loi_list_lock);
170 cli->cl_dirty_max_pages = pages_number;
171 osc_wake_cache_waiters(cli);
172 spin_unlock(&cli->cl_loi_list_lock);
176 LUSTRE_RW_ATTR(max_dirty_mb);
178 static int osc_cached_mb_seq_show(struct seq_file *m, void *v)
180 struct obd_device *dev = m->private;
181 struct client_obd *cli = &dev->u.cli;
182 int shift = 20 - PAGE_SHIFT;
188 (atomic_long_read(&cli->cl_lru_in_list) +
189 atomic_long_read(&cli->cl_lru_busy)) >> shift,
190 atomic_long_read(&cli->cl_lru_busy),
191 cli->cl_lru_reclaim);
196 /* shrink the number of caching pages to a specific number */
197 static ssize_t osc_cached_mb_seq_write(struct file *file,
198 const char __user *buffer,
199 size_t count, loff_t *off)
201 struct obd_device *dev = ((struct seq_file *)file->private_data)->private;
202 struct client_obd *cli = &dev->u.cli;
203 long pages_number, rc;
208 if (count >= sizeof(kernbuf))
211 if (copy_from_user(kernbuf, buffer, count))
215 mult = 1 << (20 - PAGE_SHIFT);
216 buffer += lprocfs_find_named_value(kernbuf, "used_mb:", &count) -
218 rc = lprocfs_write_frac_u64_helper(buffer, count, &val, mult);
224 pages_number = (long)val;
226 if (pages_number < 0)
229 rc = atomic_long_read(&cli->cl_lru_in_list) - pages_number;
234 env = cl_env_get(&refcheck);
236 (void)osc_lru_shrink(env, cli, rc, true);
237 cl_env_put(env, &refcheck);
244 LPROC_SEQ_FOPS(osc_cached_mb);
246 static ssize_t cur_dirty_bytes_show(struct kobject *kobj,
247 struct attribute *attr,
250 struct obd_device *dev = container_of(kobj, struct obd_device,
252 struct client_obd *cli = &dev->u.cli;
255 spin_lock(&cli->cl_loi_list_lock);
256 len = sprintf(buf, "%lu\n", cli->cl_dirty_pages << PAGE_SHIFT);
257 spin_unlock(&cli->cl_loi_list_lock);
261 LUSTRE_RO_ATTR(cur_dirty_bytes);
263 static ssize_t cur_grant_bytes_show(struct kobject *kobj,
264 struct attribute *attr,
267 struct obd_device *dev = container_of(kobj, struct obd_device,
269 struct client_obd *cli = &dev->u.cli;
272 spin_lock(&cli->cl_loi_list_lock);
273 len = sprintf(buf, "%lu\n", cli->cl_avail_grant);
274 spin_unlock(&cli->cl_loi_list_lock);
279 static ssize_t cur_grant_bytes_store(struct kobject *kobj,
280 struct attribute *attr,
284 struct obd_device *obd = container_of(kobj, struct obd_device,
286 struct client_obd *cli = &obd->u.cli;
288 unsigned long long val;
290 rc = kstrtoull(buffer, 10, &val);
294 /* this is only for shrinking grant */
295 spin_lock(&cli->cl_loi_list_lock);
296 if (val >= cli->cl_avail_grant) {
297 spin_unlock(&cli->cl_loi_list_lock);
300 spin_unlock(&cli->cl_loi_list_lock);
302 if (cli->cl_import->imp_state == LUSTRE_IMP_FULL)
303 rc = osc_shrink_grant_to_target(cli, val);
308 LUSTRE_RW_ATTR(cur_grant_bytes);
310 static ssize_t cur_lost_grant_bytes_show(struct kobject *kobj,
311 struct attribute *attr,
314 struct obd_device *dev = container_of(kobj, struct obd_device,
316 struct client_obd *cli = &dev->u.cli;
319 spin_lock(&cli->cl_loi_list_lock);
320 len = sprintf(buf, "%lu\n", cli->cl_lost_grant);
321 spin_unlock(&cli->cl_loi_list_lock);
325 LUSTRE_RO_ATTR(cur_lost_grant_bytes);
327 static ssize_t grant_shrink_interval_show(struct kobject *kobj,
328 struct attribute *attr,
331 struct obd_device *obd = container_of(kobj, struct obd_device,
334 return sprintf(buf, "%d\n", obd->u.cli.cl_grant_shrink_interval);
337 static ssize_t grant_shrink_interval_store(struct kobject *kobj,
338 struct attribute *attr,
342 struct obd_device *obd = container_of(kobj, struct obd_device,
347 rc = kstrtoul(buffer, 10, &val);
354 obd->u.cli.cl_grant_shrink_interval = val;
358 LUSTRE_RW_ATTR(grant_shrink_interval);
360 static ssize_t checksums_show(struct kobject *kobj,
361 struct attribute *attr,
364 struct obd_device *obd = container_of(kobj, struct obd_device,
367 return sprintf(buf, "%d\n", obd->u.cli.cl_checksum ? 1 : 0);
370 static ssize_t checksums_store(struct kobject *kobj,
371 struct attribute *attr,
375 struct obd_device *obd = container_of(kobj, struct obd_device,
380 rc = kstrtoul(buffer, 10, &val);
384 obd->u.cli.cl_checksum = (val ? 1 : 0);
388 LUSTRE_RW_ATTR(checksums);
390 static int osc_checksum_type_seq_show(struct seq_file *m, void *v)
392 struct obd_device *obd = m->private;
400 for (i = 0; i < ARRAY_SIZE(cksum_name); i++) {
401 if (((1 << i) & obd->u.cli.cl_supp_cksum_types) == 0)
403 if (obd->u.cli.cl_cksum_type == (1 << i))
404 seq_printf(m, "[%s] ", cksum_name[i]);
406 seq_printf(m, "%s ", cksum_name[i]);
412 static ssize_t osc_checksum_type_seq_write(struct file *file,
413 const char __user *buffer,
414 size_t count, loff_t *off)
416 struct obd_device *obd = ((struct seq_file *)file->private_data)->private;
425 if (count > sizeof(kernbuf) - 1)
427 if (copy_from_user(kernbuf, buffer, count))
429 if (count > 0 && kernbuf[count - 1] == '\n')
430 kernbuf[count - 1] = '\0';
432 kernbuf[count] = '\0';
434 for (i = 0; i < ARRAY_SIZE(cksum_name); i++) {
435 if (((1 << i) & obd->u.cli.cl_supp_cksum_types) == 0)
437 if (!strcmp(kernbuf, cksum_name[i])) {
438 obd->u.cli.cl_cksum_type = 1 << i;
445 LPROC_SEQ_FOPS(osc_checksum_type);
447 static ssize_t resend_count_show(struct kobject *kobj,
448 struct attribute *attr,
451 struct obd_device *obd = container_of(kobj, struct obd_device,
454 return sprintf(buf, "%u\n", atomic_read(&obd->u.cli.cl_resends));
457 static ssize_t resend_count_store(struct kobject *kobj,
458 struct attribute *attr,
462 struct obd_device *obd = container_of(kobj, struct obd_device,
467 rc = kstrtoul(buffer, 10, &val);
471 atomic_set(&obd->u.cli.cl_resends, val);
475 LUSTRE_RW_ATTR(resend_count);
477 static ssize_t contention_seconds_show(struct kobject *kobj,
478 struct attribute *attr,
481 struct obd_device *obd = container_of(kobj, struct obd_device,
483 struct osc_device *od = obd2osc_dev(obd);
485 return sprintf(buf, "%u\n", od->od_contention_time);
488 static ssize_t contention_seconds_store(struct kobject *kobj,
489 struct attribute *attr,
493 struct obd_device *obd = container_of(kobj, struct obd_device,
495 struct osc_device *od = obd2osc_dev(obd);
499 rc = kstrtoint(buffer, 10, &val);
506 od->od_contention_time = val;
510 LUSTRE_RW_ATTR(contention_seconds);
512 static ssize_t lockless_truncate_show(struct kobject *kobj,
513 struct attribute *attr,
516 struct obd_device *obd = container_of(kobj, struct obd_device,
518 struct osc_device *od = obd2osc_dev(obd);
520 return sprintf(buf, "%u\n", od->od_lockless_truncate);
523 static ssize_t lockless_truncate_store(struct kobject *kobj,
524 struct attribute *attr,
528 struct obd_device *obd = container_of(kobj, struct obd_device,
530 struct osc_device *od = obd2osc_dev(obd);
534 rc = kstrtouint(buffer, 10, &val);
538 od->od_lockless_truncate = val;
542 LUSTRE_RW_ATTR(lockless_truncate);
544 static ssize_t destroys_in_flight_show(struct kobject *kobj,
545 struct attribute *attr,
548 struct obd_device *obd = container_of(kobj, struct obd_device,
551 return sprintf(buf, "%u\n",
552 atomic_read(&obd->u.cli.cl_destroy_in_flight));
554 LUSTRE_RO_ATTR(destroys_in_flight);
556 static ssize_t max_pages_per_rpc_show(struct kobject *kobj,
557 struct attribute *attr,
560 struct obd_device *dev = container_of(kobj, struct obd_device,
562 struct client_obd *cli = &dev->u.cli;
564 return sprintf(buf, "%d\n", cli->cl_max_pages_per_rpc);
567 static ssize_t max_pages_per_rpc_store(struct kobject *kobj,
568 struct attribute *attr,
572 struct obd_device *dev = container_of(kobj, struct obd_device,
574 struct client_obd *cli = &dev->u.cli;
575 struct obd_connect_data *ocd = &cli->cl_import->imp_connect_data;
577 unsigned long long val;
579 rc = kstrtoull(buffer, 10, &val);
583 /* if the max_pages is specified in bytes, convert to pages */
584 if (val >= ONE_MB_BRW_SIZE)
587 chunk_mask = ~((1 << (cli->cl_chunkbits - PAGE_SHIFT)) - 1);
588 /* max_pages_per_rpc must be chunk aligned */
589 val = (val + ~chunk_mask) & chunk_mask;
590 if (!val || (ocd->ocd_brw_size &&
591 val > ocd->ocd_brw_size >> PAGE_SHIFT)) {
594 spin_lock(&cli->cl_loi_list_lock);
595 cli->cl_max_pages_per_rpc = val;
596 client_adjust_max_dirty(cli);
597 spin_unlock(&cli->cl_loi_list_lock);
601 LUSTRE_RW_ATTR(max_pages_per_rpc);
603 static ssize_t unstable_stats_show(struct kobject *kobj,
604 struct attribute *attr,
607 struct obd_device *dev = container_of(kobj, struct obd_device,
609 struct client_obd *cli = &dev->u.cli;
613 pages = atomic_long_read(&cli->cl_unstable_count);
614 mb = (pages * PAGE_SIZE) >> 20;
616 return sprintf(buf, "unstable_pages: %20ld\n"
617 "unstable_mb: %10d\n", pages, mb);
619 LUSTRE_RO_ATTR(unstable_stats);
621 LPROC_SEQ_FOPS_RO_TYPE(osc, connect_flags);
622 LPROC_SEQ_FOPS_RO_TYPE(osc, server_uuid);
623 LPROC_SEQ_FOPS_RO_TYPE(osc, conn_uuid);
624 LPROC_SEQ_FOPS_RO_TYPE(osc, timeouts);
625 LPROC_SEQ_FOPS_RO_TYPE(osc, state);
627 LPROC_SEQ_FOPS_WR_ONLY(osc, ping);
629 LPROC_SEQ_FOPS_RW_TYPE(osc, import);
630 LPROC_SEQ_FOPS_RW_TYPE(osc, pinger_recov);
632 static struct lprocfs_vars lprocfs_osc_obd_vars[] = {
633 { "ping", &osc_ping_fops, NULL, 0222 },
634 { "connect_flags", &osc_connect_flags_fops, NULL, 0 },
635 /*{ "filegroups", lprocfs_rd_filegroups, NULL, 0 },*/
636 { "ost_server_uuid", &osc_server_uuid_fops, NULL, 0 },
637 { "ost_conn_uuid", &osc_conn_uuid_fops, NULL, 0 },
638 { "osc_cached_mb", &osc_cached_mb_fops, NULL },
639 { "checksum_type", &osc_checksum_type_fops, NULL },
640 { "timeouts", &osc_timeouts_fops, NULL, 0 },
641 { "import", &osc_import_fops, NULL },
642 { "state", &osc_state_fops, NULL, 0 },
643 { "pinger_recov", &osc_pinger_recov_fops, NULL },
647 #define pct(a, b) (b ? a * 100 / b : 0)
649 static int osc_rpc_stats_seq_show(struct seq_file *seq, void *v)
651 struct timespec64 now;
652 struct obd_device *dev = seq->private;
653 struct client_obd *cli = &dev->u.cli;
654 unsigned long read_tot = 0, write_tot = 0, read_cum, write_cum;
657 ktime_get_real_ts64(&now);
659 spin_lock(&cli->cl_loi_list_lock);
661 seq_printf(seq, "snapshot_time: %llu.%9lu (secs.usecs)\n",
662 (s64)now.tv_sec, (unsigned long)now.tv_nsec);
663 seq_printf(seq, "read RPCs in flight: %d\n",
664 cli->cl_r_in_flight);
665 seq_printf(seq, "write RPCs in flight: %d\n",
666 cli->cl_w_in_flight);
667 seq_printf(seq, "pending write pages: %d\n",
668 atomic_read(&cli->cl_pending_w_pages));
669 seq_printf(seq, "pending read pages: %d\n",
670 atomic_read(&cli->cl_pending_r_pages));
672 seq_puts(seq, "\n\t\t\tread\t\t\twrite\n");
673 seq_puts(seq, "pages per rpc rpcs % cum % |");
674 seq_puts(seq, " rpcs % cum %\n");
676 read_tot = lprocfs_oh_sum(&cli->cl_read_page_hist);
677 write_tot = lprocfs_oh_sum(&cli->cl_write_page_hist);
681 for (i = 0; i < OBD_HIST_MAX; i++) {
682 unsigned long r = cli->cl_read_page_hist.oh_buckets[i];
683 unsigned long w = cli->cl_write_page_hist.oh_buckets[i];
687 seq_printf(seq, "%d:\t\t%10lu %3lu %3lu | %10lu %3lu %3lu\n",
688 1 << i, r, pct(r, read_tot),
689 pct(read_cum, read_tot), w,
691 pct(write_cum, write_tot));
692 if (read_cum == read_tot && write_cum == write_tot)
696 seq_puts(seq, "\n\t\t\tread\t\t\twrite\n");
697 seq_puts(seq, "rpcs in flight rpcs % cum % |");
698 seq_puts(seq, " rpcs % cum %\n");
700 read_tot = lprocfs_oh_sum(&cli->cl_read_rpc_hist);
701 write_tot = lprocfs_oh_sum(&cli->cl_write_rpc_hist);
705 for (i = 0; i < OBD_HIST_MAX; i++) {
706 unsigned long r = cli->cl_read_rpc_hist.oh_buckets[i];
707 unsigned long w = cli->cl_write_rpc_hist.oh_buckets[i];
711 seq_printf(seq, "%d:\t\t%10lu %3lu %3lu | %10lu %3lu %3lu\n",
712 i, r, pct(r, read_tot),
713 pct(read_cum, read_tot), w,
715 pct(write_cum, write_tot));
716 if (read_cum == read_tot && write_cum == write_tot)
720 seq_puts(seq, "\n\t\t\tread\t\t\twrite\n");
721 seq_puts(seq, "offset rpcs % cum % |");
722 seq_puts(seq, " rpcs % cum %\n");
724 read_tot = lprocfs_oh_sum(&cli->cl_read_offset_hist);
725 write_tot = lprocfs_oh_sum(&cli->cl_write_offset_hist);
729 for (i = 0; i < OBD_HIST_MAX; i++) {
730 unsigned long r = cli->cl_read_offset_hist.oh_buckets[i];
731 unsigned long w = cli->cl_write_offset_hist.oh_buckets[i];
735 seq_printf(seq, "%d:\t\t%10lu %3lu %3lu | %10lu %3lu %3lu\n",
736 (i == 0) ? 0 : 1 << (i - 1),
737 r, pct(r, read_tot), pct(read_cum, read_tot),
738 w, pct(w, write_tot), pct(write_cum, write_tot));
739 if (read_cum == read_tot && write_cum == write_tot)
743 spin_unlock(&cli->cl_loi_list_lock);
750 static ssize_t osc_rpc_stats_seq_write(struct file *file,
751 const char __user *buf,
752 size_t len, loff_t *off)
754 struct seq_file *seq = file->private_data;
755 struct obd_device *dev = seq->private;
756 struct client_obd *cli = &dev->u.cli;
758 lprocfs_oh_clear(&cli->cl_read_rpc_hist);
759 lprocfs_oh_clear(&cli->cl_write_rpc_hist);
760 lprocfs_oh_clear(&cli->cl_read_page_hist);
761 lprocfs_oh_clear(&cli->cl_write_page_hist);
762 lprocfs_oh_clear(&cli->cl_read_offset_hist);
763 lprocfs_oh_clear(&cli->cl_write_offset_hist);
768 LPROC_SEQ_FOPS(osc_rpc_stats);
770 static int osc_stats_seq_show(struct seq_file *seq, void *v)
772 struct timespec64 now;
773 struct obd_device *dev = seq->private;
774 struct osc_stats *stats = &obd2osc_dev(dev)->od_stats;
776 ktime_get_real_ts64(&now);
778 seq_printf(seq, "snapshot_time: %llu.%9lu (secs.usecs)\n",
779 (s64)now.tv_sec, (unsigned long)now.tv_nsec);
780 seq_printf(seq, "lockless_write_bytes\t\t%llu\n",
781 stats->os_lockless_writes);
782 seq_printf(seq, "lockless_read_bytes\t\t%llu\n",
783 stats->os_lockless_reads);
784 seq_printf(seq, "lockless_truncate\t\t%llu\n",
785 stats->os_lockless_truncates);
789 static ssize_t osc_stats_seq_write(struct file *file,
790 const char __user *buf,
791 size_t len, loff_t *off)
793 struct seq_file *seq = file->private_data;
794 struct obd_device *dev = seq->private;
795 struct osc_stats *stats = &obd2osc_dev(dev)->od_stats;
797 memset(stats, 0, sizeof(*stats));
801 LPROC_SEQ_FOPS(osc_stats);
803 int lproc_osc_attach_seqstat(struct obd_device *dev)
807 rc = ldebugfs_seq_create(dev->obd_debugfs_entry, "osc_stats", 0644,
808 &osc_stats_fops, dev);
810 rc = ldebugfs_obd_seq_create(dev, "rpc_stats", 0644,
811 &osc_rpc_stats_fops, dev);
816 static struct attribute *osc_attrs[] = {
817 &lustre_attr_active.attr,
818 &lustre_attr_checksums.attr,
819 &lustre_attr_contention_seconds.attr,
820 &lustre_attr_cur_dirty_bytes.attr,
821 &lustre_attr_cur_grant_bytes.attr,
822 &lustre_attr_cur_lost_grant_bytes.attr,
823 &lustre_attr_destroys_in_flight.attr,
824 &lustre_attr_grant_shrink_interval.attr,
825 &lustre_attr_lockless_truncate.attr,
826 &lustre_attr_max_dirty_mb.attr,
827 &lustre_attr_max_pages_per_rpc.attr,
828 &lustre_attr_max_rpcs_in_flight.attr,
829 &lustre_attr_resend_count.attr,
830 &lustre_attr_unstable_stats.attr,
834 static const struct attribute_group osc_attr_group = {
838 void lprocfs_osc_init_vars(struct lprocfs_static_vars *lvars)
840 lvars->sysfs_vars = &osc_attr_group;
841 lvars->obd_vars = lprocfs_osc_obd_vars;