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, 2013, Intel Corporation.
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 spin_lock(&sbi->ll_lock);
243 pages_number = sbi->ll_ra_info.ra_max_pages;
244 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 spin_lock(&sbi->ll_lock);
269 sbi->ll_ra_info.ra_max_pages = pages_number;
270 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 spin_lock(&sbi->ll_lock);
284 pages_number = sbi->ll_ra_info.ra_max_pages_per_file;
285 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 spin_lock(&sbi->ll_lock);
312 sbi->ll_ra_info.ra_max_pages_per_file = pages_number;
313 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 spin_lock(&sbi->ll_lock);
327 pages_number = sbi->ll_ra_info.ra_max_read_ahead_whole_pages;
328 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 spin_lock(&sbi->ll_lock);
357 sbi->ll_ra_info.ra_max_read_ahead_whole_pages = pages_number;
358 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);
368 struct cl_client_cache *cache = &sbi->ll_cache;
369 int shift = 20 - CFS_PAGE_SHIFT;
374 max_cached_mb = cache->ccc_lru_max >> shift;
375 unused_mb = cfs_atomic_read(&cache->ccc_lru_left) >> shift;
376 return snprintf(page, count,
378 "max_cached_mb: %d\n"
381 "reclaim_count: %u\n",
382 cfs_atomic_read(&cache->ccc_users),
384 max_cached_mb - unused_mb,
386 cache->ccc_lru_shrinkers);
389 static int ll_wr_max_cached_mb(struct file *file, const char *buffer,
390 unsigned long count, void *data)
392 struct super_block *sb = data;
393 struct ll_sb_info *sbi = ll_s2sbi(sb);
394 struct cl_client_cache *cache = &sbi->ll_cache;
395 int mult, rc, pages_number;
400 mult = 1 << (20 - CFS_PAGE_SHIFT);
401 buffer = lprocfs_find_named_value(buffer, "max_cached_mb:", &count);
402 rc = lprocfs_write_frac_helper(buffer, count, &pages_number, mult);
406 if (pages_number < 0 || pages_number > cfs_num_physpages) {
407 CERROR("%s: can't set max cache more than %lu MB\n",
408 ll_get_fsname(sb, NULL, 0),
409 cfs_num_physpages >> (20 - CFS_PAGE_SHIFT));
413 if (sbi->ll_dt_exp == NULL)
416 spin_lock(&sbi->ll_lock);
417 diff = pages_number - cache->ccc_lru_max;
418 spin_unlock(&sbi->ll_lock);
420 /* easy - add more LRU slots. */
422 cfs_atomic_add(diff, &cache->ccc_lru_left);
430 /* reduce LRU budget from free slots. */
434 ov = cfs_atomic_read(&cache->ccc_lru_left);
438 nv = ov > diff ? ov - diff : 0;
439 rc = cfs_atomic_cmpxchg(&cache->ccc_lru_left, ov, nv);
440 if (likely(ov == rc)) {
450 /* difficult - have to ask OSCs to drop LRU slots. */
452 rc = obd_set_info_async(NULL, sbi->ll_dt_exp,
453 sizeof(KEY_CACHE_LRU_SHRINK),
454 KEY_CACHE_LRU_SHRINK,
455 sizeof(tmp), &tmp, NULL);
462 spin_lock(&sbi->ll_lock);
463 cache->ccc_lru_max = pages_number;
464 spin_unlock(&sbi->ll_lock);
467 cfs_atomic_add(nrpages, &cache->ccc_lru_left);
472 static int ll_rd_checksum(char *page, char **start, off_t off,
473 int count, int *eof, void *data)
475 struct super_block *sb = data;
476 struct ll_sb_info *sbi = ll_s2sbi(sb);
478 return snprintf(page, count, "%u\n",
479 (sbi->ll_flags & LL_SBI_CHECKSUM) ? 1 : 0);
482 static int ll_wr_checksum(struct file *file, const char *buffer,
483 unsigned long count, void *data)
485 struct super_block *sb = data;
486 struct ll_sb_info *sbi = ll_s2sbi(sb);
493 rc = lprocfs_write_helper(buffer, count, &val);
497 sbi->ll_flags |= LL_SBI_CHECKSUM;
499 sbi->ll_flags &= ~LL_SBI_CHECKSUM;
501 rc = obd_set_info_async(NULL, sbi->ll_dt_exp, sizeof(KEY_CHECKSUM),
502 KEY_CHECKSUM, sizeof(val), &val, NULL);
504 CWARN("Failed to set OSC checksum flags: %d\n", rc);
509 static int ll_rd_max_rw_chunk(char *page, char **start, off_t off,
510 int count, int *eof, void *data)
512 struct super_block *sb = data;
514 return snprintf(page, count, "%lu\n", ll_s2sbi(sb)->ll_max_rw_chunk);
517 static int ll_wr_max_rw_chunk(struct file *file, const char *buffer,
518 unsigned long count, void *data)
520 struct super_block *sb = data;
523 rc = lprocfs_write_helper(buffer, count, &val);
526 ll_s2sbi(sb)->ll_max_rw_chunk = val;
530 static int ll_rd_track_id(char *page, int count, void *data,
531 enum stats_track_type type)
533 struct super_block *sb = data;
535 if (ll_s2sbi(sb)->ll_stats_track_type == type) {
536 return snprintf(page, count, "%d\n",
537 ll_s2sbi(sb)->ll_stats_track_id);
539 } else if (ll_s2sbi(sb)->ll_stats_track_type == STATS_TRACK_ALL) {
540 return snprintf(page, count, "0 (all)\n");
542 return snprintf(page, count, "untracked\n");
546 static int ll_wr_track_id(const char *buffer, unsigned long count, void *data,
547 enum stats_track_type type)
549 struct super_block *sb = data;
552 rc = lprocfs_write_helper(buffer, count, &pid);
555 ll_s2sbi(sb)->ll_stats_track_id = pid;
557 ll_s2sbi(sb)->ll_stats_track_type = STATS_TRACK_ALL;
559 ll_s2sbi(sb)->ll_stats_track_type = type;
560 lprocfs_clear_stats(ll_s2sbi(sb)->ll_stats);
564 static int ll_rd_track_pid(char *page, char **start, off_t off,
565 int count, int *eof, void *data)
567 return (ll_rd_track_id(page, count, data, STATS_TRACK_PID));
570 static int ll_wr_track_pid(struct file *file, const char *buffer,
571 unsigned long count, void *data)
573 return (ll_wr_track_id(buffer, count, data, STATS_TRACK_PID));
576 static int ll_rd_track_ppid(char *page, char **start, off_t off,
577 int count, int *eof, void *data)
579 return (ll_rd_track_id(page, count, data, STATS_TRACK_PPID));
582 static int ll_wr_track_ppid(struct file *file, const char *buffer,
583 unsigned long count, void *data)
585 return (ll_wr_track_id(buffer, count, data, STATS_TRACK_PPID));
588 static int ll_rd_track_gid(char *page, char **start, off_t off,
589 int count, int *eof, void *data)
591 return (ll_rd_track_id(page, count, data, STATS_TRACK_GID));
594 static int ll_wr_track_gid(struct file *file, const char *buffer,
595 unsigned long count, void *data)
597 return (ll_wr_track_id(buffer, count, data, STATS_TRACK_GID));
600 static int ll_rd_statahead_max(char *page, char **start, off_t off,
601 int count, int *eof, void *data)
603 struct super_block *sb = data;
604 struct ll_sb_info *sbi = ll_s2sbi(sb);
606 return snprintf(page, count, "%u\n", sbi->ll_sa_max);
609 static int ll_wr_statahead_max(struct file *file, const char *buffer,
610 unsigned long count, void *data)
612 struct super_block *sb = data;
613 struct ll_sb_info *sbi = ll_s2sbi(sb);
616 rc = lprocfs_write_helper(buffer, count, &val);
620 if (val >= 0 && val <= LL_SA_RPC_MAX)
621 sbi->ll_sa_max = val;
623 CERROR("Bad statahead_max value %d. Valid values are in the "
624 "range [0, %d]\n", val, LL_SA_RPC_MAX);
629 static int ll_rd_statahead_agl(char *page, char **start, off_t off,
630 int count, int *eof, void *data)
632 struct super_block *sb = data;
633 struct ll_sb_info *sbi = ll_s2sbi(sb);
635 return snprintf(page, count, "%u\n",
636 sbi->ll_flags & LL_SBI_AGL_ENABLED ? 1 : 0);
639 static int ll_wr_statahead_agl(struct file *file, const char *buffer,
640 unsigned long count, void *data)
642 struct super_block *sb = data;
643 struct ll_sb_info *sbi = ll_s2sbi(sb);
646 rc = lprocfs_write_helper(buffer, count, &val);
651 sbi->ll_flags |= LL_SBI_AGL_ENABLED;
653 sbi->ll_flags &= ~LL_SBI_AGL_ENABLED;
658 static int ll_rd_statahead_stats(char *page, char **start, off_t off,
659 int count, int *eof, void *data)
661 struct super_block *sb = data;
662 struct ll_sb_info *sbi = ll_s2sbi(sb);
664 return snprintf(page, count,
665 "statahead total: %u\n"
666 "statahead wrong: %u\n"
668 atomic_read(&sbi->ll_sa_total),
669 atomic_read(&sbi->ll_sa_wrong),
670 atomic_read(&sbi->ll_agl_total));
673 static int ll_rd_lazystatfs(char *page, char **start, off_t off,
674 int count, int *eof, void *data)
676 struct super_block *sb = data;
677 struct ll_sb_info *sbi = ll_s2sbi(sb);
679 return snprintf(page, count, "%u\n",
680 (sbi->ll_flags & LL_SBI_LAZYSTATFS) ? 1 : 0);
683 static int ll_wr_lazystatfs(struct file *file, const char *buffer,
684 unsigned long count, void *data)
686 struct super_block *sb = data;
687 struct ll_sb_info *sbi = ll_s2sbi(sb);
690 rc = lprocfs_write_helper(buffer, count, &val);
695 sbi->ll_flags |= LL_SBI_LAZYSTATFS;
697 sbi->ll_flags &= ~LL_SBI_LAZYSTATFS;
702 static int ll_rd_maxea_size(char *page, char **start, off_t off,
703 int count, int *eof, void *data)
705 struct super_block *sb = data;
706 struct ll_sb_info *sbi = ll_s2sbi(sb);
710 rc = ll_get_max_mdsize(sbi, &ealen);
714 return snprintf(page, count, "%u\n", ealen);
717 static int ll_rd_sbi_flags(char *page, char **start, off_t off,
718 int count, int *eof, void *data)
720 const char *str[] = LL_SBI_FLAGS;
721 struct super_block *sb = data;
722 int flags = ll_s2sbi(sb)->ll_flags;
727 if (ARRAY_SIZE(str) <= i) {
728 CERROR("%s: Revise array LL_SBI_FLAGS to match sbi "
729 "flags please.\n", ll_get_fsname(sb, NULL, 0));
734 rc += snprintf(page + rc, count - rc, "%s ", str[i]);
739 rc += snprintf(page + rc, count - rc, "\b\n");
743 static struct lprocfs_vars lprocfs_llite_obd_vars[] = {
744 { "uuid", ll_rd_sb_uuid, 0, 0 },
745 //{ "mntpt_path", ll_rd_path, 0, 0 },
746 { "fstype", ll_rd_fstype, 0, 0 },
747 { "site", ll_rd_site_stats, 0, 0 },
748 { "blocksize", ll_rd_blksize, 0, 0 },
749 { "kbytestotal", ll_rd_kbytestotal, 0, 0 },
750 { "kbytesfree", ll_rd_kbytesfree, 0, 0 },
751 { "kbytesavail", ll_rd_kbytesavail, 0, 0 },
752 { "filestotal", ll_rd_filestotal, 0, 0 },
753 { "filesfree", ll_rd_filesfree, 0, 0 },
754 { "client_type", ll_rd_client_type, 0, 0 },
755 //{ "filegroups", lprocfs_rd_filegroups, 0, 0 },
756 { "max_read_ahead_mb", ll_rd_max_readahead_mb,
757 ll_wr_max_readahead_mb, 0 },
758 { "max_read_ahead_per_file_mb", ll_rd_max_readahead_per_file_mb,
759 ll_wr_max_readahead_per_file_mb, 0 },
760 { "max_read_ahead_whole_mb", ll_rd_max_read_ahead_whole_mb,
761 ll_wr_max_read_ahead_whole_mb, 0 },
762 { "max_cached_mb", ll_rd_max_cached_mb, ll_wr_max_cached_mb, 0 },
763 { "checksum_pages", ll_rd_checksum, ll_wr_checksum, 0 },
764 { "max_rw_chunk", ll_rd_max_rw_chunk, ll_wr_max_rw_chunk, 0 },
765 { "stats_track_pid", ll_rd_track_pid, ll_wr_track_pid, 0 },
766 { "stats_track_ppid", ll_rd_track_ppid, ll_wr_track_ppid, 0 },
767 { "stats_track_gid", ll_rd_track_gid, ll_wr_track_gid, 0 },
768 { "statahead_max", ll_rd_statahead_max, ll_wr_statahead_max, 0 },
769 { "statahead_agl", ll_rd_statahead_agl, ll_wr_statahead_agl, 0 },
770 { "statahead_stats", ll_rd_statahead_stats, 0, 0 },
771 { "lazystatfs", ll_rd_lazystatfs, ll_wr_lazystatfs, 0 },
772 { "max_easize", ll_rd_maxea_size, 0, 0 },
773 { "sbi_flags", ll_rd_sbi_flags, 0, 0 },
777 #define MAX_STRING_SIZE 128
779 struct llite_file_opcode {
783 } llite_opcode_table[LPROC_LL_FILE_OPCODES] = {
785 { LPROC_LL_DIRTY_HITS, LPROCFS_TYPE_REGS, "dirty_pages_hits" },
786 { LPROC_LL_DIRTY_MISSES, LPROCFS_TYPE_REGS, "dirty_pages_misses" },
787 { LPROC_LL_READ_BYTES, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_BYTES,
789 { LPROC_LL_WRITE_BYTES, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_BYTES,
791 { LPROC_LL_BRW_READ, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
793 { LPROC_LL_BRW_WRITE, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
795 { LPROC_LL_OSC_READ, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_BYTES,
797 { LPROC_LL_OSC_WRITE, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_BYTES,
799 { LPROC_LL_IOCTL, LPROCFS_TYPE_REGS, "ioctl" },
800 { LPROC_LL_OPEN, LPROCFS_TYPE_REGS, "open" },
801 { LPROC_LL_RELEASE, LPROCFS_TYPE_REGS, "close" },
802 { LPROC_LL_MAP, LPROCFS_TYPE_REGS, "mmap" },
803 { LPROC_LL_LLSEEK, LPROCFS_TYPE_REGS, "seek" },
804 { LPROC_LL_FSYNC, LPROCFS_TYPE_REGS, "fsync" },
805 { LPROC_LL_READDIR, LPROCFS_TYPE_REGS, "readdir" },
806 /* inode operation */
807 { LPROC_LL_SETATTR, LPROCFS_TYPE_REGS, "setattr" },
808 { LPROC_LL_TRUNC, LPROCFS_TYPE_REGS, "truncate" },
809 { LPROC_LL_FLOCK, LPROCFS_TYPE_REGS, "flock" },
810 { LPROC_LL_GETATTR, LPROCFS_TYPE_REGS, "getattr" },
811 /* dir inode operation */
812 { LPROC_LL_CREATE, LPROCFS_TYPE_REGS, "create" },
813 { LPROC_LL_LINK, LPROCFS_TYPE_REGS, "link" },
814 { LPROC_LL_UNLINK, LPROCFS_TYPE_REGS, "unlink" },
815 { LPROC_LL_SYMLINK, LPROCFS_TYPE_REGS, "symlink" },
816 { LPROC_LL_MKDIR, LPROCFS_TYPE_REGS, "mkdir" },
817 { LPROC_LL_RMDIR, LPROCFS_TYPE_REGS, "rmdir" },
818 { LPROC_LL_MKNOD, LPROCFS_TYPE_REGS, "mknod" },
819 { LPROC_LL_RENAME, LPROCFS_TYPE_REGS, "rename" },
820 /* special inode operation */
821 { LPROC_LL_STAFS, LPROCFS_TYPE_REGS, "statfs" },
822 { LPROC_LL_ALLOC_INODE, LPROCFS_TYPE_REGS, "alloc_inode" },
823 { LPROC_LL_SETXATTR, LPROCFS_TYPE_REGS, "setxattr" },
824 { LPROC_LL_GETXATTR, LPROCFS_TYPE_REGS, "getxattr" },
825 { LPROC_LL_LISTXATTR, LPROCFS_TYPE_REGS, "listxattr" },
826 { LPROC_LL_REMOVEXATTR, LPROCFS_TYPE_REGS, "removexattr" },
827 { LPROC_LL_INODE_PERM, LPROCFS_TYPE_REGS, "inode_permission" },
830 void ll_stats_ops_tally(struct ll_sb_info *sbi, int op, int count)
834 if (sbi->ll_stats_track_type == STATS_TRACK_ALL)
835 lprocfs_counter_add(sbi->ll_stats, op, count);
836 else if (sbi->ll_stats_track_type == STATS_TRACK_PID &&
837 sbi->ll_stats_track_id == current->pid)
838 lprocfs_counter_add(sbi->ll_stats, op, count);
839 else if (sbi->ll_stats_track_type == STATS_TRACK_PPID &&
840 sbi->ll_stats_track_id == current->parent->pid)
841 lprocfs_counter_add(sbi->ll_stats, op, count);
842 else if (sbi->ll_stats_track_type == STATS_TRACK_GID &&
843 sbi->ll_stats_track_id == cfs_curproc_gid())
844 lprocfs_counter_add(sbi->ll_stats, op, count);
846 EXPORT_SYMBOL(ll_stats_ops_tally);
848 static const char *ra_stat_string[] = {
849 [RA_STAT_HIT] = "hits",
850 [RA_STAT_MISS] = "misses",
851 [RA_STAT_DISTANT_READPAGE] = "readpage not consecutive",
852 [RA_STAT_MISS_IN_WINDOW] = "miss inside window",
853 [RA_STAT_FAILED_GRAB_PAGE] = "failed grab_cache_page",
854 [RA_STAT_FAILED_MATCH] = "failed lock match",
855 [RA_STAT_DISCARDED] = "read but discarded",
856 [RA_STAT_ZERO_LEN] = "zero length file",
857 [RA_STAT_ZERO_WINDOW] = "zero size window",
858 [RA_STAT_EOF] = "read-ahead to EOF",
859 [RA_STAT_MAX_IN_FLIGHT] = "hit max r-a issue",
860 [RA_STAT_WRONG_GRAB_PAGE] = "wrong page from grab_cache_page",
864 int lprocfs_register_mountpoint(struct proc_dir_entry *parent,
865 struct super_block *sb, char *osc, char *mdc)
867 struct lprocfs_vars lvars[2];
868 struct lustre_sb_info *lsi = s2lsi(sb);
869 struct ll_sb_info *sbi = ll_s2sbi(sb);
870 struct obd_device *obd;
871 char name[MAX_STRING_SIZE + 1], *ptr;
872 int err, id, len, rc;
875 memset(lvars, 0, sizeof(lvars));
877 name[MAX_STRING_SIZE] = '\0';
878 lvars[0].name = name;
880 LASSERT(sbi != NULL);
881 LASSERT(mdc != NULL);
882 LASSERT(osc != NULL);
885 len = strlen(lsi->lsi_lmd->lmd_profile);
886 ptr = strrchr(lsi->lsi_lmd->lmd_profile, '-');
887 if (ptr && (strcmp(ptr, "-client") == 0))
891 snprintf(name, MAX_STRING_SIZE, "%.*s-%p", len,
892 lsi->lsi_lmd->lmd_profile, sb);
894 sbi->ll_proc_root = lprocfs_register(name, parent, NULL, NULL);
895 if (IS_ERR(sbi->ll_proc_root)) {
896 err = PTR_ERR(sbi->ll_proc_root);
897 sbi->ll_proc_root = NULL;
901 rc = lprocfs_seq_create(sbi->ll_proc_root, "dump_page_cache", 0444,
902 &vvp_dump_pgcache_file_ops, sbi);
904 CWARN("Error adding the dump_page_cache file\n");
906 rc = lprocfs_seq_create(sbi->ll_proc_root, "extents_stats", 0644,
907 &ll_rw_extents_stats_fops, sbi);
909 CWARN("Error adding the extent_stats file\n");
911 rc = lprocfs_seq_create(sbi->ll_proc_root, "extents_stats_per_process",
912 0644, &ll_rw_extents_stats_pp_fops, sbi);
914 CWARN("Error adding the extents_stats_per_process file\n");
916 rc = lprocfs_seq_create(sbi->ll_proc_root, "offset_stats", 0644,
917 &ll_rw_offset_stats_fops, sbi);
919 CWARN("Error adding the offset_stats file\n");
921 /* File operations stats */
922 sbi->ll_stats = lprocfs_alloc_stats(LPROC_LL_FILE_OPCODES,
923 LPROCFS_STATS_FLAG_NONE);
924 if (sbi->ll_stats == NULL)
925 GOTO(out, err = -ENOMEM);
926 /* do counter init */
927 for (id = 0; id < LPROC_LL_FILE_OPCODES; id++) {
928 __u32 type = llite_opcode_table[id].type;
930 if (type & LPROCFS_TYPE_REGS)
932 else if (type & LPROCFS_TYPE_BYTES)
934 else if (type & LPROCFS_TYPE_PAGES)
936 lprocfs_counter_init(sbi->ll_stats,
937 llite_opcode_table[id].opcode,
938 (type & LPROCFS_CNTR_AVGMINMAX),
939 llite_opcode_table[id].opname, ptr);
941 err = lprocfs_register_stats(sbi->ll_proc_root, "stats", sbi->ll_stats);
945 sbi->ll_ra_stats = lprocfs_alloc_stats(ARRAY_SIZE(ra_stat_string),
946 LPROCFS_STATS_FLAG_NONE);
947 if (sbi->ll_ra_stats == NULL)
948 GOTO(out, err = -ENOMEM);
950 for (id = 0; id < ARRAY_SIZE(ra_stat_string); id++)
951 lprocfs_counter_init(sbi->ll_ra_stats, id, 0,
952 ra_stat_string[id], "pages");
953 err = lprocfs_register_stats(sbi->ll_proc_root, "read_ahead_stats",
959 err = lprocfs_add_vars(sbi->ll_proc_root, lprocfs_llite_obd_vars, sb);
964 obd = class_name2obd(mdc);
966 LASSERT(obd != NULL);
967 LASSERT(obd->obd_magic == OBD_DEVICE_MAGIC);
968 LASSERT(obd->obd_type->typ_name != NULL);
970 snprintf(name, MAX_STRING_SIZE, "%s/common_name",
971 obd->obd_type->typ_name);
972 lvars[0].read_fptr = lprocfs_rd_name;
973 err = lprocfs_add_vars(sbi->ll_proc_root, lvars, obd);
977 snprintf(name, MAX_STRING_SIZE, "%s/uuid", obd->obd_type->typ_name);
978 lvars[0].read_fptr = lprocfs_rd_uuid;
979 err = lprocfs_add_vars(sbi->ll_proc_root, lvars, obd);
984 obd = class_name2obd(osc);
986 LASSERT(obd != NULL);
987 LASSERT(obd->obd_magic == OBD_DEVICE_MAGIC);
988 LASSERT(obd->obd_type->typ_name != NULL);
990 snprintf(name, MAX_STRING_SIZE, "%s/common_name",
991 obd->obd_type->typ_name);
992 lvars[0].read_fptr = lprocfs_rd_name;
993 err = lprocfs_add_vars(sbi->ll_proc_root, lvars, obd);
997 snprintf(name, MAX_STRING_SIZE, "%s/uuid", obd->obd_type->typ_name);
998 lvars[0].read_fptr = lprocfs_rd_uuid;
999 err = lprocfs_add_vars(sbi->ll_proc_root, lvars, obd);
1002 lprocfs_remove(&sbi->ll_proc_root);
1003 lprocfs_free_stats(&sbi->ll_ra_stats);
1004 lprocfs_free_stats(&sbi->ll_stats);
1009 void lprocfs_unregister_mountpoint(struct ll_sb_info *sbi)
1011 if (sbi->ll_proc_root) {
1012 lprocfs_remove(&sbi->ll_proc_root);
1013 lprocfs_free_stats(&sbi->ll_ra_stats);
1014 lprocfs_free_stats(&sbi->ll_stats);
1017 #undef MAX_STRING_SIZE
1019 #define pct(a,b) (b ? a * 100 / b : 0)
1021 static void ll_display_extents_info(struct ll_rw_extents_info *io_extents,
1022 struct seq_file *seq, int which)
1024 unsigned long read_tot = 0, write_tot = 0, read_cum, write_cum;
1025 unsigned long start, end, r, w;
1026 char *unitp = "KMGTPEZY";
1028 struct per_process_info *pp_info = &io_extents->pp_extents[which];
1034 for(i = 0; i < LL_HIST_MAX; i++) {
1035 read_tot += pp_info->pp_r_hist.oh_buckets[i];
1036 write_tot += pp_info->pp_w_hist.oh_buckets[i];
1039 for(i = 0; i < LL_HIST_MAX; i++) {
1040 r = pp_info->pp_r_hist.oh_buckets[i];
1041 w = pp_info->pp_w_hist.oh_buckets[i];
1044 end = 1 << (i + LL_HIST_START - units);
1045 seq_printf(seq, "%4lu%c - %4lu%c%c: %14lu %4lu %4lu | "
1046 "%14lu %4lu %4lu\n", start, *unitp, end, *unitp,
1047 (i == LL_HIST_MAX - 1) ? '+' : ' ',
1048 r, pct(r, read_tot), pct(read_cum, read_tot),
1049 w, pct(w, write_tot), pct(write_cum, write_tot));
1051 if (start == 1<<10) {
1056 if (read_cum == read_tot && write_cum == write_tot)
1061 static int ll_rw_extents_stats_pp_seq_show(struct seq_file *seq, void *v)
1064 struct ll_sb_info *sbi = seq->private;
1065 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1068 cfs_gettimeofday(&now);
1070 if (!sbi->ll_rw_stats_on) {
1071 seq_printf(seq, "disabled\n"
1072 "write anything in this file to activate, "
1073 "then 0 or \"[D/d]isabled\" to deactivate\n");
1076 seq_printf(seq, "snapshot_time: %lu.%lu (secs.usecs)\n",
1077 now.tv_sec, now.tv_usec);
1078 seq_printf(seq, "%15s %19s | %20s\n", " ", "read", "write");
1079 seq_printf(seq, "%13s %14s %4s %4s | %14s %4s %4s\n",
1080 "extents", "calls", "%", "cum%",
1081 "calls", "%", "cum%");
1082 spin_lock(&sbi->ll_pp_extent_lock);
1083 for (k = 0; k < LL_PROCESS_HIST_MAX; k++) {
1084 if (io_extents->pp_extents[k].pid != 0) {
1085 seq_printf(seq, "\nPID: %d\n",
1086 io_extents->pp_extents[k].pid);
1087 ll_display_extents_info(io_extents, seq, k);
1090 spin_unlock(&sbi->ll_pp_extent_lock);
1094 static ssize_t ll_rw_extents_stats_pp_seq_write(struct file *file,
1095 const char *buf, size_t len,
1098 struct seq_file *seq = file->private_data;
1099 struct ll_sb_info *sbi = seq->private;
1100 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1102 int value = 1, rc = 0;
1104 rc = lprocfs_write_helper(buf, len, &value);
1105 if (rc < 0 && (strcmp(buf, "disabled") == 0 ||
1106 strcmp(buf, "Disabled") == 0))
1110 sbi->ll_rw_stats_on = 0;
1112 sbi->ll_rw_stats_on = 1;
1114 spin_lock(&sbi->ll_pp_extent_lock);
1115 for (i = 0; i < LL_PROCESS_HIST_MAX; i++) {
1116 io_extents->pp_extents[i].pid = 0;
1117 lprocfs_oh_clear(&io_extents->pp_extents[i].pp_r_hist);
1118 lprocfs_oh_clear(&io_extents->pp_extents[i].pp_w_hist);
1120 spin_unlock(&sbi->ll_pp_extent_lock);
1124 LPROC_SEQ_FOPS(ll_rw_extents_stats_pp);
1126 static int ll_rw_extents_stats_seq_show(struct seq_file *seq, void *v)
1129 struct ll_sb_info *sbi = seq->private;
1130 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1132 cfs_gettimeofday(&now);
1134 if (!sbi->ll_rw_stats_on) {
1135 seq_printf(seq, "disabled\n"
1136 "write anything in this file to activate, "
1137 "then 0 or \"[D/d]isabled\" to deactivate\n");
1140 seq_printf(seq, "snapshot_time: %lu.%lu (secs.usecs)\n",
1141 now.tv_sec, now.tv_usec);
1143 seq_printf(seq, "%15s %19s | %20s\n", " ", "read", "write");
1144 seq_printf(seq, "%13s %14s %4s %4s | %14s %4s %4s\n",
1145 "extents", "calls", "%", "cum%",
1146 "calls", "%", "cum%");
1147 spin_lock(&sbi->ll_lock);
1148 ll_display_extents_info(io_extents, seq, LL_PROCESS_HIST_MAX);
1149 spin_unlock(&sbi->ll_lock);
1154 static ssize_t ll_rw_extents_stats_seq_write(struct file *file, const char *buf,
1155 size_t len, loff_t *off)
1157 struct seq_file *seq = file->private_data;
1158 struct ll_sb_info *sbi = seq->private;
1159 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1161 int value = 1, rc = 0;
1163 rc = lprocfs_write_helper(buf, len, &value);
1164 if (rc < 0 && (strcmp(buf, "disabled") == 0 ||
1165 strcmp(buf, "Disabled") == 0))
1169 sbi->ll_rw_stats_on = 0;
1171 sbi->ll_rw_stats_on = 1;
1172 spin_lock(&sbi->ll_pp_extent_lock);
1173 for (i = 0; i <= LL_PROCESS_HIST_MAX; i++) {
1174 io_extents->pp_extents[i].pid = 0;
1175 lprocfs_oh_clear(&io_extents->pp_extents[i].pp_r_hist);
1176 lprocfs_oh_clear(&io_extents->pp_extents[i].pp_w_hist);
1178 spin_unlock(&sbi->ll_pp_extent_lock);
1183 LPROC_SEQ_FOPS(ll_rw_extents_stats);
1185 void ll_rw_stats_tally(struct ll_sb_info *sbi, pid_t pid,
1186 struct ll_file_data *file, loff_t pos,
1187 size_t count, int rw)
1190 struct ll_rw_process_info *process;
1191 struct ll_rw_process_info *offset;
1192 int *off_count = &sbi->ll_rw_offset_entry_count;
1193 int *process_count = &sbi->ll_offset_process_count;
1194 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1196 if(!sbi->ll_rw_stats_on)
1198 process = sbi->ll_rw_process_info;
1199 offset = sbi->ll_rw_offset_info;
1201 spin_lock(&sbi->ll_pp_extent_lock);
1202 /* Extent statistics */
1203 for(i = 0; i < LL_PROCESS_HIST_MAX; i++) {
1204 if(io_extents->pp_extents[i].pid == pid) {
1212 sbi->ll_extent_process_count =
1213 (sbi->ll_extent_process_count + 1) % LL_PROCESS_HIST_MAX;
1214 cur = sbi->ll_extent_process_count;
1215 io_extents->pp_extents[cur].pid = pid;
1216 lprocfs_oh_clear(&io_extents->pp_extents[cur].pp_r_hist);
1217 lprocfs_oh_clear(&io_extents->pp_extents[cur].pp_w_hist);
1220 for(i = 0; (count >= (1 << LL_HIST_START << i)) &&
1221 (i < (LL_HIST_MAX - 1)); i++);
1223 io_extents->pp_extents[cur].pp_r_hist.oh_buckets[i]++;
1224 io_extents->pp_extents[LL_PROCESS_HIST_MAX].pp_r_hist.oh_buckets[i]++;
1226 io_extents->pp_extents[cur].pp_w_hist.oh_buckets[i]++;
1227 io_extents->pp_extents[LL_PROCESS_HIST_MAX].pp_w_hist.oh_buckets[i]++;
1229 spin_unlock(&sbi->ll_pp_extent_lock);
1231 spin_lock(&sbi->ll_process_lock);
1232 /* Offset statistics */
1233 for (i = 0; i < LL_PROCESS_HIST_MAX; i++) {
1234 if (process[i].rw_pid == pid) {
1235 if (process[i].rw_last_file != file) {
1236 process[i].rw_range_start = pos;
1237 process[i].rw_last_file_pos = pos + count;
1238 process[i].rw_smallest_extent = count;
1239 process[i].rw_largest_extent = count;
1240 process[i].rw_offset = 0;
1241 process[i].rw_last_file = file;
1242 spin_unlock(&sbi->ll_process_lock);
1245 if (process[i].rw_last_file_pos != pos) {
1247 (*off_count + 1) % LL_OFFSET_HIST_MAX;
1248 offset[*off_count].rw_op = process[i].rw_op;
1249 offset[*off_count].rw_pid = pid;
1250 offset[*off_count].rw_range_start =
1251 process[i].rw_range_start;
1252 offset[*off_count].rw_range_end =
1253 process[i].rw_last_file_pos;
1254 offset[*off_count].rw_smallest_extent =
1255 process[i].rw_smallest_extent;
1256 offset[*off_count].rw_largest_extent =
1257 process[i].rw_largest_extent;
1258 offset[*off_count].rw_offset =
1259 process[i].rw_offset;
1260 process[i].rw_op = rw;
1261 process[i].rw_range_start = pos;
1262 process[i].rw_smallest_extent = count;
1263 process[i].rw_largest_extent = count;
1264 process[i].rw_offset = pos -
1265 process[i].rw_last_file_pos;
1267 if(process[i].rw_smallest_extent > count)
1268 process[i].rw_smallest_extent = count;
1269 if(process[i].rw_largest_extent < count)
1270 process[i].rw_largest_extent = count;
1271 process[i].rw_last_file_pos = pos + count;
1272 spin_unlock(&sbi->ll_process_lock);
1276 *process_count = (*process_count + 1) % LL_PROCESS_HIST_MAX;
1277 process[*process_count].rw_pid = pid;
1278 process[*process_count].rw_op = rw;
1279 process[*process_count].rw_range_start = pos;
1280 process[*process_count].rw_last_file_pos = pos + count;
1281 process[*process_count].rw_smallest_extent = count;
1282 process[*process_count].rw_largest_extent = count;
1283 process[*process_count].rw_offset = 0;
1284 process[*process_count].rw_last_file = file;
1285 spin_unlock(&sbi->ll_process_lock);
1288 static int ll_rw_offset_stats_seq_show(struct seq_file *seq, void *v)
1291 struct ll_sb_info *sbi = seq->private;
1292 struct ll_rw_process_info *offset = sbi->ll_rw_offset_info;
1293 struct ll_rw_process_info *process = sbi->ll_rw_process_info;
1296 cfs_gettimeofday(&now);
1298 if (!sbi->ll_rw_stats_on) {
1299 seq_printf(seq, "disabled\n"
1300 "write anything in this file to activate, "
1301 "then 0 or \"[D/d]isabled\" to deactivate\n");
1304 spin_lock(&sbi->ll_process_lock);
1306 seq_printf(seq, "snapshot_time: %lu.%lu (secs.usecs)\n",
1307 now.tv_sec, now.tv_usec);
1308 seq_printf(seq, "%3s %10s %14s %14s %17s %17s %14s\n",
1309 "R/W", "PID", "RANGE START", "RANGE END",
1310 "SMALLEST EXTENT", "LARGEST EXTENT", "OFFSET");
1311 /* We stored the discontiguous offsets here; print them first */
1312 for(i = 0; i < LL_OFFSET_HIST_MAX; i++) {
1313 if (offset[i].rw_pid != 0)
1314 seq_printf(seq,"%3c %10d %14Lu %14Lu %17lu %17lu %14Lu",
1315 offset[i].rw_op ? 'W' : 'R',
1317 offset[i].rw_range_start,
1318 offset[i].rw_range_end,
1319 (unsigned long)offset[i].rw_smallest_extent,
1320 (unsigned long)offset[i].rw_largest_extent,
1321 offset[i].rw_offset);
1323 /* Then print the current offsets for each process */
1324 for(i = 0; i < LL_PROCESS_HIST_MAX; i++) {
1325 if (process[i].rw_pid != 0)
1326 seq_printf(seq,"%3c %10d %14Lu %14Lu %17lu %17lu %14Lu",
1327 process[i].rw_op ? 'W' : 'R',
1329 process[i].rw_range_start,
1330 process[i].rw_last_file_pos,
1331 (unsigned long)process[i].rw_smallest_extent,
1332 (unsigned long)process[i].rw_largest_extent,
1333 process[i].rw_offset);
1335 spin_unlock(&sbi->ll_process_lock);
1340 static ssize_t ll_rw_offset_stats_seq_write(struct file *file, const char *buf,
1341 size_t len, loff_t *off)
1343 struct seq_file *seq = file->private_data;
1344 struct ll_sb_info *sbi = seq->private;
1345 struct ll_rw_process_info *process_info = sbi->ll_rw_process_info;
1346 struct ll_rw_process_info *offset_info = sbi->ll_rw_offset_info;
1347 int value = 1, rc = 0;
1349 rc = lprocfs_write_helper(buf, len, &value);
1351 if (rc < 0 && (strcmp(buf, "disabled") == 0 ||
1352 strcmp(buf, "Disabled") == 0))
1356 sbi->ll_rw_stats_on = 0;
1358 sbi->ll_rw_stats_on = 1;
1360 spin_lock(&sbi->ll_process_lock);
1361 sbi->ll_offset_process_count = 0;
1362 sbi->ll_rw_offset_entry_count = 0;
1363 memset(process_info, 0, sizeof(struct ll_rw_process_info) *
1364 LL_PROCESS_HIST_MAX);
1365 memset(offset_info, 0, sizeof(struct ll_rw_process_info) *
1366 LL_OFFSET_HIST_MAX);
1367 spin_unlock(&sbi->ll_process_lock);
1372 LPROC_SEQ_FOPS(ll_rw_offset_stats);
1374 void lprocfs_llite_init_vars(struct lprocfs_static_vars *lvars)
1376 lvars->module_vars = NULL;
1377 lvars->obd_vars = lprocfs_llite_obd_vars;
1379 #endif /* LPROCFS */