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);
53 rc = snprintf(page, count, "%u\n", osfs.os_bsize);
59 static int ll_rd_kbytestotal(char *page, char **start, off_t off, int count,
62 struct super_block *sb = (struct super_block *)data;
63 struct obd_statfs osfs;
67 rc = ll_statfs_internal(sb, &osfs, cfs_time_current_64() - HZ);
69 __u32 blk_size = osfs.os_bsize >> 10;
70 __u64 result = osfs.os_blocks;
72 while (blk_size >>= 1)
76 rc = snprintf(page, count, LPU64"\n", result);
82 static int ll_rd_kbytesfree(char *page, char **start, off_t off, int count,
85 struct super_block *sb = (struct super_block *)data;
86 struct obd_statfs osfs;
90 rc = ll_statfs_internal(sb, &osfs, cfs_time_current_64() - HZ);
92 __u32 blk_size = osfs.os_bsize >> 10;
93 __u64 result = osfs.os_bfree;
95 while (blk_size >>= 1)
99 rc = snprintf(page, count, LPU64"\n", result);
104 static int ll_rd_kbytesavail(char *page, char **start, off_t off, int count,
105 int *eof, void *data)
107 struct super_block *sb = (struct super_block *)data;
108 struct obd_statfs osfs;
112 rc = ll_statfs_internal(sb, &osfs, cfs_time_current_64() - HZ);
114 __u32 blk_size = osfs.os_bsize >> 10;
115 __u64 result = osfs.os_bavail;
117 while (blk_size >>= 1)
121 rc = snprintf(page, count, LPU64"\n", result);
126 static int ll_rd_filestotal(char *page, char **start, off_t off, int count,
127 int *eof, void *data)
129 struct super_block *sb = (struct super_block *)data;
130 struct obd_statfs osfs;
134 rc = ll_statfs_internal(sb, &osfs, cfs_time_current_64() - HZ);
137 rc = snprintf(page, count, LPU64"\n", osfs.os_files);
142 static int ll_rd_filesfree(char *page, char **start, off_t off, int count,
143 int *eof, void *data)
145 struct super_block *sb = (struct super_block *)data;
146 struct obd_statfs osfs;
150 rc = ll_statfs_internal(sb, &osfs, cfs_time_current_64() - HZ);
153 rc = snprintf(page, count, LPU64"\n", osfs.os_ffree);
159 static int ll_rd_fstype(char *page, char **start, off_t off, int count,
160 int *eof, void *data)
162 struct super_block *sb = (struct super_block*)data;
166 return snprintf(page, count, "%s\n", sb->s_type->name);
169 static int ll_rd_sb_uuid(char *page, char **start, off_t off, int count,
170 int *eof, void *data)
172 struct super_block *sb = (struct super_block *)data;
176 return snprintf(page, count, "%s\n", ll_s2sbi(sb)->ll_sb_uuid.uuid);
179 static int ll_rd_max_readahead_mb(char *page, char **start, off_t off,
180 int count, int *eof, void *data)
182 struct super_block *sb = data;
183 struct ll_sb_info *sbi = ll_s2sbi(sb);
187 spin_lock(&sbi->ll_lock);
188 pages_number = sbi->ll_ra_info.ra_max_pages;
189 spin_unlock(&sbi->ll_lock);
191 mult = 1 << (20 - CFS_PAGE_SHIFT);
192 return lprocfs_read_frac_helper(page, count, pages_number, mult);
195 static int ll_wr_max_readahead_mb(struct file *file, const char *buffer,
196 unsigned long count, void *data)
198 struct super_block *sb = data;
199 struct ll_sb_info *sbi = ll_s2sbi(sb);
200 int mult, rc, pages_number;
202 mult = 1 << (20 - CFS_PAGE_SHIFT);
203 rc = lprocfs_write_frac_helper(buffer, count, &pages_number, mult);
207 if (pages_number < 0 || pages_number > num_physpages / 2) {
208 CERROR("can't set file readahead more than %lu MB\n",
209 num_physpages >> (20 - CFS_PAGE_SHIFT + 1)); /*1/2 of RAM*/
213 spin_lock(&sbi->ll_lock);
214 sbi->ll_ra_info.ra_max_pages = pages_number;
215 spin_unlock(&sbi->ll_lock);
220 static int ll_rd_max_read_ahead_whole_mb(char *page, char **start, off_t off,
221 int count, int *eof, void *data)
223 struct super_block *sb = data;
224 struct ll_sb_info *sbi = ll_s2sbi(sb);
228 spin_lock(&sbi->ll_lock);
229 pages_number = sbi->ll_ra_info.ra_max_read_ahead_whole_pages;
230 spin_unlock(&sbi->ll_lock);
232 mult = 1 << (20 - CFS_PAGE_SHIFT);
233 return lprocfs_read_frac_helper(page, count, pages_number, mult);
236 static int ll_wr_max_read_ahead_whole_mb(struct file *file, const char *buffer,
237 unsigned long count, void *data)
239 struct super_block *sb = data;
240 struct ll_sb_info *sbi = ll_s2sbi(sb);
241 int mult, rc, pages_number;
243 mult = 1 << (20 - CFS_PAGE_SHIFT);
244 rc = lprocfs_write_frac_helper(buffer, count, &pages_number, mult);
248 /* Cap this at the current max readahead window size, the readahead
249 * algorithm does this anyway so it's pointless to set it larger. */
250 if (pages_number < 0 || pages_number > sbi->ll_ra_info.ra_max_pages) {
251 CERROR("can't set max_read_ahead_whole_mb more than "
252 "max_read_ahead_mb: %lu\n",
253 sbi->ll_ra_info.ra_max_pages >> (20 - CFS_PAGE_SHIFT));
257 spin_lock(&sbi->ll_lock);
258 sbi->ll_ra_info.ra_max_read_ahead_whole_pages = pages_number;
259 spin_unlock(&sbi->ll_lock);
264 static int ll_rd_max_cached_mb(char *page, char **start, off_t off,
265 int count, int *eof, void *data)
267 struct super_block *sb = data;
268 struct ll_sb_info *sbi = ll_s2sbi(sb);
272 spin_lock(&sbi->ll_lock);
273 pages_number = sbi->ll_async_page_max;
274 spin_unlock(&sbi->ll_lock);
276 mult = 1 << (20 - CFS_PAGE_SHIFT);
277 return lprocfs_read_frac_helper(page, count, pages_number, mult);;
280 static int ll_wr_max_cached_mb(struct file *file, const char *buffer,
281 unsigned long count, void *data)
283 struct super_block *sb = data;
284 struct ll_sb_info *sbi = ll_s2sbi(sb);
285 int mult, rc, pages_number;
287 mult = 1 << (20 - CFS_PAGE_SHIFT);
288 rc = lprocfs_write_frac_helper(buffer, count, &pages_number, mult);
292 if (pages_number < 0 || pages_number > num_physpages) {
293 CERROR("can't set max cache more than %lu MB\n",
294 num_physpages >> (20 - CFS_PAGE_SHIFT));
298 spin_lock(&sbi->ll_lock);
299 sbi->ll_async_page_max = pages_number ;
300 spin_unlock(&sbi->ll_lock);
302 if (!sbi->ll_osc_exp)
303 /* Not set up yet, don't call llap_shrink_cache */
306 if (sbi->ll_async_page_count >= sbi->ll_async_page_max)
307 llap_shrink_cache(sbi, 0);
312 static int ll_rd_checksum(char *page, char **start, off_t off,
313 int count, int *eof, void *data)
315 struct super_block *sb = data;
316 struct ll_sb_info *sbi = ll_s2sbi(sb);
318 return snprintf(page, count, "%u\n",
319 (sbi->ll_flags & LL_SBI_CHECKSUM) ? 1 : 0);
322 static int ll_wr_checksum(struct file *file, const char *buffer,
323 unsigned long count, void *data)
325 struct super_block *sb = data;
326 struct ll_sb_info *sbi = ll_s2sbi(sb);
329 if (!sbi->ll_osc_exp)
333 rc = lprocfs_write_helper(buffer, count, &val);
337 sbi->ll_flags |= LL_SBI_CHECKSUM;
339 sbi->ll_flags &= ~LL_SBI_CHECKSUM;
341 rc = obd_set_info_async(sbi->ll_osc_exp, strlen("checksum"), "checksum",
342 sizeof(val), &val, NULL);
344 CWARN("Failed to set OSC checksum flags: %d\n", rc);
349 static int ll_rd_max_rw_chunk(char *page, char **start, off_t off,
350 int count, int *eof, void *data)
352 struct super_block *sb = data;
354 return snprintf(page, count, "%lu\n", ll_s2sbi(sb)->ll_max_rw_chunk);
357 static int ll_wr_max_rw_chunk(struct file *file, const char *buffer,
358 unsigned long count, void *data)
360 struct super_block *sb = data;
363 rc = lprocfs_write_helper(buffer, count, &val);
366 ll_s2sbi(sb)->ll_max_rw_chunk = val;
370 static int ll_rd_track_id(char *page, int count, void *data,
371 enum stats_track_type type)
373 struct super_block *sb = data;
375 if (ll_s2sbi(sb)->ll_stats_track_type == type) {
376 return snprintf(page, count, "%d\n",
377 ll_s2sbi(sb)->ll_stats_track_id);
379 } else if (ll_s2sbi(sb)->ll_stats_track_type == STATS_TRACK_ALL) {
380 return snprintf(page, count, "0 (all)\n");
382 return snprintf(page, count, "untracked\n");
386 static int ll_wr_track_id(const char *buffer, unsigned long count, void *data,
387 enum stats_track_type type)
389 struct super_block *sb = data;
392 rc = lprocfs_write_helper(buffer, count, &pid);
395 ll_s2sbi(sb)->ll_stats_track_id = pid;
397 ll_s2sbi(sb)->ll_stats_track_type = STATS_TRACK_ALL;
399 ll_s2sbi(sb)->ll_stats_track_type = type;
400 lprocfs_clear_stats(ll_s2sbi(sb)->ll_stats);
404 static int ll_rd_track_pid(char *page, char **start, off_t off,
405 int count, int *eof, void *data)
407 return (ll_rd_track_id(page, count, data, STATS_TRACK_PID));
410 static int ll_wr_track_pid(struct file *file, const char *buffer,
411 unsigned long count, void *data)
413 return (ll_wr_track_id(buffer, count, data, STATS_TRACK_PID));
416 static int ll_rd_track_ppid(char *page, char **start, off_t off,
417 int count, int *eof, void *data)
419 return (ll_rd_track_id(page, count, data, STATS_TRACK_PPID));
422 static int ll_wr_track_ppid(struct file *file, const char *buffer,
423 unsigned long count, void *data)
425 return (ll_wr_track_id(buffer, count, data, STATS_TRACK_PPID));
428 static int ll_rd_track_gid(char *page, char **start, off_t off,
429 int count, int *eof, void *data)
431 return (ll_rd_track_id(page, count, data, STATS_TRACK_GID));
434 static int ll_wr_track_gid(struct file *file, const char *buffer,
435 unsigned long count, void *data)
437 return (ll_wr_track_id(buffer, count, data, STATS_TRACK_GID));
440 static struct lprocfs_vars lprocfs_obd_vars[] = {
441 { "uuid", ll_rd_sb_uuid, 0, 0 },
442 //{ "mntpt_path", ll_rd_path, 0, 0 },
443 { "fstype", ll_rd_fstype, 0, 0 },
444 { "blocksize", ll_rd_blksize, 0, 0 },
445 { "kbytestotal", ll_rd_kbytestotal, 0, 0 },
446 { "kbytesfree", ll_rd_kbytesfree, 0, 0 },
447 { "kbytesavail", ll_rd_kbytesavail, 0, 0 },
448 { "filestotal", ll_rd_filestotal, 0, 0 },
449 { "filesfree", ll_rd_filesfree, 0, 0 },
450 //{ "filegroups", lprocfs_rd_filegroups, 0, 0 },
451 { "max_read_ahead_mb", ll_rd_max_readahead_mb,
452 ll_wr_max_readahead_mb, 0 },
453 { "max_read_ahead_whole_mb", ll_rd_max_read_ahead_whole_mb,
454 ll_wr_max_read_ahead_whole_mb, 0 },
455 { "max_cached_mb", ll_rd_max_cached_mb, ll_wr_max_cached_mb, 0 },
456 { "checksum_pages", ll_rd_checksum, ll_wr_checksum, 0 },
457 { "max_rw_chunk", ll_rd_max_rw_chunk, ll_wr_max_rw_chunk, 0 },
458 { "stats_track_pid", ll_rd_track_pid, ll_wr_track_pid, 0 },
459 { "stats_track_ppid", ll_rd_track_ppid, ll_wr_track_ppid, 0 },
460 { "stats_track_gid", ll_rd_track_gid, ll_wr_track_gid, 0 },
464 #define MAX_STRING_SIZE 128
466 struct llite_file_opcode {
470 } llite_opcode_table[LPROC_LL_FILE_OPCODES] = {
472 { LPROC_LL_DIRTY_HITS, LPROCFS_TYPE_REGS, "dirty_pages_hits" },
473 { LPROC_LL_DIRTY_MISSES, LPROCFS_TYPE_REGS, "dirty_pages_misses" },
474 { LPROC_LL_WB_WRITEPAGE, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
475 "writeback_from_writepage" },
476 { LPROC_LL_WB_PRESSURE, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
477 "writeback_from_pressure" },
478 { LPROC_LL_WB_OK, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
479 "writeback_ok_pages" },
480 { LPROC_LL_WB_FAIL, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
481 "writeback_failed_pages" },
482 { LPROC_LL_READ_BYTES, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_BYTES,
484 { LPROC_LL_WRITE_BYTES, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_BYTES,
486 { LPROC_LL_BRW_READ, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
488 { LPROC_LL_BRW_WRITE, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
491 { LPROC_LL_IOCTL, LPROCFS_TYPE_REGS, "ioctl" },
492 { LPROC_LL_OPEN, LPROCFS_TYPE_REGS, "open" },
493 { LPROC_LL_RELEASE, LPROCFS_TYPE_REGS, "close" },
494 { LPROC_LL_MAP, LPROCFS_TYPE_REGS, "mmap" },
495 { LPROC_LL_LLSEEK, LPROCFS_TYPE_REGS, "seek" },
496 { LPROC_LL_FSYNC, LPROCFS_TYPE_REGS, "fsync" },
497 /* inode operation */
498 { LPROC_LL_SETATTR, LPROCFS_TYPE_REGS, "setattr" },
499 { LPROC_LL_TRUNC, LPROCFS_TYPE_REGS, "truncate" },
500 { LPROC_LL_FLOCK, LPROCFS_TYPE_REGS, "flock" },
501 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
502 { LPROC_LL_GETATTR, LPROCFS_TYPE_REGS, "getattr" },
504 { LPROC_LL_REVALIDATE, LPROCFS_TYPE_REGS, "getattr" },
506 /* special inode operation */
507 { LPROC_LL_STAFS, LPROCFS_TYPE_REGS, "statfs" },
508 { LPROC_LL_ALLOC_INODE, LPROCFS_TYPE_REGS, "alloc_inode" },
509 { LPROC_LL_SETXATTR, LPROCFS_TYPE_REGS, "setxattr" },
510 { LPROC_LL_GETXATTR, LPROCFS_TYPE_REGS, "getxattr" },
511 { LPROC_LL_LISTXATTR, LPROCFS_TYPE_REGS, "listxattr" },
512 { LPROC_LL_REMOVEXATTR, LPROCFS_TYPE_REGS, "removexattr" },
513 { LPROC_LL_INODE_PERM, LPROCFS_TYPE_REGS, "inode_permission" },
514 { LPROC_LL_DIRECT_READ, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
516 { LPROC_LL_DIRECT_WRITE, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
521 void ll_stats_ops_tally(struct ll_sb_info *sbi, int op, int count)
525 if (sbi->ll_stats_track_type == STATS_TRACK_ALL)
526 lprocfs_counter_add(sbi->ll_stats, op, count);
527 else if (sbi->ll_stats_track_type == STATS_TRACK_PID &&
528 sbi->ll_stats_track_id == current->pid)
529 lprocfs_counter_add(sbi->ll_stats, op, count);
530 else if (sbi->ll_stats_track_type == STATS_TRACK_PPID &&
531 sbi->ll_stats_track_id == current->p_pptr->pid)
532 lprocfs_counter_add(sbi->ll_stats, op, count);
533 else if (sbi->ll_stats_track_type == STATS_TRACK_GID &&
534 sbi->ll_stats_track_id == current->gid)
535 lprocfs_counter_add(sbi->ll_stats, op, count);
538 int lprocfs_register_mountpoint(struct proc_dir_entry *parent,
539 struct super_block *sb, char *osc, char *mdc)
541 struct lprocfs_vars lvars[2];
542 struct lustre_sb_info *lsi = s2lsi(sb);
543 struct ll_sb_info *sbi = ll_s2sbi(sb);
544 struct obd_device *obd;
545 char name[MAX_STRING_SIZE + 1], *ptr;
547 struct proc_dir_entry *entry;
550 memset(lvars, 0, sizeof(lvars));
552 name[MAX_STRING_SIZE] = '\0';
553 lvars[0].name = name;
555 LASSERT(sbi != NULL);
556 LASSERT(mdc != NULL);
557 LASSERT(osc != NULL);
560 len = strlen(lsi->lsi_lmd->lmd_profile);
561 ptr = strrchr(lsi->lsi_lmd->lmd_profile, '-');
562 if (ptr && (strcmp(ptr, "-client") == 0))
566 snprintf(name, MAX_STRING_SIZE, "%.*s-%p", len,
567 lsi->lsi_lmd->lmd_profile, sb);
569 sbi->ll_proc_root = lprocfs_register(name, parent, NULL, NULL);
570 if (IS_ERR(sbi->ll_proc_root)) {
571 err = PTR_ERR(sbi->ll_proc_root);
572 sbi->ll_proc_root = NULL;
576 entry = create_proc_entry("dump_page_cache", 0444, sbi->ll_proc_root);
578 GOTO(out, err = -ENOMEM);
579 entry->proc_fops = &llite_dump_pgcache_fops;
582 entry = create_proc_entry("read_ahead_stats", 0644, sbi->ll_proc_root);
584 GOTO(out, err = -ENOMEM);
585 entry->proc_fops = &ll_ra_stats_fops;
588 entry = create_proc_entry("extents_stats", 0644, sbi->ll_proc_root);
590 GOTO(out, err = -ENOMEM);
591 entry->proc_fops = &ll_rw_extents_stats_fops;
594 entry = create_proc_entry("extents_stats_per_process", 0644,
597 GOTO(out, err = -ENOMEM);
598 entry->proc_fops = &ll_rw_extents_stats_pp_fops;
601 entry = create_proc_entry("offset_stats", 0644, sbi->ll_proc_root);
603 GOTO(out, err = -ENOMEM);
604 entry->proc_fops = &ll_rw_offset_stats_fops;
607 /* File operations stats */
608 sbi->ll_stats = lprocfs_alloc_stats(LPROC_LL_FILE_OPCODES);
609 if (sbi->ll_stats == NULL)
610 GOTO(out, err = -ENOMEM);
611 /* do counter init */
612 for (id = 0; id < LPROC_LL_FILE_OPCODES; id++) {
613 __u32 type = llite_opcode_table[id].type;
615 if (type & LPROCFS_TYPE_REGS)
617 else if (type & LPROCFS_TYPE_BYTES)
619 else if (type & LPROCFS_TYPE_PAGES)
621 lprocfs_counter_init(sbi->ll_stats,
622 llite_opcode_table[id].opcode,
623 (type & LPROCFS_CNTR_AVGMINMAX),
624 llite_opcode_table[id].opname, ptr);
626 err = lprocfs_register_stats(sbi->ll_proc_root, "stats", sbi->ll_stats);
630 err = lprocfs_add_vars(sbi->ll_proc_root, lprocfs_obd_vars, sb);
635 obd = class_name2obd(mdc);
637 LASSERT(obd != NULL);
638 LASSERT(obd->obd_magic == OBD_DEVICE_MAGIC);
639 LASSERT(obd->obd_type->typ_name != NULL);
641 snprintf(name, MAX_STRING_SIZE, "%s/common_name",
642 obd->obd_type->typ_name);
643 lvars[0].read_fptr = lprocfs_rd_name;
644 err = lprocfs_add_vars(sbi->ll_proc_root, lvars, obd);
648 snprintf(name, MAX_STRING_SIZE, "%s/uuid", obd->obd_type->typ_name);
649 lvars[0].read_fptr = lprocfs_rd_uuid;
650 err = lprocfs_add_vars(sbi->ll_proc_root, lvars, obd);
655 obd = class_name2obd(osc);
657 LASSERT(obd != NULL);
658 LASSERT(obd->obd_magic == OBD_DEVICE_MAGIC);
659 LASSERT(obd->obd_type->typ_name != NULL);
661 snprintf(name, MAX_STRING_SIZE, "%s/common_name",
662 obd->obd_type->typ_name);
663 lvars[0].read_fptr = lprocfs_rd_name;
664 err = lprocfs_add_vars(sbi->ll_proc_root, lvars, obd);
668 snprintf(name, MAX_STRING_SIZE, "%s/uuid", obd->obd_type->typ_name);
669 lvars[0].read_fptr = lprocfs_rd_uuid;
670 err = lprocfs_add_vars(sbi->ll_proc_root, lvars, obd);
673 lprocfs_remove(&sbi->ll_proc_root);
674 lprocfs_free_stats(&sbi->ll_stats);
679 void lprocfs_unregister_mountpoint(struct ll_sb_info *sbi)
681 if (sbi->ll_proc_root) {
682 lprocfs_remove(&sbi->ll_proc_root);
683 lprocfs_free_stats(&sbi->ll_stats);
686 #undef MAX_STRING_SIZE
688 #define seq_page_flag(seq, page, flag, has_flags) do { \
689 if (test_bit(PG_##flag, &(page)->flags)) { \
693 seq_putc(seq, '|'); \
694 seq_puts(seq, #flag); \
698 static void *llite_dump_pgcache_seq_start(struct seq_file *seq, loff_t *pos)
700 struct ll_async_page *dummy_llap = seq->private;
702 if (dummy_llap->llap_magic == 2)
708 static int llite_dump_pgcache_seq_show(struct seq_file *seq, void *v)
710 struct ll_async_page *llap, *dummy_llap = seq->private;
711 struct ll_sb_info *sbi = dummy_llap->llap_cookie;
713 /* 2.4 doesn't seem to have SEQ_START_TOKEN, so we implement
714 * it in our own state */
715 if (dummy_llap->llap_magic == 0) {
716 seq_printf(seq, "gener | llap cookie origin wq du wb | page "
717 "inode index count [ page flags ]\n");
721 spin_lock(&sbi->ll_lock);
723 llap = llite_pglist_next_llap(sbi, &dummy_llap->llap_pglist_item);
726 struct page *page = llap->llap_page;
728 LASSERTF(llap->llap_origin < LLAP__ORIGIN_MAX, "%u\n",
731 seq_printf(seq," %5lu | %p %p %s %s %s %s | %p %lu/%u(%p) "
734 llap, llap->llap_cookie,
735 llap_origins[llap->llap_origin],
736 llap->llap_write_queued ? "wq" : "- ",
737 llap->llap_defer_uptodate ? "du" : "- ",
738 PageWriteback(page) ? "wb" : "-",
739 page, page->mapping->host->i_ino,
740 page->mapping->host->i_generation,
741 page->mapping->host, page->index,
743 seq_page_flag(seq, page, locked, has_flags);
744 seq_page_flag(seq, page, error, has_flags);
745 seq_page_flag(seq, page, referenced, has_flags);
746 seq_page_flag(seq, page, uptodate, has_flags);
747 seq_page_flag(seq, page, dirty, has_flags);
748 #if (LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,12))
749 seq_page_flag(seq, page, highmem, has_flags);
751 seq_page_flag(seq, page, writeback, has_flags);
753 seq_puts(seq, "-]\n");
755 seq_puts(seq, "]\n");
758 spin_unlock(&sbi->ll_lock);
763 static void *llite_dump_pgcache_seq_next(struct seq_file *seq, void *v,
766 struct ll_async_page *llap, *dummy_llap = seq->private;
767 struct ll_sb_info *sbi = dummy_llap->llap_cookie;
769 /* bail if we just displayed the banner */
770 if (dummy_llap->llap_magic == 0) {
771 dummy_llap->llap_magic = 1;
775 /* we've just displayed the llap that is after us in the list.
776 * we advance to a position beyond it, returning null if there
777 * isn't another llap in the list beyond that new position. */
778 spin_lock(&sbi->ll_lock);
779 llap = llite_pglist_next_llap(sbi, &dummy_llap->llap_pglist_item);
780 list_del_init(&dummy_llap->llap_pglist_item);
782 list_add(&dummy_llap->llap_pglist_item,&llap->llap_pglist_item);
783 llap =llite_pglist_next_llap(sbi,&dummy_llap->llap_pglist_item);
785 spin_unlock(&sbi->ll_lock);
789 dummy_llap->llap_magic = 2;
795 static void null_stop(struct seq_file *seq, void *v)
799 struct seq_operations llite_dump_pgcache_seq_sops = {
800 .start = llite_dump_pgcache_seq_start,
802 .next = llite_dump_pgcache_seq_next,
803 .show = llite_dump_pgcache_seq_show,
806 /* we're displaying llaps in a list_head list. we don't want to hold a lock
807 * while we walk the entire list, and we don't want to have to seek into
808 * the right position in the list as an app advances with many syscalls. we
809 * allocate a dummy llap and hang it off file->private. its position in
810 * the list records where the app is currently displaying. this way our
811 * seq .start and .stop don't actually do anything. .next returns null
812 * when the dummy hits the end of the list which eventually leads to .release
813 * where we tear down. this kind of displaying is super-racey, so we put
814 * a generation counter on the list so the output shows when the list
815 * changes between reads.
817 static int llite_dump_pgcache_seq_open(struct inode *inode, struct file *file)
819 struct proc_dir_entry *dp = PDE(inode);
820 struct ll_async_page *dummy_llap;
821 struct seq_file *seq;
822 struct ll_sb_info *sbi = dp->data;
825 LPROCFS_ENTRY_AND_CHECK(dp);
827 OBD_ALLOC_PTR_WAIT(dummy_llap);
828 if (dummy_llap == NULL)
831 dummy_llap->llap_page = NULL;
832 dummy_llap->llap_cookie = sbi;
833 dummy_llap->llap_magic = 0;
835 rc = seq_open(file, &llite_dump_pgcache_seq_sops);
837 OBD_FREE(dummy_llap, sizeof(*dummy_llap));
840 seq = file->private_data;
841 seq->private = dummy_llap;
843 spin_lock(&sbi->ll_lock);
844 list_add(&dummy_llap->llap_pglist_item, &sbi->ll_pglist);
845 spin_unlock(&sbi->ll_lock);
853 static int llite_dump_pgcache_seq_release(struct inode *inode,
856 struct seq_file *seq = file->private_data;
857 struct ll_async_page *dummy_llap = seq->private;
858 struct ll_sb_info *sbi = dummy_llap->llap_cookie;
860 spin_lock(&sbi->ll_lock);
861 if (!list_empty(&dummy_llap->llap_pglist_item))
862 list_del_init(&dummy_llap->llap_pglist_item);
863 spin_unlock(&sbi->ll_lock);
864 OBD_FREE(dummy_llap, sizeof(*dummy_llap));
866 return lprocfs_seq_release(inode, file);
869 struct file_operations llite_dump_pgcache_fops = {
870 .owner = THIS_MODULE,
871 .open = llite_dump_pgcache_seq_open,
873 .release = llite_dump_pgcache_seq_release,
876 static int ll_ra_stats_seq_show(struct seq_file *seq, void *v)
879 struct ll_sb_info *sbi = seq->private;
880 struct ll_ra_info *ra = &sbi->ll_ra_info;
882 static char *ra_stat_strings[] = {
883 [RA_STAT_HIT] = "hits",
884 [RA_STAT_MISS] = "misses",
885 [RA_STAT_DISTANT_READPAGE] = "readpage not consecutive",
886 [RA_STAT_MISS_IN_WINDOW] = "miss inside window",
887 [RA_STAT_FAILED_GRAB_PAGE] = "failed grab_cache_page",
888 [RA_STAT_FAILED_MATCH] = "failed lock match",
889 [RA_STAT_DISCARDED] = "read but discarded",
890 [RA_STAT_ZERO_LEN] = "zero length file",
891 [RA_STAT_ZERO_WINDOW] = "zero size window",
892 [RA_STAT_EOF] = "read-ahead to EOF",
893 [RA_STAT_MAX_IN_FLIGHT] = "hit max r-a issue",
894 [RA_STAT_WRONG_GRAB_PAGE] = "wrong page from grab_cache_page",
897 do_gettimeofday(&now);
899 spin_lock(&sbi->ll_lock);
901 seq_printf(seq, "snapshot_time: %lu.%lu (secs.usecs)\n",
902 now.tv_sec, now.tv_usec);
903 seq_printf(seq, "pending issued pages: %lu\n",
906 for(i = 0; i < _NR_RA_STAT; i++)
907 seq_printf(seq, "%-25s %lu\n", ra_stat_strings[i],
910 spin_unlock(&sbi->ll_lock);
915 static ssize_t ll_ra_stats_seq_write(struct file *file, const char *buf,
916 size_t len, loff_t *off)
918 struct seq_file *seq = file->private_data;
919 struct ll_sb_info *sbi = seq->private;
920 struct ll_ra_info *ra = &sbi->ll_ra_info;
922 spin_lock(&sbi->ll_lock);
923 memset(ra->ra_stats, 0, sizeof(ra->ra_stats));
924 spin_unlock(&sbi->ll_lock);
929 LPROC_SEQ_FOPS(ll_ra_stats);
931 #define pct(a,b) (b ? a * 100 / b : 0)
933 static void ll_display_extents_info(struct ll_rw_extents_info *io_extents,
934 struct seq_file *seq, int which)
936 unsigned long read_tot = 0, write_tot = 0, read_cum, write_cum;
937 unsigned long start, end, r, w;
938 char *unitp = "KMGTPEZY";
940 struct per_process_info *pp_info = &io_extents->pp_extents[which];
946 for(i = 0; i < LL_HIST_MAX; i++) {
947 read_tot += pp_info->pp_r_hist.oh_buckets[i];
948 write_tot += pp_info->pp_w_hist.oh_buckets[i];
951 for(i = 0; i < LL_HIST_MAX; i++) {
952 r = pp_info->pp_r_hist.oh_buckets[i];
953 w = pp_info->pp_w_hist.oh_buckets[i];
956 end = 1 << (i + LL_HIST_START - units);
957 seq_printf(seq, "%4lu%c - %4lu%c%c: %14lu %4lu %4lu | "
958 "%14lu %4lu %4lu\n", start, *unitp, end, *unitp,
959 (i == LL_HIST_MAX - 1) ? '+' : ' ',
960 r, pct(r, read_tot), pct(read_cum, read_tot),
961 w, pct(w, write_tot), pct(write_cum, write_tot));
963 if (start == 1<<10) {
968 if (read_cum == read_tot && write_cum == write_tot)
973 static int ll_rw_extents_stats_pp_seq_show(struct seq_file *seq, void *v)
976 struct ll_sb_info *sbi = seq->private;
977 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
980 do_gettimeofday(&now);
982 if (!sbi->ll_rw_stats_on) {
983 seq_printf(seq, "Disabled\n"
984 "Write anything in this file to activate\n");
987 seq_printf(seq, "snapshot_time: %lu.%lu (secs.usecs)\n",
988 now.tv_sec, now.tv_usec);
989 seq_printf(seq, "%15s %19s | %20s\n", " ", "read", "write");
990 seq_printf(seq, "%13s %14s %4s %4s | %14s %4s %4s\n",
991 "extents", "calls", "%", "cum%",
992 "calls", "%", "cum%");
993 spin_lock(&sbi->ll_pp_extent_lock);
994 for(k = 0; k < LL_PROCESS_HIST_MAX; k++) {
995 if(io_extents->pp_extents[k].pid != 0) {
996 seq_printf(seq, "\nPID: %d\n",
997 io_extents->pp_extents[k].pid);
998 ll_display_extents_info(io_extents, seq, k);
1001 spin_unlock(&sbi->ll_pp_extent_lock);
1005 static ssize_t ll_rw_extents_stats_pp_seq_write(struct file *file,
1006 const char *buf, size_t len,
1009 struct seq_file *seq = file->private_data;
1010 struct ll_sb_info *sbi = seq->private;
1011 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1014 sbi->ll_rw_stats_on = 1;
1015 spin_lock(&sbi->ll_pp_extent_lock);
1016 for(i = 0; i < LL_PROCESS_HIST_MAX; i++) {
1017 io_extents->pp_extents[i].pid = 0;
1018 lprocfs_oh_clear(&io_extents->pp_extents[i].pp_r_hist);
1019 lprocfs_oh_clear(&io_extents->pp_extents[i].pp_w_hist);
1021 spin_unlock(&sbi->ll_pp_extent_lock);
1025 LPROC_SEQ_FOPS(ll_rw_extents_stats_pp);
1027 static int ll_rw_extents_stats_seq_show(struct seq_file *seq, void *v)
1030 struct ll_sb_info *sbi = seq->private;
1031 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1033 do_gettimeofday(&now);
1035 if (!sbi->ll_rw_stats_on) {
1036 seq_printf(seq, "Disabled\n"
1037 "Write anything in this file to activate\n");
1040 seq_printf(seq, "snapshot_time: %lu.%lu (secs.usecs)\n",
1041 now.tv_sec, now.tv_usec);
1043 seq_printf(seq, "%15s %19s | %20s\n", " ", "read", "write");
1044 seq_printf(seq, "%13s %14s %4s %4s | %14s %4s %4s\n",
1045 "extents", "calls", "%", "cum%",
1046 "calls", "%", "cum%");
1047 spin_lock(&sbi->ll_lock);
1048 ll_display_extents_info(io_extents, seq, LL_PROCESS_HIST_MAX);
1049 spin_unlock(&sbi->ll_lock);
1054 static ssize_t ll_rw_extents_stats_seq_write(struct file *file, const char *buf,
1055 size_t len, loff_t *off)
1057 struct seq_file *seq = file->private_data;
1058 struct ll_sb_info *sbi = seq->private;
1059 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1062 sbi->ll_rw_stats_on = 1;
1063 spin_lock(&sbi->ll_pp_extent_lock);
1064 for(i = 0; i <= LL_PROCESS_HIST_MAX; i++)
1066 io_extents->pp_extents[i].pid = 0;
1067 lprocfs_oh_clear(&io_extents->pp_extents[i].pp_r_hist);
1068 lprocfs_oh_clear(&io_extents->pp_extents[i].pp_w_hist);
1070 spin_unlock(&sbi->ll_pp_extent_lock);
1075 LPROC_SEQ_FOPS(ll_rw_extents_stats);
1077 void ll_rw_stats_tally(struct ll_sb_info *sbi, pid_t pid, struct file
1078 *file, size_t count, int rw)
1081 struct ll_rw_process_info *process;
1082 struct ll_rw_process_info *offset;
1083 int *off_count = &sbi->ll_rw_offset_entry_count;
1084 int *process_count = &sbi->ll_offset_process_count;
1085 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1087 if(!sbi->ll_rw_stats_on)
1089 process = sbi->ll_rw_process_info;
1090 offset = sbi->ll_rw_offset_info;
1092 spin_lock(&sbi->ll_pp_extent_lock);
1093 /* Extent statistics */
1094 for(i = 0; i < LL_PROCESS_HIST_MAX; i++) {
1095 if(io_extents->pp_extents[i].pid == pid) {
1103 sbi->ll_extent_process_count =
1104 (sbi->ll_extent_process_count + 1) % LL_PROCESS_HIST_MAX;
1105 cur = sbi->ll_extent_process_count;
1106 io_extents->pp_extents[cur].pid = pid;
1107 lprocfs_oh_clear(&io_extents->pp_extents[cur].pp_r_hist);
1108 lprocfs_oh_clear(&io_extents->pp_extents[cur].pp_w_hist);
1111 for(i = 0; (count >= (1 << LL_HIST_START << i)) &&
1112 (i < (LL_HIST_MAX - 1)); i++);
1114 io_extents->pp_extents[cur].pp_r_hist.oh_buckets[i]++;
1115 io_extents->pp_extents[LL_PROCESS_HIST_MAX].pp_r_hist.oh_buckets[i]++;
1117 io_extents->pp_extents[cur].pp_w_hist.oh_buckets[i]++;
1118 io_extents->pp_extents[LL_PROCESS_HIST_MAX].pp_w_hist.oh_buckets[i]++;
1120 spin_unlock(&sbi->ll_pp_extent_lock);
1122 spin_lock(&sbi->ll_process_lock);
1123 /* Offset statistics */
1124 for (i = 0; i < LL_PROCESS_HIST_MAX; i++) {
1125 if (process[i].rw_pid == pid) {
1126 if (process[i].rw_last_file != file) {
1127 process[i].rw_range_start = file->f_pos;
1128 process[i].rw_last_file_pos =
1129 file->f_pos + count;
1130 process[i].rw_smallest_extent = count;
1131 process[i].rw_largest_extent = count;
1132 process[i].rw_offset = 0;
1133 process[i].rw_last_file = file;
1134 spin_unlock(&sbi->ll_process_lock);
1137 if (process[i].rw_last_file_pos != file->f_pos) {
1139 (*off_count + 1) % LL_OFFSET_HIST_MAX;
1140 offset[*off_count].rw_op = process[i].rw_op;
1141 offset[*off_count].rw_pid = pid;
1142 offset[*off_count].rw_range_start =
1143 process[i].rw_range_start;
1144 offset[*off_count].rw_range_end =
1145 process[i].rw_last_file_pos;
1146 offset[*off_count].rw_smallest_extent =
1147 process[i].rw_smallest_extent;
1148 offset[*off_count].rw_largest_extent =
1149 process[i].rw_largest_extent;
1150 offset[*off_count].rw_offset =
1151 process[i].rw_offset;
1152 process[i].rw_op = rw;
1153 process[i].rw_range_start = file->f_pos;
1154 process[i].rw_smallest_extent = count;
1155 process[i].rw_largest_extent = count;
1156 process[i].rw_offset = file->f_pos -
1157 process[i].rw_last_file_pos;
1159 if(process[i].rw_smallest_extent > count)
1160 process[i].rw_smallest_extent = count;
1161 if(process[i].rw_largest_extent < count)
1162 process[i].rw_largest_extent = count;
1163 process[i].rw_last_file_pos = file->f_pos + count;
1164 spin_unlock(&sbi->ll_process_lock);
1168 *process_count = (*process_count + 1) % LL_PROCESS_HIST_MAX;
1169 process[*process_count].rw_pid = pid;
1170 process[*process_count].rw_op = rw;
1171 process[*process_count].rw_range_start = file->f_pos;
1172 process[*process_count].rw_last_file_pos = file->f_pos + count;
1173 process[*process_count].rw_smallest_extent = count;
1174 process[*process_count].rw_largest_extent = count;
1175 process[*process_count].rw_offset = 0;
1176 process[*process_count].rw_last_file = file;
1177 spin_unlock(&sbi->ll_process_lock);
1180 char lpszt[] = LPSZ;
1182 static int ll_rw_offset_stats_seq_show(struct seq_file *seq, void *v)
1185 struct ll_sb_info *sbi = seq->private;
1186 struct ll_rw_process_info *offset = sbi->ll_rw_offset_info;
1187 struct ll_rw_process_info *process = sbi->ll_rw_process_info;
1191 do_gettimeofday(&now);
1193 if (!sbi->ll_rw_stats_on) {
1194 seq_printf(seq, "Disabled\n"
1195 "Write anything in this file to activate\n");
1198 spin_lock(&sbi->ll_process_lock);
1200 seq_printf(seq, "snapshot_time: %lu.%lu (secs.usecs)\n",
1201 now.tv_sec, now.tv_usec);
1202 seq_printf(seq, "%3s %10s %14s %14s %17s %17s %14s\n",
1203 "R/W", "PID", "RANGE START", "RANGE END",
1204 "SMALLEST EXTENT", "LARGEST EXTENT", "OFFSET");
1205 sprintf(format, "%s%s%s%s%s\n",
1206 "%3c %10d %14Lu %14Lu %17", lpszt+1, " %17", lpszt+1, " %14Ld");
1207 /* We stored the discontiguous offsets here; print them first */
1208 for(i = 0; i < LL_OFFSET_HIST_MAX; i++) {
1209 if (offset[i].rw_pid != 0)
1210 /* Is there a way to snip the '%' off of LPSZ? */
1211 seq_printf(seq, format,
1212 offset[i].rw_op ? 'W' : 'R',
1214 offset[i].rw_range_start,
1215 offset[i].rw_range_end,
1216 offset[i].rw_smallest_extent,
1217 offset[i].rw_largest_extent,
1218 offset[i].rw_offset);
1220 /* Then print the current offsets for each process */
1221 for(i = 0; i < LL_PROCESS_HIST_MAX; i++) {
1222 if (process[i].rw_pid != 0)
1223 seq_printf(seq, format,
1224 process[i].rw_op ? 'W' : 'R',
1226 process[i].rw_range_start,
1227 process[i].rw_last_file_pos,
1228 process[i].rw_smallest_extent,
1229 process[i].rw_largest_extent,
1230 process[i].rw_offset);
1232 spin_unlock(&sbi->ll_process_lock);
1237 static ssize_t ll_rw_offset_stats_seq_write(struct file *file, const char *buf,
1238 size_t len, loff_t *off)
1240 struct seq_file *seq = file->private_data;
1241 struct ll_sb_info *sbi = seq->private;
1242 struct ll_rw_process_info *process_info = sbi->ll_rw_process_info;
1243 struct ll_rw_process_info *offset_info = sbi->ll_rw_offset_info;
1245 sbi->ll_rw_stats_on = 1;
1247 spin_lock(&sbi->ll_process_lock);
1248 sbi->ll_offset_process_count = 0;
1249 sbi->ll_rw_offset_entry_count = 0;
1250 memset(process_info, 0, sizeof(struct ll_rw_process_info) *
1251 LL_PROCESS_HIST_MAX);
1252 memset(offset_info, 0, sizeof(struct ll_rw_process_info) *
1253 LL_OFFSET_HIST_MAX);
1254 spin_unlock(&sbi->ll_process_lock);
1259 LPROC_SEQ_FOPS(ll_rw_offset_stats);
1261 LPROCFS_INIT_VARS(llite, NULL, lprocfs_obd_vars)
1262 #endif /* LPROCFS */