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.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2012, 2017, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
30 * Lustre is a trademark of Sun Microsystems, Inc.
32 #define DEBUG_SUBSYSTEM S_LLITE
34 #include <linux/version.h>
35 #include <linux/user_namespace.h>
36 #ifdef HAVE_UIDGID_HEADER
37 # include <linux/uidgid.h>
39 #include <uapi/linux/lustre/lustre_param.h>
40 #include <lprocfs_status.h>
41 #include <obd_support.h>
43 #include "llite_internal.h"
44 #include "vvp_internal.h"
46 struct proc_dir_entry *proc_lustre_fs_root;
47 static struct kobject *llite_kobj;
49 int llite_tunables_register(void)
53 proc_lustre_fs_root = lprocfs_register("llite", proc_lustre_root,
55 if (IS_ERR(proc_lustre_fs_root)) {
56 rc = PTR_ERR(proc_lustre_fs_root);
57 CERROR("cannot register '/proc/fs/lustre/llite': rc = %d\n",
59 proc_lustre_fs_root = NULL;
63 llite_kobj = class_setup_tunables("llite");
64 if (IS_ERR(llite_kobj)) {
65 rc = PTR_ERR(llite_kobj);
72 void llite_tunables_unregister(void)
75 kobject_put(llite_kobj);
77 lprocfs_remove(&proc_lustre_fs_root);
81 /* /proc/lustre/llite mount point registration */
82 static const struct file_operations ll_rw_extents_stats_fops;
83 static const struct file_operations ll_rw_extents_stats_pp_fops;
84 static const struct file_operations ll_rw_offset_stats_fops;
85 static __s64 ll_stats_pid_write(const char __user *buf, size_t len);
87 static ssize_t blocksize_show(struct kobject *kobj, struct attribute *attr,
90 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
92 struct obd_statfs osfs;
95 rc = ll_statfs_internal(sbi, &osfs, OBD_STATFS_NODELAY);
99 return sprintf(buf, "%u\n", osfs.os_bsize);
101 LUSTRE_RO_ATTR(blocksize);
103 static ssize_t stat_blocksize_show(struct kobject *kobj, struct attribute *attr,
106 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
109 return sprintf(buf, "%u\n", sbi->ll_stat_blksize);
112 static ssize_t stat_blocksize_store(struct kobject *kobj,
113 struct attribute *attr,
117 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
122 rc = kstrtouint(buffer, 10, &val);
126 if (val != 0 && (val < PAGE_SIZE || (val & (val - 1))) != 0)
129 sbi->ll_stat_blksize = val;
133 LUSTRE_RW_ATTR(stat_blocksize);
135 static ssize_t kbytestotal_show(struct kobject *kobj, struct attribute *attr,
138 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
140 struct obd_statfs osfs;
145 rc = ll_statfs_internal(sbi, &osfs, OBD_STATFS_NODELAY);
149 blk_size = osfs.os_bsize >> 10;
150 result = osfs.os_blocks;
152 while (blk_size >>= 1)
155 return sprintf(buf, "%llu\n", result);
157 LUSTRE_RO_ATTR(kbytestotal);
159 static ssize_t kbytesfree_show(struct kobject *kobj, struct attribute *attr,
162 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
164 struct obd_statfs osfs;
169 rc = ll_statfs_internal(sbi, &osfs, OBD_STATFS_NODELAY);
173 blk_size = osfs.os_bsize >> 10;
174 result = osfs.os_bfree;
176 while (blk_size >>= 1)
179 return sprintf(buf, "%llu\n", result);
181 LUSTRE_RO_ATTR(kbytesfree);
183 static ssize_t kbytesavail_show(struct kobject *kobj, struct attribute *attr,
186 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
188 struct obd_statfs osfs;
193 rc = ll_statfs_internal(sbi, &osfs, OBD_STATFS_NODELAY);
197 blk_size = osfs.os_bsize >> 10;
198 result = osfs.os_bavail;
200 while (blk_size >>= 1)
203 return sprintf(buf, "%llu\n", result);
205 LUSTRE_RO_ATTR(kbytesavail);
207 static ssize_t filestotal_show(struct kobject *kobj, struct attribute *attr,
210 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
212 struct obd_statfs osfs;
215 rc = ll_statfs_internal(sbi, &osfs, OBD_STATFS_NODELAY);
219 return sprintf(buf, "%llu\n", osfs.os_files);
221 LUSTRE_RO_ATTR(filestotal);
223 static ssize_t filesfree_show(struct kobject *kobj, struct attribute *attr,
226 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
228 struct obd_statfs osfs;
231 rc = ll_statfs_internal(sbi, &osfs, OBD_STATFS_NODELAY);
235 return sprintf(buf, "%llu\n", osfs.os_ffree);
237 LUSTRE_RO_ATTR(filesfree);
239 static ssize_t client_type_show(struct kobject *kobj, struct attribute *attr,
242 return sprintf(buf, "local client\n");
244 LUSTRE_RO_ATTR(client_type);
246 static ssize_t fstype_show(struct kobject *kobj, struct attribute *attr,
249 return sprintf(buf, "lustre\n");
251 LUSTRE_RO_ATTR(fstype);
253 static ssize_t uuid_show(struct kobject *kobj, struct attribute *attr,
256 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
259 return sprintf(buf, "%s\n", sbi->ll_sb_uuid.uuid);
261 LUSTRE_RO_ATTR(uuid);
263 static int ll_site_stats_seq_show(struct seq_file *m, void *v)
265 struct super_block *sb = m->private;
268 * See description of statistical counters in struct cl_site, and
271 return cl_site_stats_print(lu2cl_site(ll_s2sbi(sb)->ll_site), m);
273 LPROC_SEQ_FOPS_RO(ll_site_stats);
275 static int ll_max_readahead_mb_seq_show(struct seq_file *m, void *v)
277 struct super_block *sb = m->private;
278 struct ll_sb_info *sbi = ll_s2sbi(sb);
282 spin_lock(&sbi->ll_lock);
283 pages_number = sbi->ll_ra_info.ra_max_pages;
284 spin_unlock(&sbi->ll_lock);
286 mult = 1 << (20 - PAGE_SHIFT);
287 return lprocfs_seq_read_frac_helper(m, pages_number, mult);
291 ll_max_readahead_mb_seq_write(struct file *file, const char __user *buffer,
292 size_t count, loff_t *off)
294 struct seq_file *m = file->private_data;
295 struct super_block *sb = m->private;
296 struct ll_sb_info *sbi = ll_s2sbi(sb);
300 rc = lprocfs_str_with_units_to_s64(buffer, count, &pages_number, 'M');
304 pages_number >>= PAGE_SHIFT;
306 if (pages_number < 0 || pages_number > totalram_pages / 2) {
308 CERROR("%s: can't set max_readahead_mb=%lu > %luMB\n",
309 ll_get_fsname(sb, NULL, 0),
310 (unsigned long)pages_number >> (20 - PAGE_SHIFT),
311 totalram_pages >> (20 - PAGE_SHIFT + 1));
315 spin_lock(&sbi->ll_lock);
316 sbi->ll_ra_info.ra_max_pages = pages_number;
317 spin_unlock(&sbi->ll_lock);
320 LPROC_SEQ_FOPS(ll_max_readahead_mb);
322 static int ll_max_readahead_per_file_mb_seq_show(struct seq_file *m, void *v)
324 struct super_block *sb = m->private;
325 struct ll_sb_info *sbi = ll_s2sbi(sb);
329 spin_lock(&sbi->ll_lock);
330 pages_number = sbi->ll_ra_info.ra_max_pages_per_file;
331 spin_unlock(&sbi->ll_lock);
333 mult = 1 << (20 - PAGE_SHIFT);
334 return lprocfs_seq_read_frac_helper(m, pages_number, mult);
338 ll_max_readahead_per_file_mb_seq_write(struct file *file,
339 const char __user *buffer,
340 size_t count, loff_t *off)
342 struct seq_file *m = file->private_data;
343 struct super_block *sb = m->private;
344 struct ll_sb_info *sbi = ll_s2sbi(sb);
348 rc = lprocfs_str_with_units_to_s64(buffer, count, &pages_number, 'M');
352 pages_number >>= PAGE_SHIFT;
354 if (pages_number < 0 || pages_number > sbi->ll_ra_info.ra_max_pages) {
355 CERROR("%s: can't set max_readahead_per_file_mb=%lu > "
356 "max_read_ahead_mb=%lu\n", ll_get_fsname(sb, NULL, 0),
357 (unsigned long)pages_number >> (20 - PAGE_SHIFT),
358 sbi->ll_ra_info.ra_max_pages >> (20 - PAGE_SHIFT));
362 spin_lock(&sbi->ll_lock);
363 sbi->ll_ra_info.ra_max_pages_per_file = pages_number;
364 spin_unlock(&sbi->ll_lock);
367 LPROC_SEQ_FOPS(ll_max_readahead_per_file_mb);
369 static int ll_max_read_ahead_whole_mb_seq_show(struct seq_file *m, void *v)
371 struct super_block *sb = m->private;
372 struct ll_sb_info *sbi = ll_s2sbi(sb);
376 spin_lock(&sbi->ll_lock);
377 pages_number = sbi->ll_ra_info.ra_max_read_ahead_whole_pages;
378 spin_unlock(&sbi->ll_lock);
380 mult = 1 << (20 - PAGE_SHIFT);
381 return lprocfs_seq_read_frac_helper(m, pages_number, mult);
385 ll_max_read_ahead_whole_mb_seq_write(struct file *file,
386 const char __user *buffer,
387 size_t count, loff_t *off)
389 struct seq_file *m = file->private_data;
390 struct super_block *sb = m->private;
391 struct ll_sb_info *sbi = ll_s2sbi(sb);
395 rc = lprocfs_str_with_units_to_s64(buffer, count, &pages_number, 'M');
399 pages_number >>= PAGE_SHIFT;
401 /* Cap this at the current max readahead window size, the readahead
402 * algorithm does this anyway so it's pointless to set it larger. */
403 if (pages_number < 0 ||
404 pages_number > sbi->ll_ra_info.ra_max_pages_per_file) {
405 int pages_shift = 20 - PAGE_SHIFT;
406 CERROR("%s: can't set max_read_ahead_whole_mb=%lu > "
407 "max_read_ahead_per_file_mb=%lu\n",
408 ll_get_fsname(sb, NULL, 0),
409 (unsigned long)pages_number >> pages_shift,
410 sbi->ll_ra_info.ra_max_pages_per_file >> pages_shift);
414 spin_lock(&sbi->ll_lock);
415 sbi->ll_ra_info.ra_max_read_ahead_whole_pages = pages_number;
416 spin_unlock(&sbi->ll_lock);
419 LPROC_SEQ_FOPS(ll_max_read_ahead_whole_mb);
421 static int ll_max_cached_mb_seq_show(struct seq_file *m, void *v)
423 struct super_block *sb = m->private;
424 struct ll_sb_info *sbi = ll_s2sbi(sb);
425 struct cl_client_cache *cache = sbi->ll_cache;
426 int shift = 20 - PAGE_SHIFT;
430 max_cached_mb = cache->ccc_lru_max >> shift;
431 unused_mb = atomic_long_read(&cache->ccc_lru_left) >> shift;
432 seq_printf(m, "users: %d\n"
433 "max_cached_mb: %ld\n"
436 "reclaim_count: %u\n",
437 atomic_read(&cache->ccc_users),
439 max_cached_mb - unused_mb,
441 cache->ccc_lru_shrinkers);
446 ll_max_cached_mb_seq_write(struct file *file, const char __user *buffer,
447 size_t count, loff_t *off)
449 struct seq_file *m = file->private_data;
450 struct super_block *sb = m->private;
451 struct ll_sb_info *sbi = ll_s2sbi(sb);
452 struct cl_client_cache *cache = sbi->ll_cache;
462 if (count >= sizeof(kernbuf))
465 if (copy_from_user(kernbuf, buffer, count))
469 buffer += lprocfs_find_named_value(kernbuf, "max_cached_mb:", &count) -
471 rc = lprocfs_str_with_units_to_s64(buffer, count, &pages_number, 'M');
475 pages_number >>= PAGE_SHIFT;
477 if (pages_number < 0 || pages_number > totalram_pages) {
478 CERROR("%s: can't set max cache more than %lu MB\n",
479 ll_get_fsname(sb, NULL, 0),
480 totalram_pages >> (20 - PAGE_SHIFT));
483 /* Allow enough cache so clients can make well-formed RPCs */
484 pages_number = max_t(long, pages_number, PTLRPC_MAX_BRW_PAGES);
486 spin_lock(&sbi->ll_lock);
487 diff = pages_number - cache->ccc_lru_max;
488 spin_unlock(&sbi->ll_lock);
490 /* easy - add more LRU slots. */
492 atomic_long_add(diff, &cache->ccc_lru_left);
496 env = cl_env_get(&refcheck);
504 /* reduce LRU budget from free slots. */
508 ov = atomic_long_read(&cache->ccc_lru_left);
512 nv = ov > diff ? ov - diff : 0;
513 rc = atomic_long_cmpxchg(&cache->ccc_lru_left, ov, nv);
514 if (likely(ov == rc)) {
524 if (sbi->ll_dt_exp == NULL) { /* being initialized */
529 /* difficult - have to ask OSCs to drop LRU slots. */
531 rc = obd_set_info_async(env, sbi->ll_dt_exp,
532 sizeof(KEY_CACHE_LRU_SHRINK),
533 KEY_CACHE_LRU_SHRINK,
534 sizeof(tmp), &tmp, NULL);
538 cl_env_put(env, &refcheck);
542 spin_lock(&sbi->ll_lock);
543 cache->ccc_lru_max = pages_number;
544 spin_unlock(&sbi->ll_lock);
547 atomic_long_add(nrpages, &cache->ccc_lru_left);
551 LPROC_SEQ_FOPS(ll_max_cached_mb);
553 static ssize_t checksums_show(struct kobject *kobj, struct attribute *attr,
556 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
559 return sprintf(buf, "%u\n", (sbi->ll_flags & LL_SBI_CHECKSUM) ? 1 : 0);
562 static ssize_t checksums_store(struct kobject *kobj, struct attribute *attr,
563 const char *buffer, size_t count)
565 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
575 rc = kstrtobool(buffer, &val);
579 sbi->ll_flags |= LL_SBI_CHECKSUM;
581 sbi->ll_flags &= ~LL_SBI_CHECKSUM;
584 rc = obd_set_info_async(NULL, sbi->ll_dt_exp, sizeof(KEY_CHECKSUM),
585 KEY_CHECKSUM, sizeof(tmp), &tmp, NULL);
587 CWARN("Failed to set OSC checksum flags: %d\n", rc);
591 LUSTRE_RW_ATTR(checksums);
593 LUSTRE_ATTR(checksum_pages, 0644, checksums_show, checksums_store);
595 static ssize_t ll_rd_track_id(struct kobject *kobj, char *buf,
596 enum stats_track_type type)
598 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
601 if (sbi->ll_stats_track_type == type)
602 return sprintf(buf, "%d\n", sbi->ll_stats_track_id);
603 else if (sbi->ll_stats_track_type == STATS_TRACK_ALL)
604 return sprintf(buf, "0 (all)\n");
606 return sprintf(buf, "untracked\n");
609 static ssize_t ll_wr_track_id(struct kobject *kobj, const char *buffer,
610 size_t count, enum stats_track_type type)
612 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
617 rc = kstrtoul(buffer, 10, &pid);
621 sbi->ll_stats_track_id = pid;
623 sbi->ll_stats_track_type = STATS_TRACK_ALL;
625 sbi->ll_stats_track_type = type;
626 lprocfs_clear_stats(sbi->ll_stats);
630 static ssize_t stats_track_pid_show(struct kobject *kobj,
631 struct attribute *attr,
634 return ll_rd_track_id(kobj, buf, STATS_TRACK_PID);
637 static ssize_t stats_track_pid_store(struct kobject *kobj,
638 struct attribute *attr,
642 return ll_wr_track_id(kobj, buffer, count, STATS_TRACK_PID);
644 LUSTRE_RW_ATTR(stats_track_pid);
646 static ssize_t stats_track_ppid_show(struct kobject *kobj,
647 struct attribute *attr,
650 return ll_rd_track_id(kobj, buf, STATS_TRACK_PPID);
653 static ssize_t stats_track_ppid_store(struct kobject *kobj,
654 struct attribute *attr,
658 return ll_wr_track_id(kobj, buffer, count, STATS_TRACK_PPID);
660 LUSTRE_RW_ATTR(stats_track_ppid);
662 static ssize_t stats_track_gid_show(struct kobject *kobj,
663 struct attribute *attr,
666 return ll_rd_track_id(kobj, buf, STATS_TRACK_GID);
669 static ssize_t stats_track_gid_store(struct kobject *kobj,
670 struct attribute *attr,
674 return ll_wr_track_id(kobj, buffer, count, STATS_TRACK_GID);
676 LUSTRE_RW_ATTR(stats_track_gid);
678 static ssize_t statahead_running_max_show(struct kobject *kobj,
679 struct attribute *attr,
682 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
685 return snprintf(buf, 16, "%u\n", sbi->ll_sa_running_max);
688 static ssize_t statahead_running_max_store(struct kobject *kobj,
689 struct attribute *attr,
693 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
698 rc = kstrtoul(buffer, 0, &val);
702 if (val <= LL_SA_RUNNING_MAX) {
703 sbi->ll_sa_running_max = val;
707 CERROR("Bad statahead_running_max value %lu. Valid values "
708 "are in the range [0, %d]\n", val, LL_SA_RUNNING_MAX);
712 LUSTRE_RW_ATTR(statahead_running_max);
714 static ssize_t statahead_max_show(struct kobject *kobj,
715 struct attribute *attr,
718 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
721 return sprintf(buf, "%u\n", sbi->ll_sa_max);
724 static ssize_t statahead_max_store(struct kobject *kobj,
725 struct attribute *attr,
729 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
734 rc = kstrtoul(buffer, 0, &val);
738 if (val <= LL_SA_RPC_MAX)
739 sbi->ll_sa_max = val;
741 CERROR("Bad statahead_max value %lu. Valid values are in the range [0, %d]\n",
746 LUSTRE_RW_ATTR(statahead_max);
748 static ssize_t statahead_agl_show(struct kobject *kobj,
749 struct attribute *attr,
752 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
755 return sprintf(buf, "%u\n", sbi->ll_flags & LL_SBI_AGL_ENABLED ? 1 : 0);
758 static ssize_t statahead_agl_store(struct kobject *kobj,
759 struct attribute *attr,
763 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
768 rc = kstrtobool(buffer, &val);
773 sbi->ll_flags |= LL_SBI_AGL_ENABLED;
775 sbi->ll_flags &= ~LL_SBI_AGL_ENABLED;
779 LUSTRE_RW_ATTR(statahead_agl);
781 static int ll_statahead_stats_seq_show(struct seq_file *m, void *v)
783 struct super_block *sb = m->private;
784 struct ll_sb_info *sbi = ll_s2sbi(sb);
786 seq_printf(m, "statahead total: %u\n"
787 "statahead wrong: %u\n"
789 atomic_read(&sbi->ll_sa_total),
790 atomic_read(&sbi->ll_sa_wrong),
791 atomic_read(&sbi->ll_agl_total));
794 LPROC_SEQ_FOPS_RO(ll_statahead_stats);
796 static ssize_t lazystatfs_show(struct kobject *kobj,
797 struct attribute *attr,
800 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
803 return sprintf(buf, "%u\n", (sbi->ll_flags & LL_SBI_LAZYSTATFS) ? 1 : 0);
806 static ssize_t lazystatfs_store(struct kobject *kobj,
807 struct attribute *attr,
811 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
816 rc = kstrtobool(buffer, &val);
821 sbi->ll_flags |= LL_SBI_LAZYSTATFS;
823 sbi->ll_flags &= ~LL_SBI_LAZYSTATFS;
827 LUSTRE_RW_ATTR(lazystatfs);
829 static ssize_t max_easize_show(struct kobject *kobj,
830 struct attribute *attr,
833 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
838 rc = ll_get_max_mdsize(sbi, &ealen);
842 return sprintf(buf, "%u\n", ealen);
844 LUSTRE_RO_ATTR(max_easize);
847 * Get default_easize.
849 * \see client_obd::cl_default_mds_easize
851 * \param[in] m seq_file handle
852 * \param[in] v unused for single entry
854 * \retval 0 on success
855 * \retval negative negated errno on failure
857 static ssize_t default_easize_show(struct kobject *kobj,
858 struct attribute *attr,
861 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
866 rc = ll_get_default_mdsize(sbi, &ealen);
870 return sprintf(buf, "%u\n", ealen);
874 * Set default_easize.
876 * Range checking on the passed value is handled by
877 * ll_set_default_mdsize().
879 * \see client_obd::cl_default_mds_easize
881 * \param[in] file proc file
882 * \param[in] buffer string passed from user space
883 * \param[in] count \a buffer length
884 * \param[in] off unused for single entry
886 * \retval positive \a count on success
887 * \retval negative negated errno on failure
889 static ssize_t default_easize_store(struct kobject *kobj,
890 struct attribute *attr,
894 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
902 rc = kstrtouint(buffer, 10, &val);
906 rc = ll_set_default_mdsize(sbi, val);
912 LUSTRE_RW_ATTR(default_easize);
914 static int ll_sbi_flags_seq_show(struct seq_file *m, void *v)
916 const char *str[] = LL_SBI_FLAGS;
917 struct super_block *sb = m->private;
918 int flags = ll_s2sbi(sb)->ll_flags;
922 if (ARRAY_SIZE(str) <= i) {
923 CERROR("%s: Revise array LL_SBI_FLAGS to match sbi "
924 "flags please.\n", ll_get_fsname(sb, NULL, 0));
929 seq_printf(m, "%s ", str[i]);
933 seq_printf(m, "\b\n");
936 LPROC_SEQ_FOPS_RO(ll_sbi_flags);
938 static ssize_t xattr_cache_show(struct kobject *kobj,
939 struct attribute *attr,
942 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
945 return sprintf(buf, "%u\n", sbi->ll_xattr_cache_enabled);
948 static ssize_t xattr_cache_store(struct kobject *kobj,
949 struct attribute *attr,
953 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
958 rc = kstrtobool(buffer, &val);
962 if (val && !(sbi->ll_flags & LL_SBI_XATTR_CACHE))
965 sbi->ll_xattr_cache_enabled = val;
966 sbi->ll_xattr_cache_set = 1;
970 LUSTRE_RW_ATTR(xattr_cache);
972 static ssize_t tiny_write_show(struct kobject *kobj,
973 struct attribute *attr,
976 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
979 return sprintf(buf, "%u\n", !!(sbi->ll_flags & LL_SBI_TINY_WRITE));
982 static ssize_t tiny_write_store(struct kobject *kobj,
983 struct attribute *attr,
987 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
992 rc = kstrtobool(buffer, &val);
996 spin_lock(&sbi->ll_lock);
998 sbi->ll_flags |= LL_SBI_TINY_WRITE;
1000 sbi->ll_flags &= ~LL_SBI_TINY_WRITE;
1001 spin_unlock(&sbi->ll_lock);
1005 LUSTRE_RW_ATTR(tiny_write);
1007 static ssize_t fast_read_show(struct kobject *kobj,
1008 struct attribute *attr,
1011 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
1014 return sprintf(buf, "%u\n", !!(sbi->ll_flags & LL_SBI_FAST_READ));
1017 static ssize_t fast_read_store(struct kobject *kobj,
1018 struct attribute *attr,
1022 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
1027 rc = kstrtobool(buffer, &val);
1031 spin_lock(&sbi->ll_lock);
1033 sbi->ll_flags |= LL_SBI_FAST_READ;
1035 sbi->ll_flags &= ~LL_SBI_FAST_READ;
1036 spin_unlock(&sbi->ll_lock);
1040 LUSTRE_RW_ATTR(fast_read);
1042 static ssize_t pio_show(struct kobject *kobj,
1043 struct attribute *attr,
1046 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
1049 return sprintf(buf, "%u\n", !!(sbi->ll_flags & LL_SBI_PIO));
1052 static ssize_t pio_store(struct kobject *kobj,
1053 struct attribute *attr,
1057 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
1062 rc = kstrtobool(buffer, &val);
1066 spin_lock(&sbi->ll_lock);
1068 sbi->ll_flags |= LL_SBI_PIO;
1070 sbi->ll_flags &= ~LL_SBI_PIO;
1071 spin_unlock(&sbi->ll_lock);
1075 LUSTRE_RW_ATTR(pio);
1077 static int ll_unstable_stats_seq_show(struct seq_file *m, void *v)
1079 struct super_block *sb = m->private;
1080 struct ll_sb_info *sbi = ll_s2sbi(sb);
1081 struct cl_client_cache *cache = sbi->ll_cache;
1085 pages = atomic_long_read(&cache->ccc_unstable_nr);
1086 mb = (pages * PAGE_SIZE) >> 20;
1088 seq_printf(m, "unstable_check: %8d\n"
1089 "unstable_pages: %12ld\n"
1090 "unstable_mb: %8d\n",
1091 cache->ccc_unstable_check, pages, mb);
1095 static ssize_t ll_unstable_stats_seq_write(struct file *file,
1096 const char __user *buffer,
1097 size_t count, loff_t *unused)
1099 struct seq_file *seq = file->private_data;
1100 struct ll_sb_info *sbi = ll_s2sbi((struct super_block *)seq->private);
1107 if (count >= sizeof(kernbuf))
1110 if (copy_from_user(kernbuf, buffer, count))
1114 buffer += lprocfs_find_named_value(kernbuf, "unstable_check:", &count) -
1116 rc = kstrtobool_from_user(buffer, count, &val);
1120 /* borrow lru lock to set the value */
1121 spin_lock(&sbi->ll_cache->ccc_lru_lock);
1122 sbi->ll_cache->ccc_unstable_check = val;
1123 spin_unlock(&sbi->ll_cache->ccc_lru_lock);
1127 LPROC_SEQ_FOPS(ll_unstable_stats);
1129 static int ll_root_squash_seq_show(struct seq_file *m, void *v)
1131 struct super_block *sb = m->private;
1132 struct ll_sb_info *sbi = ll_s2sbi(sb);
1133 struct root_squash_info *squash = &sbi->ll_squash;
1135 seq_printf(m, "%u:%u\n", squash->rsi_uid, squash->rsi_gid);
1139 static ssize_t ll_root_squash_seq_write(struct file *file,
1140 const char __user *buffer,
1141 size_t count, loff_t *off)
1143 struct seq_file *m = file->private_data;
1144 struct super_block *sb = m->private;
1145 struct ll_sb_info *sbi = ll_s2sbi(sb);
1146 struct root_squash_info *squash = &sbi->ll_squash;
1148 return lprocfs_wr_root_squash(buffer, count, squash,
1149 ll_get_fsname(sb, NULL, 0));
1151 LPROC_SEQ_FOPS(ll_root_squash);
1153 static int ll_nosquash_nids_seq_show(struct seq_file *m, void *v)
1155 struct super_block *sb = m->private;
1156 struct ll_sb_info *sbi = ll_s2sbi(sb);
1157 struct root_squash_info *squash = &sbi->ll_squash;
1160 down_read(&squash->rsi_sem);
1161 if (!list_empty(&squash->rsi_nosquash_nids)) {
1162 len = cfs_print_nidlist(m->buf + m->count, m->size - m->count,
1163 &squash->rsi_nosquash_nids);
1167 seq_puts(m, "NONE\n");
1169 up_read(&squash->rsi_sem);
1174 static ssize_t ll_nosquash_nids_seq_write(struct file *file,
1175 const char __user *buffer,
1176 size_t count, loff_t *off)
1178 struct seq_file *m = file->private_data;
1179 struct super_block *sb = m->private;
1180 struct ll_sb_info *sbi = ll_s2sbi(sb);
1181 struct root_squash_info *squash = &sbi->ll_squash;
1184 rc = lprocfs_wr_nosquash_nids(buffer, count, squash,
1185 ll_get_fsname(sb, NULL, 0));
1189 ll_compute_rootsquash_state(sbi);
1193 LPROC_SEQ_FOPS(ll_nosquash_nids);
1195 struct lprocfs_vars lprocfs_llite_obd_vars[] = {
1197 .fops = &ll_site_stats_fops },
1198 { .name = "max_read_ahead_mb",
1199 .fops = &ll_max_readahead_mb_fops },
1200 { .name = "max_read_ahead_per_file_mb",
1201 .fops = &ll_max_readahead_per_file_mb_fops },
1202 { .name = "max_read_ahead_whole_mb",
1203 .fops = &ll_max_read_ahead_whole_mb_fops },
1204 { .name = "max_cached_mb",
1205 .fops = &ll_max_cached_mb_fops },
1206 { .name = "statahead_stats",
1207 .fops = &ll_statahead_stats_fops },
1208 { .name = "sbi_flags",
1209 .fops = &ll_sbi_flags_fops },
1210 { .name = "unstable_stats",
1211 .fops = &ll_unstable_stats_fops },
1212 { .name = "root_squash",
1213 .fops = &ll_root_squash_fops },
1214 { .name = "nosquash_nids",
1215 .fops = &ll_nosquash_nids_fops },
1219 #define MAX_STRING_SIZE 128
1221 static struct attribute *llite_attrs[] = {
1222 &lustre_attr_blocksize.attr,
1223 &lustre_attr_stat_blocksize.attr,
1224 &lustre_attr_kbytestotal.attr,
1225 &lustre_attr_kbytesfree.attr,
1226 &lustre_attr_kbytesavail.attr,
1227 &lustre_attr_filestotal.attr,
1228 &lustre_attr_filesfree.attr,
1229 &lustre_attr_client_type.attr,
1230 &lustre_attr_fstype.attr,
1231 &lustre_attr_uuid.attr,
1232 &lustre_attr_checksums.attr,
1233 &lustre_attr_checksum_pages.attr,
1234 &lustre_attr_stats_track_pid.attr,
1235 &lustre_attr_stats_track_ppid.attr,
1236 &lustre_attr_stats_track_gid.attr,
1237 &lustre_attr_statahead_running_max.attr,
1238 &lustre_attr_statahead_max.attr,
1239 &lustre_attr_statahead_agl.attr,
1240 &lustre_attr_lazystatfs.attr,
1241 &lustre_attr_max_easize.attr,
1242 &lustre_attr_default_easize.attr,
1243 &lustre_attr_xattr_cache.attr,
1244 &lustre_attr_fast_read.attr,
1245 &lustre_attr_pio.attr,
1246 &lustre_attr_tiny_write.attr,
1250 static void llite_kobj_release(struct kobject *kobj)
1252 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
1254 complete(&sbi->ll_kobj_unregister);
1257 static struct kobj_type llite_ktype = {
1258 .default_attrs = llite_attrs,
1259 .sysfs_ops = &lustre_sysfs_ops,
1260 .release = llite_kobj_release,
1263 static const struct llite_file_opcode {
1267 } llite_opcode_table[LPROC_LL_FILE_OPCODES] = {
1268 /* file operation */
1269 { LPROC_LL_DIRTY_HITS, LPROCFS_TYPE_REGS, "dirty_pages_hits" },
1270 { LPROC_LL_DIRTY_MISSES, LPROCFS_TYPE_REGS, "dirty_pages_misses" },
1271 { LPROC_LL_READ_BYTES, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_BYTES,
1273 { LPROC_LL_WRITE_BYTES, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_BYTES,
1275 { LPROC_LL_BRW_READ, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
1277 { LPROC_LL_BRW_WRITE, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
1279 { LPROC_LL_IOCTL, LPROCFS_TYPE_REGS, "ioctl" },
1280 { LPROC_LL_OPEN, LPROCFS_TYPE_REGS, "open" },
1281 { LPROC_LL_RELEASE, LPROCFS_TYPE_REGS, "close" },
1282 { LPROC_LL_MAP, LPROCFS_TYPE_REGS, "mmap" },
1283 { LPROC_LL_FAULT, LPROCFS_TYPE_REGS, "page_fault" },
1284 { LPROC_LL_MKWRITE, LPROCFS_TYPE_REGS, "page_mkwrite" },
1285 { LPROC_LL_LLSEEK, LPROCFS_TYPE_REGS, "seek" },
1286 { LPROC_LL_FSYNC, LPROCFS_TYPE_REGS, "fsync" },
1287 { LPROC_LL_READDIR, LPROCFS_TYPE_REGS, "readdir" },
1288 /* inode operation */
1289 { LPROC_LL_SETATTR, LPROCFS_TYPE_REGS, "setattr" },
1290 { LPROC_LL_TRUNC, LPROCFS_TYPE_REGS, "truncate" },
1291 { LPROC_LL_FLOCK, LPROCFS_TYPE_REGS, "flock" },
1292 { LPROC_LL_GETATTR, LPROCFS_TYPE_REGS, "getattr" },
1293 /* dir inode operation */
1294 { LPROC_LL_CREATE, LPROCFS_TYPE_REGS, "create" },
1295 { LPROC_LL_LINK, LPROCFS_TYPE_REGS, "link" },
1296 { LPROC_LL_UNLINK, LPROCFS_TYPE_REGS, "unlink" },
1297 { LPROC_LL_SYMLINK, LPROCFS_TYPE_REGS, "symlink" },
1298 { LPROC_LL_MKDIR, LPROCFS_TYPE_REGS, "mkdir" },
1299 { LPROC_LL_RMDIR, LPROCFS_TYPE_REGS, "rmdir" },
1300 { LPROC_LL_MKNOD, LPROCFS_TYPE_REGS, "mknod" },
1301 { LPROC_LL_RENAME, LPROCFS_TYPE_REGS, "rename" },
1302 /* special inode operation */
1303 { LPROC_LL_STAFS, LPROCFS_TYPE_REGS, "statfs" },
1304 { LPROC_LL_ALLOC_INODE, LPROCFS_TYPE_REGS, "alloc_inode" },
1305 { LPROC_LL_SETXATTR, LPROCFS_TYPE_REGS, "setxattr" },
1306 { LPROC_LL_GETXATTR, LPROCFS_TYPE_REGS, "getxattr" },
1307 { LPROC_LL_GETXATTR_HITS, LPROCFS_TYPE_REGS, "getxattr_hits" },
1308 { LPROC_LL_LISTXATTR, LPROCFS_TYPE_REGS, "listxattr" },
1309 { LPROC_LL_REMOVEXATTR, LPROCFS_TYPE_REGS, "removexattr" },
1310 { LPROC_LL_INODE_PERM, LPROCFS_TYPE_REGS, "inode_permission" },
1313 void ll_stats_ops_tally(struct ll_sb_info *sbi, int op, int count)
1317 if (sbi->ll_stats_track_type == STATS_TRACK_ALL)
1318 lprocfs_counter_add(sbi->ll_stats, op, count);
1319 else if (sbi->ll_stats_track_type == STATS_TRACK_PID &&
1320 sbi->ll_stats_track_id == current->pid)
1321 lprocfs_counter_add(sbi->ll_stats, op, count);
1322 else if (sbi->ll_stats_track_type == STATS_TRACK_PPID &&
1323 sbi->ll_stats_track_id == current->parent->pid)
1324 lprocfs_counter_add(sbi->ll_stats, op, count);
1325 else if (sbi->ll_stats_track_type == STATS_TRACK_GID &&
1326 sbi->ll_stats_track_id ==
1327 from_kgid(&init_user_ns, current_gid()))
1328 lprocfs_counter_add(sbi->ll_stats, op, count);
1330 EXPORT_SYMBOL(ll_stats_ops_tally);
1332 static const char *ra_stat_string[] = {
1333 [RA_STAT_HIT] = "hits",
1334 [RA_STAT_MISS] = "misses",
1335 [RA_STAT_DISTANT_READPAGE] = "readpage not consecutive",
1336 [RA_STAT_MISS_IN_WINDOW] = "miss inside window",
1337 [RA_STAT_FAILED_GRAB_PAGE] = "failed grab_cache_page",
1338 [RA_STAT_FAILED_MATCH] = "failed lock match",
1339 [RA_STAT_DISCARDED] = "read but discarded",
1340 [RA_STAT_ZERO_LEN] = "zero length file",
1341 [RA_STAT_ZERO_WINDOW] = "zero size window",
1342 [RA_STAT_EOF] = "read-ahead to EOF",
1343 [RA_STAT_MAX_IN_FLIGHT] = "hit max r-a issue",
1344 [RA_STAT_WRONG_GRAB_PAGE] = "wrong page from grab_cache_page",
1345 [RA_STAT_FAILED_REACH_END] = "failed to reach end"
1348 int ll_debugfs_register_super(struct super_block *sb, const char *name)
1350 struct lustre_sb_info *lsi = s2lsi(sb);
1351 struct ll_sb_info *sbi = ll_s2sbi(sb);
1352 struct lprocfs_vars lvars[2];
1356 memset(lvars, 0, sizeof(lvars));
1357 lvars[0].name = name;
1359 LASSERT(sbi != NULL);
1361 sbi->ll_proc_root = lprocfs_register(name, proc_lustre_fs_root,
1363 if (IS_ERR(sbi->ll_proc_root)) {
1364 err = PTR_ERR(sbi->ll_proc_root);
1365 sbi->ll_proc_root = NULL;
1369 rc = lprocfs_seq_create(sbi->ll_proc_root, "dump_page_cache", 0444,
1370 &vvp_dump_pgcache_file_ops, sbi);
1372 CWARN("Error adding the dump_page_cache file\n");
1374 rc = lprocfs_seq_create(sbi->ll_proc_root, "extents_stats", 0644,
1375 &ll_rw_extents_stats_fops, sbi);
1377 CWARN("Error adding the extent_stats file\n");
1379 rc = lprocfs_seq_create(sbi->ll_proc_root, "extents_stats_per_process",
1380 0644, &ll_rw_extents_stats_pp_fops, sbi);
1382 CWARN("Error adding the extents_stats_per_process file\n");
1384 rc = lprocfs_seq_create(sbi->ll_proc_root, "offset_stats", 0644,
1385 &ll_rw_offset_stats_fops, sbi);
1387 CWARN("Error adding the offset_stats file\n");
1389 /* File operations stats */
1390 sbi->ll_stats = lprocfs_alloc_stats(LPROC_LL_FILE_OPCODES,
1391 LPROCFS_STATS_FLAG_NONE);
1392 if (sbi->ll_stats == NULL)
1393 GOTO(out_proc, err = -ENOMEM);
1395 /* do counter init */
1396 for (id = 0; id < LPROC_LL_FILE_OPCODES; id++) {
1397 __u32 type = llite_opcode_table[id].type;
1399 if (type & LPROCFS_TYPE_REGS)
1401 else if (type & LPROCFS_TYPE_BYTES)
1403 else if (type & LPROCFS_TYPE_PAGES)
1405 lprocfs_counter_init(sbi->ll_stats,
1406 llite_opcode_table[id].opcode,
1407 (type & LPROCFS_CNTR_AVGMINMAX),
1408 llite_opcode_table[id].opname, ptr);
1411 err = lprocfs_register_stats(sbi->ll_proc_root, "stats", sbi->ll_stats);
1413 GOTO(out_stats, err);
1415 sbi->ll_ra_stats = lprocfs_alloc_stats(ARRAY_SIZE(ra_stat_string),
1416 LPROCFS_STATS_FLAG_NONE);
1417 if (sbi->ll_ra_stats == NULL)
1418 GOTO(out_stats, err = -ENOMEM);
1420 for (id = 0; id < ARRAY_SIZE(ra_stat_string); id++)
1421 lprocfs_counter_init(sbi->ll_ra_stats, id, 0,
1422 ra_stat_string[id], "pages");
1423 err = lprocfs_register_stats(sbi->ll_proc_root, "read_ahead_stats",
1426 GOTO(out_ra_stats, err);
1428 err = lprocfs_add_vars(sbi->ll_proc_root, lprocfs_llite_obd_vars, sb);
1430 GOTO(out_ra_stats, err);
1432 /* Yes we also register sysfs mount kset here as well */
1433 sbi->ll_kset.kobj.parent = llite_kobj;
1434 sbi->ll_kset.kobj.ktype = &llite_ktype;
1435 init_completion(&sbi->ll_kobj_unregister);
1436 err = kobject_set_name(&sbi->ll_kset.kobj, "%s", name);
1438 GOTO(out_ra_stats, err);
1440 err = kset_register(&sbi->ll_kset);
1442 GOTO(out_ra_stats, err);
1444 lsi->lsi_kobj = kobject_get(&sbi->ll_kset.kobj);
1448 lprocfs_free_stats(&sbi->ll_ra_stats);
1450 lprocfs_free_stats(&sbi->ll_stats);
1452 lprocfs_remove(&sbi->ll_proc_root);
1457 void ll_debugfs_unregister_super(struct super_block *sb)
1459 struct lustre_sb_info *lsi = s2lsi(sb);
1460 struct ll_sb_info *sbi = ll_s2sbi(sb);
1463 sysfs_remove_link(&sbi->ll_kset.kobj,
1464 sbi->ll_dt_obd->obd_type->typ_name);
1467 sysfs_remove_link(&sbi->ll_kset.kobj,
1468 sbi->ll_md_obd->obd_type->typ_name);
1470 kobject_put(lsi->lsi_kobj);
1472 kset_unregister(&sbi->ll_kset);
1473 wait_for_completion(&sbi->ll_kobj_unregister);
1475 if (sbi->ll_proc_root) {
1476 lprocfs_remove(&sbi->ll_proc_root);
1477 lprocfs_free_stats(&sbi->ll_ra_stats);
1478 lprocfs_free_stats(&sbi->ll_stats);
1481 #undef MAX_STRING_SIZE
1483 #define pct(a,b) (b ? a * 100 / b : 0)
1485 static void ll_display_extents_info(struct ll_rw_extents_info *io_extents,
1486 struct seq_file *seq, int which)
1488 unsigned long read_tot = 0, write_tot = 0, read_cum, write_cum;
1489 unsigned long start, end, r, w;
1490 char *unitp = "KMGTPEZY";
1492 struct per_process_info *pp_info = &io_extents->pp_extents[which];
1498 for(i = 0; i < LL_HIST_MAX; i++) {
1499 read_tot += pp_info->pp_r_hist.oh_buckets[i];
1500 write_tot += pp_info->pp_w_hist.oh_buckets[i];
1503 for(i = 0; i < LL_HIST_MAX; i++) {
1504 r = pp_info->pp_r_hist.oh_buckets[i];
1505 w = pp_info->pp_w_hist.oh_buckets[i];
1508 end = 1 << (i + LL_HIST_START - units);
1509 seq_printf(seq, "%4lu%c - %4lu%c%c: %14lu %4lu %4lu | "
1510 "%14lu %4lu %4lu\n", start, *unitp, end, *unitp,
1511 (i == LL_HIST_MAX - 1) ? '+' : ' ',
1512 r, pct(r, read_tot), pct(read_cum, read_tot),
1513 w, pct(w, write_tot), pct(write_cum, write_tot));
1515 if (start == 1<<10) {
1520 if (read_cum == read_tot && write_cum == write_tot)
1525 static int ll_rw_extents_stats_pp_seq_show(struct seq_file *seq, void *v)
1527 struct timespec64 now;
1528 struct ll_sb_info *sbi = seq->private;
1529 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1532 ktime_get_real_ts64(&now);
1534 if (!sbi->ll_rw_stats_on) {
1535 seq_puts(seq, "disabled\n write anything to this file to activate, then '0' or 'disable' to deactivate\n");
1538 seq_printf(seq, "snapshot_time: %llu.%09lu (secs.nsecs)\n",
1539 (s64)now.tv_sec, now.tv_nsec);
1540 seq_printf(seq, "%15s %19s | %20s\n", " ", "read", "write");
1541 seq_printf(seq, "%13s %14s %4s %4s | %14s %4s %4s\n",
1542 "extents", "calls", "%", "cum%",
1543 "calls", "%", "cum%");
1544 spin_lock(&sbi->ll_pp_extent_lock);
1545 for (k = 0; k < LL_PROCESS_HIST_MAX; k++) {
1546 if (io_extents->pp_extents[k].pid != 0) {
1547 seq_printf(seq, "\nPID: %d\n",
1548 io_extents->pp_extents[k].pid);
1549 ll_display_extents_info(io_extents, seq, k);
1552 spin_unlock(&sbi->ll_pp_extent_lock);
1556 static ssize_t ll_rw_extents_stats_pp_seq_write(struct file *file,
1557 const char __user *buf,
1561 struct seq_file *seq = file->private_data;
1562 struct ll_sb_info *sbi = seq->private;
1563 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1570 value = ll_stats_pid_write(buf, len);
1573 sbi->ll_rw_stats_on = 0;
1575 sbi->ll_rw_stats_on = 1;
1577 spin_lock(&sbi->ll_pp_extent_lock);
1578 for (i = 0; i < LL_PROCESS_HIST_MAX; i++) {
1579 io_extents->pp_extents[i].pid = 0;
1580 lprocfs_oh_clear(&io_extents->pp_extents[i].pp_r_hist);
1581 lprocfs_oh_clear(&io_extents->pp_extents[i].pp_w_hist);
1583 spin_unlock(&sbi->ll_pp_extent_lock);
1587 LPROC_SEQ_FOPS(ll_rw_extents_stats_pp);
1589 static int ll_rw_extents_stats_seq_show(struct seq_file *seq, void *v)
1591 struct timespec64 now;
1592 struct ll_sb_info *sbi = seq->private;
1593 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1595 ktime_get_real_ts64(&now);
1597 if (!sbi->ll_rw_stats_on) {
1598 seq_puts(seq, "disabled\n write anything to this file to activate, then '0' or 'disable' to deactivate\n");
1601 seq_printf(seq, "snapshot_time: %llu.%09lu (secs.nsecs)\n",
1602 (s64)now.tv_sec, now.tv_nsec);
1604 seq_printf(seq, "%15s %19s | %20s\n", " ", "read", "write");
1605 seq_printf(seq, "%13s %14s %4s %4s | %14s %4s %4s\n",
1606 "extents", "calls", "%", "cum%",
1607 "calls", "%", "cum%");
1608 spin_lock(&sbi->ll_lock);
1609 ll_display_extents_info(io_extents, seq, LL_PROCESS_HIST_MAX);
1610 spin_unlock(&sbi->ll_lock);
1615 static ssize_t ll_rw_extents_stats_seq_write(struct file *file,
1616 const char __user *buf,
1617 size_t len, loff_t *off)
1619 struct seq_file *seq = file->private_data;
1620 struct ll_sb_info *sbi = seq->private;
1621 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1628 value = ll_stats_pid_write(buf, len);
1631 sbi->ll_rw_stats_on = 0;
1633 sbi->ll_rw_stats_on = 1;
1635 spin_lock(&sbi->ll_pp_extent_lock);
1636 for (i = 0; i <= LL_PROCESS_HIST_MAX; i++) {
1637 io_extents->pp_extents[i].pid = 0;
1638 lprocfs_oh_clear(&io_extents->pp_extents[i].pp_r_hist);
1639 lprocfs_oh_clear(&io_extents->pp_extents[i].pp_w_hist);
1641 spin_unlock(&sbi->ll_pp_extent_lock);
1645 LPROC_SEQ_FOPS(ll_rw_extents_stats);
1647 void ll_rw_stats_tally(struct ll_sb_info *sbi, pid_t pid,
1648 struct ll_file_data *file, loff_t pos,
1649 size_t count, int rw)
1652 struct ll_rw_process_info *process;
1653 struct ll_rw_process_info *offset;
1654 int *off_count = &sbi->ll_rw_offset_entry_count;
1655 int *process_count = &sbi->ll_offset_process_count;
1656 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1658 if(!sbi->ll_rw_stats_on)
1660 process = sbi->ll_rw_process_info;
1661 offset = sbi->ll_rw_offset_info;
1663 spin_lock(&sbi->ll_pp_extent_lock);
1664 /* Extent statistics */
1665 for(i = 0; i < LL_PROCESS_HIST_MAX; i++) {
1666 if(io_extents->pp_extents[i].pid == pid) {
1674 sbi->ll_extent_process_count =
1675 (sbi->ll_extent_process_count + 1) % LL_PROCESS_HIST_MAX;
1676 cur = sbi->ll_extent_process_count;
1677 io_extents->pp_extents[cur].pid = pid;
1678 lprocfs_oh_clear(&io_extents->pp_extents[cur].pp_r_hist);
1679 lprocfs_oh_clear(&io_extents->pp_extents[cur].pp_w_hist);
1682 for(i = 0; (count >= (1 << LL_HIST_START << i)) &&
1683 (i < (LL_HIST_MAX - 1)); i++);
1685 io_extents->pp_extents[cur].pp_r_hist.oh_buckets[i]++;
1686 io_extents->pp_extents[LL_PROCESS_HIST_MAX].pp_r_hist.oh_buckets[i]++;
1688 io_extents->pp_extents[cur].pp_w_hist.oh_buckets[i]++;
1689 io_extents->pp_extents[LL_PROCESS_HIST_MAX].pp_w_hist.oh_buckets[i]++;
1691 spin_unlock(&sbi->ll_pp_extent_lock);
1693 spin_lock(&sbi->ll_process_lock);
1694 /* Offset statistics */
1695 for (i = 0; i < LL_PROCESS_HIST_MAX; i++) {
1696 if (process[i].rw_pid == pid) {
1697 if (process[i].rw_last_file != file) {
1698 process[i].rw_range_start = pos;
1699 process[i].rw_last_file_pos = pos + count;
1700 process[i].rw_smallest_extent = count;
1701 process[i].rw_largest_extent = count;
1702 process[i].rw_offset = 0;
1703 process[i].rw_last_file = file;
1704 spin_unlock(&sbi->ll_process_lock);
1707 if (process[i].rw_last_file_pos != pos) {
1709 (*off_count + 1) % LL_OFFSET_HIST_MAX;
1710 offset[*off_count].rw_op = process[i].rw_op;
1711 offset[*off_count].rw_pid = pid;
1712 offset[*off_count].rw_range_start =
1713 process[i].rw_range_start;
1714 offset[*off_count].rw_range_end =
1715 process[i].rw_last_file_pos;
1716 offset[*off_count].rw_smallest_extent =
1717 process[i].rw_smallest_extent;
1718 offset[*off_count].rw_largest_extent =
1719 process[i].rw_largest_extent;
1720 offset[*off_count].rw_offset =
1721 process[i].rw_offset;
1722 process[i].rw_op = rw;
1723 process[i].rw_range_start = pos;
1724 process[i].rw_smallest_extent = count;
1725 process[i].rw_largest_extent = count;
1726 process[i].rw_offset = pos -
1727 process[i].rw_last_file_pos;
1729 if(process[i].rw_smallest_extent > count)
1730 process[i].rw_smallest_extent = count;
1731 if(process[i].rw_largest_extent < count)
1732 process[i].rw_largest_extent = count;
1733 process[i].rw_last_file_pos = pos + count;
1734 spin_unlock(&sbi->ll_process_lock);
1738 *process_count = (*process_count + 1) % LL_PROCESS_HIST_MAX;
1739 process[*process_count].rw_pid = pid;
1740 process[*process_count].rw_op = rw;
1741 process[*process_count].rw_range_start = pos;
1742 process[*process_count].rw_last_file_pos = pos + count;
1743 process[*process_count].rw_smallest_extent = count;
1744 process[*process_count].rw_largest_extent = count;
1745 process[*process_count].rw_offset = 0;
1746 process[*process_count].rw_last_file = file;
1747 spin_unlock(&sbi->ll_process_lock);
1750 static int ll_rw_offset_stats_seq_show(struct seq_file *seq, void *v)
1752 struct timespec64 now;
1753 struct ll_sb_info *sbi = seq->private;
1754 struct ll_rw_process_info *offset = sbi->ll_rw_offset_info;
1755 struct ll_rw_process_info *process = sbi->ll_rw_process_info;
1758 ktime_get_real_ts64(&now);
1760 if (!sbi->ll_rw_stats_on) {
1761 seq_puts(seq, "disabled\n write anything to this file to activate, then '0' or 'disable' to deactivate\n");
1764 spin_lock(&sbi->ll_process_lock);
1766 seq_printf(seq, "snapshot_time: %llu.%09lu (secs.nsecs)\n",
1767 (s64)now.tv_sec, now.tv_nsec);
1768 seq_printf(seq, "%3s %10s %14s %14s %17s %17s %14s\n",
1769 "R/W", "PID", "RANGE START", "RANGE END",
1770 "SMALLEST EXTENT", "LARGEST EXTENT", "OFFSET");
1772 /* We stored the discontiguous offsets here; print them first */
1773 for (i = 0; i < LL_OFFSET_HIST_MAX; i++) {
1774 if (offset[i].rw_pid != 0)
1776 "%3c %10d %14llu %14llu %17lu %17lu %14llu\n",
1777 offset[i].rw_op == READ ? 'R' : 'W',
1779 offset[i].rw_range_start,
1780 offset[i].rw_range_end,
1781 (unsigned long)offset[i].rw_smallest_extent,
1782 (unsigned long)offset[i].rw_largest_extent,
1783 offset[i].rw_offset);
1786 /* Then print the current offsets for each process */
1787 for (i = 0; i < LL_PROCESS_HIST_MAX; i++) {
1788 if (process[i].rw_pid != 0)
1790 "%3c %10d %14llu %14llu %17lu %17lu %14llu\n",
1791 process[i].rw_op == READ ? 'R' : 'W',
1793 process[i].rw_range_start,
1794 process[i].rw_last_file_pos,
1795 (unsigned long)process[i].rw_smallest_extent,
1796 (unsigned long)process[i].rw_largest_extent,
1797 process[i].rw_offset);
1799 spin_unlock(&sbi->ll_process_lock);
1804 static ssize_t ll_rw_offset_stats_seq_write(struct file *file,
1805 const char __user *buf,
1806 size_t len, loff_t *off)
1808 struct seq_file *seq = file->private_data;
1809 struct ll_sb_info *sbi = seq->private;
1810 struct ll_rw_process_info *process_info = sbi->ll_rw_process_info;
1811 struct ll_rw_process_info *offset_info = sbi->ll_rw_offset_info;
1817 value = ll_stats_pid_write(buf, len);
1820 sbi->ll_rw_stats_on = 0;
1822 sbi->ll_rw_stats_on = 1;
1824 spin_lock(&sbi->ll_process_lock);
1825 sbi->ll_offset_process_count = 0;
1826 sbi->ll_rw_offset_entry_count = 0;
1827 memset(process_info, 0, sizeof(struct ll_rw_process_info) *
1828 LL_PROCESS_HIST_MAX);
1829 memset(offset_info, 0, sizeof(struct ll_rw_process_info) *
1830 LL_OFFSET_HIST_MAX);
1831 spin_unlock(&sbi->ll_process_lock);
1837 * ll_stats_pid_write() - Determine if stats collection should be enabled
1838 * @buf: Buffer containing the data written
1839 * @len: Number of bytes in the buffer
1841 * Several proc files begin collecting stats when a value is written, and stop
1842 * collecting when either '0' or 'disable' is written. This function checks the
1843 * written value to see if collection should be enabled or disabled.
1845 * Return: If '0' or 'disable' is provided, 0 is returned. If the text
1846 * equivalent of a number is written, that number is returned. Otherwise,
1847 * 1 is returned. Non-zero return values indicate collection should be enabled.
1849 static __s64 ll_stats_pid_write(const char __user *buf, size_t len)
1851 unsigned long long value = 1;
1855 rc = kstrtoull_from_user(buf, len, 0, &value);
1856 if (rc < 0 && len < sizeof(kernbuf)) {
1858 if (copy_from_user(kernbuf, buf, len))
1862 if (kernbuf[len - 1] == '\n')
1863 kernbuf[len - 1] = 0;
1865 if (strncasecmp(kernbuf, "disable", 7) == 0)
1872 LPROC_SEQ_FOPS(ll_rw_offset_stats);
1873 #endif /* CONFIG_PROC_FS */