4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2012, Whamcloud, Inc.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 #define DEBUG_SUBSYSTEM S_LLITE
38 #include <linux/version.h>
39 #include <lustre_lite.h>
40 #include <lprocfs_status.h>
41 #include <linux/seq_file.h>
42 #include <obd_support.h>
44 #include "llite_internal.h"
46 struct proc_dir_entry *proc_lustre_fs_root;
49 /* /proc/lustre/llite mount point registration */
50 extern struct file_operations vvp_dump_pgcache_file_ops;
51 struct file_operations ll_rw_extents_stats_fops;
52 struct file_operations ll_rw_extents_stats_pp_fops;
53 struct file_operations ll_rw_offset_stats_fops;
55 static int ll_rd_blksize(char *page, char **start, off_t off, int count,
58 struct super_block *sb = (struct super_block *)data;
59 struct obd_statfs osfs;
63 rc = ll_statfs_internal(sb, &osfs,
64 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
68 rc = snprintf(page, count, "%u\n", osfs.os_bsize);
74 static int ll_rd_kbytestotal(char *page, char **start, off_t off, int count,
77 struct super_block *sb = (struct super_block *)data;
78 struct obd_statfs osfs;
82 rc = ll_statfs_internal(sb, &osfs,
83 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
86 __u32 blk_size = osfs.os_bsize >> 10;
87 __u64 result = osfs.os_blocks;
89 while (blk_size >>= 1)
93 rc = snprintf(page, count, LPU64"\n", result);
99 static int ll_rd_kbytesfree(char *page, char **start, off_t off, int count,
100 int *eof, void *data)
102 struct super_block *sb = (struct super_block *)data;
103 struct obd_statfs osfs;
107 rc = ll_statfs_internal(sb, &osfs,
108 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
111 __u32 blk_size = osfs.os_bsize >> 10;
112 __u64 result = osfs.os_bfree;
114 while (blk_size >>= 1)
118 rc = snprintf(page, count, LPU64"\n", result);
123 static int ll_rd_kbytesavail(char *page, char **start, off_t off, int count,
124 int *eof, void *data)
126 struct super_block *sb = (struct super_block *)data;
127 struct obd_statfs osfs;
131 rc = ll_statfs_internal(sb, &osfs,
132 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
135 __u32 blk_size = osfs.os_bsize >> 10;
136 __u64 result = osfs.os_bavail;
138 while (blk_size >>= 1)
142 rc = snprintf(page, count, LPU64"\n", result);
147 static int ll_rd_filestotal(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,
156 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
160 rc = snprintf(page, count, LPU64"\n", osfs.os_files);
165 static int ll_rd_filesfree(char *page, char **start, off_t off, int count,
166 int *eof, void *data)
168 struct super_block *sb = (struct super_block *)data;
169 struct obd_statfs osfs;
173 rc = ll_statfs_internal(sb, &osfs,
174 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
178 rc = snprintf(page, count, LPU64"\n", osfs.os_ffree);
184 static int ll_rd_client_type(char *page, char **start, off_t off, int count,
185 int *eof, void *data)
187 struct ll_sb_info *sbi = ll_s2sbi((struct super_block *)data);
190 LASSERT(sbi != NULL);
193 if (sbi->ll_flags & LL_SBI_RMT_CLIENT)
194 rc = snprintf(page, count, "remote client\n");
196 rc = snprintf(page, count, "local client\n");
201 static int ll_rd_fstype(char *page, char **start, off_t off, int count,
202 int *eof, void *data)
204 struct super_block *sb = (struct super_block*)data;
208 return snprintf(page, count, "%s\n", sb->s_type->name);
211 static int ll_rd_sb_uuid(char *page, char **start, off_t off, int count,
212 int *eof, void *data)
214 struct super_block *sb = (struct super_block *)data;
218 return snprintf(page, count, "%s\n", ll_s2sbi(sb)->ll_sb_uuid.uuid);
221 static int ll_rd_site_stats(char *page, char **start, off_t off,
222 int count, int *eof, void *data)
224 struct super_block *sb = data;
227 * See description of statistical counters in struct cl_site, and
230 return cl_site_stats_print(lu2cl_site(ll_s2sbi(sb)->ll_site),
234 static int ll_rd_max_readahead_mb(char *page, char **start, off_t off,
235 int count, int *eof, void *data)
237 struct super_block *sb = data;
238 struct ll_sb_info *sbi = ll_s2sbi(sb);
242 cfs_spin_lock(&sbi->ll_lock);
243 pages_number = sbi->ll_ra_info.ra_max_pages;
244 cfs_spin_unlock(&sbi->ll_lock);
246 mult = 1 << (20 - PAGE_CACHE_SHIFT);
247 return lprocfs_read_frac_helper(page, count, pages_number, mult);
250 static int ll_wr_max_readahead_mb(struct file *file, const char *buffer,
251 unsigned long count, void *data)
253 struct super_block *sb = data;
254 struct ll_sb_info *sbi = ll_s2sbi(sb);
255 int mult, rc, pages_number;
257 mult = 1 << (20 - CFS_PAGE_SHIFT);
258 rc = lprocfs_write_frac_helper(buffer, count, &pages_number, mult);
262 if (pages_number < 0 || pages_number > cfs_num_physpages / 2) {
263 CERROR("can't set file readahead more than %lu MB\n",
264 cfs_num_physpages >> (20 - CFS_PAGE_SHIFT + 1)); /*1/2 of RAM*/
268 cfs_spin_lock(&sbi->ll_lock);
269 sbi->ll_ra_info.ra_max_pages = pages_number;
270 cfs_spin_unlock(&sbi->ll_lock);
275 static int ll_rd_max_readahead_per_file_mb(char *page, char **start, off_t off,
276 int count, int *eof, void *data)
278 struct super_block *sb = data;
279 struct ll_sb_info *sbi = ll_s2sbi(sb);
283 cfs_spin_lock(&sbi->ll_lock);
284 pages_number = sbi->ll_ra_info.ra_max_pages_per_file;
285 cfs_spin_unlock(&sbi->ll_lock);
287 mult = 1 << (20 - CFS_PAGE_SHIFT);
288 return lprocfs_read_frac_helper(page, count, pages_number, mult);
291 static int ll_wr_max_readahead_per_file_mb(struct file *file, const char *buffer,
292 unsigned long count, void *data)
294 struct super_block *sb = data;
295 struct ll_sb_info *sbi = ll_s2sbi(sb);
296 int mult, rc, pages_number;
298 mult = 1 << (20 - CFS_PAGE_SHIFT);
299 rc = lprocfs_write_frac_helper(buffer, count, &pages_number, mult);
303 if (pages_number < 0 ||
304 pages_number > sbi->ll_ra_info.ra_max_pages) {
305 CERROR("can't set file readahead more than"
306 "max_read_ahead_mb %lu MB\n",
307 sbi->ll_ra_info.ra_max_pages);
311 cfs_spin_lock(&sbi->ll_lock);
312 sbi->ll_ra_info.ra_max_pages_per_file = pages_number;
313 cfs_spin_unlock(&sbi->ll_lock);
318 static int ll_rd_max_read_ahead_whole_mb(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);
326 cfs_spin_lock(&sbi->ll_lock);
327 pages_number = sbi->ll_ra_info.ra_max_read_ahead_whole_pages;
328 cfs_spin_unlock(&sbi->ll_lock);
330 mult = 1 << (20 - CFS_PAGE_SHIFT);
331 return lprocfs_read_frac_helper(page, count, pages_number, mult);
334 static int ll_wr_max_read_ahead_whole_mb(struct file *file, const char *buffer,
335 unsigned long count, void *data)
337 struct super_block *sb = data;
338 struct ll_sb_info *sbi = ll_s2sbi(sb);
339 int mult, rc, pages_number;
341 mult = 1 << (20 - CFS_PAGE_SHIFT);
342 rc = lprocfs_write_frac_helper(buffer, count, &pages_number, mult);
346 /* Cap this at the current max readahead window size, the readahead
347 * algorithm does this anyway so it's pointless to set it larger. */
348 if (pages_number < 0 ||
349 pages_number > sbi->ll_ra_info.ra_max_pages_per_file) {
350 CERROR("can't set max_read_ahead_whole_mb more than "
351 "max_read_ahead_per_file_mb: %lu\n",
352 sbi->ll_ra_info.ra_max_pages_per_file >> (20 - CFS_PAGE_SHIFT));
356 cfs_spin_lock(&sbi->ll_lock);
357 sbi->ll_ra_info.ra_max_read_ahead_whole_pages = pages_number;
358 cfs_spin_unlock(&sbi->ll_lock);
363 static int ll_rd_max_cached_mb(char *page, char **start, off_t off,
364 int count, int *eof, void *data)
366 struct super_block *sb = data;
367 struct ll_sb_info *sbi = ll_s2sbi(sb);
371 cfs_spin_lock(&sbi->ll_lock);
372 pages_number = sbi->ll_async_page_max;
373 cfs_spin_unlock(&sbi->ll_lock);
375 mult = 1 << (20 - CFS_PAGE_SHIFT);
376 return lprocfs_read_frac_helper(page, count, pages_number, mult);;
379 static int ll_wr_max_cached_mb(struct file *file, const char *buffer,
380 unsigned long count, void *data)
382 struct super_block *sb = data;
383 struct ll_sb_info *sbi = ll_s2sbi(sb);
384 int mult, rc, pages_number;
386 mult = 1 << (20 - CFS_PAGE_SHIFT);
387 rc = lprocfs_write_frac_helper(buffer, count, &pages_number, mult);
391 if (pages_number < 0 || pages_number > cfs_num_physpages) {
392 CERROR("can't set max cache more than %lu MB\n",
393 cfs_num_physpages >> (20 - CFS_PAGE_SHIFT));
397 cfs_spin_lock(&sbi->ll_lock);
398 sbi->ll_async_page_max = pages_number ;
399 cfs_spin_unlock(&sbi->ll_lock);
402 /* Not set up yet, don't call llap_shrink_cache */
408 static int ll_rd_checksum(char *page, char **start, off_t off,
409 int count, int *eof, void *data)
411 struct super_block *sb = data;
412 struct ll_sb_info *sbi = ll_s2sbi(sb);
414 return snprintf(page, count, "%u\n",
415 (sbi->ll_flags & LL_SBI_CHECKSUM) ? 1 : 0);
418 static int ll_wr_checksum(struct file *file, const char *buffer,
419 unsigned long count, void *data)
421 struct super_block *sb = data;
422 struct ll_sb_info *sbi = ll_s2sbi(sb);
429 rc = lprocfs_write_helper(buffer, count, &val);
433 sbi->ll_flags |= LL_SBI_CHECKSUM;
435 sbi->ll_flags &= ~LL_SBI_CHECKSUM;
437 rc = obd_set_info_async(NULL, sbi->ll_dt_exp, sizeof(KEY_CHECKSUM),
438 KEY_CHECKSUM, sizeof(val), &val, NULL);
440 CWARN("Failed to set OSC checksum flags: %d\n", rc);
445 static int ll_rd_max_rw_chunk(char *page, char **start, off_t off,
446 int count, int *eof, void *data)
448 struct super_block *sb = data;
450 return snprintf(page, count, "%lu\n", ll_s2sbi(sb)->ll_max_rw_chunk);
453 static int ll_wr_max_rw_chunk(struct file *file, const char *buffer,
454 unsigned long count, void *data)
456 struct super_block *sb = data;
459 rc = lprocfs_write_helper(buffer, count, &val);
462 ll_s2sbi(sb)->ll_max_rw_chunk = val;
466 static int ll_rd_track_id(char *page, int count, void *data,
467 enum stats_track_type type)
469 struct super_block *sb = data;
471 if (ll_s2sbi(sb)->ll_stats_track_type == type) {
472 return snprintf(page, count, "%d\n",
473 ll_s2sbi(sb)->ll_stats_track_id);
475 } else if (ll_s2sbi(sb)->ll_stats_track_type == STATS_TRACK_ALL) {
476 return snprintf(page, count, "0 (all)\n");
478 return snprintf(page, count, "untracked\n");
482 static int ll_wr_track_id(const char *buffer, unsigned long count, void *data,
483 enum stats_track_type type)
485 struct super_block *sb = data;
488 rc = lprocfs_write_helper(buffer, count, &pid);
491 ll_s2sbi(sb)->ll_stats_track_id = pid;
493 ll_s2sbi(sb)->ll_stats_track_type = STATS_TRACK_ALL;
495 ll_s2sbi(sb)->ll_stats_track_type = type;
496 lprocfs_clear_stats(ll_s2sbi(sb)->ll_stats);
500 static int ll_rd_track_pid(char *page, char **start, off_t off,
501 int count, int *eof, void *data)
503 return (ll_rd_track_id(page, count, data, STATS_TRACK_PID));
506 static int ll_wr_track_pid(struct file *file, const char *buffer,
507 unsigned long count, void *data)
509 return (ll_wr_track_id(buffer, count, data, STATS_TRACK_PID));
512 static int ll_rd_track_ppid(char *page, char **start, off_t off,
513 int count, int *eof, void *data)
515 return (ll_rd_track_id(page, count, data, STATS_TRACK_PPID));
518 static int ll_wr_track_ppid(struct file *file, const char *buffer,
519 unsigned long count, void *data)
521 return (ll_wr_track_id(buffer, count, data, STATS_TRACK_PPID));
524 static int ll_rd_track_gid(char *page, char **start, off_t off,
525 int count, int *eof, void *data)
527 return (ll_rd_track_id(page, count, data, STATS_TRACK_GID));
530 static int ll_wr_track_gid(struct file *file, const char *buffer,
531 unsigned long count, void *data)
533 return (ll_wr_track_id(buffer, count, data, STATS_TRACK_GID));
536 static int ll_rd_statahead_max(char *page, char **start, off_t off,
537 int count, int *eof, void *data)
539 struct super_block *sb = data;
540 struct ll_sb_info *sbi = ll_s2sbi(sb);
542 return snprintf(page, count, "%u\n", sbi->ll_sa_max);
545 static int ll_wr_statahead_max(struct file *file, const char *buffer,
546 unsigned long count, void *data)
548 struct super_block *sb = data;
549 struct ll_sb_info *sbi = ll_s2sbi(sb);
552 rc = lprocfs_write_helper(buffer, count, &val);
556 if (val >= 0 && val <= LL_SA_RPC_MAX)
557 sbi->ll_sa_max = val;
559 CERROR("Bad statahead_max value %d. Valid values are in the "
560 "range [0, %d]\n", val, LL_SA_RPC_MAX);
565 static int ll_rd_statahead_agl(char *page, char **start, off_t off,
566 int count, int *eof, void *data)
568 struct super_block *sb = data;
569 struct ll_sb_info *sbi = ll_s2sbi(sb);
571 return snprintf(page, count, "%u\n",
572 sbi->ll_flags & LL_SBI_AGL_ENABLED ? 1 : 0);
575 static int ll_wr_statahead_agl(struct file *file, const char *buffer,
576 unsigned long count, void *data)
578 struct super_block *sb = data;
579 struct ll_sb_info *sbi = ll_s2sbi(sb);
582 rc = lprocfs_write_helper(buffer, count, &val);
587 sbi->ll_flags |= LL_SBI_AGL_ENABLED;
589 sbi->ll_flags &= ~LL_SBI_AGL_ENABLED;
594 static int ll_rd_statahead_stats(char *page, char **start, off_t off,
595 int count, int *eof, void *data)
597 struct super_block *sb = data;
598 struct ll_sb_info *sbi = ll_s2sbi(sb);
600 return snprintf(page, count,
601 "statahead total: %u\n"
602 "statahead wrong: %u\n"
604 atomic_read(&sbi->ll_sa_total),
605 atomic_read(&sbi->ll_sa_wrong),
606 atomic_read(&sbi->ll_agl_total));
609 static int ll_rd_lazystatfs(char *page, char **start, off_t off,
610 int count, int *eof, void *data)
612 struct super_block *sb = data;
613 struct ll_sb_info *sbi = ll_s2sbi(sb);
615 return snprintf(page, count, "%u\n",
616 (sbi->ll_flags & LL_SBI_LAZYSTATFS) ? 1 : 0);
619 static int ll_wr_lazystatfs(struct file *file, const char *buffer,
620 unsigned long count, void *data)
622 struct super_block *sb = data;
623 struct ll_sb_info *sbi = ll_s2sbi(sb);
626 rc = lprocfs_write_helper(buffer, count, &val);
631 sbi->ll_flags |= LL_SBI_LAZYSTATFS;
633 sbi->ll_flags &= ~LL_SBI_LAZYSTATFS;
638 static int ll_rd_maxea_size(char *page, char **start, off_t off,
639 int count, int *eof, void *data)
641 struct super_block *sb = data;
642 struct ll_sb_info *sbi = ll_s2sbi(sb);
646 rc = ll_get_max_mdsize(sbi, &ealen);
650 return snprintf(page, count, "%u\n", ealen);
653 static struct lprocfs_vars lprocfs_llite_obd_vars[] = {
654 { "uuid", ll_rd_sb_uuid, 0, 0 },
655 //{ "mntpt_path", ll_rd_path, 0, 0 },
656 { "fstype", ll_rd_fstype, 0, 0 },
657 { "site", ll_rd_site_stats, 0, 0 },
658 { "blocksize", ll_rd_blksize, 0, 0 },
659 { "kbytestotal", ll_rd_kbytestotal, 0, 0 },
660 { "kbytesfree", ll_rd_kbytesfree, 0, 0 },
661 { "kbytesavail", ll_rd_kbytesavail, 0, 0 },
662 { "filestotal", ll_rd_filestotal, 0, 0 },
663 { "filesfree", ll_rd_filesfree, 0, 0 },
664 { "client_type", ll_rd_client_type, 0, 0 },
665 //{ "filegroups", lprocfs_rd_filegroups, 0, 0 },
666 { "max_read_ahead_mb", ll_rd_max_readahead_mb,
667 ll_wr_max_readahead_mb, 0 },
668 { "max_read_ahead_per_file_mb", ll_rd_max_readahead_per_file_mb,
669 ll_wr_max_readahead_per_file_mb, 0 },
670 { "max_read_ahead_whole_mb", ll_rd_max_read_ahead_whole_mb,
671 ll_wr_max_read_ahead_whole_mb, 0 },
672 { "max_cached_mb", ll_rd_max_cached_mb, ll_wr_max_cached_mb, 0 },
673 { "checksum_pages", ll_rd_checksum, ll_wr_checksum, 0 },
674 { "max_rw_chunk", ll_rd_max_rw_chunk, ll_wr_max_rw_chunk, 0 },
675 { "stats_track_pid", ll_rd_track_pid, ll_wr_track_pid, 0 },
676 { "stats_track_ppid", ll_rd_track_ppid, ll_wr_track_ppid, 0 },
677 { "stats_track_gid", ll_rd_track_gid, ll_wr_track_gid, 0 },
678 { "statahead_max", ll_rd_statahead_max, ll_wr_statahead_max, 0 },
679 { "statahead_agl", ll_rd_statahead_agl, ll_wr_statahead_agl, 0 },
680 { "statahead_stats", ll_rd_statahead_stats, 0, 0 },
681 { "lazystatfs", ll_rd_lazystatfs, ll_wr_lazystatfs, 0 },
682 { "max_easize", ll_rd_maxea_size, 0, 0 },
686 #define MAX_STRING_SIZE 128
688 struct llite_file_opcode {
692 } llite_opcode_table[LPROC_LL_FILE_OPCODES] = {
694 { LPROC_LL_DIRTY_HITS, LPROCFS_TYPE_REGS, "dirty_pages_hits" },
695 { LPROC_LL_DIRTY_MISSES, LPROCFS_TYPE_REGS, "dirty_pages_misses" },
696 { LPROC_LL_READ_BYTES, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_BYTES,
698 { LPROC_LL_WRITE_BYTES, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_BYTES,
700 { LPROC_LL_BRW_READ, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
702 { LPROC_LL_BRW_WRITE, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
704 { LPROC_LL_OSC_READ, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_BYTES,
706 { LPROC_LL_OSC_WRITE, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_BYTES,
708 { LPROC_LL_IOCTL, LPROCFS_TYPE_REGS, "ioctl" },
709 { LPROC_LL_OPEN, LPROCFS_TYPE_REGS, "open" },
710 { LPROC_LL_RELEASE, LPROCFS_TYPE_REGS, "close" },
711 { LPROC_LL_MAP, LPROCFS_TYPE_REGS, "mmap" },
712 { LPROC_LL_LLSEEK, LPROCFS_TYPE_REGS, "seek" },
713 { LPROC_LL_FSYNC, LPROCFS_TYPE_REGS, "fsync" },
714 { LPROC_LL_READDIR, LPROCFS_TYPE_REGS, "readdir" },
715 /* inode operation */
716 { LPROC_LL_SETATTR, LPROCFS_TYPE_REGS, "setattr" },
717 { LPROC_LL_TRUNC, LPROCFS_TYPE_REGS, "truncate" },
718 { LPROC_LL_FLOCK, LPROCFS_TYPE_REGS, "flock" },
719 { LPROC_LL_GETATTR, LPROCFS_TYPE_REGS, "getattr" },
720 /* dir inode operation */
721 { LPROC_LL_CREATE, LPROCFS_TYPE_REGS, "create" },
722 { LPROC_LL_LINK, LPROCFS_TYPE_REGS, "link" },
723 { LPROC_LL_UNLINK, LPROCFS_TYPE_REGS, "unlink" },
724 { LPROC_LL_SYMLINK, LPROCFS_TYPE_REGS, "symlink" },
725 { LPROC_LL_MKDIR, LPROCFS_TYPE_REGS, "mkdir" },
726 { LPROC_LL_RMDIR, LPROCFS_TYPE_REGS, "rmdir" },
727 { LPROC_LL_MKNOD, LPROCFS_TYPE_REGS, "mknod" },
728 { LPROC_LL_RENAME, LPROCFS_TYPE_REGS, "rename" },
729 /* special inode operation */
730 { LPROC_LL_STAFS, LPROCFS_TYPE_REGS, "statfs" },
731 { LPROC_LL_ALLOC_INODE, LPROCFS_TYPE_REGS, "alloc_inode" },
732 { LPROC_LL_SETXATTR, LPROCFS_TYPE_REGS, "setxattr" },
733 { LPROC_LL_GETXATTR, LPROCFS_TYPE_REGS, "getxattr" },
734 { LPROC_LL_LISTXATTR, LPROCFS_TYPE_REGS, "listxattr" },
735 { LPROC_LL_REMOVEXATTR, LPROCFS_TYPE_REGS, "removexattr" },
736 { LPROC_LL_INODE_PERM, LPROCFS_TYPE_REGS, "inode_permission" },
739 void ll_stats_ops_tally(struct ll_sb_info *sbi, int op, int count)
743 if (sbi->ll_stats_track_type == STATS_TRACK_ALL)
744 lprocfs_counter_add(sbi->ll_stats, op, count);
745 else if (sbi->ll_stats_track_type == STATS_TRACK_PID &&
746 sbi->ll_stats_track_id == current->pid)
747 lprocfs_counter_add(sbi->ll_stats, op, count);
748 else if (sbi->ll_stats_track_type == STATS_TRACK_PPID &&
749 sbi->ll_stats_track_id == current->parent->pid)
750 lprocfs_counter_add(sbi->ll_stats, op, count);
751 else if (sbi->ll_stats_track_type == STATS_TRACK_GID &&
752 sbi->ll_stats_track_id == cfs_curproc_gid())
753 lprocfs_counter_add(sbi->ll_stats, op, count);
755 EXPORT_SYMBOL(ll_stats_ops_tally);
757 static const char *ra_stat_string[] = {
758 [RA_STAT_HIT] = "hits",
759 [RA_STAT_MISS] = "misses",
760 [RA_STAT_DISTANT_READPAGE] = "readpage not consecutive",
761 [RA_STAT_MISS_IN_WINDOW] = "miss inside window",
762 [RA_STAT_FAILED_GRAB_PAGE] = "failed grab_cache_page",
763 [RA_STAT_FAILED_MATCH] = "failed lock match",
764 [RA_STAT_DISCARDED] = "read but discarded",
765 [RA_STAT_ZERO_LEN] = "zero length file",
766 [RA_STAT_ZERO_WINDOW] = "zero size window",
767 [RA_STAT_EOF] = "read-ahead to EOF",
768 [RA_STAT_MAX_IN_FLIGHT] = "hit max r-a issue",
769 [RA_STAT_WRONG_GRAB_PAGE] = "wrong page from grab_cache_page",
773 int lprocfs_register_mountpoint(struct proc_dir_entry *parent,
774 struct super_block *sb, char *osc, char *mdc)
776 struct lprocfs_vars lvars[2];
777 struct lustre_sb_info *lsi = s2lsi(sb);
778 struct ll_sb_info *sbi = ll_s2sbi(sb);
779 struct obd_device *obd;
780 char name[MAX_STRING_SIZE + 1], *ptr;
781 int err, id, len, rc;
784 memset(lvars, 0, sizeof(lvars));
786 name[MAX_STRING_SIZE] = '\0';
787 lvars[0].name = name;
789 LASSERT(sbi != NULL);
790 LASSERT(mdc != NULL);
791 LASSERT(osc != NULL);
794 len = strlen(lsi->lsi_lmd->lmd_profile);
795 ptr = strrchr(lsi->lsi_lmd->lmd_profile, '-');
796 if (ptr && (strcmp(ptr, "-client") == 0))
800 snprintf(name, MAX_STRING_SIZE, "%.*s-%p", len,
801 lsi->lsi_lmd->lmd_profile, sb);
803 sbi->ll_proc_root = lprocfs_register(name, parent, NULL, NULL);
804 if (IS_ERR(sbi->ll_proc_root)) {
805 err = PTR_ERR(sbi->ll_proc_root);
806 sbi->ll_proc_root = NULL;
810 rc = lprocfs_seq_create(sbi->ll_proc_root, "dump_page_cache", 0444,
811 &vvp_dump_pgcache_file_ops, sbi);
813 CWARN("Error adding the dump_page_cache file\n");
815 rc = lprocfs_seq_create(sbi->ll_proc_root, "extents_stats", 0644,
816 &ll_rw_extents_stats_fops, sbi);
818 CWARN("Error adding the extent_stats file\n");
820 rc = lprocfs_seq_create(sbi->ll_proc_root, "extents_stats_per_process",
821 0644, &ll_rw_extents_stats_pp_fops, sbi);
823 CWARN("Error adding the extents_stats_per_process file\n");
825 rc = lprocfs_seq_create(sbi->ll_proc_root, "offset_stats", 0644,
826 &ll_rw_offset_stats_fops, sbi);
828 CWARN("Error adding the offset_stats file\n");
830 /* File operations stats */
831 sbi->ll_stats = lprocfs_alloc_stats(LPROC_LL_FILE_OPCODES,
832 LPROCFS_STATS_FLAG_NONE);
833 if (sbi->ll_stats == NULL)
834 GOTO(out, err = -ENOMEM);
835 /* do counter init */
836 for (id = 0; id < LPROC_LL_FILE_OPCODES; id++) {
837 __u32 type = llite_opcode_table[id].type;
839 if (type & LPROCFS_TYPE_REGS)
841 else if (type & LPROCFS_TYPE_BYTES)
843 else if (type & LPROCFS_TYPE_PAGES)
845 lprocfs_counter_init(sbi->ll_stats,
846 llite_opcode_table[id].opcode,
847 (type & LPROCFS_CNTR_AVGMINMAX),
848 llite_opcode_table[id].opname, ptr);
850 err = lprocfs_register_stats(sbi->ll_proc_root, "stats", sbi->ll_stats);
854 sbi->ll_ra_stats = lprocfs_alloc_stats(ARRAY_SIZE(ra_stat_string),
855 LPROCFS_STATS_FLAG_NONE);
856 if (sbi->ll_ra_stats == NULL)
857 GOTO(out, err = -ENOMEM);
859 for (id = 0; id < ARRAY_SIZE(ra_stat_string); id++)
860 lprocfs_counter_init(sbi->ll_ra_stats, id, 0,
861 ra_stat_string[id], "pages");
862 err = lprocfs_register_stats(sbi->ll_proc_root, "read_ahead_stats",
868 err = lprocfs_add_vars(sbi->ll_proc_root, lprocfs_llite_obd_vars, sb);
873 obd = class_name2obd(mdc);
875 LASSERT(obd != NULL);
876 LASSERT(obd->obd_magic == OBD_DEVICE_MAGIC);
877 LASSERT(obd->obd_type->typ_name != NULL);
879 snprintf(name, MAX_STRING_SIZE, "%s/common_name",
880 obd->obd_type->typ_name);
881 lvars[0].read_fptr = lprocfs_rd_name;
882 err = lprocfs_add_vars(sbi->ll_proc_root, lvars, obd);
886 snprintf(name, MAX_STRING_SIZE, "%s/uuid", obd->obd_type->typ_name);
887 lvars[0].read_fptr = lprocfs_rd_uuid;
888 err = lprocfs_add_vars(sbi->ll_proc_root, lvars, obd);
893 obd = class_name2obd(osc);
895 LASSERT(obd != NULL);
896 LASSERT(obd->obd_magic == OBD_DEVICE_MAGIC);
897 LASSERT(obd->obd_type->typ_name != NULL);
899 snprintf(name, MAX_STRING_SIZE, "%s/common_name",
900 obd->obd_type->typ_name);
901 lvars[0].read_fptr = lprocfs_rd_name;
902 err = lprocfs_add_vars(sbi->ll_proc_root, lvars, obd);
906 snprintf(name, MAX_STRING_SIZE, "%s/uuid", obd->obd_type->typ_name);
907 lvars[0].read_fptr = lprocfs_rd_uuid;
908 err = lprocfs_add_vars(sbi->ll_proc_root, lvars, obd);
911 lprocfs_remove(&sbi->ll_proc_root);
912 lprocfs_free_stats(&sbi->ll_ra_stats);
913 lprocfs_free_stats(&sbi->ll_stats);
918 void lprocfs_unregister_mountpoint(struct ll_sb_info *sbi)
920 if (sbi->ll_proc_root) {
921 lprocfs_remove(&sbi->ll_proc_root);
922 lprocfs_free_stats(&sbi->ll_ra_stats);
923 lprocfs_free_stats(&sbi->ll_stats);
926 #undef MAX_STRING_SIZE
928 #define pct(a,b) (b ? a * 100 / b : 0)
930 static void ll_display_extents_info(struct ll_rw_extents_info *io_extents,
931 struct seq_file *seq, int which)
933 unsigned long read_tot = 0, write_tot = 0, read_cum, write_cum;
934 unsigned long start, end, r, w;
935 char *unitp = "KMGTPEZY";
937 struct per_process_info *pp_info = &io_extents->pp_extents[which];
943 for(i = 0; i < LL_HIST_MAX; i++) {
944 read_tot += pp_info->pp_r_hist.oh_buckets[i];
945 write_tot += pp_info->pp_w_hist.oh_buckets[i];
948 for(i = 0; i < LL_HIST_MAX; i++) {
949 r = pp_info->pp_r_hist.oh_buckets[i];
950 w = pp_info->pp_w_hist.oh_buckets[i];
953 end = 1 << (i + LL_HIST_START - units);
954 seq_printf(seq, "%4lu%c - %4lu%c%c: %14lu %4lu %4lu | "
955 "%14lu %4lu %4lu\n", start, *unitp, end, *unitp,
956 (i == LL_HIST_MAX - 1) ? '+' : ' ',
957 r, pct(r, read_tot), pct(read_cum, read_tot),
958 w, pct(w, write_tot), pct(write_cum, write_tot));
960 if (start == 1<<10) {
965 if (read_cum == read_tot && write_cum == write_tot)
970 static int ll_rw_extents_stats_pp_seq_show(struct seq_file *seq, void *v)
973 struct ll_sb_info *sbi = seq->private;
974 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
977 cfs_gettimeofday(&now);
979 if (!sbi->ll_rw_stats_on) {
980 seq_printf(seq, "disabled\n"
981 "write anything in this file to activate, "
982 "then 0 or \"[D/d]isabled\" to deactivate\n");
985 seq_printf(seq, "snapshot_time: %lu.%lu (secs.usecs)\n",
986 now.tv_sec, now.tv_usec);
987 seq_printf(seq, "%15s %19s | %20s\n", " ", "read", "write");
988 seq_printf(seq, "%13s %14s %4s %4s | %14s %4s %4s\n",
989 "extents", "calls", "%", "cum%",
990 "calls", "%", "cum%");
991 cfs_spin_lock(&sbi->ll_pp_extent_lock);
992 for(k = 0; k < LL_PROCESS_HIST_MAX; k++) {
993 if(io_extents->pp_extents[k].pid != 0) {
994 seq_printf(seq, "\nPID: %d\n",
995 io_extents->pp_extents[k].pid);
996 ll_display_extents_info(io_extents, seq, k);
999 cfs_spin_unlock(&sbi->ll_pp_extent_lock);
1003 static ssize_t ll_rw_extents_stats_pp_seq_write(struct file *file,
1004 const char *buf, size_t len,
1007 struct seq_file *seq = file->private_data;
1008 struct ll_sb_info *sbi = seq->private;
1009 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1011 int value = 1, rc = 0;
1013 rc = lprocfs_write_helper(buf, len, &value);
1014 if (rc < 0 && (strcmp(buf, "disabled") == 0 ||
1015 strcmp(buf, "Disabled") == 0))
1019 sbi->ll_rw_stats_on = 0;
1021 sbi->ll_rw_stats_on = 1;
1023 cfs_spin_lock(&sbi->ll_pp_extent_lock);
1024 for(i = 0; i < LL_PROCESS_HIST_MAX; i++) {
1025 io_extents->pp_extents[i].pid = 0;
1026 lprocfs_oh_clear(&io_extents->pp_extents[i].pp_r_hist);
1027 lprocfs_oh_clear(&io_extents->pp_extents[i].pp_w_hist);
1029 cfs_spin_unlock(&sbi->ll_pp_extent_lock);
1033 LPROC_SEQ_FOPS(ll_rw_extents_stats_pp);
1035 static int ll_rw_extents_stats_seq_show(struct seq_file *seq, void *v)
1038 struct ll_sb_info *sbi = seq->private;
1039 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1041 cfs_gettimeofday(&now);
1043 if (!sbi->ll_rw_stats_on) {
1044 seq_printf(seq, "disabled\n"
1045 "write anything in this file to activate, "
1046 "then 0 or \"[D/d]isabled\" to deactivate\n");
1049 seq_printf(seq, "snapshot_time: %lu.%lu (secs.usecs)\n",
1050 now.tv_sec, now.tv_usec);
1052 seq_printf(seq, "%15s %19s | %20s\n", " ", "read", "write");
1053 seq_printf(seq, "%13s %14s %4s %4s | %14s %4s %4s\n",
1054 "extents", "calls", "%", "cum%",
1055 "calls", "%", "cum%");
1056 cfs_spin_lock(&sbi->ll_lock);
1057 ll_display_extents_info(io_extents, seq, LL_PROCESS_HIST_MAX);
1058 cfs_spin_unlock(&sbi->ll_lock);
1063 static ssize_t ll_rw_extents_stats_seq_write(struct file *file, const char *buf,
1064 size_t len, loff_t *off)
1066 struct seq_file *seq = file->private_data;
1067 struct ll_sb_info *sbi = seq->private;
1068 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1070 int value = 1, rc = 0;
1072 rc = lprocfs_write_helper(buf, len, &value);
1073 if (rc < 0 && (strcmp(buf, "disabled") == 0 ||
1074 strcmp(buf, "Disabled") == 0))
1078 sbi->ll_rw_stats_on = 0;
1080 sbi->ll_rw_stats_on = 1;
1081 cfs_spin_lock(&sbi->ll_pp_extent_lock);
1082 for(i = 0; i <= LL_PROCESS_HIST_MAX; i++)
1084 io_extents->pp_extents[i].pid = 0;
1085 lprocfs_oh_clear(&io_extents->pp_extents[i].pp_r_hist);
1086 lprocfs_oh_clear(&io_extents->pp_extents[i].pp_w_hist);
1088 cfs_spin_unlock(&sbi->ll_pp_extent_lock);
1093 LPROC_SEQ_FOPS(ll_rw_extents_stats);
1095 void ll_rw_stats_tally(struct ll_sb_info *sbi, pid_t pid,
1096 struct ll_file_data *file, loff_t pos,
1097 size_t count, int rw)
1100 struct ll_rw_process_info *process;
1101 struct ll_rw_process_info *offset;
1102 int *off_count = &sbi->ll_rw_offset_entry_count;
1103 int *process_count = &sbi->ll_offset_process_count;
1104 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1106 if(!sbi->ll_rw_stats_on)
1108 process = sbi->ll_rw_process_info;
1109 offset = sbi->ll_rw_offset_info;
1111 cfs_spin_lock(&sbi->ll_pp_extent_lock);
1112 /* Extent statistics */
1113 for(i = 0; i < LL_PROCESS_HIST_MAX; i++) {
1114 if(io_extents->pp_extents[i].pid == pid) {
1122 sbi->ll_extent_process_count =
1123 (sbi->ll_extent_process_count + 1) % LL_PROCESS_HIST_MAX;
1124 cur = sbi->ll_extent_process_count;
1125 io_extents->pp_extents[cur].pid = pid;
1126 lprocfs_oh_clear(&io_extents->pp_extents[cur].pp_r_hist);
1127 lprocfs_oh_clear(&io_extents->pp_extents[cur].pp_w_hist);
1130 for(i = 0; (count >= (1 << LL_HIST_START << i)) &&
1131 (i < (LL_HIST_MAX - 1)); i++);
1133 io_extents->pp_extents[cur].pp_r_hist.oh_buckets[i]++;
1134 io_extents->pp_extents[LL_PROCESS_HIST_MAX].pp_r_hist.oh_buckets[i]++;
1136 io_extents->pp_extents[cur].pp_w_hist.oh_buckets[i]++;
1137 io_extents->pp_extents[LL_PROCESS_HIST_MAX].pp_w_hist.oh_buckets[i]++;
1139 cfs_spin_unlock(&sbi->ll_pp_extent_lock);
1141 cfs_spin_lock(&sbi->ll_process_lock);
1142 /* Offset statistics */
1143 for (i = 0; i < LL_PROCESS_HIST_MAX; i++) {
1144 if (process[i].rw_pid == pid) {
1145 if (process[i].rw_last_file != file) {
1146 process[i].rw_range_start = pos;
1147 process[i].rw_last_file_pos = pos + count;
1148 process[i].rw_smallest_extent = count;
1149 process[i].rw_largest_extent = count;
1150 process[i].rw_offset = 0;
1151 process[i].rw_last_file = file;
1152 cfs_spin_unlock(&sbi->ll_process_lock);
1155 if (process[i].rw_last_file_pos != pos) {
1157 (*off_count + 1) % LL_OFFSET_HIST_MAX;
1158 offset[*off_count].rw_op = process[i].rw_op;
1159 offset[*off_count].rw_pid = pid;
1160 offset[*off_count].rw_range_start =
1161 process[i].rw_range_start;
1162 offset[*off_count].rw_range_end =
1163 process[i].rw_last_file_pos;
1164 offset[*off_count].rw_smallest_extent =
1165 process[i].rw_smallest_extent;
1166 offset[*off_count].rw_largest_extent =
1167 process[i].rw_largest_extent;
1168 offset[*off_count].rw_offset =
1169 process[i].rw_offset;
1170 process[i].rw_op = rw;
1171 process[i].rw_range_start = pos;
1172 process[i].rw_smallest_extent = count;
1173 process[i].rw_largest_extent = count;
1174 process[i].rw_offset = pos -
1175 process[i].rw_last_file_pos;
1177 if(process[i].rw_smallest_extent > count)
1178 process[i].rw_smallest_extent = count;
1179 if(process[i].rw_largest_extent < count)
1180 process[i].rw_largest_extent = count;
1181 process[i].rw_last_file_pos = pos + count;
1182 cfs_spin_unlock(&sbi->ll_process_lock);
1186 *process_count = (*process_count + 1) % LL_PROCESS_HIST_MAX;
1187 process[*process_count].rw_pid = pid;
1188 process[*process_count].rw_op = rw;
1189 process[*process_count].rw_range_start = pos;
1190 process[*process_count].rw_last_file_pos = pos + count;
1191 process[*process_count].rw_smallest_extent = count;
1192 process[*process_count].rw_largest_extent = count;
1193 process[*process_count].rw_offset = 0;
1194 process[*process_count].rw_last_file = file;
1195 cfs_spin_unlock(&sbi->ll_process_lock);
1198 static int ll_rw_offset_stats_seq_show(struct seq_file *seq, void *v)
1201 struct ll_sb_info *sbi = seq->private;
1202 struct ll_rw_process_info *offset = sbi->ll_rw_offset_info;
1203 struct ll_rw_process_info *process = sbi->ll_rw_process_info;
1206 cfs_gettimeofday(&now);
1208 if (!sbi->ll_rw_stats_on) {
1209 seq_printf(seq, "disabled\n"
1210 "write anything in this file to activate, "
1211 "then 0 or \"[D/d]isabled\" to deactivate\n");
1214 cfs_spin_lock(&sbi->ll_process_lock);
1216 seq_printf(seq, "snapshot_time: %lu.%lu (secs.usecs)\n",
1217 now.tv_sec, now.tv_usec);
1218 seq_printf(seq, "%3s %10s %14s %14s %17s %17s %14s\n",
1219 "R/W", "PID", "RANGE START", "RANGE END",
1220 "SMALLEST EXTENT", "LARGEST EXTENT", "OFFSET");
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 seq_printf(seq,"%3c %10d %14Lu %14Lu %17lu %17lu %14Lu",
1225 offset[i].rw_op ? 'W' : 'R',
1227 offset[i].rw_range_start,
1228 offset[i].rw_range_end,
1229 (unsigned long)offset[i].rw_smallest_extent,
1230 (unsigned long)offset[i].rw_largest_extent,
1231 offset[i].rw_offset);
1233 /* Then print the current offsets for each process */
1234 for(i = 0; i < LL_PROCESS_HIST_MAX; i++) {
1235 if (process[i].rw_pid != 0)
1236 seq_printf(seq,"%3c %10d %14Lu %14Lu %17lu %17lu %14Lu",
1237 process[i].rw_op ? 'W' : 'R',
1239 process[i].rw_range_start,
1240 process[i].rw_last_file_pos,
1241 (unsigned long)process[i].rw_smallest_extent,
1242 (unsigned long)process[i].rw_largest_extent,
1243 process[i].rw_offset);
1245 cfs_spin_unlock(&sbi->ll_process_lock);
1250 static ssize_t ll_rw_offset_stats_seq_write(struct file *file, const char *buf,
1251 size_t len, loff_t *off)
1253 struct seq_file *seq = file->private_data;
1254 struct ll_sb_info *sbi = seq->private;
1255 struct ll_rw_process_info *process_info = sbi->ll_rw_process_info;
1256 struct ll_rw_process_info *offset_info = sbi->ll_rw_offset_info;
1257 int value = 1, rc = 0;
1259 rc = lprocfs_write_helper(buf, len, &value);
1261 if (rc < 0 && (strcmp(buf, "disabled") == 0 ||
1262 strcmp(buf, "Disabled") == 0))
1266 sbi->ll_rw_stats_on = 0;
1268 sbi->ll_rw_stats_on = 1;
1270 cfs_spin_lock(&sbi->ll_process_lock);
1271 sbi->ll_offset_process_count = 0;
1272 sbi->ll_rw_offset_entry_count = 0;
1273 memset(process_info, 0, sizeof(struct ll_rw_process_info) *
1274 LL_PROCESS_HIST_MAX);
1275 memset(offset_info, 0, sizeof(struct ll_rw_process_info) *
1276 LL_OFFSET_HIST_MAX);
1277 cfs_spin_unlock(&sbi->ll_process_lock);
1282 LPROC_SEQ_FOPS(ll_rw_offset_stats);
1284 void lprocfs_llite_init_vars(struct lprocfs_static_vars *lvars)
1286 lvars->module_vars = NULL;
1287 lvars->obd_vars = lprocfs_llite_obd_vars;
1289 #endif /* LPROCFS */