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) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2011, 2013, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lustre/osd/osd_lproc.c
38 * Author: Mikhail Pershin <tappro@sun.com>
41 #define DEBUG_SUBSYSTEM S_CLASS
43 #include <lprocfs_status.h>
44 #include <lustre/lustre_idl.h>
46 #include "osd_internal.h"
50 void osd_brw_stats_update(struct osd_device *osd, struct osd_iobuf *iobuf)
52 struct brw_stats *s = &osd->od_brw_stats;
53 unsigned long *last_block = NULL;
54 struct page **pages = iobuf->dr_pages;
55 struct page *last_page = NULL;
56 unsigned long discont_pages = 0;
57 unsigned long discont_blocks = 0;
58 unsigned long *blocks = iobuf->dr_blocks;
59 int i, nr_pages = iobuf->dr_npages;
61 int rw = iobuf->dr_rw;
63 if (unlikely(nr_pages == 0))
66 blocks_per_page = PAGE_CACHE_SIZE >> osd_sb(osd)->s_blocksize_bits;
68 lprocfs_oh_tally_log2(&s->hist[BRW_R_PAGES+rw], nr_pages);
70 while (nr_pages-- > 0) {
71 if (last_page && (*pages)->index != (last_page->index + 1))
75 for (i = 0; i < blocks_per_page; i++) {
76 if (last_block && *blocks != (*last_block + 1))
78 last_block = blocks++;
82 lprocfs_oh_tally(&s->hist[BRW_R_DISCONT_PAGES+rw], discont_pages);
83 lprocfs_oh_tally(&s->hist[BRW_R_DISCONT_BLOCKS+rw], discont_blocks);
86 #define pct(a, b) (b ? a * 100 / b : 0)
88 static void display_brw_stats(struct seq_file *seq, char *name, char *units,
89 struct obd_histogram *read, struct obd_histogram *write, int scale)
91 unsigned long read_tot, write_tot, r, w, read_cum = 0, write_cum = 0;
94 seq_printf(seq, "\n%26s read | write\n", " ");
95 seq_printf(seq, "%-22s %-5s %% cum %% | %-11s %% cum %%\n",
98 read_tot = lprocfs_oh_sum(read);
99 write_tot = lprocfs_oh_sum(write);
100 for (i = 0; i < OBD_HIST_MAX; i++) {
101 r = read->oh_buckets[i];
102 w = write->oh_buckets[i];
105 if (read_cum == 0 && write_cum == 0)
109 seq_printf(seq, "%u", i);
111 seq_printf(seq, "%u", scale << i);
113 seq_printf(seq, "%uK", scale << (i-10));
115 seq_printf(seq, "%uM", scale << (i-20));
117 seq_printf(seq, ":\t\t%10lu %3lu %3lu | %4lu %3lu %3lu\n",
118 r, pct(r, read_tot), pct(read_cum, read_tot),
119 w, pct(w, write_tot), pct(write_cum, write_tot));
121 if (read_cum == read_tot && write_cum == write_tot)
126 static void brw_stats_show(struct seq_file *seq, struct brw_stats *brw_stats)
130 /* this sampling races with updates */
131 do_gettimeofday(&now);
132 seq_printf(seq, "snapshot_time: %lu.%lu (secs.usecs)\n",
133 now.tv_sec, now.tv_usec);
135 display_brw_stats(seq, "pages per bulk r/w", "rpcs",
136 &brw_stats->hist[BRW_R_PAGES],
137 &brw_stats->hist[BRW_W_PAGES], 1);
139 display_brw_stats(seq, "discontiguous pages", "rpcs",
140 &brw_stats->hist[BRW_R_DISCONT_PAGES],
141 &brw_stats->hist[BRW_W_DISCONT_PAGES], 0);
143 display_brw_stats(seq, "discontiguous blocks", "rpcs",
144 &brw_stats->hist[BRW_R_DISCONT_BLOCKS],
145 &brw_stats->hist[BRW_W_DISCONT_BLOCKS], 0);
147 display_brw_stats(seq, "disk fragmented I/Os", "ios",
148 &brw_stats->hist[BRW_R_DIO_FRAGS],
149 &brw_stats->hist[BRW_W_DIO_FRAGS], 0);
151 display_brw_stats(seq, "disk I/Os in flight", "ios",
152 &brw_stats->hist[BRW_R_RPC_HIST],
153 &brw_stats->hist[BRW_W_RPC_HIST], 0);
155 display_brw_stats(seq, "I/O time (1/1000s)", "ios",
156 &brw_stats->hist[BRW_R_IO_TIME],
157 &brw_stats->hist[BRW_W_IO_TIME], 1000 / HZ);
159 display_brw_stats(seq, "disk I/O size", "ios",
160 &brw_stats->hist[BRW_R_DISK_IOSIZE],
161 &brw_stats->hist[BRW_W_DISK_IOSIZE], 1);
166 static int osd_brw_stats_seq_show(struct seq_file *seq, void *v)
168 struct osd_device *osd = seq->private;
170 brw_stats_show(seq, &osd->od_brw_stats);
175 static ssize_t osd_brw_stats_seq_write(struct file *file, const char *buf,
176 size_t len, loff_t *off)
178 struct seq_file *seq = file->private_data;
179 struct osd_device *osd = seq->private;
182 for (i = 0; i < BRW_LAST; i++)
183 lprocfs_oh_clear(&osd->od_brw_stats.hist[i]);
188 LPROC_SEQ_FOPS(osd_brw_stats);
190 static int osd_stats_init(struct osd_device *osd)
195 for (i = 0; i < BRW_LAST; i++)
196 spin_lock_init(&osd->od_brw_stats.hist[i].oh_lock);
198 osd->od_stats = lprocfs_alloc_stats(LPROC_OSD_LAST, 0);
199 if (osd->od_stats != NULL) {
200 result = lprocfs_register_stats(osd->od_proc_entry, "stats",
205 lprocfs_counter_init(osd->od_stats, LPROC_OSD_GET_PAGE,
206 LPROCFS_CNTR_AVGMINMAX|LPROCFS_CNTR_STDDEV,
208 lprocfs_counter_init(osd->od_stats, LPROC_OSD_NO_PAGE,
209 LPROCFS_CNTR_AVGMINMAX,
210 "get_page_failures", "num");
211 lprocfs_counter_init(osd->od_stats, LPROC_OSD_CACHE_ACCESS,
212 LPROCFS_CNTR_AVGMINMAX,
213 "cache_access", "pages");
214 lprocfs_counter_init(osd->od_stats, LPROC_OSD_CACHE_HIT,
215 LPROCFS_CNTR_AVGMINMAX,
216 "cache_hit", "pages");
217 lprocfs_counter_init(osd->od_stats, LPROC_OSD_CACHE_MISS,
218 LPROCFS_CNTR_AVGMINMAX,
219 "cache_miss", "pages");
220 #if OSD_THANDLE_STATS
221 lprocfs_counter_init(osd->od_stats, LPROC_OSD_THANDLE_STARTING,
222 LPROCFS_CNTR_AVGMINMAX,
223 "thandle starting", "usec");
224 lprocfs_counter_init(osd->od_stats, LPROC_OSD_THANDLE_OPEN,
225 LPROCFS_CNTR_AVGMINMAX,
226 "thandle open", "usec");
227 lprocfs_counter_init(osd->od_stats, LPROC_OSD_THANDLE_CLOSING,
228 LPROCFS_CNTR_AVGMINMAX,
229 "thandle closing", "usec");
231 result = lprocfs_seq_create(osd->od_proc_entry, "brw_stats",
232 0644, &osd_brw_stats_fops, osd);
240 int osd_procfs_init(struct osd_device *osd, const char *name)
242 struct lprocfs_static_vars lvars;
243 struct obd_type *type;
247 /* at the moment there is no linkage between lu_type
248 * and obd_type, so we lookup obd_type this way */
249 type = class_search_type(LUSTRE_OSD_LDISKFS_NAME);
251 LASSERT(name != NULL);
252 LASSERT(type != NULL);
254 /* Find the type procroot and add the proc entry for this device */
255 lprocfs_osd_init_vars(&lvars);
256 osd->od_proc_entry = lprocfs_register(name, type->typ_procroot,
257 lvars.obd_vars, &osd->od_dt_dev);
258 if (IS_ERR(osd->od_proc_entry)) {
259 rc = PTR_ERR(osd->od_proc_entry);
260 CERROR("Error %d setting up lprocfs for %s\n",
262 osd->od_proc_entry = NULL;
266 rc = osd_stats_init(osd);
271 osd_procfs_fini(osd);
275 int osd_procfs_fini(struct osd_device *osd)
278 lprocfs_free_stats(&osd->od_stats);
280 if (osd->od_proc_entry) {
281 lprocfs_remove(&osd->od_proc_entry);
282 osd->od_proc_entry = NULL;
287 static int lprocfs_osd_rd_fstype(char *page, char **start, off_t off, int count,
288 int *eof, void *data)
290 struct osd_device *osd = osd_dt_dev(data);
292 LASSERT(osd != NULL);
293 return snprintf(page, count, "ldiskfs\n");
296 static int lprocfs_osd_rd_mntdev(char *page, char **start, off_t off, int count,
297 int *eof, void *data)
299 struct osd_device *osd = osd_dt_dev(data);
301 LASSERT(osd != NULL);
302 if (unlikely(osd->od_mnt == NULL))
307 return snprintf(page, count, "%s\n", osd->od_mntdev);
310 static int lprocfs_osd_rd_cache(char *page, char **start, off_t off,
311 int count, int *eof, void *data)
313 struct osd_device *osd = osd_dt_dev(data);
315 LASSERT(osd != NULL);
316 if (unlikely(osd->od_mnt == NULL))
319 return snprintf(page, count, "%u\n", osd->od_read_cache);
322 static int lprocfs_osd_wr_cache(struct file *file, const char *buffer,
323 unsigned long count, void *data)
325 struct osd_device *osd = osd_dt_dev(data);
328 LASSERT(osd != NULL);
329 if (unlikely(osd->od_mnt == NULL))
332 rc = lprocfs_write_helper(buffer, count, &val);
336 osd->od_read_cache = !!val;
340 static int lprocfs_osd_rd_wcache(char *page, char **start, off_t off,
341 int count, int *eof, void *data)
343 struct osd_device *osd = osd_dt_dev(data);
345 LASSERT(osd != NULL);
346 if (unlikely(osd->od_mnt == NULL))
349 return snprintf(page, count, "%u\n", osd->od_writethrough_cache);
352 static int lprocfs_osd_wr_wcache(struct file *file, const char *buffer,
353 unsigned long count, void *data)
355 struct osd_device *osd = osd_dt_dev(data);
358 LASSERT(osd != NULL);
359 if (unlikely(osd->od_mnt == NULL))
362 rc = lprocfs_write_helper(buffer, count, &val);
366 osd->od_writethrough_cache = !!val;
370 static int lprocfs_osd_wr_force_sync(struct file *file, const char *buffer,
371 unsigned long count, void *data)
373 struct osd_device *osd = osd_dt_dev(data);
374 struct dt_device *dt = data;
378 LASSERT(osd != NULL);
379 if (unlikely(osd->od_mnt == NULL))
382 rc = lu_env_init(&env, LCT_LOCAL);
385 rc = dt_sync(&env, dt);
388 return rc == 0 ? count : rc;
391 static int lprocfs_osd_rd_pdo(char *page, char **start, off_t off, int count,
392 int *eof, void *data)
396 return snprintf(page, count, "%s\n", ldiskfs_pdo ? "ON" : "OFF");
399 static int lprocfs_osd_wr_pdo(struct file *file, const char *buffer,
400 unsigned long count, void *data)
405 rc = lprocfs_write_helper(buffer, count, &pdo);
414 static int lprocfs_osd_rd_auto_scrub(char *page, char **start, off_t off,
415 int count, int *eof, void *data)
417 struct osd_device *dev = osd_dt_dev(data);
419 LASSERT(dev != NULL);
420 if (unlikely(dev->od_mnt == NULL))
424 return snprintf(page, count, "%d\n", !dev->od_noscrub);
427 static int lprocfs_osd_wr_auto_scrub(struct file *file, const char *buffer,
428 unsigned long count, void *data)
430 struct osd_device *dev = osd_dt_dev(data);
433 LASSERT(dev != NULL);
434 if (unlikely(dev->od_mnt == NULL))
437 rc = lprocfs_write_helper(buffer, count, &val);
441 dev->od_noscrub = !val;
445 static int lprocfs_osd_rd_track_declares_assert(char *page, char **start,
446 off_t off, int count,
447 int *eof, void *data)
451 return snprintf(page, count, "%d\n", ldiskfs_track_declares_assert);
454 static int lprocfs_osd_wr_track_declares_assert(struct file *file,
456 unsigned long count, void *data)
458 int track_declares_assert;
461 rc = lprocfs_write_helper(buffer, count, &track_declares_assert);
465 ldiskfs_track_declares_assert = !!track_declares_assert;
470 static int lprocfs_osd_rd_oi_scrub(char *page, char **start, off_t off,
471 int count, int *eof, void *data)
473 struct osd_device *dev = osd_dt_dev(data);
475 LASSERT(dev != NULL);
476 if (unlikely(dev->od_mnt == NULL))
480 return osd_scrub_dump(dev, page, count);
483 int lprocfs_osd_rd_readcache(char *page, char **start, off_t off, int count,
484 int *eof, void *data)
486 struct osd_device *osd = osd_dt_dev(data);
489 LASSERT(osd != NULL);
490 if (unlikely(osd->od_mnt == NULL))
493 rc = snprintf(page, count, LPU64"\n", osd->od_readcache_max_filesize);
497 int lprocfs_osd_wr_readcache(struct file *file, const char *buffer,
498 unsigned long count, void *data)
500 struct osd_device *osd = osd_dt_dev(data);
504 LASSERT(osd != NULL);
505 if (unlikely(osd->od_mnt == NULL))
508 rc = lprocfs_write_u64_helper(buffer, count, &val);
512 osd->od_readcache_max_filesize = val > OSD_MAX_CACHE_SIZE ?
513 OSD_MAX_CACHE_SIZE : val;
517 static int lprocfs_osd_rd_lma_self_repair(char *page, char **start, off_t off,
518 int count, int *eof, void *data)
520 struct osd_device *dev = osd_dt_dev(data);
522 LASSERT(dev != NULL);
523 if (unlikely(dev->od_mnt == NULL))
527 return snprintf(page, count, "%d\n", !!dev->od_lma_self_repair);
530 static int lprocfs_osd_wr_lma_self_repair(struct file *file, const char *buffer,
531 unsigned long count, void *data)
533 struct osd_device *dev = osd_dt_dev(data);
537 LASSERT(dev != NULL);
538 if (unlikely(dev->od_mnt == NULL))
541 rc = lprocfs_write_helper(buffer, count, &val);
545 dev->od_lma_self_repair = !!val;
549 struct lprocfs_vars lprocfs_osd_obd_vars[] = {
550 { "blocksize", lprocfs_dt_rd_blksize, 0, 0 },
551 { "kbytestotal", lprocfs_dt_rd_kbytestotal, 0, 0 },
552 { "kbytesfree", lprocfs_dt_rd_kbytesfree, 0, 0 },
553 { "kbytesavail", lprocfs_dt_rd_kbytesavail, 0, 0 },
554 { "filestotal", lprocfs_dt_rd_filestotal, 0, 0 },
555 { "filesfree", lprocfs_dt_rd_filesfree, 0, 0 },
556 { "fstype", lprocfs_osd_rd_fstype, 0, 0 },
557 { "mntdev", lprocfs_osd_rd_mntdev, 0, 0 },
558 { "force_sync", 0, lprocfs_osd_wr_force_sync },
559 { "pdo", lprocfs_osd_rd_pdo, lprocfs_osd_wr_pdo, 0 },
560 { "auto_scrub", lprocfs_osd_rd_auto_scrub,
561 lprocfs_osd_wr_auto_scrub, 0 },
562 { "oi_scrub", lprocfs_osd_rd_oi_scrub, 0, 0 },
563 { "force_sync", 0, lprocfs_osd_wr_force_sync },
564 { "read_cache_enable", lprocfs_osd_rd_cache, lprocfs_osd_wr_cache, 0 },
565 { "writethrough_cache_enable", lprocfs_osd_rd_wcache,
566 lprocfs_osd_wr_wcache, 0 },
567 { "readcache_max_filesize", lprocfs_osd_rd_readcache,
568 lprocfs_osd_wr_readcache, 0 },
569 { "lma_self_repair", lprocfs_osd_rd_lma_self_repair,
570 lprocfs_osd_wr_lma_self_repair, 0, 0 },
574 struct lprocfs_vars lprocfs_osd_module_vars[] = {
575 { "num_refs", lprocfs_rd_numrefs, 0, 0 },
576 { "track_declares_assert", lprocfs_osd_rd_track_declares_assert,
577 lprocfs_osd_wr_track_declares_assert,
582 void lprocfs_osd_init_vars(struct lprocfs_static_vars *lvars)
584 lvars->module_vars = lprocfs_osd_module_vars;
585 lvars->obd_vars = lprocfs_osd_obd_vars;