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 - PAGE_CACHE_SHIFT);
258 rc = lprocfs_write_frac_helper(buffer, count, &pages_number, mult);
262 if (pages_number < 0 || pages_number > num_physpages / 2) {
264 CERROR("can't set file readahead more than %lu MB\n",
265 num_physpages >> (20 - PAGE_CACHE_SHIFT + 1));
269 spin_lock(&sbi->ll_lock);
270 sbi->ll_ra_info.ra_max_pages = pages_number;
271 spin_unlock(&sbi->ll_lock);
276 static int ll_rd_max_readahead_per_file_mb(char *page, char **start, off_t off,
277 int count, int *eof, void *data)
279 struct super_block *sb = data;
280 struct ll_sb_info *sbi = ll_s2sbi(sb);
284 spin_lock(&sbi->ll_lock);
285 pages_number = sbi->ll_ra_info.ra_max_pages_per_file;
286 spin_unlock(&sbi->ll_lock);
288 mult = 1 << (20 - PAGE_CACHE_SHIFT);
289 return lprocfs_read_frac_helper(page, count, pages_number, mult);
292 static int ll_wr_max_readahead_per_file_mb(struct file *file, const char *buffer,
293 unsigned long count, void *data)
295 struct super_block *sb = data;
296 struct ll_sb_info *sbi = ll_s2sbi(sb);
297 int mult, rc, pages_number;
299 mult = 1 << (20 - PAGE_CACHE_SHIFT);
300 rc = lprocfs_write_frac_helper(buffer, count, &pages_number, mult);
304 if (pages_number < 0 ||
305 pages_number > sbi->ll_ra_info.ra_max_pages) {
306 CERROR("can't set file readahead more than"
307 "max_read_ahead_mb %lu MB\n",
308 sbi->ll_ra_info.ra_max_pages);
312 spin_lock(&sbi->ll_lock);
313 sbi->ll_ra_info.ra_max_pages_per_file = pages_number;
314 spin_unlock(&sbi->ll_lock);
319 static int ll_rd_max_read_ahead_whole_mb(char *page, char **start, off_t off,
320 int count, int *eof, void *data)
322 struct super_block *sb = data;
323 struct ll_sb_info *sbi = ll_s2sbi(sb);
327 spin_lock(&sbi->ll_lock);
328 pages_number = sbi->ll_ra_info.ra_max_read_ahead_whole_pages;
329 spin_unlock(&sbi->ll_lock);
331 mult = 1 << (20 - PAGE_CACHE_SHIFT);
332 return lprocfs_read_frac_helper(page, count, pages_number, mult);
335 static int ll_wr_max_read_ahead_whole_mb(struct file *file, const char *buffer,
336 unsigned long count, void *data)
338 struct super_block *sb = data;
339 struct ll_sb_info *sbi = ll_s2sbi(sb);
340 int mult, rc, pages_number;
342 mult = 1 << (20 - PAGE_CACHE_SHIFT);
343 rc = lprocfs_write_frac_helper(buffer, count, &pages_number, mult);
347 /* Cap this at the current max readahead window size, the readahead
348 * algorithm does this anyway so it's pointless to set it larger. */
349 if (pages_number < 0 ||
350 pages_number > sbi->ll_ra_info.ra_max_pages_per_file) {
351 CERROR("can't set max_read_ahead_whole_mb more than "
352 "max_read_ahead_per_file_mb: %lu\n",
353 sbi->ll_ra_info.ra_max_pages_per_file >>
354 (20 - PAGE_CACHE_SHIFT));
358 spin_lock(&sbi->ll_lock);
359 sbi->ll_ra_info.ra_max_read_ahead_whole_pages = pages_number;
360 spin_unlock(&sbi->ll_lock);
365 static int ll_rd_max_cached_mb(char *page, char **start, off_t off,
366 int count, int *eof, void *data)
368 struct super_block *sb = data;
369 struct ll_sb_info *sbi = ll_s2sbi(sb);
370 struct cl_client_cache *cache = &sbi->ll_cache;
371 int shift = 20 - PAGE_CACHE_SHIFT;
376 max_cached_mb = cache->ccc_lru_max >> shift;
377 unused_mb = cfs_atomic_read(&cache->ccc_lru_left) >> shift;
378 return snprintf(page, count,
380 "max_cached_mb: %d\n"
383 "reclaim_count: %u\n",
384 cfs_atomic_read(&cache->ccc_users),
386 max_cached_mb - unused_mb,
388 cache->ccc_lru_shrinkers);
391 static int ll_wr_max_cached_mb(struct file *file, const char *buffer,
392 unsigned long count, void *data)
394 struct super_block *sb = data;
395 struct ll_sb_info *sbi = ll_s2sbi(sb);
396 struct cl_client_cache *cache = &sbi->ll_cache;
397 int mult, rc, pages_number;
402 mult = 1 << (20 - PAGE_CACHE_SHIFT);
403 buffer = lprocfs_find_named_value(buffer, "max_cached_mb:", &count);
404 rc = lprocfs_write_frac_helper(buffer, count, &pages_number, mult);
408 if (pages_number < 0 || pages_number > num_physpages) {
409 CERROR("%s: can't set max cache more than %lu MB\n",
410 ll_get_fsname(sb, NULL, 0),
411 num_physpages >> (20 - PAGE_CACHE_SHIFT));
415 if (sbi->ll_dt_exp == NULL)
418 spin_lock(&sbi->ll_lock);
419 diff = pages_number - cache->ccc_lru_max;
420 spin_unlock(&sbi->ll_lock);
422 /* easy - add more LRU slots. */
424 cfs_atomic_add(diff, &cache->ccc_lru_left);
432 /* reduce LRU budget from free slots. */
436 ov = cfs_atomic_read(&cache->ccc_lru_left);
440 nv = ov > diff ? ov - diff : 0;
441 rc = cfs_atomic_cmpxchg(&cache->ccc_lru_left, ov, nv);
442 if (likely(ov == rc)) {
452 /* difficult - have to ask OSCs to drop LRU slots. */
454 rc = obd_set_info_async(NULL, sbi->ll_dt_exp,
455 sizeof(KEY_CACHE_LRU_SHRINK),
456 KEY_CACHE_LRU_SHRINK,
457 sizeof(tmp), &tmp, NULL);
464 spin_lock(&sbi->ll_lock);
465 cache->ccc_lru_max = pages_number;
466 spin_unlock(&sbi->ll_lock);
469 cfs_atomic_add(nrpages, &cache->ccc_lru_left);
474 static int ll_rd_checksum(char *page, char **start, off_t off,
475 int count, int *eof, void *data)
477 struct super_block *sb = data;
478 struct ll_sb_info *sbi = ll_s2sbi(sb);
480 return snprintf(page, count, "%u\n",
481 (sbi->ll_flags & LL_SBI_CHECKSUM) ? 1 : 0);
484 static int ll_wr_checksum(struct file *file, const char *buffer,
485 unsigned long count, void *data)
487 struct super_block *sb = data;
488 struct ll_sb_info *sbi = ll_s2sbi(sb);
495 rc = lprocfs_write_helper(buffer, count, &val);
499 sbi->ll_flags |= LL_SBI_CHECKSUM;
501 sbi->ll_flags &= ~LL_SBI_CHECKSUM;
503 rc = obd_set_info_async(NULL, sbi->ll_dt_exp, sizeof(KEY_CHECKSUM),
504 KEY_CHECKSUM, sizeof(val), &val, NULL);
506 CWARN("Failed to set OSC checksum flags: %d\n", rc);
511 static int ll_rd_max_rw_chunk(char *page, char **start, off_t off,
512 int count, int *eof, void *data)
514 struct super_block *sb = data;
516 return snprintf(page, count, "%lu\n", ll_s2sbi(sb)->ll_max_rw_chunk);
519 static int ll_wr_max_rw_chunk(struct file *file, const char *buffer,
520 unsigned long count, void *data)
522 struct super_block *sb = data;
525 rc = lprocfs_write_helper(buffer, count, &val);
528 ll_s2sbi(sb)->ll_max_rw_chunk = val;
532 static int ll_rd_track_id(char *page, int count, void *data,
533 enum stats_track_type type)
535 struct super_block *sb = data;
537 if (ll_s2sbi(sb)->ll_stats_track_type == type) {
538 return snprintf(page, count, "%d\n",
539 ll_s2sbi(sb)->ll_stats_track_id);
541 } else if (ll_s2sbi(sb)->ll_stats_track_type == STATS_TRACK_ALL) {
542 return snprintf(page, count, "0 (all)\n");
544 return snprintf(page, count, "untracked\n");
548 static int ll_wr_track_id(const char *buffer, unsigned long count, void *data,
549 enum stats_track_type type)
551 struct super_block *sb = data;
554 rc = lprocfs_write_helper(buffer, count, &pid);
557 ll_s2sbi(sb)->ll_stats_track_id = pid;
559 ll_s2sbi(sb)->ll_stats_track_type = STATS_TRACK_ALL;
561 ll_s2sbi(sb)->ll_stats_track_type = type;
562 lprocfs_clear_stats(ll_s2sbi(sb)->ll_stats);
566 static int ll_rd_track_pid(char *page, char **start, off_t off,
567 int count, int *eof, void *data)
569 return (ll_rd_track_id(page, count, data, STATS_TRACK_PID));
572 static int ll_wr_track_pid(struct file *file, const char *buffer,
573 unsigned long count, void *data)
575 return (ll_wr_track_id(buffer, count, data, STATS_TRACK_PID));
578 static int ll_rd_track_ppid(char *page, char **start, off_t off,
579 int count, int *eof, void *data)
581 return (ll_rd_track_id(page, count, data, STATS_TRACK_PPID));
584 static int ll_wr_track_ppid(struct file *file, const char *buffer,
585 unsigned long count, void *data)
587 return (ll_wr_track_id(buffer, count, data, STATS_TRACK_PPID));
590 static int ll_rd_track_gid(char *page, char **start, off_t off,
591 int count, int *eof, void *data)
593 return (ll_rd_track_id(page, count, data, STATS_TRACK_GID));
596 static int ll_wr_track_gid(struct file *file, const char *buffer,
597 unsigned long count, void *data)
599 return (ll_wr_track_id(buffer, count, data, STATS_TRACK_GID));
602 static int ll_rd_statahead_max(char *page, char **start, off_t off,
603 int count, int *eof, void *data)
605 struct super_block *sb = data;
606 struct ll_sb_info *sbi = ll_s2sbi(sb);
608 return snprintf(page, count, "%u\n", sbi->ll_sa_max);
611 static int ll_wr_statahead_max(struct file *file, const char *buffer,
612 unsigned long count, void *data)
614 struct super_block *sb = data;
615 struct ll_sb_info *sbi = ll_s2sbi(sb);
618 rc = lprocfs_write_helper(buffer, count, &val);
622 if (val >= 0 && val <= LL_SA_RPC_MAX)
623 sbi->ll_sa_max = val;
625 CERROR("Bad statahead_max value %d. Valid values are in the "
626 "range [0, %d]\n", val, LL_SA_RPC_MAX);
631 static int ll_rd_statahead_agl(char *page, char **start, off_t off,
632 int count, int *eof, void *data)
634 struct super_block *sb = data;
635 struct ll_sb_info *sbi = ll_s2sbi(sb);
637 return snprintf(page, count, "%u\n",
638 sbi->ll_flags & LL_SBI_AGL_ENABLED ? 1 : 0);
641 static int ll_wr_statahead_agl(struct file *file, const char *buffer,
642 unsigned long count, void *data)
644 struct super_block *sb = data;
645 struct ll_sb_info *sbi = ll_s2sbi(sb);
648 rc = lprocfs_write_helper(buffer, count, &val);
653 sbi->ll_flags |= LL_SBI_AGL_ENABLED;
655 sbi->ll_flags &= ~LL_SBI_AGL_ENABLED;
660 static int ll_rd_statahead_stats(char *page, char **start, off_t off,
661 int count, int *eof, void *data)
663 struct super_block *sb = data;
664 struct ll_sb_info *sbi = ll_s2sbi(sb);
666 return snprintf(page, count,
667 "statahead total: %u\n"
668 "statahead wrong: %u\n"
670 atomic_read(&sbi->ll_sa_total),
671 atomic_read(&sbi->ll_sa_wrong),
672 atomic_read(&sbi->ll_agl_total));
675 static int ll_rd_lazystatfs(char *page, char **start, off_t off,
676 int count, int *eof, void *data)
678 struct super_block *sb = data;
679 struct ll_sb_info *sbi = ll_s2sbi(sb);
681 return snprintf(page, count, "%u\n",
682 (sbi->ll_flags & LL_SBI_LAZYSTATFS) ? 1 : 0);
685 static int ll_wr_lazystatfs(struct file *file, const char *buffer,
686 unsigned long count, void *data)
688 struct super_block *sb = data;
689 struct ll_sb_info *sbi = ll_s2sbi(sb);
692 rc = lprocfs_write_helper(buffer, count, &val);
697 sbi->ll_flags |= LL_SBI_LAZYSTATFS;
699 sbi->ll_flags &= ~LL_SBI_LAZYSTATFS;
704 static int ll_rd_maxea_size(char *page, char **start, off_t off,
705 int count, int *eof, void *data)
707 struct super_block *sb = data;
708 struct ll_sb_info *sbi = ll_s2sbi(sb);
712 rc = ll_get_max_mdsize(sbi, &ealen);
716 return snprintf(page, count, "%u\n", ealen);
719 static int ll_rd_sbi_flags(char *page, char **start, off_t off,
720 int count, int *eof, void *data)
722 const char *str[] = LL_SBI_FLAGS;
723 struct super_block *sb = data;
724 int flags = ll_s2sbi(sb)->ll_flags;
729 if (ARRAY_SIZE(str) <= i) {
730 CERROR("%s: Revise array LL_SBI_FLAGS to match sbi "
731 "flags please.\n", ll_get_fsname(sb, NULL, 0));
736 rc += snprintf(page + rc, count - rc, "%s ", str[i]);
741 rc += snprintf(page + rc, count - rc, "\b\n");
745 static struct lprocfs_vars lprocfs_llite_obd_vars[] = {
746 { "uuid", ll_rd_sb_uuid, 0, 0 },
747 //{ "mntpt_path", ll_rd_path, 0, 0 },
748 { "fstype", ll_rd_fstype, 0, 0 },
749 { "site", ll_rd_site_stats, 0, 0 },
750 { "blocksize", ll_rd_blksize, 0, 0 },
751 { "kbytestotal", ll_rd_kbytestotal, 0, 0 },
752 { "kbytesfree", ll_rd_kbytesfree, 0, 0 },
753 { "kbytesavail", ll_rd_kbytesavail, 0, 0 },
754 { "filestotal", ll_rd_filestotal, 0, 0 },
755 { "filesfree", ll_rd_filesfree, 0, 0 },
756 { "client_type", ll_rd_client_type, 0, 0 },
757 //{ "filegroups", lprocfs_rd_filegroups, 0, 0 },
758 { "max_read_ahead_mb", ll_rd_max_readahead_mb,
759 ll_wr_max_readahead_mb, 0 },
760 { "max_read_ahead_per_file_mb", ll_rd_max_readahead_per_file_mb,
761 ll_wr_max_readahead_per_file_mb, 0 },
762 { "max_read_ahead_whole_mb", ll_rd_max_read_ahead_whole_mb,
763 ll_wr_max_read_ahead_whole_mb, 0 },
764 { "max_cached_mb", ll_rd_max_cached_mb, ll_wr_max_cached_mb, 0 },
765 { "checksum_pages", ll_rd_checksum, ll_wr_checksum, 0 },
766 { "max_rw_chunk", ll_rd_max_rw_chunk, ll_wr_max_rw_chunk, 0 },
767 { "stats_track_pid", ll_rd_track_pid, ll_wr_track_pid, 0 },
768 { "stats_track_ppid", ll_rd_track_ppid, ll_wr_track_ppid, 0 },
769 { "stats_track_gid", ll_rd_track_gid, ll_wr_track_gid, 0 },
770 { "statahead_max", ll_rd_statahead_max, ll_wr_statahead_max, 0 },
771 { "statahead_agl", ll_rd_statahead_agl, ll_wr_statahead_agl, 0 },
772 { "statahead_stats", ll_rd_statahead_stats, 0, 0 },
773 { "lazystatfs", ll_rd_lazystatfs, ll_wr_lazystatfs, 0 },
774 { "max_easize", ll_rd_maxea_size, 0, 0 },
775 { "sbi_flags", ll_rd_sbi_flags, 0, 0 },
779 #define MAX_STRING_SIZE 128
781 struct llite_file_opcode {
785 } llite_opcode_table[LPROC_LL_FILE_OPCODES] = {
787 { LPROC_LL_DIRTY_HITS, LPROCFS_TYPE_REGS, "dirty_pages_hits" },
788 { LPROC_LL_DIRTY_MISSES, LPROCFS_TYPE_REGS, "dirty_pages_misses" },
789 { LPROC_LL_READ_BYTES, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_BYTES,
791 { LPROC_LL_WRITE_BYTES, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_BYTES,
793 { LPROC_LL_BRW_READ, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
795 { LPROC_LL_BRW_WRITE, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
797 { LPROC_LL_OSC_READ, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_BYTES,
799 { LPROC_LL_OSC_WRITE, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_BYTES,
801 { LPROC_LL_IOCTL, LPROCFS_TYPE_REGS, "ioctl" },
802 { LPROC_LL_OPEN, LPROCFS_TYPE_REGS, "open" },
803 { LPROC_LL_RELEASE, LPROCFS_TYPE_REGS, "close" },
804 { LPROC_LL_MAP, LPROCFS_TYPE_REGS, "mmap" },
805 { LPROC_LL_LLSEEK, LPROCFS_TYPE_REGS, "seek" },
806 { LPROC_LL_FSYNC, LPROCFS_TYPE_REGS, "fsync" },
807 { LPROC_LL_READDIR, LPROCFS_TYPE_REGS, "readdir" },
808 /* inode operation */
809 { LPROC_LL_SETATTR, LPROCFS_TYPE_REGS, "setattr" },
810 { LPROC_LL_TRUNC, LPROCFS_TYPE_REGS, "truncate" },
811 { LPROC_LL_FLOCK, LPROCFS_TYPE_REGS, "flock" },
812 { LPROC_LL_GETATTR, LPROCFS_TYPE_REGS, "getattr" },
813 /* dir inode operation */
814 { LPROC_LL_CREATE, LPROCFS_TYPE_REGS, "create" },
815 { LPROC_LL_LINK, LPROCFS_TYPE_REGS, "link" },
816 { LPROC_LL_UNLINK, LPROCFS_TYPE_REGS, "unlink" },
817 { LPROC_LL_SYMLINK, LPROCFS_TYPE_REGS, "symlink" },
818 { LPROC_LL_MKDIR, LPROCFS_TYPE_REGS, "mkdir" },
819 { LPROC_LL_RMDIR, LPROCFS_TYPE_REGS, "rmdir" },
820 { LPROC_LL_MKNOD, LPROCFS_TYPE_REGS, "mknod" },
821 { LPROC_LL_RENAME, LPROCFS_TYPE_REGS, "rename" },
822 /* special inode operation */
823 { LPROC_LL_STAFS, LPROCFS_TYPE_REGS, "statfs" },
824 { LPROC_LL_ALLOC_INODE, LPROCFS_TYPE_REGS, "alloc_inode" },
825 { LPROC_LL_SETXATTR, LPROCFS_TYPE_REGS, "setxattr" },
826 { LPROC_LL_GETXATTR, LPROCFS_TYPE_REGS, "getxattr" },
827 { LPROC_LL_LISTXATTR, LPROCFS_TYPE_REGS, "listxattr" },
828 { LPROC_LL_REMOVEXATTR, LPROCFS_TYPE_REGS, "removexattr" },
829 { LPROC_LL_INODE_PERM, LPROCFS_TYPE_REGS, "inode_permission" },
832 void ll_stats_ops_tally(struct ll_sb_info *sbi, int op, int count)
836 if (sbi->ll_stats_track_type == STATS_TRACK_ALL)
837 lprocfs_counter_add(sbi->ll_stats, op, count);
838 else if (sbi->ll_stats_track_type == STATS_TRACK_PID &&
839 sbi->ll_stats_track_id == current->pid)
840 lprocfs_counter_add(sbi->ll_stats, op, count);
841 else if (sbi->ll_stats_track_type == STATS_TRACK_PPID &&
842 sbi->ll_stats_track_id == current->parent->pid)
843 lprocfs_counter_add(sbi->ll_stats, op, count);
844 else if (sbi->ll_stats_track_type == STATS_TRACK_GID &&
845 sbi->ll_stats_track_id == cfs_curproc_gid())
846 lprocfs_counter_add(sbi->ll_stats, op, count);
848 EXPORT_SYMBOL(ll_stats_ops_tally);
850 static const char *ra_stat_string[] = {
851 [RA_STAT_HIT] = "hits",
852 [RA_STAT_MISS] = "misses",
853 [RA_STAT_DISTANT_READPAGE] = "readpage not consecutive",
854 [RA_STAT_MISS_IN_WINDOW] = "miss inside window",
855 [RA_STAT_FAILED_GRAB_PAGE] = "failed grab_cache_page",
856 [RA_STAT_FAILED_MATCH] = "failed lock match",
857 [RA_STAT_DISCARDED] = "read but discarded",
858 [RA_STAT_ZERO_LEN] = "zero length file",
859 [RA_STAT_ZERO_WINDOW] = "zero size window",
860 [RA_STAT_EOF] = "read-ahead to EOF",
861 [RA_STAT_MAX_IN_FLIGHT] = "hit max r-a issue",
862 [RA_STAT_WRONG_GRAB_PAGE] = "wrong page from grab_cache_page",
866 int lprocfs_register_mountpoint(struct proc_dir_entry *parent,
867 struct super_block *sb, char *osc, char *mdc)
869 struct lprocfs_vars lvars[2];
870 struct lustre_sb_info *lsi = s2lsi(sb);
871 struct ll_sb_info *sbi = ll_s2sbi(sb);
872 struct obd_device *obd;
873 char name[MAX_STRING_SIZE + 1], *ptr;
874 int err, id, len, rc;
877 memset(lvars, 0, sizeof(lvars));
879 name[MAX_STRING_SIZE] = '\0';
880 lvars[0].name = name;
882 LASSERT(sbi != NULL);
883 LASSERT(mdc != NULL);
884 LASSERT(osc != NULL);
887 len = strlen(lsi->lsi_lmd->lmd_profile);
888 ptr = strrchr(lsi->lsi_lmd->lmd_profile, '-');
889 if (ptr && (strcmp(ptr, "-client") == 0))
893 snprintf(name, MAX_STRING_SIZE, "%.*s-%p", len,
894 lsi->lsi_lmd->lmd_profile, sb);
896 sbi->ll_proc_root = lprocfs_register(name, parent, NULL, NULL);
897 if (IS_ERR(sbi->ll_proc_root)) {
898 err = PTR_ERR(sbi->ll_proc_root);
899 sbi->ll_proc_root = NULL;
903 rc = lprocfs_seq_create(sbi->ll_proc_root, "dump_page_cache", 0444,
904 &vvp_dump_pgcache_file_ops, sbi);
906 CWARN("Error adding the dump_page_cache file\n");
908 rc = lprocfs_seq_create(sbi->ll_proc_root, "extents_stats", 0644,
909 &ll_rw_extents_stats_fops, sbi);
911 CWARN("Error adding the extent_stats file\n");
913 rc = lprocfs_seq_create(sbi->ll_proc_root, "extents_stats_per_process",
914 0644, &ll_rw_extents_stats_pp_fops, sbi);
916 CWARN("Error adding the extents_stats_per_process file\n");
918 rc = lprocfs_seq_create(sbi->ll_proc_root, "offset_stats", 0644,
919 &ll_rw_offset_stats_fops, sbi);
921 CWARN("Error adding the offset_stats file\n");
923 /* File operations stats */
924 sbi->ll_stats = lprocfs_alloc_stats(LPROC_LL_FILE_OPCODES,
925 LPROCFS_STATS_FLAG_NONE);
926 if (sbi->ll_stats == NULL)
927 GOTO(out, err = -ENOMEM);
928 /* do counter init */
929 for (id = 0; id < LPROC_LL_FILE_OPCODES; id++) {
930 __u32 type = llite_opcode_table[id].type;
932 if (type & LPROCFS_TYPE_REGS)
934 else if (type & LPROCFS_TYPE_BYTES)
936 else if (type & LPROCFS_TYPE_PAGES)
938 lprocfs_counter_init(sbi->ll_stats,
939 llite_opcode_table[id].opcode,
940 (type & LPROCFS_CNTR_AVGMINMAX),
941 llite_opcode_table[id].opname, ptr);
943 err = lprocfs_register_stats(sbi->ll_proc_root, "stats", sbi->ll_stats);
947 sbi->ll_ra_stats = lprocfs_alloc_stats(ARRAY_SIZE(ra_stat_string),
948 LPROCFS_STATS_FLAG_NONE);
949 if (sbi->ll_ra_stats == NULL)
950 GOTO(out, err = -ENOMEM);
952 for (id = 0; id < ARRAY_SIZE(ra_stat_string); id++)
953 lprocfs_counter_init(sbi->ll_ra_stats, id, 0,
954 ra_stat_string[id], "pages");
955 err = lprocfs_register_stats(sbi->ll_proc_root, "read_ahead_stats",
961 err = lprocfs_add_vars(sbi->ll_proc_root, lprocfs_llite_obd_vars, sb);
966 obd = class_name2obd(mdc);
968 LASSERT(obd != NULL);
969 LASSERT(obd->obd_magic == OBD_DEVICE_MAGIC);
970 LASSERT(obd->obd_type->typ_name != NULL);
972 snprintf(name, MAX_STRING_SIZE, "%s/common_name",
973 obd->obd_type->typ_name);
974 lvars[0].read_fptr = lprocfs_rd_name;
975 err = lprocfs_add_vars(sbi->ll_proc_root, lvars, obd);
979 snprintf(name, MAX_STRING_SIZE, "%s/uuid", obd->obd_type->typ_name);
980 lvars[0].read_fptr = lprocfs_rd_uuid;
981 err = lprocfs_add_vars(sbi->ll_proc_root, lvars, obd);
986 obd = class_name2obd(osc);
988 LASSERT(obd != NULL);
989 LASSERT(obd->obd_magic == OBD_DEVICE_MAGIC);
990 LASSERT(obd->obd_type->typ_name != NULL);
992 snprintf(name, MAX_STRING_SIZE, "%s/common_name",
993 obd->obd_type->typ_name);
994 lvars[0].read_fptr = lprocfs_rd_name;
995 err = lprocfs_add_vars(sbi->ll_proc_root, lvars, obd);
999 snprintf(name, MAX_STRING_SIZE, "%s/uuid", obd->obd_type->typ_name);
1000 lvars[0].read_fptr = lprocfs_rd_uuid;
1001 err = lprocfs_add_vars(sbi->ll_proc_root, lvars, obd);
1004 lprocfs_remove(&sbi->ll_proc_root);
1005 lprocfs_free_stats(&sbi->ll_ra_stats);
1006 lprocfs_free_stats(&sbi->ll_stats);
1011 void lprocfs_unregister_mountpoint(struct ll_sb_info *sbi)
1013 if (sbi->ll_proc_root) {
1014 lprocfs_remove(&sbi->ll_proc_root);
1015 lprocfs_free_stats(&sbi->ll_ra_stats);
1016 lprocfs_free_stats(&sbi->ll_stats);
1019 #undef MAX_STRING_SIZE
1021 #define pct(a,b) (b ? a * 100 / b : 0)
1023 static void ll_display_extents_info(struct ll_rw_extents_info *io_extents,
1024 struct seq_file *seq, int which)
1026 unsigned long read_tot = 0, write_tot = 0, read_cum, write_cum;
1027 unsigned long start, end, r, w;
1028 char *unitp = "KMGTPEZY";
1030 struct per_process_info *pp_info = &io_extents->pp_extents[which];
1036 for(i = 0; i < LL_HIST_MAX; i++) {
1037 read_tot += pp_info->pp_r_hist.oh_buckets[i];
1038 write_tot += pp_info->pp_w_hist.oh_buckets[i];
1041 for(i = 0; i < LL_HIST_MAX; i++) {
1042 r = pp_info->pp_r_hist.oh_buckets[i];
1043 w = pp_info->pp_w_hist.oh_buckets[i];
1046 end = 1 << (i + LL_HIST_START - units);
1047 seq_printf(seq, "%4lu%c - %4lu%c%c: %14lu %4lu %4lu | "
1048 "%14lu %4lu %4lu\n", start, *unitp, end, *unitp,
1049 (i == LL_HIST_MAX - 1) ? '+' : ' ',
1050 r, pct(r, read_tot), pct(read_cum, read_tot),
1051 w, pct(w, write_tot), pct(write_cum, write_tot));
1053 if (start == 1<<10) {
1058 if (read_cum == read_tot && write_cum == write_tot)
1063 static int ll_rw_extents_stats_pp_seq_show(struct seq_file *seq, void *v)
1066 struct ll_sb_info *sbi = seq->private;
1067 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1070 cfs_gettimeofday(&now);
1072 if (!sbi->ll_rw_stats_on) {
1073 seq_printf(seq, "disabled\n"
1074 "write anything in this file to activate, "
1075 "then 0 or \"[D/d]isabled\" to deactivate\n");
1078 seq_printf(seq, "snapshot_time: %lu.%lu (secs.usecs)\n",
1079 now.tv_sec, now.tv_usec);
1080 seq_printf(seq, "%15s %19s | %20s\n", " ", "read", "write");
1081 seq_printf(seq, "%13s %14s %4s %4s | %14s %4s %4s\n",
1082 "extents", "calls", "%", "cum%",
1083 "calls", "%", "cum%");
1084 spin_lock(&sbi->ll_pp_extent_lock);
1085 for (k = 0; k < LL_PROCESS_HIST_MAX; k++) {
1086 if (io_extents->pp_extents[k].pid != 0) {
1087 seq_printf(seq, "\nPID: %d\n",
1088 io_extents->pp_extents[k].pid);
1089 ll_display_extents_info(io_extents, seq, k);
1092 spin_unlock(&sbi->ll_pp_extent_lock);
1096 static ssize_t ll_rw_extents_stats_pp_seq_write(struct file *file,
1097 const char *buf, size_t len,
1100 struct seq_file *seq = file->private_data;
1101 struct ll_sb_info *sbi = seq->private;
1102 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1104 int value = 1, rc = 0;
1106 rc = lprocfs_write_helper(buf, len, &value);
1107 if (rc < 0 && (strcmp(buf, "disabled") == 0 ||
1108 strcmp(buf, "Disabled") == 0))
1112 sbi->ll_rw_stats_on = 0;
1114 sbi->ll_rw_stats_on = 1;
1116 spin_lock(&sbi->ll_pp_extent_lock);
1117 for (i = 0; i < LL_PROCESS_HIST_MAX; i++) {
1118 io_extents->pp_extents[i].pid = 0;
1119 lprocfs_oh_clear(&io_extents->pp_extents[i].pp_r_hist);
1120 lprocfs_oh_clear(&io_extents->pp_extents[i].pp_w_hist);
1122 spin_unlock(&sbi->ll_pp_extent_lock);
1126 LPROC_SEQ_FOPS(ll_rw_extents_stats_pp);
1128 static int ll_rw_extents_stats_seq_show(struct seq_file *seq, void *v)
1131 struct ll_sb_info *sbi = seq->private;
1132 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1134 cfs_gettimeofday(&now);
1136 if (!sbi->ll_rw_stats_on) {
1137 seq_printf(seq, "disabled\n"
1138 "write anything in this file to activate, "
1139 "then 0 or \"[D/d]isabled\" to deactivate\n");
1142 seq_printf(seq, "snapshot_time: %lu.%lu (secs.usecs)\n",
1143 now.tv_sec, now.tv_usec);
1145 seq_printf(seq, "%15s %19s | %20s\n", " ", "read", "write");
1146 seq_printf(seq, "%13s %14s %4s %4s | %14s %4s %4s\n",
1147 "extents", "calls", "%", "cum%",
1148 "calls", "%", "cum%");
1149 spin_lock(&sbi->ll_lock);
1150 ll_display_extents_info(io_extents, seq, LL_PROCESS_HIST_MAX);
1151 spin_unlock(&sbi->ll_lock);
1156 static ssize_t ll_rw_extents_stats_seq_write(struct file *file, const char *buf,
1157 size_t len, loff_t *off)
1159 struct seq_file *seq = file->private_data;
1160 struct ll_sb_info *sbi = seq->private;
1161 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1163 int value = 1, rc = 0;
1165 rc = lprocfs_write_helper(buf, len, &value);
1166 if (rc < 0 && (strcmp(buf, "disabled") == 0 ||
1167 strcmp(buf, "Disabled") == 0))
1171 sbi->ll_rw_stats_on = 0;
1173 sbi->ll_rw_stats_on = 1;
1174 spin_lock(&sbi->ll_pp_extent_lock);
1175 for (i = 0; i <= LL_PROCESS_HIST_MAX; i++) {
1176 io_extents->pp_extents[i].pid = 0;
1177 lprocfs_oh_clear(&io_extents->pp_extents[i].pp_r_hist);
1178 lprocfs_oh_clear(&io_extents->pp_extents[i].pp_w_hist);
1180 spin_unlock(&sbi->ll_pp_extent_lock);
1185 LPROC_SEQ_FOPS(ll_rw_extents_stats);
1187 void ll_rw_stats_tally(struct ll_sb_info *sbi, pid_t pid,
1188 struct ll_file_data *file, loff_t pos,
1189 size_t count, int rw)
1192 struct ll_rw_process_info *process;
1193 struct ll_rw_process_info *offset;
1194 int *off_count = &sbi->ll_rw_offset_entry_count;
1195 int *process_count = &sbi->ll_offset_process_count;
1196 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1198 if(!sbi->ll_rw_stats_on)
1200 process = sbi->ll_rw_process_info;
1201 offset = sbi->ll_rw_offset_info;
1203 spin_lock(&sbi->ll_pp_extent_lock);
1204 /* Extent statistics */
1205 for(i = 0; i < LL_PROCESS_HIST_MAX; i++) {
1206 if(io_extents->pp_extents[i].pid == pid) {
1214 sbi->ll_extent_process_count =
1215 (sbi->ll_extent_process_count + 1) % LL_PROCESS_HIST_MAX;
1216 cur = sbi->ll_extent_process_count;
1217 io_extents->pp_extents[cur].pid = pid;
1218 lprocfs_oh_clear(&io_extents->pp_extents[cur].pp_r_hist);
1219 lprocfs_oh_clear(&io_extents->pp_extents[cur].pp_w_hist);
1222 for(i = 0; (count >= (1 << LL_HIST_START << i)) &&
1223 (i < (LL_HIST_MAX - 1)); i++);
1225 io_extents->pp_extents[cur].pp_r_hist.oh_buckets[i]++;
1226 io_extents->pp_extents[LL_PROCESS_HIST_MAX].pp_r_hist.oh_buckets[i]++;
1228 io_extents->pp_extents[cur].pp_w_hist.oh_buckets[i]++;
1229 io_extents->pp_extents[LL_PROCESS_HIST_MAX].pp_w_hist.oh_buckets[i]++;
1231 spin_unlock(&sbi->ll_pp_extent_lock);
1233 spin_lock(&sbi->ll_process_lock);
1234 /* Offset statistics */
1235 for (i = 0; i < LL_PROCESS_HIST_MAX; i++) {
1236 if (process[i].rw_pid == pid) {
1237 if (process[i].rw_last_file != file) {
1238 process[i].rw_range_start = pos;
1239 process[i].rw_last_file_pos = pos + count;
1240 process[i].rw_smallest_extent = count;
1241 process[i].rw_largest_extent = count;
1242 process[i].rw_offset = 0;
1243 process[i].rw_last_file = file;
1244 spin_unlock(&sbi->ll_process_lock);
1247 if (process[i].rw_last_file_pos != pos) {
1249 (*off_count + 1) % LL_OFFSET_HIST_MAX;
1250 offset[*off_count].rw_op = process[i].rw_op;
1251 offset[*off_count].rw_pid = pid;
1252 offset[*off_count].rw_range_start =
1253 process[i].rw_range_start;
1254 offset[*off_count].rw_range_end =
1255 process[i].rw_last_file_pos;
1256 offset[*off_count].rw_smallest_extent =
1257 process[i].rw_smallest_extent;
1258 offset[*off_count].rw_largest_extent =
1259 process[i].rw_largest_extent;
1260 offset[*off_count].rw_offset =
1261 process[i].rw_offset;
1262 process[i].rw_op = rw;
1263 process[i].rw_range_start = pos;
1264 process[i].rw_smallest_extent = count;
1265 process[i].rw_largest_extent = count;
1266 process[i].rw_offset = pos -
1267 process[i].rw_last_file_pos;
1269 if(process[i].rw_smallest_extent > count)
1270 process[i].rw_smallest_extent = count;
1271 if(process[i].rw_largest_extent < count)
1272 process[i].rw_largest_extent = count;
1273 process[i].rw_last_file_pos = pos + count;
1274 spin_unlock(&sbi->ll_process_lock);
1278 *process_count = (*process_count + 1) % LL_PROCESS_HIST_MAX;
1279 process[*process_count].rw_pid = pid;
1280 process[*process_count].rw_op = rw;
1281 process[*process_count].rw_range_start = pos;
1282 process[*process_count].rw_last_file_pos = pos + count;
1283 process[*process_count].rw_smallest_extent = count;
1284 process[*process_count].rw_largest_extent = count;
1285 process[*process_count].rw_offset = 0;
1286 process[*process_count].rw_last_file = file;
1287 spin_unlock(&sbi->ll_process_lock);
1290 static int ll_rw_offset_stats_seq_show(struct seq_file *seq, void *v)
1293 struct ll_sb_info *sbi = seq->private;
1294 struct ll_rw_process_info *offset = sbi->ll_rw_offset_info;
1295 struct ll_rw_process_info *process = sbi->ll_rw_process_info;
1298 cfs_gettimeofday(&now);
1300 if (!sbi->ll_rw_stats_on) {
1301 seq_printf(seq, "disabled\n"
1302 "write anything in this file to activate, "
1303 "then 0 or \"[D/d]isabled\" to deactivate\n");
1306 spin_lock(&sbi->ll_process_lock);
1308 seq_printf(seq, "snapshot_time: %lu.%lu (secs.usecs)\n",
1309 now.tv_sec, now.tv_usec);
1310 seq_printf(seq, "%3s %10s %14s %14s %17s %17s %14s\n",
1311 "R/W", "PID", "RANGE START", "RANGE END",
1312 "SMALLEST EXTENT", "LARGEST EXTENT", "OFFSET");
1314 /* We stored the discontiguous offsets here; print them first */
1315 for (i = 0; i < LL_OFFSET_HIST_MAX; i++) {
1316 if (offset[i].rw_pid != 0)
1318 "%3c %10d %14Lu %14Lu %17lu %17lu %14Lu",
1319 offset[i].rw_op == READ ? 'R' : 'W',
1321 offset[i].rw_range_start,
1322 offset[i].rw_range_end,
1323 (unsigned long)offset[i].rw_smallest_extent,
1324 (unsigned long)offset[i].rw_largest_extent,
1325 offset[i].rw_offset);
1328 /* Then print the current offsets for each process */
1329 for (i = 0; i < LL_PROCESS_HIST_MAX; i++) {
1330 if (process[i].rw_pid != 0)
1332 "%3c %10d %14Lu %14Lu %17lu %17lu %14Lu",
1333 process[i].rw_op == READ ? 'R' : 'W',
1335 process[i].rw_range_start,
1336 process[i].rw_last_file_pos,
1337 (unsigned long)process[i].rw_smallest_extent,
1338 (unsigned long)process[i].rw_largest_extent,
1339 process[i].rw_offset);
1341 spin_unlock(&sbi->ll_process_lock);
1346 static ssize_t ll_rw_offset_stats_seq_write(struct file *file, const char *buf,
1347 size_t len, loff_t *off)
1349 struct seq_file *seq = file->private_data;
1350 struct ll_sb_info *sbi = seq->private;
1351 struct ll_rw_process_info *process_info = sbi->ll_rw_process_info;
1352 struct ll_rw_process_info *offset_info = sbi->ll_rw_offset_info;
1353 int value = 1, rc = 0;
1355 rc = lprocfs_write_helper(buf, len, &value);
1357 if (rc < 0 && (strcmp(buf, "disabled") == 0 ||
1358 strcmp(buf, "Disabled") == 0))
1362 sbi->ll_rw_stats_on = 0;
1364 sbi->ll_rw_stats_on = 1;
1366 spin_lock(&sbi->ll_process_lock);
1367 sbi->ll_offset_process_count = 0;
1368 sbi->ll_rw_offset_entry_count = 0;
1369 memset(process_info, 0, sizeof(struct ll_rw_process_info) *
1370 LL_PROCESS_HIST_MAX);
1371 memset(offset_info, 0, sizeof(struct ll_rw_process_info) *
1372 LL_OFFSET_HIST_MAX);
1373 spin_unlock(&sbi->ll_process_lock);
1378 LPROC_SEQ_FOPS(ll_rw_offset_stats);
1380 void lprocfs_llite_init_vars(struct lprocfs_static_vars *lvars)
1382 lvars->module_vars = NULL;
1383 lvars->obd_vars = lprocfs_llite_obd_vars;
1385 #endif /* LPROCFS */