1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2002 Cluster File Systems, Inc.
6 * This file is part of Lustre, http://www.lustre.org.
8 * Lustre is free software; you can redistribute it and/or
9 * modify it under the terms of version 2 of the GNU General Public
10 * License as published by the Free Software Foundation.
12 * Lustre is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Lustre; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #define DEBUG_SUBSYSTEM S_LLITE
24 #include <linux/version.h>
25 #include <lustre_lite.h>
26 #include <lprocfs_status.h>
27 #include <linux/seq_file.h>
28 #include <obd_support.h>
30 #include "llite_internal.h"
32 struct proc_dir_entry *proc_lustre_fs_root;
35 /* /proc/lustre/llite mount point registration */
36 struct file_operations llite_dump_pgcache_fops;
37 struct file_operations ll_ra_stats_fops;
38 struct file_operations ll_rw_extents_stats_fops;
39 struct file_operations ll_rw_extents_stats_pp_fops;
40 struct file_operations ll_rw_offset_stats_fops;
42 static int ll_rd_blksize(char *page, char **start, off_t off, int count,
45 struct super_block *sb = (struct super_block *)data;
46 struct obd_statfs osfs;
50 rc = ll_statfs_internal(sb, &osfs, cfs_time_current_64() - HZ,
54 rc = snprintf(page, count, "%u\n", osfs.os_bsize);
60 static int ll_rd_kbytestotal(char *page, char **start, off_t off, int count,
63 struct super_block *sb = (struct super_block *)data;
64 struct obd_statfs osfs;
68 rc = ll_statfs_internal(sb, &osfs, cfs_time_current_64() - HZ,
71 __u32 blk_size = osfs.os_bsize >> 10;
72 __u64 result = osfs.os_blocks;
74 while (blk_size >>= 1)
78 rc = snprintf(page, count, LPU64"\n", result);
84 static int ll_rd_kbytesfree(char *page, char **start, off_t off, int count,
87 struct super_block *sb = (struct super_block *)data;
88 struct obd_statfs osfs;
92 rc = ll_statfs_internal(sb, &osfs, cfs_time_current_64() - HZ,
95 __u32 blk_size = osfs.os_bsize >> 10;
96 __u64 result = osfs.os_bfree;
98 while (blk_size >>= 1)
102 rc = snprintf(page, count, LPU64"\n", result);
107 static int ll_rd_kbytesavail(char *page, char **start, off_t off, int count,
108 int *eof, void *data)
110 struct super_block *sb = (struct super_block *)data;
111 struct obd_statfs osfs;
115 rc = ll_statfs_internal(sb, &osfs, cfs_time_current_64() - HZ,
118 __u32 blk_size = osfs.os_bsize >> 10;
119 __u64 result = osfs.os_bavail;
121 while (blk_size >>= 1)
125 rc = snprintf(page, count, LPU64"\n", result);
130 static int ll_rd_filestotal(char *page, char **start, off_t off, int count,
131 int *eof, void *data)
133 struct super_block *sb = (struct super_block *)data;
134 struct obd_statfs osfs;
138 rc = ll_statfs_internal(sb, &osfs, cfs_time_current_64() - HZ,
142 rc = snprintf(page, count, LPU64"\n", osfs.os_files);
147 static int ll_rd_filesfree(char *page, char **start, off_t off, int count,
148 int *eof, void *data)
150 struct super_block *sb = (struct super_block *)data;
151 struct obd_statfs osfs;
155 rc = ll_statfs_internal(sb, &osfs, cfs_time_current_64() - HZ,
159 rc = snprintf(page, count, LPU64"\n", osfs.os_ffree);
165 static int ll_rd_fstype(char *page, char **start, off_t off, int count,
166 int *eof, void *data)
168 struct super_block *sb = (struct super_block*)data;
172 return snprintf(page, count, "%s\n", sb->s_type->name);
175 static int ll_rd_sb_uuid(char *page, char **start, off_t off, int count,
176 int *eof, void *data)
178 struct super_block *sb = (struct super_block *)data;
182 return snprintf(page, count, "%s\n", ll_s2sbi(sb)->ll_sb_uuid.uuid);
185 static int ll_rd_max_readahead_mb(char *page, char **start, off_t off,
186 int count, int *eof, void *data)
188 struct super_block *sb = data;
189 struct ll_sb_info *sbi = ll_s2sbi(sb);
193 spin_lock(&sbi->ll_lock);
194 pages_number = sbi->ll_ra_info.ra_max_pages;
195 spin_unlock(&sbi->ll_lock);
197 mult = 1 << (20 - CFS_PAGE_SHIFT);
198 return lprocfs_read_frac_helper(page, count, pages_number, mult);
201 static int ll_wr_max_readahead_mb(struct file *file, const char *buffer,
202 unsigned long count, void *data)
204 struct super_block *sb = data;
205 struct ll_sb_info *sbi = ll_s2sbi(sb);
206 int mult, rc, pages_number;
208 mult = 1 << (20 - CFS_PAGE_SHIFT);
209 rc = lprocfs_write_frac_helper(buffer, count, &pages_number, mult);
213 if (pages_number < 0 || pages_number > num_physpages / 2) {
214 CERROR("can't set file readahead more than %lu MB\n",
215 num_physpages >> (20 - CFS_PAGE_SHIFT + 1)); /*1/2 of RAM*/
219 spin_lock(&sbi->ll_lock);
220 sbi->ll_ra_info.ra_max_pages = pages_number;
221 spin_unlock(&sbi->ll_lock);
226 static int ll_rd_max_read_ahead_whole_mb(char *page, char **start, off_t off,
227 int count, int *eof, void *data)
229 struct super_block *sb = data;
230 struct ll_sb_info *sbi = ll_s2sbi(sb);
234 spin_lock(&sbi->ll_lock);
235 pages_number = sbi->ll_ra_info.ra_max_read_ahead_whole_pages;
236 spin_unlock(&sbi->ll_lock);
238 mult = 1 << (20 - CFS_PAGE_SHIFT);
239 return lprocfs_read_frac_helper(page, count, pages_number, mult);
242 static int ll_wr_max_read_ahead_whole_mb(struct file *file, const char *buffer,
243 unsigned long count, void *data)
245 struct super_block *sb = data;
246 struct ll_sb_info *sbi = ll_s2sbi(sb);
247 int mult, rc, pages_number;
249 mult = 1 << (20 - CFS_PAGE_SHIFT);
250 rc = lprocfs_write_frac_helper(buffer, count, &pages_number, mult);
254 /* Cap this at the current max readahead window size, the readahead
255 * algorithm does this anyway so it's pointless to set it larger. */
256 if (pages_number < 0 || pages_number > sbi->ll_ra_info.ra_max_pages) {
257 CERROR("can't set max_read_ahead_whole_mb more than "
258 "max_read_ahead_mb: %lu\n",
259 sbi->ll_ra_info.ra_max_pages >> (20 - CFS_PAGE_SHIFT));
263 spin_lock(&sbi->ll_lock);
264 sbi->ll_ra_info.ra_max_read_ahead_whole_pages = pages_number;
265 spin_unlock(&sbi->ll_lock);
270 static int ll_rd_max_cached_mb(char *page, char **start, off_t off,
271 int count, int *eof, void *data)
273 struct super_block *sb = data;
274 struct ll_sb_info *sbi = ll_s2sbi(sb);
278 spin_lock(&sbi->ll_lock);
279 pages_number = sbi->ll_async_page_max;
280 spin_unlock(&sbi->ll_lock);
282 mult = 1 << (20 - CFS_PAGE_SHIFT);
283 return lprocfs_read_frac_helper(page, count, pages_number, mult);;
286 static int ll_wr_max_cached_mb(struct file *file, const char *buffer,
287 unsigned long count, void *data)
289 struct super_block *sb = data;
290 struct ll_sb_info *sbi = ll_s2sbi(sb);
291 int mult, rc, pages_number;
293 mult = 1 << (20 - CFS_PAGE_SHIFT);
294 rc = lprocfs_write_frac_helper(buffer, count, &pages_number, mult);
298 if (pages_number < 0 || pages_number > num_physpages) {
299 CERROR("can't set max cache more than %lu MB\n",
300 num_physpages >> (20 - CFS_PAGE_SHIFT));
304 spin_lock(&sbi->ll_lock);
305 sbi->ll_async_page_max = pages_number ;
306 spin_unlock(&sbi->ll_lock);
308 if (!sbi->ll_osc_exp)
309 /* Not set up yet, don't call llap_shrink_cache */
312 if (sbi->ll_async_page_count >= sbi->ll_async_page_max)
313 llap_shrink_cache(sbi, 0);
318 static int ll_rd_checksum(char *page, char **start, off_t off,
319 int count, int *eof, void *data)
321 struct super_block *sb = data;
322 struct ll_sb_info *sbi = ll_s2sbi(sb);
324 return snprintf(page, count, "%u\n",
325 (sbi->ll_flags & LL_SBI_LLITE_CHECKSUM) ? 1 : 0);
328 static int ll_wr_checksum(struct file *file, const char *buffer,
329 unsigned long count, void *data)
331 struct super_block *sb = data;
332 struct ll_sb_info *sbi = ll_s2sbi(sb);
335 if (!sbi->ll_osc_exp)
339 rc = lprocfs_write_helper(buffer, count, &val);
343 sbi->ll_flags |= (LL_SBI_LLITE_CHECKSUM|LL_SBI_DATA_CHECKSUM);
345 sbi->ll_flags &= ~(LL_SBI_LLITE_CHECKSUM|LL_SBI_DATA_CHECKSUM);
347 rc = obd_set_info_async(sbi->ll_osc_exp, strlen("checksum"), "checksum",
348 sizeof(val), &val, NULL);
350 CWARN("Failed to set OSC checksum flags: %d\n", rc);
355 static int ll_rd_max_rw_chunk(char *page, char **start, off_t off,
356 int count, int *eof, void *data)
358 struct super_block *sb = data;
360 return snprintf(page, count, "%lu\n", ll_s2sbi(sb)->ll_max_rw_chunk);
363 static int ll_wr_max_rw_chunk(struct file *file, const char *buffer,
364 unsigned long count, void *data)
366 struct super_block *sb = data;
369 rc = lprocfs_write_helper(buffer, count, &val);
372 ll_s2sbi(sb)->ll_max_rw_chunk = val;
376 static int ll_rd_track_id(char *page, int count, void *data,
377 enum stats_track_type type)
379 struct super_block *sb = data;
381 if (ll_s2sbi(sb)->ll_stats_track_type == type) {
382 return snprintf(page, count, "%d\n",
383 ll_s2sbi(sb)->ll_stats_track_id);
385 } else if (ll_s2sbi(sb)->ll_stats_track_type == STATS_TRACK_ALL) {
386 return snprintf(page, count, "0 (all)\n");
388 return snprintf(page, count, "untracked\n");
392 static int ll_wr_track_id(const char *buffer, unsigned long count, void *data,
393 enum stats_track_type type)
395 struct super_block *sb = data;
398 rc = lprocfs_write_helper(buffer, count, &pid);
401 ll_s2sbi(sb)->ll_stats_track_id = pid;
403 ll_s2sbi(sb)->ll_stats_track_type = STATS_TRACK_ALL;
405 ll_s2sbi(sb)->ll_stats_track_type = type;
406 lprocfs_clear_stats(ll_s2sbi(sb)->ll_stats);
410 static int ll_rd_track_pid(char *page, char **start, off_t off,
411 int count, int *eof, void *data)
413 return (ll_rd_track_id(page, count, data, STATS_TRACK_PID));
416 static int ll_wr_track_pid(struct file *file, const char *buffer,
417 unsigned long count, void *data)
419 return (ll_wr_track_id(buffer, count, data, STATS_TRACK_PID));
422 static int ll_rd_track_ppid(char *page, char **start, off_t off,
423 int count, int *eof, void *data)
425 return (ll_rd_track_id(page, count, data, STATS_TRACK_PPID));
428 static int ll_wr_track_ppid(struct file *file, const char *buffer,
429 unsigned long count, void *data)
431 return (ll_wr_track_id(buffer, count, data, STATS_TRACK_PPID));
434 static int ll_rd_track_gid(char *page, char **start, off_t off,
435 int count, int *eof, void *data)
437 return (ll_rd_track_id(page, count, data, STATS_TRACK_GID));
440 static int ll_wr_track_gid(struct file *file, const char *buffer,
441 unsigned long count, void *data)
443 return (ll_wr_track_id(buffer, count, data, STATS_TRACK_GID));
446 static int ll_rd_contention_time(char *page, char **start, off_t off,
447 int count, int *eof, void *data)
449 struct super_block *sb = data;
452 return snprintf(page, count, "%u\n", ll_s2sbi(sb)->ll_contention_time);
456 static int ll_wr_contention_time(struct file *file, const char *buffer,
457 unsigned long count, void *data)
459 struct super_block *sb = data;
460 struct ll_sb_info *sbi = ll_s2sbi(sb);
462 return lprocfs_write_helper(buffer, count,&sbi->ll_contention_time) ?:
466 static int ll_rd_statahead_max(char *page, char **start, off_t off,
467 int count, int *eof, void *data)
469 struct super_block *sb = data;
470 struct ll_sb_info *sbi = ll_s2sbi(sb);
472 return snprintf(page, count, "%u\n", sbi->ll_sa_max);
475 static int ll_wr_statahead_max(struct file *file, const char *buffer,
476 unsigned long count, void *data)
478 struct super_block *sb = data;
479 struct ll_sb_info *sbi = ll_s2sbi(sb);
482 rc = lprocfs_write_helper(buffer, count, &val);
486 if (val >= 0 && val <= LL_SA_RPC_MAX)
487 sbi->ll_sa_max = val;
489 CERROR("Bad statahead_max value %d. Valid values are in the "
490 "range [0, %d]\n", val, LL_SA_RPC_MAX);
495 static int ll_rd_statahead_stats(char *page, char **start, off_t off,
496 int count, int *eof, void *data)
498 struct super_block *sb = data;
499 struct ll_sb_info *sbi = ll_s2sbi(sb);
501 return snprintf(page, count,
502 "statahead wrong: %u\n"
503 "statahead total: %u\n"
507 "miss count: %llu\n",
516 static struct lprocfs_vars lprocfs_llite_obd_vars[] = {
517 { "uuid", ll_rd_sb_uuid, 0, 0 },
518 //{ "mntpt_path", ll_rd_path, 0, 0 },
519 { "fstype", ll_rd_fstype, 0, 0 },
520 { "blocksize", ll_rd_blksize, 0, 0 },
521 { "kbytestotal", ll_rd_kbytestotal, 0, 0 },
522 { "kbytesfree", ll_rd_kbytesfree, 0, 0 },
523 { "kbytesavail", ll_rd_kbytesavail, 0, 0 },
524 { "filestotal", ll_rd_filestotal, 0, 0 },
525 { "filesfree", ll_rd_filesfree, 0, 0 },
526 //{ "filegroups", lprocfs_rd_filegroups, 0, 0 },
527 { "max_read_ahead_mb", ll_rd_max_readahead_mb,
528 ll_wr_max_readahead_mb, 0 },
529 { "max_read_ahead_whole_mb", ll_rd_max_read_ahead_whole_mb,
530 ll_wr_max_read_ahead_whole_mb, 0 },
531 { "max_cached_mb", ll_rd_max_cached_mb, ll_wr_max_cached_mb, 0 },
532 { "checksum_pages", ll_rd_checksum, ll_wr_checksum, 0 },
533 { "max_rw_chunk", ll_rd_max_rw_chunk, ll_wr_max_rw_chunk, 0 },
534 { "stats_track_pid", ll_rd_track_pid, ll_wr_track_pid, 0 },
535 { "stats_track_ppid", ll_rd_track_ppid, ll_wr_track_ppid, 0 },
536 { "stats_track_gid", ll_rd_track_gid, ll_wr_track_gid, 0 },
537 { "contention_seconds", ll_rd_contention_time, ll_wr_contention_time, 0},
538 { "statahead_max", ll_rd_statahead_max, ll_wr_statahead_max, 0 },
539 { "statahead_stats", ll_rd_statahead_stats, 0, 0 },
543 #define MAX_STRING_SIZE 128
545 struct llite_file_opcode {
549 } llite_opcode_table[LPROC_LL_FILE_OPCODES] = {
551 { LPROC_LL_DIRTY_HITS, LPROCFS_TYPE_REGS, "dirty_pages_hits" },
552 { LPROC_LL_DIRTY_MISSES, LPROCFS_TYPE_REGS, "dirty_pages_misses" },
553 { LPROC_LL_WB_WRITEPAGE, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
554 "writeback_from_writepage" },
555 { LPROC_LL_WB_PRESSURE, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
556 "writeback_from_pressure" },
557 { LPROC_LL_WB_OK, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
558 "writeback_ok_pages" },
559 { LPROC_LL_WB_FAIL, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
560 "writeback_failed_pages" },
561 { LPROC_LL_READ_BYTES, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_BYTES,
563 { LPROC_LL_WRITE_BYTES, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_BYTES,
565 { LPROC_LL_BRW_READ, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
567 { LPROC_LL_BRW_WRITE, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
570 { LPROC_LL_IOCTL, LPROCFS_TYPE_REGS, "ioctl" },
571 { LPROC_LL_OPEN, LPROCFS_TYPE_REGS, "open" },
572 { LPROC_LL_RELEASE, LPROCFS_TYPE_REGS, "close" },
573 { LPROC_LL_MAP, LPROCFS_TYPE_REGS, "mmap" },
574 { LPROC_LL_LLSEEK, LPROCFS_TYPE_REGS, "seek" },
575 { LPROC_LL_FSYNC, LPROCFS_TYPE_REGS, "fsync" },
576 /* inode operation */
577 { LPROC_LL_SETATTR, LPROCFS_TYPE_REGS, "setattr" },
578 { LPROC_LL_TRUNC, LPROCFS_TYPE_REGS, "truncate" },
579 { LPROC_LL_FLOCK, LPROCFS_TYPE_REGS, "flock" },
580 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
581 { LPROC_LL_GETATTR, LPROCFS_TYPE_REGS, "getattr" },
583 { LPROC_LL_REVALIDATE, LPROCFS_TYPE_REGS, "getattr" },
585 /* special inode operation */
586 { LPROC_LL_STAFS, LPROCFS_TYPE_REGS, "statfs" },
587 { LPROC_LL_ALLOC_INODE, LPROCFS_TYPE_REGS, "alloc_inode" },
588 { LPROC_LL_SETXATTR, LPROCFS_TYPE_REGS, "setxattr" },
589 { LPROC_LL_GETXATTR, LPROCFS_TYPE_REGS, "getxattr" },
590 { LPROC_LL_LISTXATTR, LPROCFS_TYPE_REGS, "listxattr" },
591 { LPROC_LL_REMOVEXATTR, LPROCFS_TYPE_REGS, "removexattr" },
592 { LPROC_LL_INODE_PERM, LPROCFS_TYPE_REGS, "inode_permission" },
593 { LPROC_LL_DIRECT_READ, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
595 { LPROC_LL_DIRECT_WRITE, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
597 { LPROC_LL_LOCKLESS_READ, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_BYTES,
598 "lockless_read_bytes" },
599 { LPROC_LL_LOCKLESS_WRITE, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_BYTES,
600 "lockless_write_bytes" },
604 void ll_stats_ops_tally(struct ll_sb_info *sbi, int op, int count)
608 if (sbi->ll_stats_track_type == STATS_TRACK_ALL)
609 lprocfs_counter_add(sbi->ll_stats, op, count);
610 else if (sbi->ll_stats_track_type == STATS_TRACK_PID &&
611 sbi->ll_stats_track_id == current->pid)
612 lprocfs_counter_add(sbi->ll_stats, op, count);
613 else if (sbi->ll_stats_track_type == STATS_TRACK_PPID &&
614 sbi->ll_stats_track_id == current->p_pptr->pid)
615 lprocfs_counter_add(sbi->ll_stats, op, count);
616 else if (sbi->ll_stats_track_type == STATS_TRACK_GID &&
617 sbi->ll_stats_track_id == current->gid)
618 lprocfs_counter_add(sbi->ll_stats, op, count);
620 EXPORT_SYMBOL(ll_stats_ops_tally);
622 int lprocfs_register_mountpoint(struct proc_dir_entry *parent,
623 struct super_block *sb, char *osc, char *mdc)
625 struct lprocfs_vars lvars[2];
626 struct lustre_sb_info *lsi = s2lsi(sb);
627 struct ll_sb_info *sbi = ll_s2sbi(sb);
628 struct obd_device *obd;
629 char name[MAX_STRING_SIZE + 1], *ptr;
631 struct proc_dir_entry *entry;
634 memset(lvars, 0, sizeof(lvars));
636 name[MAX_STRING_SIZE] = '\0';
637 lvars[0].name = name;
639 LASSERT(sbi != NULL);
640 LASSERT(mdc != NULL);
641 LASSERT(osc != NULL);
644 len = strlen(lsi->lsi_lmd->lmd_profile);
645 ptr = strrchr(lsi->lsi_lmd->lmd_profile, '-');
646 if (ptr && (strcmp(ptr, "-client") == 0))
650 snprintf(name, MAX_STRING_SIZE, "%.*s-%p", len,
651 lsi->lsi_lmd->lmd_profile, sb);
653 sbi->ll_proc_root = lprocfs_register(name, parent, NULL, NULL);
654 if (IS_ERR(sbi->ll_proc_root)) {
655 err = PTR_ERR(sbi->ll_proc_root);
656 sbi->ll_proc_root = NULL;
660 entry = create_proc_entry("dump_page_cache", 0444, sbi->ll_proc_root);
662 GOTO(out, err = -ENOMEM);
663 entry->proc_fops = &llite_dump_pgcache_fops;
666 entry = create_proc_entry("read_ahead_stats", 0644, sbi->ll_proc_root);
668 GOTO(out, err = -ENOMEM);
669 entry->proc_fops = &ll_ra_stats_fops;
672 entry = create_proc_entry("extents_stats", 0644, sbi->ll_proc_root);
674 GOTO(out, err = -ENOMEM);
675 entry->proc_fops = &ll_rw_extents_stats_fops;
678 entry = create_proc_entry("extents_stats_per_process", 0644,
681 GOTO(out, err = -ENOMEM);
682 entry->proc_fops = &ll_rw_extents_stats_pp_fops;
685 entry = create_proc_entry("offset_stats", 0644, sbi->ll_proc_root);
687 GOTO(out, err = -ENOMEM);
688 entry->proc_fops = &ll_rw_offset_stats_fops;
691 /* File operations stats */
692 sbi->ll_stats = lprocfs_alloc_stats(LPROC_LL_FILE_OPCODES,
693 LPROCFS_STATS_FLAG_PERCPU);
694 if (sbi->ll_stats == NULL)
695 GOTO(out, err = -ENOMEM);
696 /* do counter init */
697 for (id = 0; id < LPROC_LL_FILE_OPCODES; id++) {
698 __u32 type = llite_opcode_table[id].type;
700 if (type & LPROCFS_TYPE_REGS)
702 else if (type & LPROCFS_TYPE_BYTES)
704 else if (type & LPROCFS_TYPE_PAGES)
706 lprocfs_counter_init(sbi->ll_stats,
707 llite_opcode_table[id].opcode,
708 (type & LPROCFS_CNTR_AVGMINMAX),
709 llite_opcode_table[id].opname, ptr);
711 err = lprocfs_register_stats(sbi->ll_proc_root, "stats", sbi->ll_stats);
715 err = lprocfs_add_vars(sbi->ll_proc_root, lprocfs_llite_obd_vars, sb);
720 obd = class_name2obd(mdc);
722 LASSERT(obd != NULL);
723 LASSERT(obd->obd_magic == OBD_DEVICE_MAGIC);
724 LASSERT(obd->obd_type->typ_name != NULL);
726 snprintf(name, MAX_STRING_SIZE, "%s/common_name",
727 obd->obd_type->typ_name);
728 lvars[0].read_fptr = lprocfs_rd_name;
729 err = lprocfs_add_vars(sbi->ll_proc_root, lvars, obd);
733 snprintf(name, MAX_STRING_SIZE, "%s/uuid", obd->obd_type->typ_name);
734 lvars[0].read_fptr = lprocfs_rd_uuid;
735 err = lprocfs_add_vars(sbi->ll_proc_root, lvars, obd);
740 obd = class_name2obd(osc);
742 LASSERT(obd != NULL);
743 LASSERT(obd->obd_magic == OBD_DEVICE_MAGIC);
744 LASSERT(obd->obd_type->typ_name != NULL);
746 snprintf(name, MAX_STRING_SIZE, "%s/common_name",
747 obd->obd_type->typ_name);
748 lvars[0].read_fptr = lprocfs_rd_name;
749 err = lprocfs_add_vars(sbi->ll_proc_root, lvars, obd);
753 snprintf(name, MAX_STRING_SIZE, "%s/uuid", obd->obd_type->typ_name);
754 lvars[0].read_fptr = lprocfs_rd_uuid;
755 err = lprocfs_add_vars(sbi->ll_proc_root, lvars, obd);
758 lprocfs_remove(&sbi->ll_proc_root);
759 lprocfs_free_stats(&sbi->ll_stats);
764 void lprocfs_unregister_mountpoint(struct ll_sb_info *sbi)
766 if (sbi->ll_proc_root) {
767 lprocfs_remove(&sbi->ll_proc_root);
768 lprocfs_free_stats(&sbi->ll_stats);
771 #undef MAX_STRING_SIZE
773 #define seq_page_flag(seq, page, flag, has_flags) do { \
774 if (test_bit(PG_##flag, &(page)->flags)) { \
778 seq_putc(seq, '|'); \
779 seq_puts(seq, #flag); \
783 static void *llite_dump_pgcache_seq_start(struct seq_file *seq, loff_t *pos)
785 struct ll_async_page *dummy_llap = seq->private;
787 if (dummy_llap->llap_magic == 2)
793 static int llite_dump_pgcache_seq_show(struct seq_file *seq, void *v)
795 struct ll_async_page *llap, *dummy_llap = seq->private;
796 struct ll_sb_info *sbi = dummy_llap->llap_cookie;
798 /* 2.4 doesn't seem to have SEQ_START_TOKEN, so we implement
799 * it in our own state */
800 if (dummy_llap->llap_magic == 0) {
801 seq_printf(seq, "gener | llap cookie origin wq du wb | page "
802 "inode index count [ page flags ]\n");
806 spin_lock(&sbi->ll_lock);
808 llap = llite_pglist_next_llap(sbi, &dummy_llap->llap_pglist_item);
811 struct page *page = llap->llap_page;
813 LASSERTF(llap->llap_origin < LLAP__ORIGIN_MAX, "%u\n",
816 seq_printf(seq," %5lu | %p %p %s %s %s %s | %p %lu/%u(%p) "
819 llap, llap->llap_cookie,
820 llap_origins[llap->llap_origin],
821 llap->llap_write_queued ? "wq" : "- ",
822 llap->llap_defer_uptodate ? "du" : "- ",
823 PageWriteback(page) ? "wb" : "-",
824 page, page->mapping->host->i_ino,
825 page->mapping->host->i_generation,
826 page->mapping->host, page->index,
828 seq_page_flag(seq, page, locked, has_flags);
829 seq_page_flag(seq, page, error, has_flags);
830 seq_page_flag(seq, page, referenced, has_flags);
831 seq_page_flag(seq, page, uptodate, has_flags);
832 seq_page_flag(seq, page, dirty, has_flags);
833 #if (LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,12))
834 seq_page_flag(seq, page, highmem, has_flags);
836 seq_page_flag(seq, page, writeback, has_flags);
838 seq_puts(seq, "-]\n");
840 seq_puts(seq, "]\n");
843 spin_unlock(&sbi->ll_lock);
848 static void *llite_dump_pgcache_seq_next(struct seq_file *seq, void *v,
851 struct ll_async_page *llap, *dummy_llap = seq->private;
852 struct ll_sb_info *sbi = dummy_llap->llap_cookie;
854 /* bail if we just displayed the banner */
855 if (dummy_llap->llap_magic == 0) {
856 dummy_llap->llap_magic = 1;
860 /* we've just displayed the llap that is after us in the list.
861 * we advance to a position beyond it, returning null if there
862 * isn't another llap in the list beyond that new position. */
863 spin_lock(&sbi->ll_lock);
864 llap = llite_pglist_next_llap(sbi, &dummy_llap->llap_pglist_item);
865 list_del_init(&dummy_llap->llap_pglist_item);
867 list_add(&dummy_llap->llap_pglist_item,&llap->llap_pglist_item);
868 llap =llite_pglist_next_llap(sbi,&dummy_llap->llap_pglist_item);
870 spin_unlock(&sbi->ll_lock);
874 dummy_llap->llap_magic = 2;
880 static void null_stop(struct seq_file *seq, void *v)
884 struct seq_operations llite_dump_pgcache_seq_sops = {
885 .start = llite_dump_pgcache_seq_start,
887 .next = llite_dump_pgcache_seq_next,
888 .show = llite_dump_pgcache_seq_show,
891 /* we're displaying llaps in a list_head list. we don't want to hold a lock
892 * while we walk the entire list, and we don't want to have to seek into
893 * the right position in the list as an app advances with many syscalls. we
894 * allocate a dummy llap and hang it off file->private. its position in
895 * the list records where the app is currently displaying. this way our
896 * seq .start and .stop don't actually do anything. .next returns null
897 * when the dummy hits the end of the list which eventually leads to .release
898 * where we tear down. this kind of displaying is super-racey, so we put
899 * a generation counter on the list so the output shows when the list
900 * changes between reads.
902 static int llite_dump_pgcache_seq_open(struct inode *inode, struct file *file)
904 struct proc_dir_entry *dp = PDE(inode);
905 struct ll_async_page *dummy_llap;
906 struct seq_file *seq;
907 struct ll_sb_info *sbi = dp->data;
910 LPROCFS_ENTRY_AND_CHECK(dp);
912 OBD_ALLOC_PTR_WAIT(dummy_llap);
913 if (dummy_llap == NULL)
916 dummy_llap->llap_page = NULL;
917 dummy_llap->llap_cookie = sbi;
918 dummy_llap->llap_magic = 0;
920 rc = seq_open(file, &llite_dump_pgcache_seq_sops);
922 OBD_FREE(dummy_llap, sizeof(*dummy_llap));
925 seq = file->private_data;
926 seq->private = dummy_llap;
928 spin_lock(&sbi->ll_lock);
929 list_add(&dummy_llap->llap_pglist_item, &sbi->ll_pglist);
930 spin_unlock(&sbi->ll_lock);
938 static int llite_dump_pgcache_seq_release(struct inode *inode,
941 struct seq_file *seq = file->private_data;
942 struct ll_async_page *dummy_llap = seq->private;
943 struct ll_sb_info *sbi = dummy_llap->llap_cookie;
945 spin_lock(&sbi->ll_lock);
946 if (!list_empty(&dummy_llap->llap_pglist_item))
947 list_del_init(&dummy_llap->llap_pglist_item);
948 spin_unlock(&sbi->ll_lock);
949 OBD_FREE(dummy_llap, sizeof(*dummy_llap));
951 return lprocfs_seq_release(inode, file);
954 struct file_operations llite_dump_pgcache_fops = {
955 .owner = THIS_MODULE,
956 .open = llite_dump_pgcache_seq_open,
958 .release = llite_dump_pgcache_seq_release,
961 static int ll_ra_stats_seq_show(struct seq_file *seq, void *v)
964 struct ll_sb_info *sbi = seq->private;
965 struct ll_ra_info *ra = &sbi->ll_ra_info;
967 static char *ra_stat_strings[] = {
968 [RA_STAT_HIT] = "hits",
969 [RA_STAT_MISS] = "misses",
970 [RA_STAT_DISTANT_READPAGE] = "readpage not consecutive",
971 [RA_STAT_MISS_IN_WINDOW] = "miss inside window",
972 [RA_STAT_FAILED_GRAB_PAGE] = "failed grab_cache_page",
973 [RA_STAT_FAILED_MATCH] = "failed lock match",
974 [RA_STAT_DISCARDED] = "read but discarded",
975 [RA_STAT_ZERO_LEN] = "zero length file",
976 [RA_STAT_ZERO_WINDOW] = "zero size window",
977 [RA_STAT_EOF] = "read-ahead to EOF",
978 [RA_STAT_MAX_IN_FLIGHT] = "hit max r-a issue",
979 [RA_STAT_WRONG_GRAB_PAGE] = "wrong page from grab_cache_page",
982 do_gettimeofday(&now);
984 spin_lock(&sbi->ll_lock);
986 seq_printf(seq, "snapshot_time: %lu.%lu (secs.usecs)\n",
987 now.tv_sec, now.tv_usec);
988 seq_printf(seq, "pending issued pages: %lu\n",
991 for(i = 0; i < _NR_RA_STAT; i++)
992 seq_printf(seq, "%-25s %lu\n", ra_stat_strings[i],
995 spin_unlock(&sbi->ll_lock);
1000 static ssize_t ll_ra_stats_seq_write(struct file *file, const char *buf,
1001 size_t len, loff_t *off)
1003 struct seq_file *seq = file->private_data;
1004 struct ll_sb_info *sbi = seq->private;
1005 struct ll_ra_info *ra = &sbi->ll_ra_info;
1007 spin_lock(&sbi->ll_lock);
1008 memset(ra->ra_stats, 0, sizeof(ra->ra_stats));
1009 spin_unlock(&sbi->ll_lock);
1014 LPROC_SEQ_FOPS(ll_ra_stats);
1016 #define pct(a,b) (b ? a * 100 / b : 0)
1018 static void ll_display_extents_info(struct ll_rw_extents_info *io_extents,
1019 struct seq_file *seq, int which)
1021 unsigned long read_tot = 0, write_tot = 0, read_cum, write_cum;
1022 unsigned long start, end, r, w;
1023 char *unitp = "KMGTPEZY";
1025 struct per_process_info *pp_info = &io_extents->pp_extents[which];
1031 for(i = 0; i < LL_HIST_MAX; i++) {
1032 read_tot += pp_info->pp_r_hist.oh_buckets[i];
1033 write_tot += pp_info->pp_w_hist.oh_buckets[i];
1036 for(i = 0; i < LL_HIST_MAX; i++) {
1037 r = pp_info->pp_r_hist.oh_buckets[i];
1038 w = pp_info->pp_w_hist.oh_buckets[i];
1041 end = 1 << (i + LL_HIST_START - units);
1042 seq_printf(seq, "%4lu%c - %4lu%c%c: %14lu %4lu %4lu | "
1043 "%14lu %4lu %4lu\n", start, *unitp, end, *unitp,
1044 (i == LL_HIST_MAX - 1) ? '+' : ' ',
1045 r, pct(r, read_tot), pct(read_cum, read_tot),
1046 w, pct(w, write_tot), pct(write_cum, write_tot));
1048 if (start == 1<<10) {
1053 if (read_cum == read_tot && write_cum == write_tot)
1058 static int ll_rw_extents_stats_pp_seq_show(struct seq_file *seq, void *v)
1061 struct ll_sb_info *sbi = seq->private;
1062 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1065 do_gettimeofday(&now);
1067 if (!sbi->ll_rw_stats_on) {
1068 seq_printf(seq, "Disabled\n"
1069 "Write anything in this file to activate\n");
1072 seq_printf(seq, "snapshot_time: %lu.%lu (secs.usecs)\n",
1073 now.tv_sec, now.tv_usec);
1074 seq_printf(seq, "%15s %19s | %20s\n", " ", "read", "write");
1075 seq_printf(seq, "%13s %14s %4s %4s | %14s %4s %4s\n",
1076 "extents", "calls", "%", "cum%",
1077 "calls", "%", "cum%");
1078 spin_lock(&sbi->ll_pp_extent_lock);
1079 for(k = 0; k < LL_PROCESS_HIST_MAX; k++) {
1080 if(io_extents->pp_extents[k].pid != 0) {
1081 seq_printf(seq, "\nPID: %d\n",
1082 io_extents->pp_extents[k].pid);
1083 ll_display_extents_info(io_extents, seq, k);
1086 spin_unlock(&sbi->ll_pp_extent_lock);
1090 static ssize_t ll_rw_extents_stats_pp_seq_write(struct file *file,
1091 const char *buf, size_t len,
1094 struct seq_file *seq = file->private_data;
1095 struct ll_sb_info *sbi = seq->private;
1096 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1099 sbi->ll_rw_stats_on = 1;
1100 spin_lock(&sbi->ll_pp_extent_lock);
1101 for(i = 0; i < LL_PROCESS_HIST_MAX; i++) {
1102 io_extents->pp_extents[i].pid = 0;
1103 lprocfs_oh_clear(&io_extents->pp_extents[i].pp_r_hist);
1104 lprocfs_oh_clear(&io_extents->pp_extents[i].pp_w_hist);
1106 spin_unlock(&sbi->ll_pp_extent_lock);
1110 LPROC_SEQ_FOPS(ll_rw_extents_stats_pp);
1112 static int ll_rw_extents_stats_seq_show(struct seq_file *seq, void *v)
1115 struct ll_sb_info *sbi = seq->private;
1116 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1118 do_gettimeofday(&now);
1120 if (!sbi->ll_rw_stats_on) {
1121 seq_printf(seq, "Disabled\n"
1122 "Write anything in this file to activate\n");
1125 seq_printf(seq, "snapshot_time: %lu.%lu (secs.usecs)\n",
1126 now.tv_sec, now.tv_usec);
1128 seq_printf(seq, "%15s %19s | %20s\n", " ", "read", "write");
1129 seq_printf(seq, "%13s %14s %4s %4s | %14s %4s %4s\n",
1130 "extents", "calls", "%", "cum%",
1131 "calls", "%", "cum%");
1132 spin_lock(&sbi->ll_lock);
1133 ll_display_extents_info(io_extents, seq, LL_PROCESS_HIST_MAX);
1134 spin_unlock(&sbi->ll_lock);
1139 static ssize_t ll_rw_extents_stats_seq_write(struct file *file, const char *buf,
1140 size_t len, loff_t *off)
1142 struct seq_file *seq = file->private_data;
1143 struct ll_sb_info *sbi = seq->private;
1144 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1147 sbi->ll_rw_stats_on = 1;
1148 spin_lock(&sbi->ll_pp_extent_lock);
1149 for(i = 0; i <= LL_PROCESS_HIST_MAX; i++)
1151 io_extents->pp_extents[i].pid = 0;
1152 lprocfs_oh_clear(&io_extents->pp_extents[i].pp_r_hist);
1153 lprocfs_oh_clear(&io_extents->pp_extents[i].pp_w_hist);
1155 spin_unlock(&sbi->ll_pp_extent_lock);
1160 LPROC_SEQ_FOPS(ll_rw_extents_stats);
1162 void ll_rw_stats_tally(struct ll_sb_info *sbi, pid_t pid, struct file
1163 *file, size_t count, int rw)
1166 struct ll_rw_process_info *process;
1167 struct ll_rw_process_info *offset;
1168 int *off_count = &sbi->ll_rw_offset_entry_count;
1169 int *process_count = &sbi->ll_offset_process_count;
1170 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1172 if(!sbi->ll_rw_stats_on)
1174 process = sbi->ll_rw_process_info;
1175 offset = sbi->ll_rw_offset_info;
1177 spin_lock(&sbi->ll_pp_extent_lock);
1178 /* Extent statistics */
1179 for(i = 0; i < LL_PROCESS_HIST_MAX; i++) {
1180 if(io_extents->pp_extents[i].pid == pid) {
1188 sbi->ll_extent_process_count =
1189 (sbi->ll_extent_process_count + 1) % LL_PROCESS_HIST_MAX;
1190 cur = sbi->ll_extent_process_count;
1191 io_extents->pp_extents[cur].pid = pid;
1192 lprocfs_oh_clear(&io_extents->pp_extents[cur].pp_r_hist);
1193 lprocfs_oh_clear(&io_extents->pp_extents[cur].pp_w_hist);
1196 for(i = 0; (count >= (1 << LL_HIST_START << i)) &&
1197 (i < (LL_HIST_MAX - 1)); i++);
1199 io_extents->pp_extents[cur].pp_r_hist.oh_buckets[i]++;
1200 io_extents->pp_extents[LL_PROCESS_HIST_MAX].pp_r_hist.oh_buckets[i]++;
1202 io_extents->pp_extents[cur].pp_w_hist.oh_buckets[i]++;
1203 io_extents->pp_extents[LL_PROCESS_HIST_MAX].pp_w_hist.oh_buckets[i]++;
1205 spin_unlock(&sbi->ll_pp_extent_lock);
1207 spin_lock(&sbi->ll_process_lock);
1208 /* Offset statistics */
1209 for (i = 0; i < LL_PROCESS_HIST_MAX; i++) {
1210 if (process[i].rw_pid == pid) {
1211 if (process[i].rw_last_file != file) {
1212 process[i].rw_range_start = file->f_pos;
1213 process[i].rw_last_file_pos =
1214 file->f_pos + count;
1215 process[i].rw_smallest_extent = count;
1216 process[i].rw_largest_extent = count;
1217 process[i].rw_offset = 0;
1218 process[i].rw_last_file = file;
1219 spin_unlock(&sbi->ll_process_lock);
1222 if (process[i].rw_last_file_pos != file->f_pos) {
1224 (*off_count + 1) % LL_OFFSET_HIST_MAX;
1225 offset[*off_count].rw_op = process[i].rw_op;
1226 offset[*off_count].rw_pid = pid;
1227 offset[*off_count].rw_range_start =
1228 process[i].rw_range_start;
1229 offset[*off_count].rw_range_end =
1230 process[i].rw_last_file_pos;
1231 offset[*off_count].rw_smallest_extent =
1232 process[i].rw_smallest_extent;
1233 offset[*off_count].rw_largest_extent =
1234 process[i].rw_largest_extent;
1235 offset[*off_count].rw_offset =
1236 process[i].rw_offset;
1237 process[i].rw_op = rw;
1238 process[i].rw_range_start = file->f_pos;
1239 process[i].rw_smallest_extent = count;
1240 process[i].rw_largest_extent = count;
1241 process[i].rw_offset = file->f_pos -
1242 process[i].rw_last_file_pos;
1244 if(process[i].rw_smallest_extent > count)
1245 process[i].rw_smallest_extent = count;
1246 if(process[i].rw_largest_extent < count)
1247 process[i].rw_largest_extent = count;
1248 process[i].rw_last_file_pos = file->f_pos + count;
1249 spin_unlock(&sbi->ll_process_lock);
1253 *process_count = (*process_count + 1) % LL_PROCESS_HIST_MAX;
1254 process[*process_count].rw_pid = pid;
1255 process[*process_count].rw_op = rw;
1256 process[*process_count].rw_range_start = file->f_pos;
1257 process[*process_count].rw_last_file_pos = file->f_pos + count;
1258 process[*process_count].rw_smallest_extent = count;
1259 process[*process_count].rw_largest_extent = count;
1260 process[*process_count].rw_offset = 0;
1261 process[*process_count].rw_last_file = file;
1262 spin_unlock(&sbi->ll_process_lock);
1265 char lpszt[] = LPSZ;
1267 static int ll_rw_offset_stats_seq_show(struct seq_file *seq, void *v)
1270 struct ll_sb_info *sbi = seq->private;
1271 struct ll_rw_process_info *offset = sbi->ll_rw_offset_info;
1272 struct ll_rw_process_info *process = sbi->ll_rw_process_info;
1276 do_gettimeofday(&now);
1278 if (!sbi->ll_rw_stats_on) {
1279 seq_printf(seq, "Disabled\n"
1280 "Write anything in this file to activate\n");
1283 spin_lock(&sbi->ll_process_lock);
1285 seq_printf(seq, "snapshot_time: %lu.%lu (secs.usecs)\n",
1286 now.tv_sec, now.tv_usec);
1287 seq_printf(seq, "%3s %10s %14s %14s %17s %17s %14s\n",
1288 "R/W", "PID", "RANGE START", "RANGE END",
1289 "SMALLEST EXTENT", "LARGEST EXTENT", "OFFSET");
1290 sprintf(format, "%s%s%s%s%s\n",
1291 "%3c %10d %14Lu %14Lu %17", lpszt+1, " %17", lpszt+1, " %14Ld");
1292 /* We stored the discontiguous offsets here; print them first */
1293 for(i = 0; i < LL_OFFSET_HIST_MAX; i++) {
1294 if (offset[i].rw_pid != 0)
1295 /* Is there a way to snip the '%' off of LPSZ? */
1296 seq_printf(seq, format,
1297 offset[i].rw_op ? 'W' : 'R',
1299 offset[i].rw_range_start,
1300 offset[i].rw_range_end,
1301 offset[i].rw_smallest_extent,
1302 offset[i].rw_largest_extent,
1303 offset[i].rw_offset);
1305 /* Then print the current offsets for each process */
1306 for(i = 0; i < LL_PROCESS_HIST_MAX; i++) {
1307 if (process[i].rw_pid != 0)
1308 seq_printf(seq, format,
1309 process[i].rw_op ? 'W' : 'R',
1311 process[i].rw_range_start,
1312 process[i].rw_last_file_pos,
1313 process[i].rw_smallest_extent,
1314 process[i].rw_largest_extent,
1315 process[i].rw_offset);
1317 spin_unlock(&sbi->ll_process_lock);
1322 static ssize_t ll_rw_offset_stats_seq_write(struct file *file, const char *buf,
1323 size_t len, loff_t *off)
1325 struct seq_file *seq = file->private_data;
1326 struct ll_sb_info *sbi = seq->private;
1327 struct ll_rw_process_info *process_info = sbi->ll_rw_process_info;
1328 struct ll_rw_process_info *offset_info = sbi->ll_rw_offset_info;
1330 sbi->ll_rw_stats_on = 1;
1332 spin_lock(&sbi->ll_process_lock);
1333 sbi->ll_offset_process_count = 0;
1334 sbi->ll_rw_offset_entry_count = 0;
1335 memset(process_info, 0, sizeof(struct ll_rw_process_info) *
1336 LL_PROCESS_HIST_MAX);
1337 memset(offset_info, 0, sizeof(struct ll_rw_process_info) *
1338 LL_OFFSET_HIST_MAX);
1339 spin_unlock(&sbi->ll_process_lock);
1344 LPROC_SEQ_FOPS(ll_rw_offset_stats);
1346 void lprocfs_llite_init_vars(struct lprocfs_static_vars *lvars)
1348 lvars->module_vars = NULL;
1349 lvars->obd_vars = lprocfs_llite_obd_vars;
1351 #endif /* LPROCFS */