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_client_type(char *page, char **start, off_t off, int count,
160 int *eof, void *data)
162 struct ll_sb_info *sbi = ll_s2sbi((struct super_block *)data);
165 LASSERT(sbi != NULL);
168 if (sbi->ll_flags & LL_SBI_RMT_CLIENT)
169 rc = snprintf(page, count, "remote client\n");
171 rc = snprintf(page, count, "local client\n");
176 static int ll_rd_fstype(char *page, char **start, off_t off, int count,
177 int *eof, void *data)
179 struct super_block *sb = (struct super_block*)data;
183 return snprintf(page, count, "%s\n", sb->s_type->name);
186 static int ll_rd_sb_uuid(char *page, char **start, off_t off, int count,
187 int *eof, void *data)
189 struct super_block *sb = (struct super_block *)data;
193 return snprintf(page, count, "%s\n", ll_s2sbi(sb)->ll_sb_uuid.uuid);
196 static int ll_rd_max_readahead_mb(char *page, char **start, off_t off,
197 int count, int *eof, void *data)
199 struct super_block *sb = data;
200 struct ll_sb_info *sbi = ll_s2sbi(sb);
204 spin_lock(&sbi->ll_lock);
205 pages_number = sbi->ll_ra_info.ra_max_pages;
206 spin_unlock(&sbi->ll_lock);
208 mult = 1 << (20 - PAGE_CACHE_SHIFT);
209 return lprocfs_read_frac_helper(page, count, pages_number, mult);
212 static int ll_wr_max_readahead_mb(struct file *file, const char *buffer,
213 unsigned long count, void *data)
215 struct super_block *sb = data;
216 struct ll_sb_info *sbi = ll_s2sbi(sb);
217 int mult, rc, pages_number;
219 mult = 1 << (20 - CFS_PAGE_SHIFT);
220 rc = lprocfs_write_frac_helper(buffer, count, &pages_number, mult);
224 if (pages_number < 0 || pages_number > num_physpages / 2) {
225 CERROR("can't set file readahead more than %lu MB\n",
226 num_physpages >> (20 - CFS_PAGE_SHIFT + 1)); /*1/2 of RAM*/
230 spin_lock(&sbi->ll_lock);
231 sbi->ll_ra_info.ra_max_pages = pages_number;
232 spin_unlock(&sbi->ll_lock);
237 static int ll_rd_max_read_ahead_whole_mb(char *page, char **start, off_t off,
238 int count, int *eof, void *data)
240 struct super_block *sb = data;
241 struct ll_sb_info *sbi = ll_s2sbi(sb);
245 spin_lock(&sbi->ll_lock);
246 pages_number = sbi->ll_ra_info.ra_max_read_ahead_whole_pages;
247 spin_unlock(&sbi->ll_lock);
249 mult = 1 << (20 - CFS_PAGE_SHIFT);
250 return lprocfs_read_frac_helper(page, count, pages_number, mult);
253 static int ll_wr_max_read_ahead_whole_mb(struct file *file, const char *buffer,
254 unsigned long count, void *data)
256 struct super_block *sb = data;
257 struct ll_sb_info *sbi = ll_s2sbi(sb);
258 int mult, rc, pages_number;
260 mult = 1 << (20 - CFS_PAGE_SHIFT);
261 rc = lprocfs_write_frac_helper(buffer, count, &pages_number, mult);
265 /* Cap this at the current max readahead window size, the readahead
266 * algorithm does this anyway so it's pointless to set it larger. */
267 if (pages_number < 0 || pages_number > sbi->ll_ra_info.ra_max_pages) {
268 CERROR("can't set max_read_ahead_whole_mb more than "
269 "max_read_ahead_mb: %lu\n",
270 sbi->ll_ra_info.ra_max_pages >> (20 - CFS_PAGE_SHIFT));
274 spin_lock(&sbi->ll_lock);
275 sbi->ll_ra_info.ra_max_read_ahead_whole_pages = pages_number;
276 spin_unlock(&sbi->ll_lock);
281 static int ll_rd_max_cached_mb(char *page, char **start, off_t off,
282 int count, int *eof, void *data)
284 struct super_block *sb = data;
285 struct ll_sb_info *sbi = ll_s2sbi(sb);
289 spin_lock(&sbi->ll_lock);
290 pages_number = sbi->ll_async_page_max;
291 spin_unlock(&sbi->ll_lock);
293 mult = 1 << (20 - CFS_PAGE_SHIFT);
294 return lprocfs_read_frac_helper(page, count, pages_number, mult);;
297 static int ll_wr_max_cached_mb(struct file *file, const char *buffer,
298 unsigned long count, void *data)
300 struct super_block *sb = data;
301 struct ll_sb_info *sbi = ll_s2sbi(sb);
302 int mult, rc, pages_number;
304 mult = 1 << (20 - CFS_PAGE_SHIFT);
305 rc = lprocfs_write_frac_helper(buffer, count, &pages_number, mult);
309 if (pages_number < 0 || pages_number > num_physpages) {
310 CERROR("can't set max cache more than %lu MB\n",
311 num_physpages >> (20 - CFS_PAGE_SHIFT));
315 spin_lock(&sbi->ll_lock);
316 sbi->ll_async_page_max = pages_number ;
317 spin_unlock(&sbi->ll_lock);
320 /* Not set up yet, don't call llap_shrink_cache */
323 if (sbi->ll_async_page_count >= sbi->ll_async_page_max)
324 llap_shrink_cache(sbi, 0);
329 static int ll_rd_checksum(char *page, char **start, off_t off,
330 int count, int *eof, void *data)
332 struct super_block *sb = data;
333 struct ll_sb_info *sbi = ll_s2sbi(sb);
335 return snprintf(page, count, "%u\n",
336 (sbi->ll_flags & LL_SBI_CHECKSUM) ? 1 : 0);
339 static int ll_wr_checksum(struct file *file, const char *buffer,
340 unsigned long count, void *data)
342 struct super_block *sb = data;
343 struct ll_sb_info *sbi = ll_s2sbi(sb);
350 rc = lprocfs_write_helper(buffer, count, &val);
354 sbi->ll_flags |= LL_SBI_CHECKSUM;
356 sbi->ll_flags &= ~LL_SBI_CHECKSUM;
358 rc = obd_set_info_async(sbi->ll_dt_exp, strlen("checksum"), "checksum",
359 sizeof(val), &val, NULL);
361 CWARN("Failed to set OSC checksum flags: %d\n", rc);
366 static int ll_rd_max_rw_chunk(char *page, char **start, off_t off,
367 int count, int *eof, void *data)
369 struct super_block *sb = data;
371 return snprintf(page, count, "%lu\n", ll_s2sbi(sb)->ll_max_rw_chunk);
374 static int ll_wr_max_rw_chunk(struct file *file, const char *buffer,
375 unsigned long count, void *data)
377 struct super_block *sb = data;
380 rc = lprocfs_write_helper(buffer, count, &val);
383 ll_s2sbi(sb)->ll_max_rw_chunk = val;
387 static int ll_rd_track_id(char *page, int count, void *data,
388 enum stats_track_type type)
390 struct super_block *sb = data;
392 if (ll_s2sbi(sb)->ll_stats_track_type == type) {
393 return snprintf(page, count, "%d\n",
394 ll_s2sbi(sb)->ll_stats_track_id);
396 } else if (ll_s2sbi(sb)->ll_stats_track_type == STATS_TRACK_ALL) {
397 return snprintf(page, count, "0 (all)\n");
399 return snprintf(page, count, "untracked\n");
403 static int ll_wr_track_id(const char *buffer, unsigned long count, void *data,
404 enum stats_track_type type)
406 struct super_block *sb = data;
409 rc = lprocfs_write_helper(buffer, count, &pid);
412 ll_s2sbi(sb)->ll_stats_track_id = pid;
414 ll_s2sbi(sb)->ll_stats_track_type = STATS_TRACK_ALL;
416 ll_s2sbi(sb)->ll_stats_track_type = type;
417 lprocfs_clear_stats(ll_s2sbi(sb)->ll_stats);
421 static int ll_rd_track_pid(char *page, char **start, off_t off,
422 int count, int *eof, void *data)
424 return (ll_rd_track_id(page, count, data, STATS_TRACK_PID));
427 static int ll_wr_track_pid(struct file *file, const char *buffer,
428 unsigned long count, void *data)
430 return (ll_wr_track_id(buffer, count, data, STATS_TRACK_PID));
433 static int ll_rd_track_ppid(char *page, char **start, off_t off,
434 int count, int *eof, void *data)
436 return (ll_rd_track_id(page, count, data, STATS_TRACK_PPID));
439 static int ll_wr_track_ppid(struct file *file, const char *buffer,
440 unsigned long count, void *data)
442 return (ll_wr_track_id(buffer, count, data, STATS_TRACK_PPID));
445 static int ll_rd_track_gid(char *page, char **start, off_t off,
446 int count, int *eof, void *data)
448 return (ll_rd_track_id(page, count, data, STATS_TRACK_GID));
451 static int ll_wr_track_gid(struct file *file, const char *buffer,
452 unsigned long count, void *data)
454 return (ll_wr_track_id(buffer, count, data, STATS_TRACK_GID));
457 static struct lprocfs_vars lprocfs_obd_vars[] = {
458 { "uuid", ll_rd_sb_uuid, 0, 0 },
459 //{ "mntpt_path", ll_rd_path, 0, 0 },
460 { "fstype", ll_rd_fstype, 0, 0 },
461 { "blocksize", ll_rd_blksize, 0, 0 },
462 { "kbytestotal", ll_rd_kbytestotal, 0, 0 },
463 { "kbytesfree", ll_rd_kbytesfree, 0, 0 },
464 { "kbytesavail", ll_rd_kbytesavail, 0, 0 },
465 { "filestotal", ll_rd_filestotal, 0, 0 },
466 { "filesfree", ll_rd_filesfree, 0, 0 },
467 { "client_type", ll_rd_client_type, 0, 0 },
468 //{ "filegroups", lprocfs_rd_filegroups, 0, 0 },
469 { "max_read_ahead_mb", ll_rd_max_readahead_mb,
470 ll_wr_max_readahead_mb, 0 },
471 { "max_read_ahead_whole_mb", ll_rd_max_read_ahead_whole_mb,
472 ll_wr_max_read_ahead_whole_mb, 0 },
473 { "max_cached_mb", ll_rd_max_cached_mb, ll_wr_max_cached_mb, 0 },
474 { "checksum_pages", ll_rd_checksum, ll_wr_checksum, 0 },
475 { "max_rw_chunk", ll_rd_max_rw_chunk, ll_wr_max_rw_chunk, 0 },
476 { "stats_track_pid", ll_rd_track_pid, ll_wr_track_pid, 0 },
477 { "stats_track_ppid", ll_rd_track_ppid, ll_wr_track_ppid, 0 },
478 { "stats_track_gid", ll_rd_track_gid, ll_wr_track_gid, 0 },
482 #define MAX_STRING_SIZE 128
484 struct llite_file_opcode {
488 } llite_opcode_table[LPROC_LL_FILE_OPCODES] = {
490 { LPROC_LL_DIRTY_HITS, LPROCFS_TYPE_REGS, "dirty_pages_hits" },
491 { LPROC_LL_DIRTY_MISSES, LPROCFS_TYPE_REGS, "dirty_pages_misses" },
492 { LPROC_LL_WB_WRITEPAGE, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
493 "writeback_from_writepage" },
494 { LPROC_LL_WB_PRESSURE, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
495 "writeback_from_pressure" },
496 { LPROC_LL_WB_OK, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
497 "writeback_ok_pages" },
498 { LPROC_LL_WB_FAIL, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
499 "writeback_failed_pages" },
500 { LPROC_LL_READ_BYTES, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_BYTES,
502 { LPROC_LL_WRITE_BYTES, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_BYTES,
504 { LPROC_LL_BRW_READ, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
506 { LPROC_LL_BRW_WRITE, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
509 { LPROC_LL_IOCTL, LPROCFS_TYPE_REGS, "ioctl" },
510 { LPROC_LL_OPEN, LPROCFS_TYPE_REGS, "open" },
511 { LPROC_LL_RELEASE, LPROCFS_TYPE_REGS, "close" },
512 { LPROC_LL_MAP, LPROCFS_TYPE_REGS, "mmap" },
513 { LPROC_LL_LLSEEK, LPROCFS_TYPE_REGS, "seek" },
514 { LPROC_LL_FSYNC, LPROCFS_TYPE_REGS, "fsync" },
515 /* inode operation */
516 { LPROC_LL_SETATTR, LPROCFS_TYPE_REGS, "setattr" },
517 { LPROC_LL_TRUNC, LPROCFS_TYPE_REGS, "truncate" },
518 { LPROC_LL_FLOCK, LPROCFS_TYPE_REGS, "flock" },
519 { LPROC_LL_GETATTR, LPROCFS_TYPE_REGS, "getattr" },
520 /* special inode operation */
521 { LPROC_LL_STAFS, LPROCFS_TYPE_REGS, "statfs" },
522 { LPROC_LL_ALLOC_INODE, LPROCFS_TYPE_REGS, "alloc_inode" },
523 { LPROC_LL_SETXATTR, LPROCFS_TYPE_REGS, "setxattr" },
524 { LPROC_LL_GETXATTR, LPROCFS_TYPE_REGS, "getxattr" },
525 { LPROC_LL_LISTXATTR, LPROCFS_TYPE_REGS, "listxattr" },
526 { LPROC_LL_REMOVEXATTR, LPROCFS_TYPE_REGS, "removexattr" },
527 { LPROC_LL_INODE_PERM, LPROCFS_TYPE_REGS, "inode_permission" },
528 { LPROC_LL_DIRECT_READ, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
530 { LPROC_LL_DIRECT_WRITE, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
535 void ll_stats_ops_tally(struct ll_sb_info *sbi, int op, int count)
539 if (sbi->ll_stats_track_type == STATS_TRACK_ALL)
540 lprocfs_counter_add(sbi->ll_stats, op, count);
541 else if (sbi->ll_stats_track_type == STATS_TRACK_PID &&
542 sbi->ll_stats_track_id == current->pid)
543 lprocfs_counter_add(sbi->ll_stats, op, count);
544 else if (sbi->ll_stats_track_type == STATS_TRACK_PPID &&
545 sbi->ll_stats_track_id == current->p_pptr->pid)
546 lprocfs_counter_add(sbi->ll_stats, op, count);
547 else if (sbi->ll_stats_track_type == STATS_TRACK_GID &&
548 sbi->ll_stats_track_id == current->gid)
549 lprocfs_counter_add(sbi->ll_stats, op, count);
551 EXPORT_SYMBOL(ll_stats_ops_tally);
553 int lprocfs_register_mountpoint(struct proc_dir_entry *parent,
554 struct super_block *sb, char *osc, char *mdc)
556 struct lprocfs_vars lvars[2];
557 struct lustre_sb_info *lsi = s2lsi(sb);
558 struct ll_sb_info *sbi = ll_s2sbi(sb);
559 struct obd_device *obd;
560 char name[MAX_STRING_SIZE + 1], *ptr;
562 struct proc_dir_entry *entry;
565 memset(lvars, 0, sizeof(lvars));
567 name[MAX_STRING_SIZE] = '\0';
568 lvars[0].name = name;
570 LASSERT(sbi != NULL);
571 LASSERT(mdc != NULL);
572 LASSERT(osc != NULL);
575 len = strlen(lsi->lsi_lmd->lmd_profile);
576 ptr = strrchr(lsi->lsi_lmd->lmd_profile, '-');
577 if (ptr && (strcmp(ptr, "-client") == 0))
581 snprintf(name, MAX_STRING_SIZE, "%.*s-%p", len,
582 lsi->lsi_lmd->lmd_profile, sb);
584 sbi->ll_proc_root = lprocfs_register(name, parent, NULL, NULL);
585 if (IS_ERR(sbi->ll_proc_root)) {
586 err = PTR_ERR(sbi->ll_proc_root);
587 sbi->ll_proc_root = NULL;
591 entry = create_proc_entry("dump_page_cache", 0444, sbi->ll_proc_root);
593 GOTO(out, err = -ENOMEM);
594 entry->proc_fops = &llite_dump_pgcache_fops;
597 entry = create_proc_entry("read_ahead_stats", 0644, sbi->ll_proc_root);
599 GOTO(out, err = -ENOMEM);
600 entry->proc_fops = &ll_ra_stats_fops;
603 entry = create_proc_entry("extents_stats", 0644, sbi->ll_proc_root);
605 GOTO(out, err = -ENOMEM);
606 entry->proc_fops = &ll_rw_extents_stats_fops;
609 entry = create_proc_entry("extents_stats_per_process", 0644,
612 GOTO(out, err = -ENOMEM);
613 entry->proc_fops = &ll_rw_extents_stats_pp_fops;
616 entry = create_proc_entry("offset_stats", 0644, sbi->ll_proc_root);
618 GOTO(out, err = -ENOMEM);
619 entry->proc_fops = &ll_rw_offset_stats_fops;
622 /* File operations stats */
623 sbi->ll_stats = lprocfs_alloc_stats(LPROC_LL_FILE_OPCODES, 0);
624 if (sbi->ll_stats == NULL)
625 GOTO(out, err = -ENOMEM);
626 /* do counter init */
627 for (id = 0; id < LPROC_LL_FILE_OPCODES; id++) {
628 __u32 type = llite_opcode_table[id].type;
630 if (type & LPROCFS_TYPE_REGS)
632 else if (type & LPROCFS_TYPE_BYTES)
634 else if (type & LPROCFS_TYPE_PAGES)
636 lprocfs_counter_init(sbi->ll_stats,
637 llite_opcode_table[id].opcode,
638 (type & LPROCFS_CNTR_AVGMINMAX),
639 llite_opcode_table[id].opname, ptr);
641 err = lprocfs_register_stats(sbi->ll_proc_root, "stats", sbi->ll_stats);
645 err = lprocfs_add_vars(sbi->ll_proc_root, lprocfs_obd_vars, sb);
650 obd = class_name2obd(mdc);
652 LASSERT(obd != NULL);
653 LASSERT(obd->obd_magic == OBD_DEVICE_MAGIC);
654 LASSERT(obd->obd_type->typ_name != NULL);
656 snprintf(name, MAX_STRING_SIZE, "%s/common_name",
657 obd->obd_type->typ_name);
658 lvars[0].read_fptr = lprocfs_rd_name;
659 err = lprocfs_add_vars(sbi->ll_proc_root, lvars, obd);
663 snprintf(name, MAX_STRING_SIZE, "%s/uuid", obd->obd_type->typ_name);
664 lvars[0].read_fptr = lprocfs_rd_uuid;
665 err = lprocfs_add_vars(sbi->ll_proc_root, lvars, obd);
670 obd = class_name2obd(osc);
672 LASSERT(obd != NULL);
673 LASSERT(obd->obd_magic == OBD_DEVICE_MAGIC);
674 LASSERT(obd->obd_type->typ_name != NULL);
676 snprintf(name, MAX_STRING_SIZE, "%s/common_name",
677 obd->obd_type->typ_name);
678 lvars[0].read_fptr = lprocfs_rd_name;
679 err = lprocfs_add_vars(sbi->ll_proc_root, lvars, obd);
683 snprintf(name, MAX_STRING_SIZE, "%s/uuid", obd->obd_type->typ_name);
684 lvars[0].read_fptr = lprocfs_rd_uuid;
685 err = lprocfs_add_vars(sbi->ll_proc_root, lvars, obd);
688 lprocfs_remove(&sbi->ll_proc_root);
689 lprocfs_free_stats(&sbi->ll_stats);
694 void lprocfs_unregister_mountpoint(struct ll_sb_info *sbi)
696 if (sbi->ll_proc_root) {
697 lprocfs_remove(&sbi->ll_proc_root);
698 lprocfs_free_stats(&sbi->ll_stats);
701 #undef MAX_STRING_SIZE
703 #define seq_page_flag(seq, page, flag, has_flags) do { \
704 if (test_bit(PG_##flag, &(page)->flags)) { \
708 seq_putc(seq, '|'); \
709 seq_puts(seq, #flag); \
713 static void *llite_dump_pgcache_seq_start(struct seq_file *seq, loff_t *pos)
715 struct ll_async_page *dummy_llap = seq->private;
717 if (dummy_llap->llap_magic == 2)
723 static int llite_dump_pgcache_seq_show(struct seq_file *seq, void *v)
725 struct ll_async_page *llap, *dummy_llap = seq->private;
726 struct ll_sb_info *sbi = dummy_llap->llap_cookie;
728 /* 2.4 doesn't seem to have SEQ_START_TOKEN, so we implement
729 * it in our own state */
730 if (dummy_llap->llap_magic == 0) {
731 seq_printf(seq, "gener | llap cookie origin wq du wb | page "
732 "inode index count [ page flags ]\n");
736 spin_lock(&sbi->ll_lock);
738 llap = llite_pglist_next_llap(sbi, &dummy_llap->llap_pglist_item);
741 struct page *page = llap->llap_page;
743 LASSERTF(llap->llap_origin < LLAP__ORIGIN_MAX, "%u\n",
746 seq_printf(seq," %5lu | %p %p %s %s %s %s | %p %lu/%u(%p) "
749 llap, llap->llap_cookie,
750 llap_origins[llap->llap_origin],
751 llap->llap_write_queued ? "wq" : "- ",
752 llap->llap_defer_uptodate ? "du" : "- ",
753 PageWriteback(page) ? "wb" : "-",
754 page, page->mapping->host->i_ino,
755 page->mapping->host->i_generation,
756 page->mapping->host, page->index,
758 seq_page_flag(seq, page, locked, has_flags);
759 seq_page_flag(seq, page, error, has_flags);
760 seq_page_flag(seq, page, referenced, has_flags);
761 seq_page_flag(seq, page, uptodate, has_flags);
762 seq_page_flag(seq, page, dirty, has_flags);
763 #if (LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,12))
764 seq_page_flag(seq, page, highmem, has_flags);
766 seq_page_flag(seq, page, writeback, has_flags);
768 seq_puts(seq, "-]\n");
770 seq_puts(seq, "]\n");
773 spin_unlock(&sbi->ll_lock);
778 static void *llite_dump_pgcache_seq_next(struct seq_file *seq, void *v,
781 struct ll_async_page *llap, *dummy_llap = seq->private;
782 struct ll_sb_info *sbi = dummy_llap->llap_cookie;
784 /* bail if we just displayed the banner */
785 if (dummy_llap->llap_magic == 0) {
786 dummy_llap->llap_magic = 1;
790 /* we've just displayed the llap that is after us in the list.
791 * we advance to a position beyond it, returning null if there
792 * isn't another llap in the list beyond that new position. */
793 spin_lock(&sbi->ll_lock);
794 llap = llite_pglist_next_llap(sbi, &dummy_llap->llap_pglist_item);
795 list_del_init(&dummy_llap->llap_pglist_item);
797 list_add(&dummy_llap->llap_pglist_item,&llap->llap_pglist_item);
798 llap =llite_pglist_next_llap(sbi,&dummy_llap->llap_pglist_item);
800 spin_unlock(&sbi->ll_lock);
804 dummy_llap->llap_magic = 2;
810 static void null_stop(struct seq_file *seq, void *v)
814 struct seq_operations llite_dump_pgcache_seq_sops = {
815 .start = llite_dump_pgcache_seq_start,
817 .next = llite_dump_pgcache_seq_next,
818 .show = llite_dump_pgcache_seq_show,
821 /* we're displaying llaps in a list_head list. we don't want to hold a lock
822 * while we walk the entire list, and we don't want to have to seek into
823 * the right position in the list as an app advances with many syscalls. we
824 * allocate a dummy llap and hang it off file->private. its position in
825 * the list records where the app is currently displaying. this way our
826 * seq .start and .stop don't actually do anything. .next returns null
827 * when the dummy hits the end of the list which eventually leads to .release
828 * where we tear down. this kind of displaying is super-racey, so we put
829 * a generation counter on the list so the output shows when the list
830 * changes between reads.
832 static int llite_dump_pgcache_seq_open(struct inode *inode, struct file *file)
834 struct proc_dir_entry *dp = PDE(inode);
835 struct ll_async_page *dummy_llap;
836 struct seq_file *seq;
837 struct ll_sb_info *sbi = dp->data;
840 LPROCFS_ENTRY_AND_CHECK(dp);
842 OBD_ALLOC_PTR_WAIT(dummy_llap);
843 if (dummy_llap == NULL)
845 dummy_llap->llap_page = NULL;
846 dummy_llap->llap_cookie = sbi;
847 dummy_llap->llap_magic = 0;
849 rc = seq_open(file, &llite_dump_pgcache_seq_sops);
851 OBD_FREE(dummy_llap, sizeof(*dummy_llap));
854 seq = file->private_data;
855 seq->private = dummy_llap;
857 spin_lock(&sbi->ll_lock);
858 list_add(&dummy_llap->llap_pglist_item, &sbi->ll_pglist);
859 spin_unlock(&sbi->ll_lock);
867 static int llite_dump_pgcache_seq_release(struct inode *inode,
870 struct seq_file *seq = file->private_data;
871 struct ll_async_page *dummy_llap = seq->private;
872 struct ll_sb_info *sbi = dummy_llap->llap_cookie;
874 spin_lock(&sbi->ll_lock);
875 if (!list_empty(&dummy_llap->llap_pglist_item))
876 list_del_init(&dummy_llap->llap_pglist_item);
877 spin_unlock(&sbi->ll_lock);
878 OBD_FREE(dummy_llap, sizeof(*dummy_llap));
880 return lprocfs_seq_release(inode, file);
883 struct file_operations llite_dump_pgcache_fops = {
884 .owner = THIS_MODULE,
885 .open = llite_dump_pgcache_seq_open,
887 .release = llite_dump_pgcache_seq_release,
890 static int ll_ra_stats_seq_show(struct seq_file *seq, void *v)
893 struct ll_sb_info *sbi = seq->private;
894 struct ll_ra_info *ra = &sbi->ll_ra_info;
896 static char *ra_stat_strings[] = {
897 [RA_STAT_HIT] = "hits",
898 [RA_STAT_MISS] = "misses",
899 [RA_STAT_DISTANT_READPAGE] = "readpage not consecutive",
900 [RA_STAT_MISS_IN_WINDOW] = "miss inside window",
901 [RA_STAT_FAILED_GRAB_PAGE] = "failed grab_cache_page",
902 [RA_STAT_FAILED_MATCH] = "failed lock match",
903 [RA_STAT_DISCARDED] = "read but discarded",
904 [RA_STAT_ZERO_LEN] = "zero length file",
905 [RA_STAT_ZERO_WINDOW] = "zero size window",
906 [RA_STAT_EOF] = "read-ahead to EOF",
907 [RA_STAT_MAX_IN_FLIGHT] = "hit max r-a issue",
908 [RA_STAT_WRONG_GRAB_PAGE] = "wrong page from grab_cache_page",
911 do_gettimeofday(&now);
913 spin_lock(&sbi->ll_lock);
915 seq_printf(seq, "snapshot_time: %lu.%lu (secs.usecs)\n",
916 now.tv_sec, now.tv_usec);
917 seq_printf(seq, "pending issued pages: %lu\n",
920 for(i = 0; i < _NR_RA_STAT; i++)
921 seq_printf(seq, "%-25s %lu\n", ra_stat_strings[i],
924 spin_unlock(&sbi->ll_lock);
929 static ssize_t ll_ra_stats_seq_write(struct file *file, const char *buf,
930 size_t len, loff_t *off)
932 struct seq_file *seq = file->private_data;
933 struct ll_sb_info *sbi = seq->private;
934 struct ll_ra_info *ra = &sbi->ll_ra_info;
936 spin_lock(&sbi->ll_lock);
937 memset(ra->ra_stats, 0, sizeof(ra->ra_stats));
938 spin_unlock(&sbi->ll_lock);
943 LPROC_SEQ_FOPS(ll_ra_stats);
945 #define pct(a,b) (b ? a * 100 / b : 0)
947 static void ll_display_extents_info(struct ll_rw_extents_info *io_extents,
948 struct seq_file *seq, int which)
950 unsigned long read_tot = 0, write_tot = 0, read_cum, write_cum;
951 unsigned long start, end, r, w;
952 char *unitp = "KMGTPEZY";
954 struct per_process_info *pp_info = &io_extents->pp_extents[which];
960 for(i = 0; i < LL_HIST_MAX; i++) {
961 read_tot += pp_info->pp_r_hist.oh_buckets[i];
962 write_tot += pp_info->pp_w_hist.oh_buckets[i];
965 for(i = 0; i < LL_HIST_MAX; i++) {
966 r = pp_info->pp_r_hist.oh_buckets[i];
967 w = pp_info->pp_w_hist.oh_buckets[i];
970 end = 1 << (i + LL_HIST_START - units);
971 seq_printf(seq, "%4lu%c - %4lu%c%c: %14lu %4lu %4lu | "
972 "%14lu %4lu %4lu\n", start, *unitp, end, *unitp,
973 (i == LL_HIST_MAX - 1) ? '+' : ' ',
974 r, pct(r, read_tot), pct(read_cum, read_tot),
975 w, pct(w, write_tot), pct(write_cum, write_tot));
977 if (start == 1<<10) {
982 if (read_cum == read_tot && write_cum == write_tot)
987 static int ll_rw_extents_stats_pp_seq_show(struct seq_file *seq, void *v)
990 struct ll_sb_info *sbi = seq->private;
991 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
994 do_gettimeofday(&now);
996 if (!sbi->ll_rw_stats_on) {
997 seq_printf(seq, "Disabled\n"
998 "Write anything in this file to activate\n");
1001 seq_printf(seq, "snapshot_time: %lu.%lu (secs.usecs)\n",
1002 now.tv_sec, now.tv_usec);
1003 seq_printf(seq, "%15s %19s | %20s\n", " ", "read", "write");
1004 seq_printf(seq, "%13s %14s %4s %4s | %14s %4s %4s\n",
1005 "extents", "calls", "%", "cum%",
1006 "calls", "%", "cum%");
1007 spin_lock(&sbi->ll_pp_extent_lock);
1008 for(k = 0; k < LL_PROCESS_HIST_MAX; k++) {
1009 if(io_extents->pp_extents[k].pid != 0) {
1010 seq_printf(seq, "\nPID: %d\n",
1011 io_extents->pp_extents[k].pid);
1012 ll_display_extents_info(io_extents, seq, k);
1015 spin_unlock(&sbi->ll_pp_extent_lock);
1019 static ssize_t ll_rw_extents_stats_pp_seq_write(struct file *file,
1020 const char *buf, size_t len,
1023 struct seq_file *seq = file->private_data;
1024 struct ll_sb_info *sbi = seq->private;
1025 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1028 sbi->ll_rw_stats_on = 1;
1029 spin_lock(&sbi->ll_pp_extent_lock);
1030 for(i = 0; i < LL_PROCESS_HIST_MAX; i++) {
1031 io_extents->pp_extents[i].pid = 0;
1032 lprocfs_oh_clear(&io_extents->pp_extents[i].pp_r_hist);
1033 lprocfs_oh_clear(&io_extents->pp_extents[i].pp_w_hist);
1035 spin_unlock(&sbi->ll_pp_extent_lock);
1039 LPROC_SEQ_FOPS(ll_rw_extents_stats_pp);
1041 static int ll_rw_extents_stats_seq_show(struct seq_file *seq, void *v)
1044 struct ll_sb_info *sbi = seq->private;
1045 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1047 do_gettimeofday(&now);
1049 if (!sbi->ll_rw_stats_on) {
1050 seq_printf(seq, "Disabled\n"
1051 "Write anything in this file to activate\n");
1054 seq_printf(seq, "snapshot_time: %lu.%lu (secs.usecs)\n",
1055 now.tv_sec, now.tv_usec);
1057 seq_printf(seq, "%15s %19s | %20s\n", " ", "read", "write");
1058 seq_printf(seq, "%13s %14s %4s %4s | %14s %4s %4s\n",
1059 "extents", "calls", "%", "cum%",
1060 "calls", "%", "cum%");
1061 spin_lock(&sbi->ll_lock);
1062 ll_display_extents_info(io_extents, seq, LL_PROCESS_HIST_MAX);
1063 spin_unlock(&sbi->ll_lock);
1068 static ssize_t ll_rw_extents_stats_seq_write(struct file *file, const char *buf,
1069 size_t len, loff_t *off)
1071 struct seq_file *seq = file->private_data;
1072 struct ll_sb_info *sbi = seq->private;
1073 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1076 sbi->ll_rw_stats_on = 1;
1077 spin_lock(&sbi->ll_pp_extent_lock);
1078 for(i = 0; i <= LL_PROCESS_HIST_MAX; i++)
1080 io_extents->pp_extents[i].pid = 0;
1081 lprocfs_oh_clear(&io_extents->pp_extents[i].pp_r_hist);
1082 lprocfs_oh_clear(&io_extents->pp_extents[i].pp_w_hist);
1084 spin_unlock(&sbi->ll_pp_extent_lock);
1089 LPROC_SEQ_FOPS(ll_rw_extents_stats);
1091 void ll_rw_stats_tally(struct ll_sb_info *sbi, pid_t pid, struct file
1092 *file, size_t count, int rw)
1095 struct ll_rw_process_info *process;
1096 struct ll_rw_process_info *offset;
1097 int *off_count = &sbi->ll_rw_offset_entry_count;
1098 int *process_count = &sbi->ll_offset_process_count;
1099 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1101 if(!sbi->ll_rw_stats_on)
1103 process = sbi->ll_rw_process_info;
1104 offset = sbi->ll_rw_offset_info;
1106 spin_lock(&sbi->ll_pp_extent_lock);
1107 /* Extent statistics */
1108 for(i = 0; i < LL_PROCESS_HIST_MAX; i++) {
1109 if(io_extents->pp_extents[i].pid == pid) {
1117 sbi->ll_extent_process_count =
1118 (sbi->ll_extent_process_count + 1) % LL_PROCESS_HIST_MAX;
1119 cur = sbi->ll_extent_process_count;
1120 io_extents->pp_extents[cur].pid = pid;
1121 lprocfs_oh_clear(&io_extents->pp_extents[cur].pp_r_hist);
1122 lprocfs_oh_clear(&io_extents->pp_extents[cur].pp_w_hist);
1125 for(i = 0; (count >= (1 << LL_HIST_START << i)) &&
1126 (i < (LL_HIST_MAX - 1)); i++);
1128 io_extents->pp_extents[cur].pp_r_hist.oh_buckets[i]++;
1129 io_extents->pp_extents[LL_PROCESS_HIST_MAX].pp_r_hist.oh_buckets[i]++;
1131 io_extents->pp_extents[cur].pp_w_hist.oh_buckets[i]++;
1132 io_extents->pp_extents[LL_PROCESS_HIST_MAX].pp_w_hist.oh_buckets[i]++;
1134 spin_unlock(&sbi->ll_pp_extent_lock);
1136 spin_lock(&sbi->ll_process_lock);
1137 /* Offset statistics */
1138 for (i = 0; i < LL_PROCESS_HIST_MAX; i++) {
1139 if (process[i].rw_pid == pid) {
1140 if (process[i].rw_last_file != file) {
1141 process[i].rw_range_start = file->f_pos;
1142 process[i].rw_last_file_pos =
1143 file->f_pos + count;
1144 process[i].rw_smallest_extent = count;
1145 process[i].rw_largest_extent = count;
1146 process[i].rw_offset = 0;
1147 process[i].rw_last_file = file;
1148 spin_unlock(&sbi->ll_process_lock);
1151 if (process[i].rw_last_file_pos != file->f_pos) {
1153 (*off_count + 1) % LL_OFFSET_HIST_MAX;
1154 offset[*off_count].rw_op = process[i].rw_op;
1155 offset[*off_count].rw_pid = pid;
1156 offset[*off_count].rw_range_start =
1157 process[i].rw_range_start;
1158 offset[*off_count].rw_range_end =
1159 process[i].rw_last_file_pos;
1160 offset[*off_count].rw_smallest_extent =
1161 process[i].rw_smallest_extent;
1162 offset[*off_count].rw_largest_extent =
1163 process[i].rw_largest_extent;
1164 offset[*off_count].rw_offset =
1165 process[i].rw_offset;
1166 process[i].rw_op = rw;
1167 process[i].rw_range_start = file->f_pos;
1168 process[i].rw_smallest_extent = count;
1169 process[i].rw_largest_extent = count;
1170 process[i].rw_offset = file->f_pos -
1171 process[i].rw_last_file_pos;
1173 if(process[i].rw_smallest_extent > count)
1174 process[i].rw_smallest_extent = count;
1175 if(process[i].rw_largest_extent < count)
1176 process[i].rw_largest_extent = count;
1177 process[i].rw_last_file_pos = file->f_pos + count;
1178 spin_unlock(&sbi->ll_process_lock);
1182 *process_count = (*process_count + 1) % LL_PROCESS_HIST_MAX;
1183 process[*process_count].rw_pid = pid;
1184 process[*process_count].rw_op = rw;
1185 process[*process_count].rw_range_start = file->f_pos;
1186 process[*process_count].rw_last_file_pos = file->f_pos + count;
1187 process[*process_count].rw_smallest_extent = count;
1188 process[*process_count].rw_largest_extent = count;
1189 process[*process_count].rw_offset = 0;
1190 process[*process_count].rw_last_file = file;
1191 spin_unlock(&sbi->ll_process_lock);
1194 char lpszt[] = LPSZ;
1196 static int ll_rw_offset_stats_seq_show(struct seq_file *seq, void *v)
1199 struct ll_sb_info *sbi = seq->private;
1200 struct ll_rw_process_info *offset = sbi->ll_rw_offset_info;
1201 struct ll_rw_process_info *process = sbi->ll_rw_process_info;
1205 do_gettimeofday(&now);
1207 if (!sbi->ll_rw_stats_on) {
1208 seq_printf(seq, "Disabled\n"
1209 "Write anything in this file to activate\n");
1212 spin_lock(&sbi->ll_process_lock);
1214 seq_printf(seq, "snapshot_time: %lu.%lu (secs.usecs)\n",
1215 now.tv_sec, now.tv_usec);
1216 seq_printf(seq, "%3s %10s %14s %14s %17s %17s %14s\n",
1217 "R/W", "PID", "RANGE START", "RANGE END",
1218 "SMALLEST EXTENT", "LARGEST EXTENT", "OFFSET");
1219 sprintf(format, "%s%s%s%s%s\n",
1220 "%3c %10d %14Lu %14Lu %17", lpszt+1, " %17", lpszt+1, " %14Ld");
1221 /* We stored the discontiguous offsets here; print them first */
1222 for(i = 0; i < LL_OFFSET_HIST_MAX; i++) {
1223 if (offset[i].rw_pid != 0)
1224 /* Is there a way to snip the '%' off of LPSZ? */
1225 seq_printf(seq, format,
1226 offset[i].rw_op ? 'W' : 'R',
1228 offset[i].rw_range_start,
1229 offset[i].rw_range_end,
1230 offset[i].rw_smallest_extent,
1231 offset[i].rw_largest_extent,
1232 offset[i].rw_offset);
1234 /* Then print the current offsets for each process */
1235 for(i = 0; i < LL_PROCESS_HIST_MAX; i++) {
1236 if (process[i].rw_pid != 0)
1237 seq_printf(seq, format,
1238 process[i].rw_op ? 'W' : 'R',
1240 process[i].rw_range_start,
1241 process[i].rw_last_file_pos,
1242 process[i].rw_smallest_extent,
1243 process[i].rw_largest_extent,
1244 process[i].rw_offset);
1246 spin_unlock(&sbi->ll_process_lock);
1251 static ssize_t ll_rw_offset_stats_seq_write(struct file *file, const char *buf,
1252 size_t len, loff_t *off)
1254 struct seq_file *seq = file->private_data;
1255 struct ll_sb_info *sbi = seq->private;
1256 struct ll_rw_process_info *process_info = sbi->ll_rw_process_info;
1257 struct ll_rw_process_info *offset_info = sbi->ll_rw_offset_info;
1259 sbi->ll_rw_stats_on = 1;
1261 spin_lock(&sbi->ll_process_lock);
1262 sbi->ll_offset_process_count = 0;
1263 sbi->ll_rw_offset_entry_count = 0;
1264 memset(process_info, 0, sizeof(struct ll_rw_process_info) *
1265 LL_PROCESS_HIST_MAX);
1266 memset(offset_info, 0, sizeof(struct ll_rw_process_info) *
1267 LL_OFFSET_HIST_MAX);
1268 spin_unlock(&sbi->ll_process_lock);
1273 LPROC_SEQ_FOPS(ll_rw_offset_stats);
1275 LPROCFS_INIT_VARS(llite, NULL, lprocfs_obd_vars)
1276 #endif /* LPROCFS */