1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
30 * Use is subject to license terms.
33 * Copyright (c) 2011 Whamcloud, Inc.
36 * This file is part of Lustre, http://www.lustre.org/
37 * Lustre is a trademark of Sun Microsystems, Inc.
39 #define DEBUG_SUBSYSTEM S_LLITE
41 #include <linux/version.h>
42 #include <lustre_lite.h>
43 #include <lprocfs_status.h>
44 #include <linux/seq_file.h>
45 #include <obd_support.h>
47 #include "llite_internal.h"
49 struct proc_dir_entry *proc_lustre_fs_root;
52 /* /proc/lustre/llite mount point registration */
53 extern struct file_operations vvp_dump_pgcache_file_ops;
54 struct file_operations ll_rw_extents_stats_fops;
55 struct file_operations ll_rw_extents_stats_pp_fops;
56 struct file_operations ll_rw_offset_stats_fops;
58 static int ll_rd_blksize(char *page, char **start, off_t off, int count,
61 struct super_block *sb = (struct super_block *)data;
62 struct obd_statfs osfs;
66 rc = ll_statfs_internal(sb, &osfs,
67 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
71 rc = snprintf(page, count, "%u\n", osfs.os_bsize);
77 static int ll_rd_kbytestotal(char *page, char **start, off_t off, int count,
80 struct super_block *sb = (struct super_block *)data;
81 struct obd_statfs osfs;
85 rc = ll_statfs_internal(sb, &osfs,
86 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
89 __u32 blk_size = osfs.os_bsize >> 10;
90 __u64 result = osfs.os_blocks;
92 while (blk_size >>= 1)
96 rc = snprintf(page, count, LPU64"\n", result);
102 static int ll_rd_kbytesfree(char *page, char **start, off_t off, int count,
103 int *eof, void *data)
105 struct super_block *sb = (struct super_block *)data;
106 struct obd_statfs osfs;
110 rc = ll_statfs_internal(sb, &osfs,
111 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
114 __u32 blk_size = osfs.os_bsize >> 10;
115 __u64 result = osfs.os_bfree;
117 while (blk_size >>= 1)
121 rc = snprintf(page, count, LPU64"\n", result);
126 static int ll_rd_kbytesavail(char *page, char **start, off_t off, int count,
127 int *eof, void *data)
129 struct super_block *sb = (struct super_block *)data;
130 struct obd_statfs osfs;
134 rc = ll_statfs_internal(sb, &osfs,
135 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
138 __u32 blk_size = osfs.os_bsize >> 10;
139 __u64 result = osfs.os_bavail;
141 while (blk_size >>= 1)
145 rc = snprintf(page, count, LPU64"\n", result);
150 static int ll_rd_filestotal(char *page, char **start, off_t off, int count,
151 int *eof, void *data)
153 struct super_block *sb = (struct super_block *)data;
154 struct obd_statfs osfs;
158 rc = ll_statfs_internal(sb, &osfs,
159 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
163 rc = snprintf(page, count, LPU64"\n", osfs.os_files);
168 static int ll_rd_filesfree(char *page, char **start, off_t off, int count,
169 int *eof, void *data)
171 struct super_block *sb = (struct super_block *)data;
172 struct obd_statfs osfs;
176 rc = ll_statfs_internal(sb, &osfs,
177 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
181 rc = snprintf(page, count, LPU64"\n", osfs.os_ffree);
187 static int ll_rd_client_type(char *page, char **start, off_t off, int count,
188 int *eof, void *data)
190 struct ll_sb_info *sbi = ll_s2sbi((struct super_block *)data);
193 LASSERT(sbi != NULL);
196 if (sbi->ll_flags & LL_SBI_RMT_CLIENT)
197 rc = snprintf(page, count, "remote client\n");
199 rc = snprintf(page, count, "local client\n");
204 static int ll_rd_fstype(char *page, char **start, off_t off, int count,
205 int *eof, void *data)
207 struct super_block *sb = (struct super_block*)data;
211 return snprintf(page, count, "%s\n", sb->s_type->name);
214 static int ll_rd_sb_uuid(char *page, char **start, off_t off, int count,
215 int *eof, void *data)
217 struct super_block *sb = (struct super_block *)data;
221 return snprintf(page, count, "%s\n", ll_s2sbi(sb)->ll_sb_uuid.uuid);
224 static int ll_rd_site_stats(char *page, char **start, off_t off,
225 int count, int *eof, void *data)
227 struct super_block *sb = data;
230 * See description of statistical counters in struct cl_site, and
233 return cl_site_stats_print(lu2cl_site(ll_s2sbi(sb)->ll_site),
237 static int ll_rd_max_readahead_mb(char *page, char **start, off_t off,
238 int count, int *eof, void *data)
240 struct super_block *sb = data;
241 struct ll_sb_info *sbi = ll_s2sbi(sb);
245 cfs_spin_lock(&sbi->ll_lock);
246 pages_number = sbi->ll_ra_info.ra_max_pages;
247 cfs_spin_unlock(&sbi->ll_lock);
249 mult = 1 << (20 - PAGE_CACHE_SHIFT);
250 return lprocfs_read_frac_helper(page, count, pages_number, mult);
253 static int ll_wr_max_readahead_mb(struct file *file, const char *buffer,
254 unsigned long count, void *data)
256 struct super_block *sb = data;
257 struct ll_sb_info *sbi = ll_s2sbi(sb);
258 int mult, rc, pages_number;
260 mult = 1 << (20 - CFS_PAGE_SHIFT);
261 rc = lprocfs_write_frac_helper(buffer, count, &pages_number, mult);
265 if (pages_number < 0 || pages_number > cfs_num_physpages / 2) {
266 CERROR("can't set file readahead more than %lu MB\n",
267 cfs_num_physpages >> (20 - CFS_PAGE_SHIFT + 1)); /*1/2 of RAM*/
271 cfs_spin_lock(&sbi->ll_lock);
272 sbi->ll_ra_info.ra_max_pages = pages_number;
273 cfs_spin_unlock(&sbi->ll_lock);
278 static int ll_rd_max_readahead_per_file_mb(char *page, char **start, off_t off,
279 int count, int *eof, void *data)
281 struct super_block *sb = data;
282 struct ll_sb_info *sbi = ll_s2sbi(sb);
286 cfs_spin_lock(&sbi->ll_lock);
287 pages_number = sbi->ll_ra_info.ra_max_pages_per_file;
288 cfs_spin_unlock(&sbi->ll_lock);
290 mult = 1 << (20 - CFS_PAGE_SHIFT);
291 return lprocfs_read_frac_helper(page, count, pages_number, mult);
294 static int ll_wr_max_readahead_per_file_mb(struct file *file, const char *buffer,
295 unsigned long count, void *data)
297 struct super_block *sb = data;
298 struct ll_sb_info *sbi = ll_s2sbi(sb);
299 int mult, rc, pages_number;
301 mult = 1 << (20 - CFS_PAGE_SHIFT);
302 rc = lprocfs_write_frac_helper(buffer, count, &pages_number, mult);
306 if (pages_number < 0 ||
307 pages_number > sbi->ll_ra_info.ra_max_pages) {
308 CERROR("can't set file readahead more than"
309 "max_read_ahead_mb %lu MB\n",
310 sbi->ll_ra_info.ra_max_pages);
314 cfs_spin_lock(&sbi->ll_lock);
315 sbi->ll_ra_info.ra_max_pages_per_file = pages_number;
316 cfs_spin_unlock(&sbi->ll_lock);
321 static int ll_rd_max_read_ahead_whole_mb(char *page, char **start, off_t off,
322 int count, int *eof, void *data)
324 struct super_block *sb = data;
325 struct ll_sb_info *sbi = ll_s2sbi(sb);
329 cfs_spin_lock(&sbi->ll_lock);
330 pages_number = sbi->ll_ra_info.ra_max_read_ahead_whole_pages;
331 cfs_spin_unlock(&sbi->ll_lock);
333 mult = 1 << (20 - CFS_PAGE_SHIFT);
334 return lprocfs_read_frac_helper(page, count, pages_number, mult);
337 static int ll_wr_max_read_ahead_whole_mb(struct file *file, const char *buffer,
338 unsigned long count, void *data)
340 struct super_block *sb = data;
341 struct ll_sb_info *sbi = ll_s2sbi(sb);
342 int mult, rc, pages_number;
344 mult = 1 << (20 - CFS_PAGE_SHIFT);
345 rc = lprocfs_write_frac_helper(buffer, count, &pages_number, mult);
349 /* Cap this at the current max readahead window size, the readahead
350 * algorithm does this anyway so it's pointless to set it larger. */
351 if (pages_number < 0 ||
352 pages_number > sbi->ll_ra_info.ra_max_pages_per_file) {
353 CERROR("can't set max_read_ahead_whole_mb more than "
354 "max_read_ahead_per_file_mb: %lu\n",
355 sbi->ll_ra_info.ra_max_pages_per_file >> (20 - CFS_PAGE_SHIFT));
359 cfs_spin_lock(&sbi->ll_lock);
360 sbi->ll_ra_info.ra_max_read_ahead_whole_pages = pages_number;
361 cfs_spin_unlock(&sbi->ll_lock);
366 static int ll_rd_max_cached_mb(char *page, char **start, off_t off,
367 int count, int *eof, void *data)
369 struct super_block *sb = data;
370 struct ll_sb_info *sbi = ll_s2sbi(sb);
374 cfs_spin_lock(&sbi->ll_lock);
375 pages_number = sbi->ll_async_page_max;
376 cfs_spin_unlock(&sbi->ll_lock);
378 mult = 1 << (20 - CFS_PAGE_SHIFT);
379 return lprocfs_read_frac_helper(page, count, pages_number, mult);;
382 static int ll_wr_max_cached_mb(struct file *file, const char *buffer,
383 unsigned long count, void *data)
385 struct super_block *sb = data;
386 struct ll_sb_info *sbi = ll_s2sbi(sb);
387 int mult, rc, pages_number;
389 mult = 1 << (20 - CFS_PAGE_SHIFT);
390 rc = lprocfs_write_frac_helper(buffer, count, &pages_number, mult);
394 if (pages_number < 0 || pages_number > cfs_num_physpages) {
395 CERROR("can't set max cache more than %lu MB\n",
396 cfs_num_physpages >> (20 - CFS_PAGE_SHIFT));
400 cfs_spin_lock(&sbi->ll_lock);
401 sbi->ll_async_page_max = pages_number ;
402 cfs_spin_unlock(&sbi->ll_lock);
405 /* Not set up yet, don't call llap_shrink_cache */
411 static int ll_rd_checksum(char *page, char **start, off_t off,
412 int count, int *eof, void *data)
414 struct super_block *sb = data;
415 struct ll_sb_info *sbi = ll_s2sbi(sb);
417 return snprintf(page, count, "%u\n",
418 (sbi->ll_flags & LL_SBI_CHECKSUM) ? 1 : 0);
421 static int ll_wr_checksum(struct file *file, const char *buffer,
422 unsigned long count, void *data)
424 struct super_block *sb = data;
425 struct ll_sb_info *sbi = ll_s2sbi(sb);
432 rc = lprocfs_write_helper(buffer, count, &val);
436 sbi->ll_flags |= LL_SBI_CHECKSUM;
438 sbi->ll_flags &= ~LL_SBI_CHECKSUM;
440 rc = obd_set_info_async(sbi->ll_dt_exp, sizeof(KEY_CHECKSUM),
441 KEY_CHECKSUM, sizeof(val), &val, NULL);
443 CWARN("Failed to set OSC checksum flags: %d\n", rc);
448 static int ll_rd_max_rw_chunk(char *page, char **start, off_t off,
449 int count, int *eof, void *data)
451 struct super_block *sb = data;
453 return snprintf(page, count, "%lu\n", ll_s2sbi(sb)->ll_max_rw_chunk);
456 static int ll_wr_max_rw_chunk(struct file *file, const char *buffer,
457 unsigned long count, void *data)
459 struct super_block *sb = data;
462 rc = lprocfs_write_helper(buffer, count, &val);
465 ll_s2sbi(sb)->ll_max_rw_chunk = val;
469 static int ll_rd_track_id(char *page, int count, void *data,
470 enum stats_track_type type)
472 struct super_block *sb = data;
474 if (ll_s2sbi(sb)->ll_stats_track_type == type) {
475 return snprintf(page, count, "%d\n",
476 ll_s2sbi(sb)->ll_stats_track_id);
478 } else if (ll_s2sbi(sb)->ll_stats_track_type == STATS_TRACK_ALL) {
479 return snprintf(page, count, "0 (all)\n");
481 return snprintf(page, count, "untracked\n");
485 static int ll_wr_track_id(const char *buffer, unsigned long count, void *data,
486 enum stats_track_type type)
488 struct super_block *sb = data;
491 rc = lprocfs_write_helper(buffer, count, &pid);
494 ll_s2sbi(sb)->ll_stats_track_id = pid;
496 ll_s2sbi(sb)->ll_stats_track_type = STATS_TRACK_ALL;
498 ll_s2sbi(sb)->ll_stats_track_type = type;
499 lprocfs_clear_stats(ll_s2sbi(sb)->ll_stats);
503 static int ll_rd_track_pid(char *page, char **start, off_t off,
504 int count, int *eof, void *data)
506 return (ll_rd_track_id(page, count, data, STATS_TRACK_PID));
509 static int ll_wr_track_pid(struct file *file, const char *buffer,
510 unsigned long count, void *data)
512 return (ll_wr_track_id(buffer, count, data, STATS_TRACK_PID));
515 static int ll_rd_track_ppid(char *page, char **start, off_t off,
516 int count, int *eof, void *data)
518 return (ll_rd_track_id(page, count, data, STATS_TRACK_PPID));
521 static int ll_wr_track_ppid(struct file *file, const char *buffer,
522 unsigned long count, void *data)
524 return (ll_wr_track_id(buffer, count, data, STATS_TRACK_PPID));
527 static int ll_rd_track_gid(char *page, char **start, off_t off,
528 int count, int *eof, void *data)
530 return (ll_rd_track_id(page, count, data, STATS_TRACK_GID));
533 static int ll_wr_track_gid(struct file *file, const char *buffer,
534 unsigned long count, void *data)
536 return (ll_wr_track_id(buffer, count, data, STATS_TRACK_GID));
539 static int ll_rd_statahead_max(char *page, char **start, off_t off,
540 int count, int *eof, void *data)
542 struct super_block *sb = data;
543 struct ll_sb_info *sbi = ll_s2sbi(sb);
545 return snprintf(page, count, "%u\n", sbi->ll_sa_max);
548 static int ll_wr_statahead_max(struct file *file, const char *buffer,
549 unsigned long count, void *data)
551 struct super_block *sb = data;
552 struct ll_sb_info *sbi = ll_s2sbi(sb);
555 rc = lprocfs_write_helper(buffer, count, &val);
559 if (val >= 0 && val <= LL_SA_RPC_MAX)
560 sbi->ll_sa_max = val;
562 CERROR("Bad statahead_max value %d. Valid values are in the "
563 "range [0, %d]\n", val, LL_SA_RPC_MAX);
568 static int ll_rd_statahead_agl(char *page, char **start, off_t off,
569 int count, int *eof, void *data)
571 struct super_block *sb = data;
572 struct ll_sb_info *sbi = ll_s2sbi(sb);
574 return snprintf(page, count, "%u\n",
575 sbi->ll_flags & LL_SBI_AGL_ENABLED ? 1 : 0);
578 static int ll_wr_statahead_agl(struct file *file, const char *buffer,
579 unsigned long count, void *data)
581 struct super_block *sb = data;
582 struct ll_sb_info *sbi = ll_s2sbi(sb);
585 rc = lprocfs_write_helper(buffer, count, &val);
590 sbi->ll_flags |= LL_SBI_AGL_ENABLED;
592 sbi->ll_flags &= ~LL_SBI_AGL_ENABLED;
597 static int ll_rd_statahead_stats(char *page, char **start, off_t off,
598 int count, int *eof, void *data)
600 struct super_block *sb = data;
601 struct ll_sb_info *sbi = ll_s2sbi(sb);
603 return snprintf(page, count,
604 "statahead total: %u\n"
605 "statahead wrong: %u\n"
607 atomic_read(&sbi->ll_sa_total),
608 atomic_read(&sbi->ll_sa_wrong),
609 atomic_read(&sbi->ll_agl_total));
612 static int ll_rd_lazystatfs(char *page, char **start, off_t off,
613 int count, int *eof, void *data)
615 struct super_block *sb = data;
616 struct ll_sb_info *sbi = ll_s2sbi(sb);
618 return snprintf(page, count, "%u\n",
619 (sbi->ll_flags & LL_SBI_LAZYSTATFS) ? 1 : 0);
622 static int ll_wr_lazystatfs(struct file *file, const char *buffer,
623 unsigned long count, void *data)
625 struct super_block *sb = data;
626 struct ll_sb_info *sbi = ll_s2sbi(sb);
629 rc = lprocfs_write_helper(buffer, count, &val);
634 sbi->ll_flags |= LL_SBI_LAZYSTATFS;
636 sbi->ll_flags &= ~LL_SBI_LAZYSTATFS;
641 static int ll_rd_maxea_size(char *page, char **start, off_t off,
642 int count, int *eof, void *data)
644 struct super_block *sb = data;
645 struct ll_sb_info *sbi = ll_s2sbi(sb);
649 rc = ll_get_max_mdsize(sbi, &ealen);
653 return snprintf(page, count, "%u\n", ealen);
656 static struct lprocfs_vars lprocfs_llite_obd_vars[] = {
657 { "uuid", ll_rd_sb_uuid, 0, 0 },
658 //{ "mntpt_path", ll_rd_path, 0, 0 },
659 { "fstype", ll_rd_fstype, 0, 0 },
660 { "site", ll_rd_site_stats, 0, 0 },
661 { "blocksize", ll_rd_blksize, 0, 0 },
662 { "kbytestotal", ll_rd_kbytestotal, 0, 0 },
663 { "kbytesfree", ll_rd_kbytesfree, 0, 0 },
664 { "kbytesavail", ll_rd_kbytesavail, 0, 0 },
665 { "filestotal", ll_rd_filestotal, 0, 0 },
666 { "filesfree", ll_rd_filesfree, 0, 0 },
667 { "client_type", ll_rd_client_type, 0, 0 },
668 //{ "filegroups", lprocfs_rd_filegroups, 0, 0 },
669 { "max_read_ahead_mb", ll_rd_max_readahead_mb,
670 ll_wr_max_readahead_mb, 0 },
671 { "max_read_ahead_per_file_mb", ll_rd_max_readahead_per_file_mb,
672 ll_wr_max_readahead_per_file_mb, 0 },
673 { "max_read_ahead_whole_mb", ll_rd_max_read_ahead_whole_mb,
674 ll_wr_max_read_ahead_whole_mb, 0 },
675 { "max_cached_mb", ll_rd_max_cached_mb, ll_wr_max_cached_mb, 0 },
676 { "checksum_pages", ll_rd_checksum, ll_wr_checksum, 0 },
677 { "max_rw_chunk", ll_rd_max_rw_chunk, ll_wr_max_rw_chunk, 0 },
678 { "stats_track_pid", ll_rd_track_pid, ll_wr_track_pid, 0 },
679 { "stats_track_ppid", ll_rd_track_ppid, ll_wr_track_ppid, 0 },
680 { "stats_track_gid", ll_rd_track_gid, ll_wr_track_gid, 0 },
681 { "statahead_max", ll_rd_statahead_max, ll_wr_statahead_max, 0 },
682 { "statahead_agl", ll_rd_statahead_agl, ll_wr_statahead_agl, 0 },
683 { "statahead_stats", ll_rd_statahead_stats, 0, 0 },
684 { "lazystatfs", ll_rd_lazystatfs, ll_wr_lazystatfs, 0 },
685 { "max_easize", ll_rd_maxea_size, 0, 0 },
689 #define MAX_STRING_SIZE 128
691 struct llite_file_opcode {
695 } llite_opcode_table[LPROC_LL_FILE_OPCODES] = {
697 { LPROC_LL_DIRTY_HITS, LPROCFS_TYPE_REGS, "dirty_pages_hits" },
698 { LPROC_LL_DIRTY_MISSES, LPROCFS_TYPE_REGS, "dirty_pages_misses" },
699 { LPROC_LL_WB_WRITEPAGE, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
700 "writeback_from_writepage" },
701 { LPROC_LL_WB_PRESSURE, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
702 "writeback_from_pressure" },
703 { LPROC_LL_WB_OK, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
704 "writeback_ok_pages" },
705 { LPROC_LL_WB_FAIL, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
706 "writeback_failed_pages" },
707 { LPROC_LL_READ_BYTES, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_BYTES,
709 { LPROC_LL_WRITE_BYTES, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_BYTES,
711 { LPROC_LL_BRW_READ, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
713 { LPROC_LL_BRW_WRITE, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
715 { LPROC_LL_OSC_READ, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_BYTES,
717 { LPROC_LL_OSC_WRITE, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_BYTES,
720 { LPROC_LL_IOCTL, LPROCFS_TYPE_REGS, "ioctl" },
721 { LPROC_LL_OPEN, LPROCFS_TYPE_REGS, "open" },
722 { LPROC_LL_RELEASE, LPROCFS_TYPE_REGS, "close" },
723 { LPROC_LL_MAP, LPROCFS_TYPE_REGS, "mmap" },
724 { LPROC_LL_LLSEEK, LPROCFS_TYPE_REGS, "seek" },
725 { LPROC_LL_FSYNC, LPROCFS_TYPE_REGS, "fsync" },
726 /* inode operation */
727 { LPROC_LL_SETATTR, LPROCFS_TYPE_REGS, "setattr" },
728 { LPROC_LL_TRUNC, LPROCFS_TYPE_REGS, "truncate" },
729 { LPROC_LL_LOCKLESS_TRUNC, LPROCFS_TYPE_REGS, "lockless_truncate"},
730 { LPROC_LL_FLOCK, LPROCFS_TYPE_REGS, "flock" },
731 { LPROC_LL_GETATTR, LPROCFS_TYPE_REGS, "getattr" },
732 /* special inode operation */
733 { LPROC_LL_STAFS, LPROCFS_TYPE_REGS, "statfs" },
734 { LPROC_LL_ALLOC_INODE, LPROCFS_TYPE_REGS, "alloc_inode" },
735 { LPROC_LL_SETXATTR, LPROCFS_TYPE_REGS, "setxattr" },
736 { LPROC_LL_GETXATTR, LPROCFS_TYPE_REGS, "getxattr" },
737 { LPROC_LL_LISTXATTR, LPROCFS_TYPE_REGS, "listxattr" },
738 { LPROC_LL_REMOVEXATTR, LPROCFS_TYPE_REGS, "removexattr" },
739 { LPROC_LL_INODE_PERM, LPROCFS_TYPE_REGS, "inode_permission" },
740 { LPROC_LL_DIRECT_READ, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
742 { LPROC_LL_DIRECT_WRITE, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
744 { LPROC_LL_LOCKLESS_READ, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_BYTES,
745 "lockless_read_bytes" },
746 { LPROC_LL_LOCKLESS_WRITE, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_BYTES,
747 "lockless_write_bytes" },
751 void ll_stats_ops_tally(struct ll_sb_info *sbi, int op, int count)
755 if (sbi->ll_stats_track_type == STATS_TRACK_ALL)
756 lprocfs_counter_add(sbi->ll_stats, op, count);
757 else if (sbi->ll_stats_track_type == STATS_TRACK_PID &&
758 sbi->ll_stats_track_id == current->pid)
759 lprocfs_counter_add(sbi->ll_stats, op, count);
760 else if (sbi->ll_stats_track_type == STATS_TRACK_PPID &&
761 sbi->ll_stats_track_id == current->parent->pid)
762 lprocfs_counter_add(sbi->ll_stats, op, count);
763 else if (sbi->ll_stats_track_type == STATS_TRACK_GID &&
764 sbi->ll_stats_track_id == cfs_curproc_gid())
765 lprocfs_counter_add(sbi->ll_stats, op, count);
767 EXPORT_SYMBOL(ll_stats_ops_tally);
769 static const char *ra_stat_string[] = {
770 [RA_STAT_HIT] = "hits",
771 [RA_STAT_MISS] = "misses",
772 [RA_STAT_DISTANT_READPAGE] = "readpage not consecutive",
773 [RA_STAT_MISS_IN_WINDOW] = "miss inside window",
774 [RA_STAT_FAILED_GRAB_PAGE] = "failed grab_cache_page",
775 [RA_STAT_FAILED_MATCH] = "failed lock match",
776 [RA_STAT_DISCARDED] = "read but discarded",
777 [RA_STAT_ZERO_LEN] = "zero length file",
778 [RA_STAT_ZERO_WINDOW] = "zero size window",
779 [RA_STAT_EOF] = "read-ahead to EOF",
780 [RA_STAT_MAX_IN_FLIGHT] = "hit max r-a issue",
781 [RA_STAT_WRONG_GRAB_PAGE] = "wrong page from grab_cache_page",
785 int lprocfs_register_mountpoint(struct proc_dir_entry *parent,
786 struct super_block *sb, char *osc, char *mdc)
788 struct lprocfs_vars lvars[2];
789 struct lustre_sb_info *lsi = s2lsi(sb);
790 struct ll_sb_info *sbi = ll_s2sbi(sb);
791 struct obd_device *obd;
792 char name[MAX_STRING_SIZE + 1], *ptr;
793 int err, id, len, rc;
796 memset(lvars, 0, sizeof(lvars));
798 name[MAX_STRING_SIZE] = '\0';
799 lvars[0].name = name;
801 LASSERT(sbi != NULL);
802 LASSERT(mdc != NULL);
803 LASSERT(osc != NULL);
806 len = strlen(lsi->lsi_lmd->lmd_profile);
807 ptr = strrchr(lsi->lsi_lmd->lmd_profile, '-');
808 if (ptr && (strcmp(ptr, "-client") == 0))
812 snprintf(name, MAX_STRING_SIZE, "%.*s-%p", len,
813 lsi->lsi_lmd->lmd_profile, sb);
815 sbi->ll_proc_root = lprocfs_register(name, parent, NULL, NULL);
816 if (IS_ERR(sbi->ll_proc_root)) {
817 err = PTR_ERR(sbi->ll_proc_root);
818 sbi->ll_proc_root = NULL;
822 rc = lprocfs_seq_create(sbi->ll_proc_root, "dump_page_cache", 0444,
823 &vvp_dump_pgcache_file_ops, sbi);
825 CWARN("Error adding the dump_page_cache file\n");
827 rc = lprocfs_seq_create(sbi->ll_proc_root, "extents_stats", 0644,
828 &ll_rw_extents_stats_fops, sbi);
830 CWARN("Error adding the extent_stats file\n");
832 rc = lprocfs_seq_create(sbi->ll_proc_root, "extents_stats_per_process",
833 0644, &ll_rw_extents_stats_pp_fops, sbi);
835 CWARN("Error adding the extents_stats_per_process file\n");
837 rc = lprocfs_seq_create(sbi->ll_proc_root, "offset_stats", 0644,
838 &ll_rw_offset_stats_fops, sbi);
840 CWARN("Error adding the offset_stats file\n");
842 /* File operations stats */
843 sbi->ll_stats = lprocfs_alloc_stats(LPROC_LL_FILE_OPCODES,
844 LPROCFS_STATS_FLAG_NONE);
845 if (sbi->ll_stats == NULL)
846 GOTO(out, err = -ENOMEM);
847 /* do counter init */
848 for (id = 0; id < LPROC_LL_FILE_OPCODES; id++) {
849 __u32 type = llite_opcode_table[id].type;
851 if (type & LPROCFS_TYPE_REGS)
853 else if (type & LPROCFS_TYPE_BYTES)
855 else if (type & LPROCFS_TYPE_PAGES)
857 lprocfs_counter_init(sbi->ll_stats,
858 llite_opcode_table[id].opcode,
859 (type & LPROCFS_CNTR_AVGMINMAX),
860 llite_opcode_table[id].opname, ptr);
862 err = lprocfs_register_stats(sbi->ll_proc_root, "stats", sbi->ll_stats);
866 sbi->ll_ra_stats = lprocfs_alloc_stats(ARRAY_SIZE(ra_stat_string),
867 LPROCFS_STATS_FLAG_NONE);
868 if (sbi->ll_ra_stats == NULL)
869 GOTO(out, err = -ENOMEM);
871 for (id = 0; id < ARRAY_SIZE(ra_stat_string); id++)
872 lprocfs_counter_init(sbi->ll_ra_stats, id, 0,
873 ra_stat_string[id], "pages");
874 err = lprocfs_register_stats(sbi->ll_proc_root, "read_ahead_stats",
880 err = lprocfs_add_vars(sbi->ll_proc_root, lprocfs_llite_obd_vars, sb);
885 obd = class_name2obd(mdc);
887 LASSERT(obd != NULL);
888 LASSERT(obd->obd_magic == OBD_DEVICE_MAGIC);
889 LASSERT(obd->obd_type->typ_name != NULL);
891 snprintf(name, MAX_STRING_SIZE, "%s/common_name",
892 obd->obd_type->typ_name);
893 lvars[0].read_fptr = lprocfs_rd_name;
894 err = lprocfs_add_vars(sbi->ll_proc_root, lvars, obd);
898 snprintf(name, MAX_STRING_SIZE, "%s/uuid", obd->obd_type->typ_name);
899 lvars[0].read_fptr = lprocfs_rd_uuid;
900 err = lprocfs_add_vars(sbi->ll_proc_root, lvars, obd);
905 obd = class_name2obd(osc);
907 LASSERT(obd != NULL);
908 LASSERT(obd->obd_magic == OBD_DEVICE_MAGIC);
909 LASSERT(obd->obd_type->typ_name != NULL);
911 snprintf(name, MAX_STRING_SIZE, "%s/common_name",
912 obd->obd_type->typ_name);
913 lvars[0].read_fptr = lprocfs_rd_name;
914 err = lprocfs_add_vars(sbi->ll_proc_root, lvars, obd);
918 snprintf(name, MAX_STRING_SIZE, "%s/uuid", obd->obd_type->typ_name);
919 lvars[0].read_fptr = lprocfs_rd_uuid;
920 err = lprocfs_add_vars(sbi->ll_proc_root, lvars, obd);
923 lprocfs_remove(&sbi->ll_proc_root);
924 lprocfs_free_stats(&sbi->ll_ra_stats);
925 lprocfs_free_stats(&sbi->ll_stats);
930 void lprocfs_unregister_mountpoint(struct ll_sb_info *sbi)
932 if (sbi->ll_proc_root) {
933 lprocfs_remove(&sbi->ll_proc_root);
934 lprocfs_free_stats(&sbi->ll_ra_stats);
935 lprocfs_free_stats(&sbi->ll_stats);
938 #undef MAX_STRING_SIZE
940 #define pct(a,b) (b ? a * 100 / b : 0)
942 static void ll_display_extents_info(struct ll_rw_extents_info *io_extents,
943 struct seq_file *seq, int which)
945 unsigned long read_tot = 0, write_tot = 0, read_cum, write_cum;
946 unsigned long start, end, r, w;
947 char *unitp = "KMGTPEZY";
949 struct per_process_info *pp_info = &io_extents->pp_extents[which];
955 for(i = 0; i < LL_HIST_MAX; i++) {
956 read_tot += pp_info->pp_r_hist.oh_buckets[i];
957 write_tot += pp_info->pp_w_hist.oh_buckets[i];
960 for(i = 0; i < LL_HIST_MAX; i++) {
961 r = pp_info->pp_r_hist.oh_buckets[i];
962 w = pp_info->pp_w_hist.oh_buckets[i];
965 end = 1 << (i + LL_HIST_START - units);
966 seq_printf(seq, "%4lu%c - %4lu%c%c: %14lu %4lu %4lu | "
967 "%14lu %4lu %4lu\n", start, *unitp, end, *unitp,
968 (i == LL_HIST_MAX - 1) ? '+' : ' ',
969 r, pct(r, read_tot), pct(read_cum, read_tot),
970 w, pct(w, write_tot), pct(write_cum, write_tot));
972 if (start == 1<<10) {
977 if (read_cum == read_tot && write_cum == write_tot)
982 static int ll_rw_extents_stats_pp_seq_show(struct seq_file *seq, void *v)
985 struct ll_sb_info *sbi = seq->private;
986 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
989 cfs_gettimeofday(&now);
991 if (!sbi->ll_rw_stats_on) {
992 seq_printf(seq, "disabled\n"
993 "write anything in this file to activate, "
994 "then 0 or \"[D/d]isabled\" to deactivate\n");
997 seq_printf(seq, "snapshot_time: %lu.%lu (secs.usecs)\n",
998 now.tv_sec, now.tv_usec);
999 seq_printf(seq, "%15s %19s | %20s\n", " ", "read", "write");
1000 seq_printf(seq, "%13s %14s %4s %4s | %14s %4s %4s\n",
1001 "extents", "calls", "%", "cum%",
1002 "calls", "%", "cum%");
1003 cfs_spin_lock(&sbi->ll_pp_extent_lock);
1004 for(k = 0; k < LL_PROCESS_HIST_MAX; k++) {
1005 if(io_extents->pp_extents[k].pid != 0) {
1006 seq_printf(seq, "\nPID: %d\n",
1007 io_extents->pp_extents[k].pid);
1008 ll_display_extents_info(io_extents, seq, k);
1011 cfs_spin_unlock(&sbi->ll_pp_extent_lock);
1015 static ssize_t ll_rw_extents_stats_pp_seq_write(struct file *file,
1016 const char *buf, size_t len,
1019 struct seq_file *seq = file->private_data;
1020 struct ll_sb_info *sbi = seq->private;
1021 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1023 int value = 1, rc = 0;
1025 rc = lprocfs_write_helper(buf, len, &value);
1026 if (rc < 0 && (strcmp(buf, "disabled") == 0 ||
1027 strcmp(buf, "Disabled") == 0))
1031 sbi->ll_rw_stats_on = 0;
1033 sbi->ll_rw_stats_on = 1;
1035 cfs_spin_lock(&sbi->ll_pp_extent_lock);
1036 for(i = 0; i < LL_PROCESS_HIST_MAX; i++) {
1037 io_extents->pp_extents[i].pid = 0;
1038 lprocfs_oh_clear(&io_extents->pp_extents[i].pp_r_hist);
1039 lprocfs_oh_clear(&io_extents->pp_extents[i].pp_w_hist);
1041 cfs_spin_unlock(&sbi->ll_pp_extent_lock);
1045 LPROC_SEQ_FOPS(ll_rw_extents_stats_pp);
1047 static int ll_rw_extents_stats_seq_show(struct seq_file *seq, void *v)
1050 struct ll_sb_info *sbi = seq->private;
1051 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1053 cfs_gettimeofday(&now);
1055 if (!sbi->ll_rw_stats_on) {
1056 seq_printf(seq, "disabled\n"
1057 "write anything in this file to activate, "
1058 "then 0 or \"[D/d]isabled\" to deactivate\n");
1061 seq_printf(seq, "snapshot_time: %lu.%lu (secs.usecs)\n",
1062 now.tv_sec, now.tv_usec);
1064 seq_printf(seq, "%15s %19s | %20s\n", " ", "read", "write");
1065 seq_printf(seq, "%13s %14s %4s %4s | %14s %4s %4s\n",
1066 "extents", "calls", "%", "cum%",
1067 "calls", "%", "cum%");
1068 cfs_spin_lock(&sbi->ll_lock);
1069 ll_display_extents_info(io_extents, seq, LL_PROCESS_HIST_MAX);
1070 cfs_spin_unlock(&sbi->ll_lock);
1075 static ssize_t ll_rw_extents_stats_seq_write(struct file *file, const char *buf,
1076 size_t len, loff_t *off)
1078 struct seq_file *seq = file->private_data;
1079 struct ll_sb_info *sbi = seq->private;
1080 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1082 int value = 1, rc = 0;
1084 rc = lprocfs_write_helper(buf, len, &value);
1085 if (rc < 0 && (strcmp(buf, "disabled") == 0 ||
1086 strcmp(buf, "Disabled") == 0))
1090 sbi->ll_rw_stats_on = 0;
1092 sbi->ll_rw_stats_on = 1;
1093 cfs_spin_lock(&sbi->ll_pp_extent_lock);
1094 for(i = 0; i <= LL_PROCESS_HIST_MAX; i++)
1096 io_extents->pp_extents[i].pid = 0;
1097 lprocfs_oh_clear(&io_extents->pp_extents[i].pp_r_hist);
1098 lprocfs_oh_clear(&io_extents->pp_extents[i].pp_w_hist);
1100 cfs_spin_unlock(&sbi->ll_pp_extent_lock);
1105 LPROC_SEQ_FOPS(ll_rw_extents_stats);
1107 void ll_rw_stats_tally(struct ll_sb_info *sbi, pid_t pid,
1108 struct ll_file_data *file, loff_t pos,
1109 size_t count, int rw)
1112 struct ll_rw_process_info *process;
1113 struct ll_rw_process_info *offset;
1114 int *off_count = &sbi->ll_rw_offset_entry_count;
1115 int *process_count = &sbi->ll_offset_process_count;
1116 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1118 if(!sbi->ll_rw_stats_on)
1120 process = sbi->ll_rw_process_info;
1121 offset = sbi->ll_rw_offset_info;
1123 cfs_spin_lock(&sbi->ll_pp_extent_lock);
1124 /* Extent statistics */
1125 for(i = 0; i < LL_PROCESS_HIST_MAX; i++) {
1126 if(io_extents->pp_extents[i].pid == pid) {
1134 sbi->ll_extent_process_count =
1135 (sbi->ll_extent_process_count + 1) % LL_PROCESS_HIST_MAX;
1136 cur = sbi->ll_extent_process_count;
1137 io_extents->pp_extents[cur].pid = pid;
1138 lprocfs_oh_clear(&io_extents->pp_extents[cur].pp_r_hist);
1139 lprocfs_oh_clear(&io_extents->pp_extents[cur].pp_w_hist);
1142 for(i = 0; (count >= (1 << LL_HIST_START << i)) &&
1143 (i < (LL_HIST_MAX - 1)); i++);
1145 io_extents->pp_extents[cur].pp_r_hist.oh_buckets[i]++;
1146 io_extents->pp_extents[LL_PROCESS_HIST_MAX].pp_r_hist.oh_buckets[i]++;
1148 io_extents->pp_extents[cur].pp_w_hist.oh_buckets[i]++;
1149 io_extents->pp_extents[LL_PROCESS_HIST_MAX].pp_w_hist.oh_buckets[i]++;
1151 cfs_spin_unlock(&sbi->ll_pp_extent_lock);
1153 cfs_spin_lock(&sbi->ll_process_lock);
1154 /* Offset statistics */
1155 for (i = 0; i < LL_PROCESS_HIST_MAX; i++) {
1156 if (process[i].rw_pid == pid) {
1157 if (process[i].rw_last_file != file) {
1158 process[i].rw_range_start = pos;
1159 process[i].rw_last_file_pos = pos + count;
1160 process[i].rw_smallest_extent = count;
1161 process[i].rw_largest_extent = count;
1162 process[i].rw_offset = 0;
1163 process[i].rw_last_file = file;
1164 cfs_spin_unlock(&sbi->ll_process_lock);
1167 if (process[i].rw_last_file_pos != pos) {
1169 (*off_count + 1) % LL_OFFSET_HIST_MAX;
1170 offset[*off_count].rw_op = process[i].rw_op;
1171 offset[*off_count].rw_pid = pid;
1172 offset[*off_count].rw_range_start =
1173 process[i].rw_range_start;
1174 offset[*off_count].rw_range_end =
1175 process[i].rw_last_file_pos;
1176 offset[*off_count].rw_smallest_extent =
1177 process[i].rw_smallest_extent;
1178 offset[*off_count].rw_largest_extent =
1179 process[i].rw_largest_extent;
1180 offset[*off_count].rw_offset =
1181 process[i].rw_offset;
1182 process[i].rw_op = rw;
1183 process[i].rw_range_start = pos;
1184 process[i].rw_smallest_extent = count;
1185 process[i].rw_largest_extent = count;
1186 process[i].rw_offset = pos -
1187 process[i].rw_last_file_pos;
1189 if(process[i].rw_smallest_extent > count)
1190 process[i].rw_smallest_extent = count;
1191 if(process[i].rw_largest_extent < count)
1192 process[i].rw_largest_extent = count;
1193 process[i].rw_last_file_pos = pos + count;
1194 cfs_spin_unlock(&sbi->ll_process_lock);
1198 *process_count = (*process_count + 1) % LL_PROCESS_HIST_MAX;
1199 process[*process_count].rw_pid = pid;
1200 process[*process_count].rw_op = rw;
1201 process[*process_count].rw_range_start = pos;
1202 process[*process_count].rw_last_file_pos = pos + count;
1203 process[*process_count].rw_smallest_extent = count;
1204 process[*process_count].rw_largest_extent = count;
1205 process[*process_count].rw_offset = 0;
1206 process[*process_count].rw_last_file = file;
1207 cfs_spin_unlock(&sbi->ll_process_lock);
1210 static int ll_rw_offset_stats_seq_show(struct seq_file *seq, void *v)
1213 struct ll_sb_info *sbi = seq->private;
1214 struct ll_rw_process_info *offset = sbi->ll_rw_offset_info;
1215 struct ll_rw_process_info *process = sbi->ll_rw_process_info;
1218 cfs_gettimeofday(&now);
1220 if (!sbi->ll_rw_stats_on) {
1221 seq_printf(seq, "disabled\n"
1222 "write anything in this file to activate, "
1223 "then 0 or \"[D/d]isabled\" to deactivate\n");
1226 cfs_spin_lock(&sbi->ll_process_lock);
1228 seq_printf(seq, "snapshot_time: %lu.%lu (secs.usecs)\n",
1229 now.tv_sec, now.tv_usec);
1230 seq_printf(seq, "%3s %10s %14s %14s %17s %17s %14s\n",
1231 "R/W", "PID", "RANGE START", "RANGE END",
1232 "SMALLEST EXTENT", "LARGEST EXTENT", "OFFSET");
1233 /* We stored the discontiguous offsets here; print them first */
1234 for(i = 0; i < LL_OFFSET_HIST_MAX; i++) {
1235 if (offset[i].rw_pid != 0)
1236 seq_printf(seq,"%3c %10d %14Lu %14Lu %17lu %17lu %14Lu",
1237 offset[i].rw_op ? 'W' : 'R',
1239 offset[i].rw_range_start,
1240 offset[i].rw_range_end,
1241 (unsigned long)offset[i].rw_smallest_extent,
1242 (unsigned long)offset[i].rw_largest_extent,
1243 offset[i].rw_offset);
1245 /* Then print the current offsets for each process */
1246 for(i = 0; i < LL_PROCESS_HIST_MAX; i++) {
1247 if (process[i].rw_pid != 0)
1248 seq_printf(seq,"%3c %10d %14Lu %14Lu %17lu %17lu %14Lu",
1249 process[i].rw_op ? 'W' : 'R',
1251 process[i].rw_range_start,
1252 process[i].rw_last_file_pos,
1253 (unsigned long)process[i].rw_smallest_extent,
1254 (unsigned long)process[i].rw_largest_extent,
1255 process[i].rw_offset);
1257 cfs_spin_unlock(&sbi->ll_process_lock);
1262 static ssize_t ll_rw_offset_stats_seq_write(struct file *file, const char *buf,
1263 size_t len, loff_t *off)
1265 struct seq_file *seq = file->private_data;
1266 struct ll_sb_info *sbi = seq->private;
1267 struct ll_rw_process_info *process_info = sbi->ll_rw_process_info;
1268 struct ll_rw_process_info *offset_info = sbi->ll_rw_offset_info;
1269 int value = 1, rc = 0;
1271 rc = lprocfs_write_helper(buf, len, &value);
1273 if (rc < 0 && (strcmp(buf, "disabled") == 0 ||
1274 strcmp(buf, "Disabled") == 0))
1278 sbi->ll_rw_stats_on = 0;
1280 sbi->ll_rw_stats_on = 1;
1282 cfs_spin_lock(&sbi->ll_process_lock);
1283 sbi->ll_offset_process_count = 0;
1284 sbi->ll_rw_offset_entry_count = 0;
1285 memset(process_info, 0, sizeof(struct ll_rw_process_info) *
1286 LL_PROCESS_HIST_MAX);
1287 memset(offset_info, 0, sizeof(struct ll_rw_process_info) *
1288 LL_OFFSET_HIST_MAX);
1289 cfs_spin_unlock(&sbi->ll_process_lock);
1294 LPROC_SEQ_FOPS(ll_rw_offset_stats);
1296 void lprocfs_llite_init_vars(struct lprocfs_static_vars *lvars)
1298 lvars->module_vars = NULL;
1299 lvars->obd_vars = lprocfs_llite_obd_vars;
1301 #endif /* LPROCFS */