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/
31 #define DEBUG_SUBSYSTEM S_LLITE
33 #include <linux/version.h>
34 #include <linux/user_namespace.h>
35 #include <linux/uidgid.h>
37 #include <uapi/linux/lustre/lustre_param.h>
38 #include <lprocfs_status.h>
39 #include <obd_support.h>
41 #include "llite_internal.h"
42 #include "vvp_internal.h"
44 static struct kobject *llite_kobj;
45 static struct dentry *llite_root;
47 static void llite_kobj_release(struct kobject *kobj)
49 if (!IS_ERR_OR_NULL(llite_root)) {
50 debugfs_remove(llite_root);
57 static struct kobj_type llite_kobj_ktype = {
58 .release = llite_kobj_release,
59 .sysfs_ops = &lustre_sysfs_ops,
62 int llite_tunables_register(void)
66 llite_kobj = kzalloc(sizeof(*llite_kobj), GFP_KERNEL);
70 llite_kobj->kset = lustre_kset;
71 rc = kobject_init_and_add(llite_kobj, &llite_kobj_ktype,
72 &lustre_kset->kobj, "%s", "llite");
76 llite_root = debugfs_create_dir("llite", debugfs_lustre_root);
80 kobject_put(llite_kobj);
86 void llite_tunables_unregister(void)
88 kobject_put(llite_kobj);
92 /* <debugfs>/lustre/llite mount point registration */
93 static const struct file_operations ll_rw_extents_stats_fops;
94 static const struct file_operations ll_rw_extents_stats_pp_fops;
95 static const struct file_operations ll_rw_offset_stats_fops;
98 * ll_stats_pid_write() - Determine if stats collection should be enabled
99 * @buf: Buffer containing the data written
100 * @len: Number of bytes in the buffer
102 * Several proc files begin collecting stats when a value is written, and stop
103 * collecting when either '0' or 'disable' is written. This function checks the
104 * written value to see if collection should be enabled or disabled.
106 * Return: If '0' or 'disable' is provided, 0 is returned. If the text
107 * equivalent of a number is written, that number is returned. Otherwise,
108 * 1 is returned. Non-zero return values indicate collection should be enabled.
110 static s64 ll_stats_pid_write(const char __user *buf, size_t len)
112 unsigned long long value = 1;
116 rc = kstrtoull_from_user(buf, len, 0, &value);
117 if (rc < 0 && len < sizeof(kernbuf)) {
118 if (copy_from_user(kernbuf, buf, len))
122 if (kernbuf[len - 1] == '\n')
123 kernbuf[len - 1] = 0;
125 if (strncasecmp(kernbuf, "disable", 7) == 0)
132 static ssize_t blocksize_show(struct kobject *kobj, struct attribute *attr,
135 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
137 struct obd_statfs osfs;
140 rc = ll_statfs_internal(sbi, &osfs, OBD_STATFS_NODELAY);
144 return sprintf(buf, "%u\n", osfs.os_bsize);
146 LUSTRE_RO_ATTR(blocksize);
148 static ssize_t stat_blocksize_show(struct kobject *kobj, struct attribute *attr,
151 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
154 return sprintf(buf, "%u\n", sbi->ll_stat_blksize);
157 static ssize_t stat_blocksize_store(struct kobject *kobj,
158 struct attribute *attr,
162 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
167 rc = kstrtouint(buffer, 10, &val);
171 if (val != 0 && (val < PAGE_SIZE || (val & (val - 1))) != 0)
174 sbi->ll_stat_blksize = val;
178 LUSTRE_RW_ATTR(stat_blocksize);
180 static ssize_t kbytestotal_show(struct kobject *kobj, struct attribute *attr,
183 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
185 struct obd_statfs osfs;
190 rc = ll_statfs_internal(sbi, &osfs, OBD_STATFS_NODELAY);
194 blk_size = osfs.os_bsize >> 10;
195 result = osfs.os_blocks;
197 while (blk_size >>= 1)
200 return sprintf(buf, "%llu\n", result);
202 LUSTRE_RO_ATTR(kbytestotal);
204 static ssize_t kbytesfree_show(struct kobject *kobj, struct attribute *attr,
207 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
209 struct obd_statfs osfs;
214 rc = ll_statfs_internal(sbi, &osfs, OBD_STATFS_NODELAY);
218 blk_size = osfs.os_bsize >> 10;
219 result = osfs.os_bfree;
221 while (blk_size >>= 1)
224 return sprintf(buf, "%llu\n", result);
226 LUSTRE_RO_ATTR(kbytesfree);
228 static ssize_t kbytesavail_show(struct kobject *kobj, struct attribute *attr,
231 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
233 struct obd_statfs osfs;
238 rc = ll_statfs_internal(sbi, &osfs, OBD_STATFS_NODELAY);
242 blk_size = osfs.os_bsize >> 10;
243 result = osfs.os_bavail;
245 while (blk_size >>= 1)
248 return sprintf(buf, "%llu\n", result);
250 LUSTRE_RO_ATTR(kbytesavail);
252 static ssize_t filestotal_show(struct kobject *kobj, struct attribute *attr,
255 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
257 struct obd_statfs osfs;
260 rc = ll_statfs_internal(sbi, &osfs, OBD_STATFS_NODELAY);
264 return sprintf(buf, "%llu\n", osfs.os_files);
266 LUSTRE_RO_ATTR(filestotal);
268 static ssize_t filesfree_show(struct kobject *kobj, struct attribute *attr,
271 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
273 struct obd_statfs osfs;
276 rc = ll_statfs_internal(sbi, &osfs, OBD_STATFS_NODELAY);
280 return sprintf(buf, "%llu\n", osfs.os_ffree);
282 LUSTRE_RO_ATTR(filesfree);
284 static ssize_t client_type_show(struct kobject *kobj, struct attribute *attr,
287 return sprintf(buf, "local client\n");
289 LUSTRE_RO_ATTR(client_type);
291 LUSTRE_RW_ATTR(foreign_symlink_enable);
293 LUSTRE_RW_ATTR(foreign_symlink_prefix);
295 LUSTRE_RW_ATTR(foreign_symlink_upcall);
297 LUSTRE_WO_ATTR(foreign_symlink_upcall_info);
299 static ssize_t fstype_show(struct kobject *kobj, struct attribute *attr,
302 return sprintf(buf, "lustre\n");
304 LUSTRE_RO_ATTR(fstype);
306 static ssize_t uuid_show(struct kobject *kobj, struct attribute *attr,
309 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
312 return sprintf(buf, "%s\n", sbi->ll_sb_uuid.uuid);
314 LUSTRE_RO_ATTR(uuid);
316 static int ll_site_stats_seq_show(struct seq_file *m, void *v)
318 struct super_block *sb = m->private;
321 * See description of statistical counters in struct cl_site, and
324 return cl_site_stats_print(lu2cl_site(ll_s2sbi(sb)->ll_site), m);
327 LDEBUGFS_SEQ_FOPS_RO(ll_site_stats);
329 static ssize_t max_read_ahead_mb_show(struct kobject *kobj,
330 struct attribute *attr, char *buf)
332 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
335 return scnprintf(buf, PAGE_SIZE, "%lu\n",
336 PAGES_TO_MiB(sbi->ll_ra_info.ra_max_pages));
339 static ssize_t max_read_ahead_mb_store(struct kobject *kobj,
340 struct attribute *attr,
341 const char *buffer, size_t count)
343 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
345 u64 ra_max_mb, pages_number;
348 rc = sysfs_memparse(buffer, count, &ra_max_mb, "MiB");
352 pages_number = round_up(ra_max_mb, 1024 * 1024) >> PAGE_SHIFT;
353 CDEBUG(D_INFO, "%s: set max_read_ahead_mb=%llu (%llu pages)\n",
354 sbi->ll_fsname, PAGES_TO_MiB(pages_number), pages_number);
355 if (pages_number > cfs_totalram_pages() / 2) {
357 CERROR("%s: cannot set max_read_ahead_mb=%llu > totalram/2=%luMB\n",
358 sbi->ll_fsname, PAGES_TO_MiB(pages_number),
359 PAGES_TO_MiB(cfs_totalram_pages() / 2));
363 spin_lock(&sbi->ll_lock);
364 sbi->ll_ra_info.ra_max_pages = pages_number;
365 spin_unlock(&sbi->ll_lock);
369 LUSTRE_RW_ATTR(max_read_ahead_mb);
371 static ssize_t max_read_ahead_per_file_mb_show(struct kobject *kobj,
372 struct attribute *attr,
375 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
378 return scnprintf(buf, PAGE_SIZE, "%lu\n",
379 PAGES_TO_MiB(sbi->ll_ra_info.ra_max_pages_per_file));
382 static ssize_t max_read_ahead_per_file_mb_store(struct kobject *kobj,
383 struct attribute *attr,
387 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
389 u64 ra_max_file_mb, pages_number;
392 rc = sysfs_memparse(buffer, count, &ra_max_file_mb, "MiB");
396 pages_number = round_up(ra_max_file_mb, 1024 * 1024) >> PAGE_SHIFT;
397 if (pages_number > sbi->ll_ra_info.ra_max_pages) {
398 CERROR("%s: cannot set max_read_ahead_per_file_mb=%llu > max_read_ahead_mb=%lu\n",
399 sbi->ll_fsname, PAGES_TO_MiB(pages_number),
400 PAGES_TO_MiB(sbi->ll_ra_info.ra_max_pages));
404 spin_lock(&sbi->ll_lock);
405 sbi->ll_ra_info.ra_max_pages_per_file = pages_number;
406 spin_unlock(&sbi->ll_lock);
410 LUSTRE_RW_ATTR(max_read_ahead_per_file_mb);
412 static ssize_t max_read_ahead_whole_mb_show(struct kobject *kobj,
413 struct attribute *attr, char *buf)
415 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
418 return scnprintf(buf, PAGE_SIZE, "%lu\n",
419 PAGES_TO_MiB(sbi->ll_ra_info.ra_max_read_ahead_whole_pages));
422 static ssize_t max_read_ahead_whole_mb_store(struct kobject *kobj,
423 struct attribute *attr,
424 const char *buffer, size_t count)
426 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
428 u64 ra_max_whole_mb, pages_number;
431 rc = sysfs_memparse(buffer, count, &ra_max_whole_mb, "MiB");
435 pages_number = round_up(ra_max_whole_mb, 1024 * 1024) >> PAGE_SHIFT;
436 /* Cap this at the current max readahead window size, the readahead
437 * algorithm does this anyway so it's pointless to set it larger.
439 if (pages_number > sbi->ll_ra_info.ra_max_pages_per_file) {
440 CERROR("%s: cannot set max_read_ahead_whole_mb=%llu > max_read_ahead_per_file_mb=%lu\n",
441 sbi->ll_fsname, PAGES_TO_MiB(pages_number),
442 PAGES_TO_MiB(sbi->ll_ra_info.ra_max_pages_per_file));
447 spin_lock(&sbi->ll_lock);
448 sbi->ll_ra_info.ra_max_read_ahead_whole_pages = pages_number;
449 spin_unlock(&sbi->ll_lock);
453 LUSTRE_RW_ATTR(max_read_ahead_whole_mb);
455 static int ll_max_cached_mb_seq_show(struct seq_file *m, void *v)
457 struct super_block *sb = m->private;
458 struct ll_sb_info *sbi = ll_s2sbi(sb);
459 struct cl_client_cache *cache = sbi->ll_cache;
460 struct ll_ra_info *ra = &sbi->ll_ra_info;
464 mutex_lock(&cache->ccc_max_cache_mb_lock);
465 max_cached_mb = PAGES_TO_MiB(cache->ccc_lru_max);
466 unused_mb = PAGES_TO_MiB(atomic_long_read(&cache->ccc_lru_left));
467 mutex_unlock(&cache->ccc_max_cache_mb_lock);
469 seq_printf(m, "users: %d\n"
470 "max_cached_mb: %ld\n"
473 "reclaim_count: %u\n"
474 "max_read_ahead_mb: %lu\n"
475 "used_read_ahead_mb: %d\n",
476 atomic_read(&cache->ccc_users),
478 max_cached_mb - unused_mb,
480 cache->ccc_lru_shrinkers,
481 PAGES_TO_MiB(ra->ra_max_pages),
482 PAGES_TO_MiB(atomic_read(&ra->ra_cur_pages)));
486 static ssize_t ll_max_cached_mb_seq_write(struct file *file,
487 const char __user *buffer,
488 size_t count, loff_t *off)
490 struct seq_file *m = file->private_data;
491 struct super_block *sb = m->private;
492 struct ll_sb_info *sbi = ll_s2sbi(sb);
493 struct cl_client_cache *cache = sbi->ll_cache;
500 char kernbuf[128], *ptr;
503 if (count >= sizeof(kernbuf))
506 if (copy_from_user(kernbuf, buffer, count))
508 kernbuf[count] = '\0';
510 ptr = lprocfs_find_named_value(kernbuf, "max_cached_mb:", &count);
511 rc = sysfs_memparse(ptr, count, &pages_number, "MiB");
515 pages_number >>= PAGE_SHIFT;
517 if (pages_number < 0 || pages_number > cfs_totalram_pages()) {
518 CERROR("%s: can't set max cache more than %lu MB\n",
520 PAGES_TO_MiB(cfs_totalram_pages()));
523 /* Allow enough cache so clients can make well-formed RPCs */
524 pages_number = max_t(long, pages_number, PTLRPC_MAX_BRW_PAGES);
526 mutex_lock(&cache->ccc_max_cache_mb_lock);
527 diff = pages_number - cache->ccc_lru_max;
529 /* easy - add more LRU slots. */
531 atomic_long_add(diff, &cache->ccc_lru_left);
535 env = cl_env_get(&refcheck);
537 GOTO(out_unlock, rc = PTR_ERR(env));
543 /* reduce LRU budget from free slots. */
545 long lru_left_old, lru_left_new, lru_left_ret;
547 lru_left_old = atomic_long_read(&cache->ccc_lru_left);
548 if (lru_left_old == 0)
551 lru_left_new = lru_left_old > diff ?
552 lru_left_old - diff : 0;
554 atomic_long_cmpxchg(&cache->ccc_lru_left,
557 if (likely(lru_left_old == lru_left_ret)) {
558 diff -= lru_left_old - lru_left_new;
559 nrpages += lru_left_old - lru_left_new;
567 if (sbi->ll_dt_exp == NULL) { /* being initialized */
572 /* Request extra free slots to avoid them all being used
573 * by other processes before this can continue shrinking.
575 tmp = diff + min_t(long, diff, MiB_TO_PAGES(1024));
576 /* difficult - have to ask OSCs to drop LRU slots. */
577 rc = obd_set_info_async(env, sbi->ll_dt_exp,
578 sizeof(KEY_CACHE_LRU_SHRINK),
579 KEY_CACHE_LRU_SHRINK,
580 sizeof(tmp), &tmp, NULL);
584 cl_env_put(env, &refcheck);
588 cache->ccc_lru_max = pages_number;
591 atomic_long_add(nrpages, &cache->ccc_lru_left);
594 mutex_unlock(&cache->ccc_max_cache_mb_lock);
597 LDEBUGFS_SEQ_FOPS(ll_max_cached_mb);
599 static ssize_t checksums_show(struct kobject *kobj, struct attribute *attr,
602 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
605 return sprintf(buf, "%u\n", (sbi->ll_flags & LL_SBI_CHECKSUM) ? 1 : 0);
608 static ssize_t checksums_store(struct kobject *kobj, struct attribute *attr,
609 const char *buffer, size_t count)
611 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
621 rc = kstrtobool(buffer, &val);
625 sbi->ll_flags |= LL_SBI_CHECKSUM;
627 sbi->ll_flags &= ~LL_SBI_CHECKSUM;
630 rc = obd_set_info_async(NULL, sbi->ll_dt_exp, sizeof(KEY_CHECKSUM),
631 KEY_CHECKSUM, sizeof(tmp), &tmp, NULL);
633 CWARN("Failed to set OSC checksum flags: %d\n", rc);
637 LUSTRE_RW_ATTR(checksums);
639 LUSTRE_ATTR(checksum_pages, 0644, checksums_show, checksums_store);
641 static ssize_t ll_rd_track_id(struct kobject *kobj, char *buf,
642 enum stats_track_type type)
644 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
647 if (sbi->ll_stats_track_type == type)
648 return sprintf(buf, "%d\n", sbi->ll_stats_track_id);
649 else if (sbi->ll_stats_track_type == STATS_TRACK_ALL)
650 return sprintf(buf, "0 (all)\n");
652 return sprintf(buf, "untracked\n");
655 static ssize_t ll_wr_track_id(struct kobject *kobj, const char *buffer,
656 size_t count, enum stats_track_type type)
658 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
663 rc = kstrtoul(buffer, 10, &pid);
667 sbi->ll_stats_track_id = pid;
669 sbi->ll_stats_track_type = STATS_TRACK_ALL;
671 sbi->ll_stats_track_type = type;
672 lprocfs_clear_stats(sbi->ll_stats);
676 static ssize_t stats_track_pid_show(struct kobject *kobj,
677 struct attribute *attr,
680 return ll_rd_track_id(kobj, buf, STATS_TRACK_PID);
683 static ssize_t stats_track_pid_store(struct kobject *kobj,
684 struct attribute *attr,
688 return ll_wr_track_id(kobj, buffer, count, STATS_TRACK_PID);
690 LUSTRE_RW_ATTR(stats_track_pid);
692 static ssize_t stats_track_ppid_show(struct kobject *kobj,
693 struct attribute *attr,
696 return ll_rd_track_id(kobj, buf, STATS_TRACK_PPID);
699 static ssize_t stats_track_ppid_store(struct kobject *kobj,
700 struct attribute *attr,
704 return ll_wr_track_id(kobj, buffer, count, STATS_TRACK_PPID);
706 LUSTRE_RW_ATTR(stats_track_ppid);
708 static ssize_t stats_track_gid_show(struct kobject *kobj,
709 struct attribute *attr,
712 return ll_rd_track_id(kobj, buf, STATS_TRACK_GID);
715 static ssize_t stats_track_gid_store(struct kobject *kobj,
716 struct attribute *attr,
720 return ll_wr_track_id(kobj, buffer, count, STATS_TRACK_GID);
722 LUSTRE_RW_ATTR(stats_track_gid);
724 static ssize_t statahead_running_max_show(struct kobject *kobj,
725 struct attribute *attr,
728 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
731 return scnprintf(buf, PAGE_SIZE, "%u\n", sbi->ll_sa_running_max);
734 static ssize_t statahead_running_max_store(struct kobject *kobj,
735 struct attribute *attr,
739 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
744 rc = kstrtoul(buffer, 0, &val);
748 if (val <= LL_SA_RUNNING_MAX) {
749 sbi->ll_sa_running_max = val;
753 CERROR("Bad statahead_running_max value %lu. Valid values "
754 "are in the range [0, %d]\n", val, LL_SA_RUNNING_MAX);
758 LUSTRE_RW_ATTR(statahead_running_max);
760 static ssize_t statahead_max_show(struct kobject *kobj,
761 struct attribute *attr,
764 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
767 return sprintf(buf, "%u\n", sbi->ll_sa_max);
770 static ssize_t statahead_max_store(struct kobject *kobj,
771 struct attribute *attr,
775 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
780 rc = kstrtoul(buffer, 0, &val);
784 if (val <= LL_SA_RPC_MAX)
785 sbi->ll_sa_max = val;
787 CERROR("Bad statahead_max value %lu. Valid values are in the range [0, %d]\n",
792 LUSTRE_RW_ATTR(statahead_max);
794 static ssize_t statahead_agl_show(struct kobject *kobj,
795 struct attribute *attr,
798 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
801 return sprintf(buf, "%u\n", sbi->ll_flags & LL_SBI_AGL_ENABLED ? 1 : 0);
804 static ssize_t statahead_agl_store(struct kobject *kobj,
805 struct attribute *attr,
809 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
814 rc = kstrtobool(buffer, &val);
819 sbi->ll_flags |= LL_SBI_AGL_ENABLED;
821 sbi->ll_flags &= ~LL_SBI_AGL_ENABLED;
825 LUSTRE_RW_ATTR(statahead_agl);
827 static int ll_statahead_stats_seq_show(struct seq_file *m, void *v)
829 struct super_block *sb = m->private;
830 struct ll_sb_info *sbi = ll_s2sbi(sb);
832 seq_printf(m, "statahead total: %u\n"
833 "statahead wrong: %u\n"
835 atomic_read(&sbi->ll_sa_total),
836 atomic_read(&sbi->ll_sa_wrong),
837 atomic_read(&sbi->ll_agl_total));
841 LDEBUGFS_SEQ_FOPS_RO(ll_statahead_stats);
843 static ssize_t lazystatfs_show(struct kobject *kobj,
844 struct attribute *attr,
847 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
850 return sprintf(buf, "%u\n", (sbi->ll_flags & LL_SBI_LAZYSTATFS) ? 1 : 0);
853 static ssize_t lazystatfs_store(struct kobject *kobj,
854 struct attribute *attr,
858 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
863 rc = kstrtobool(buffer, &val);
868 sbi->ll_flags |= LL_SBI_LAZYSTATFS;
870 sbi->ll_flags &= ~LL_SBI_LAZYSTATFS;
874 LUSTRE_RW_ATTR(lazystatfs);
876 static ssize_t statfs_max_age_show(struct kobject *kobj, struct attribute *attr,
879 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
882 return scnprintf(buf, PAGE_SIZE, "%u\n", sbi->ll_statfs_max_age);
885 static ssize_t statfs_max_age_store(struct kobject *kobj,
886 struct attribute *attr, const char *buffer,
889 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
894 rc = kstrtouint(buffer, 10, &val);
897 if (val > OBD_STATFS_CACHE_MAX_AGE)
900 sbi->ll_statfs_max_age = val;
904 LUSTRE_RW_ATTR(statfs_max_age);
906 static ssize_t max_easize_show(struct kobject *kobj,
907 struct attribute *attr,
910 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
915 rc = ll_get_max_mdsize(sbi, &ealen);
919 /* Limit xattr size returned to userspace based on kernel maximum */
920 return scnprintf(buf, PAGE_SIZE, "%u\n",
921 ealen > XATTR_SIZE_MAX ? XATTR_SIZE_MAX : ealen);
923 LUSTRE_RO_ATTR(max_easize);
926 * Get default_easize.
928 * \see client_obd::cl_default_mds_easize
930 * \param[in] m seq_file handle
931 * \param[in] v unused for single entry
933 * \retval 0 on success
934 * \retval negative negated errno on failure
936 static ssize_t default_easize_show(struct kobject *kobj,
937 struct attribute *attr,
940 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
945 rc = ll_get_default_mdsize(sbi, &ealen);
949 /* Limit xattr size returned to userspace based on kernel maximum */
950 return scnprintf(buf, PAGE_SIZE, "%u\n",
951 ealen > XATTR_SIZE_MAX ? XATTR_SIZE_MAX : ealen);
955 * Set default_easize.
957 * Range checking on the passed value is handled by
958 * ll_set_default_mdsize().
960 * \see client_obd::cl_default_mds_easize
962 * \param[in] file proc file
963 * \param[in] buffer string passed from user space
964 * \param[in] count \a buffer length
965 * \param[in] off unused for single entry
967 * \retval positive \a count on success
968 * \retval negative negated errno on failure
970 static ssize_t default_easize_store(struct kobject *kobj,
971 struct attribute *attr,
975 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
983 rc = kstrtouint(buffer, 10, &val);
987 rc = ll_set_default_mdsize(sbi, val);
993 LUSTRE_RW_ATTR(default_easize);
995 static int ll_sbi_flags_seq_show(struct seq_file *m, void *v)
997 const char *const str[] = LL_SBI_FLAGS;
998 struct super_block *sb = m->private;
999 int flags = ll_s2sbi(sb)->ll_flags;
1002 while (flags != 0) {
1003 if (ARRAY_SIZE(str) <= i) {
1004 CERROR("%s: Revise array LL_SBI_FLAGS to match sbi "
1005 "flags please.\n", ll_s2sbi(sb)->ll_fsname);
1010 seq_printf(m, "%s ", str[i]);
1014 seq_printf(m, "\b\n");
1018 LDEBUGFS_SEQ_FOPS_RO(ll_sbi_flags);
1020 static ssize_t xattr_cache_show(struct kobject *kobj,
1021 struct attribute *attr,
1024 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
1027 return sprintf(buf, "%u\n", sbi->ll_xattr_cache_enabled);
1030 static ssize_t xattr_cache_store(struct kobject *kobj,
1031 struct attribute *attr,
1035 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
1040 rc = kstrtobool(buffer, &val);
1044 if (val && !(sbi->ll_flags & LL_SBI_XATTR_CACHE))
1047 sbi->ll_xattr_cache_enabled = val;
1048 sbi->ll_xattr_cache_set = 1;
1052 LUSTRE_RW_ATTR(xattr_cache);
1054 static ssize_t tiny_write_show(struct kobject *kobj,
1055 struct attribute *attr,
1058 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
1061 return sprintf(buf, "%u\n", !!(sbi->ll_flags & LL_SBI_TINY_WRITE));
1064 static ssize_t tiny_write_store(struct kobject *kobj,
1065 struct attribute *attr,
1069 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
1074 rc = kstrtobool(buffer, &val);
1078 spin_lock(&sbi->ll_lock);
1080 sbi->ll_flags |= LL_SBI_TINY_WRITE;
1082 sbi->ll_flags &= ~LL_SBI_TINY_WRITE;
1083 spin_unlock(&sbi->ll_lock);
1087 LUSTRE_RW_ATTR(tiny_write);
1089 static ssize_t max_read_ahead_async_active_show(struct kobject *kobj,
1090 struct attribute *attr,
1093 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
1096 return scnprintf(buf, PAGE_SIZE, "%u\n",
1097 sbi->ll_ra_info.ra_async_max_active);
1100 static ssize_t max_read_ahead_async_active_store(struct kobject *kobj,
1101 struct attribute *attr,
1105 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
1110 rc = kstrtouint(buffer, 10, &val);
1115 * It doesn't make any sense to make it exceed what
1116 * workqueue could acutally support. This can easily
1117 * over subscripe the cores but Lustre internally
1118 * throttles to avoid those impacts.
1120 if (val > WQ_UNBOUND_MAX_ACTIVE) {
1121 CERROR("%s: cannot set max_read_ahead_async_active=%u larger than %u\n",
1122 sbi->ll_fsname, val, WQ_UNBOUND_MAX_ACTIVE);
1126 spin_lock(&sbi->ll_lock);
1127 sbi->ll_ra_info.ra_async_max_active = val;
1128 spin_unlock(&sbi->ll_lock);
1132 LUSTRE_RW_ATTR(max_read_ahead_async_active);
1134 static ssize_t read_ahead_async_file_threshold_mb_show(struct kobject *kobj,
1135 struct attribute *attr,
1138 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
1141 return scnprintf(buf, PAGE_SIZE, "%lu\n", PAGES_TO_MiB(
1142 sbi->ll_ra_info.ra_async_pages_per_file_threshold));
1146 read_ahead_async_file_threshold_mb_store(struct kobject *kobj,
1147 struct attribute *attr,
1148 const char *buffer, size_t count)
1150 unsigned long pages_number;
1151 unsigned long max_ra_per_file;
1152 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
1156 rc = kstrtoul(buffer, 10, &pages_number);
1160 pages_number = MiB_TO_PAGES(pages_number);
1161 max_ra_per_file = sbi->ll_ra_info.ra_max_pages_per_file;
1162 if (pages_number < 0 || pages_number > max_ra_per_file) {
1163 CERROR("%s: can't set read_ahead_async_file_threshold_mb=%lu > "
1164 "max_read_readahead_per_file_mb=%lu\n", sbi->ll_fsname,
1165 PAGES_TO_MiB(pages_number),
1166 PAGES_TO_MiB(max_ra_per_file));
1169 sbi->ll_ra_info.ra_async_pages_per_file_threshold = pages_number;
1173 LUSTRE_RW_ATTR(read_ahead_async_file_threshold_mb);
1175 static ssize_t read_ahead_range_kb_show(struct kobject *kobj,
1176 struct attribute *attr,char *buf)
1178 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
1181 return snprintf(buf, PAGE_SIZE, "%lu\n",
1182 sbi->ll_ra_info.ra_range_pages << (PAGE_SHIFT - 10));
1186 read_ahead_range_kb_store(struct kobject *kobj,
1187 struct attribute *attr,
1188 const char *buffer, size_t count)
1190 unsigned long pages_number;
1191 unsigned long max_ra_per_file;
1193 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
1197 rc = sysfs_memparse(buffer, count, &val, "KiB");
1201 pages_number = val >> PAGE_SHIFT;
1202 /* Disable mmap range read */
1203 if (pages_number == 0)
1206 max_ra_per_file = sbi->ll_ra_info.ra_max_pages_per_file;
1207 if (pages_number > max_ra_per_file ||
1208 pages_number < RA_MIN_MMAP_RANGE_PAGES)
1212 spin_lock(&sbi->ll_lock);
1213 sbi->ll_ra_info.ra_range_pages = pages_number;
1214 spin_unlock(&sbi->ll_lock);
1218 LUSTRE_RW_ATTR(read_ahead_range_kb);
1220 static ssize_t fast_read_show(struct kobject *kobj,
1221 struct attribute *attr,
1224 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
1227 return sprintf(buf, "%u\n", !!(sbi->ll_flags & LL_SBI_FAST_READ));
1230 static ssize_t fast_read_store(struct kobject *kobj,
1231 struct attribute *attr,
1235 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
1240 rc = kstrtobool(buffer, &val);
1244 spin_lock(&sbi->ll_lock);
1246 sbi->ll_flags |= LL_SBI_FAST_READ;
1248 sbi->ll_flags &= ~LL_SBI_FAST_READ;
1249 spin_unlock(&sbi->ll_lock);
1253 LUSTRE_RW_ATTR(fast_read);
1255 static ssize_t file_heat_show(struct kobject *kobj,
1256 struct attribute *attr,
1259 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
1262 return scnprintf(buf, PAGE_SIZE, "%u\n",
1263 !!(sbi->ll_flags & LL_SBI_FILE_HEAT));
1266 static ssize_t file_heat_store(struct kobject *kobj,
1267 struct attribute *attr,
1271 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
1276 rc = kstrtobool(buffer, &val);
1280 spin_lock(&sbi->ll_lock);
1282 sbi->ll_flags |= LL_SBI_FILE_HEAT;
1284 sbi->ll_flags &= ~LL_SBI_FILE_HEAT;
1285 spin_unlock(&sbi->ll_lock);
1289 LUSTRE_RW_ATTR(file_heat);
1291 static ssize_t heat_decay_percentage_show(struct kobject *kobj,
1292 struct attribute *attr,
1295 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
1298 return scnprintf(buf, PAGE_SIZE, "%u\n",
1299 (sbi->ll_heat_decay_weight * 100 + 128) / 256);
1302 static ssize_t heat_decay_percentage_store(struct kobject *kobj,
1303 struct attribute *attr,
1307 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
1312 rc = kstrtoul(buffer, 10, &val);
1316 if (val < 0 || val > 100)
1319 sbi->ll_heat_decay_weight = (val * 256 + 50) / 100;
1323 LUSTRE_RW_ATTR(heat_decay_percentage);
1325 static ssize_t heat_period_second_show(struct kobject *kobj,
1326 struct attribute *attr,
1329 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
1332 return scnprintf(buf, PAGE_SIZE, "%u\n", sbi->ll_heat_period_second);
1335 static ssize_t heat_period_second_store(struct kobject *kobj,
1336 struct attribute *attr,
1340 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
1345 rc = kstrtoul(buffer, 10, &val);
1352 sbi->ll_heat_period_second = val;
1356 LUSTRE_RW_ATTR(heat_period_second);
1358 static int ll_unstable_stats_seq_show(struct seq_file *m, void *v)
1360 struct super_block *sb = m->private;
1361 struct ll_sb_info *sbi = ll_s2sbi(sb);
1362 struct cl_client_cache *cache = sbi->ll_cache;
1366 pages = atomic_long_read(&cache->ccc_unstable_nr);
1367 mb = (pages * PAGE_SIZE) >> 20;
1369 seq_printf(m, "unstable_check: %8d\n"
1370 "unstable_pages: %12ld\n"
1371 "unstable_mb: %8d\n",
1372 cache->ccc_unstable_check, pages, mb);
1376 static ssize_t ll_unstable_stats_seq_write(struct file *file,
1377 const char __user *buffer,
1378 size_t count, loff_t *unused)
1380 struct seq_file *seq = file->private_data;
1381 struct ll_sb_info *sbi = ll_s2sbi((struct super_block *)seq->private);
1388 if (count >= sizeof(kernbuf))
1391 if (copy_from_user(kernbuf, buffer, count))
1395 buffer += lprocfs_find_named_value(kernbuf, "unstable_check:", &count) -
1397 rc = kstrtobool_from_user(buffer, count, &val);
1401 /* borrow lru lock to set the value */
1402 spin_lock(&sbi->ll_cache->ccc_lru_lock);
1403 sbi->ll_cache->ccc_unstable_check = val;
1404 spin_unlock(&sbi->ll_cache->ccc_lru_lock);
1409 LDEBUGFS_SEQ_FOPS(ll_unstable_stats);
1411 static int ll_root_squash_seq_show(struct seq_file *m, void *v)
1413 struct super_block *sb = m->private;
1414 struct ll_sb_info *sbi = ll_s2sbi(sb);
1415 struct root_squash_info *squash = &sbi->ll_squash;
1417 seq_printf(m, "%u:%u\n", squash->rsi_uid, squash->rsi_gid);
1421 static ssize_t ll_root_squash_seq_write(struct file *file,
1422 const char __user *buffer,
1423 size_t count, loff_t *off)
1425 struct seq_file *m = file->private_data;
1426 struct super_block *sb = m->private;
1427 struct ll_sb_info *sbi = ll_s2sbi(sb);
1428 struct root_squash_info *squash = &sbi->ll_squash;
1430 return lprocfs_wr_root_squash(buffer, count, squash, sbi->ll_fsname);
1433 LDEBUGFS_SEQ_FOPS(ll_root_squash);
1435 static int ll_nosquash_nids_seq_show(struct seq_file *m, void *v)
1437 struct super_block *sb = m->private;
1438 struct ll_sb_info *sbi = ll_s2sbi(sb);
1439 struct root_squash_info *squash = &sbi->ll_squash;
1442 spin_lock(&squash->rsi_lock);
1443 if (!list_empty(&squash->rsi_nosquash_nids)) {
1444 len = cfs_print_nidlist(m->buf + m->count, m->size - m->count,
1445 &squash->rsi_nosquash_nids);
1449 seq_puts(m, "NONE\n");
1451 spin_unlock(&squash->rsi_lock);
1456 static ssize_t ll_nosquash_nids_seq_write(struct file *file,
1457 const char __user *buffer,
1458 size_t count, loff_t *off)
1460 struct seq_file *m = file->private_data;
1461 struct super_block *sb = m->private;
1462 struct ll_sb_info *sbi = ll_s2sbi(sb);
1463 struct root_squash_info *squash = &sbi->ll_squash;
1466 rc = lprocfs_wr_nosquash_nids(buffer, count, squash, sbi->ll_fsname);
1470 ll_compute_rootsquash_state(sbi);
1475 LDEBUGFS_SEQ_FOPS(ll_nosquash_nids);
1477 static int ll_pcc_seq_show(struct seq_file *m, void *v)
1479 struct super_block *sb = m->private;
1480 struct ll_sb_info *sbi = ll_s2sbi(sb);
1482 return pcc_super_dump(&sbi->ll_pcc_super, m);
1485 static ssize_t ll_pcc_seq_write(struct file *file, const char __user *buffer,
1486 size_t count, loff_t *off)
1488 struct seq_file *m = file->private_data;
1489 struct super_block *sb = m->private;
1490 struct ll_sb_info *sbi = ll_s2sbi(sb);
1494 if (count >= LPROCFS_WR_PCC_MAX_CMD)
1497 if (!(exp_connect_flags2(sbi->ll_md_exp) & OBD_CONNECT2_PCC))
1500 OBD_ALLOC(kernbuf, count + 1);
1501 if (kernbuf == NULL)
1504 if (copy_from_user(kernbuf, buffer, count))
1505 GOTO(out_free_kernbuff, rc = -EFAULT);
1507 rc = pcc_cmd_handle(kernbuf, count, &sbi->ll_pcc_super);
1509 OBD_FREE(kernbuf, count + 1);
1510 return rc ? rc : count;
1512 LDEBUGFS_SEQ_FOPS(ll_pcc);
1514 struct ldebugfs_vars lprocfs_llite_obd_vars[] = {
1516 .fops = &ll_site_stats_fops },
1517 { .name = "max_cached_mb",
1518 .fops = &ll_max_cached_mb_fops },
1519 { .name = "statahead_stats",
1520 .fops = &ll_statahead_stats_fops },
1521 { .name = "unstable_stats",
1522 .fops = &ll_unstable_stats_fops },
1523 { .name = "sbi_flags",
1524 .fops = &ll_sbi_flags_fops },
1525 { .name = "root_squash",
1526 .fops = &ll_root_squash_fops },
1527 { .name = "nosquash_nids",
1528 .fops = &ll_nosquash_nids_fops },
1530 .fops = &ll_pcc_fops, },
1534 #define MAX_STRING_SIZE 128
1536 static struct attribute *llite_attrs[] = {
1537 &lustre_attr_blocksize.attr,
1538 &lustre_attr_stat_blocksize.attr,
1539 &lustre_attr_kbytestotal.attr,
1540 &lustre_attr_kbytesfree.attr,
1541 &lustre_attr_kbytesavail.attr,
1542 &lustre_attr_filestotal.attr,
1543 &lustre_attr_filesfree.attr,
1544 &lustre_attr_client_type.attr,
1545 &lustre_attr_foreign_symlink_enable.attr,
1546 &lustre_attr_foreign_symlink_prefix.attr,
1547 &lustre_attr_foreign_symlink_upcall.attr,
1548 &lustre_attr_foreign_symlink_upcall_info.attr,
1549 &lustre_attr_fstype.attr,
1550 &lustre_attr_uuid.attr,
1551 &lustre_attr_checksums.attr,
1552 &lustre_attr_checksum_pages.attr,
1553 &lustre_attr_max_read_ahead_mb.attr,
1554 &lustre_attr_max_read_ahead_per_file_mb.attr,
1555 &lustre_attr_max_read_ahead_whole_mb.attr,
1556 &lustre_attr_max_read_ahead_async_active.attr,
1557 &lustre_attr_read_ahead_async_file_threshold_mb.attr,
1558 &lustre_attr_read_ahead_range_kb.attr,
1559 &lustre_attr_stats_track_pid.attr,
1560 &lustre_attr_stats_track_ppid.attr,
1561 &lustre_attr_stats_track_gid.attr,
1562 &lustre_attr_statahead_running_max.attr,
1563 &lustre_attr_statahead_max.attr,
1564 &lustre_attr_statahead_agl.attr,
1565 &lustre_attr_lazystatfs.attr,
1566 &lustre_attr_statfs_max_age.attr,
1567 &lustre_attr_max_easize.attr,
1568 &lustre_attr_default_easize.attr,
1569 &lustre_attr_xattr_cache.attr,
1570 &lustre_attr_fast_read.attr,
1571 &lustre_attr_tiny_write.attr,
1572 &lustre_attr_file_heat.attr,
1573 &lustre_attr_heat_decay_percentage.attr,
1574 &lustre_attr_heat_period_second.attr,
1578 static void sbi_kobj_release(struct kobject *kobj)
1580 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
1582 complete(&sbi->ll_kobj_unregister);
1585 static struct kobj_type sbi_ktype = {
1586 .default_attrs = llite_attrs,
1587 .sysfs_ops = &lustre_sysfs_ops,
1588 .release = sbi_kobj_release,
1591 static const struct llite_file_opcode {
1595 } llite_opcode_table[LPROC_LL_FILE_OPCODES] = {
1596 /* file operation */
1597 { LPROC_LL_READ_BYTES, LPROCFS_TYPE_BYTES_FULL, "read_bytes" },
1598 { LPROC_LL_WRITE_BYTES, LPROCFS_TYPE_BYTES_FULL, "write_bytes" },
1599 { LPROC_LL_READ, LPROCFS_TYPE_LATENCY, "read" },
1600 { LPROC_LL_WRITE, LPROCFS_TYPE_LATENCY, "write" },
1601 { LPROC_LL_IOCTL, LPROCFS_TYPE_REQS, "ioctl" },
1602 { LPROC_LL_OPEN, LPROCFS_TYPE_LATENCY, "open" },
1603 { LPROC_LL_RELEASE, LPROCFS_TYPE_LATENCY, "close" },
1604 { LPROC_LL_MMAP, LPROCFS_TYPE_LATENCY, "mmap" },
1605 { LPROC_LL_FAULT, LPROCFS_TYPE_LATENCY, "page_fault" },
1606 { LPROC_LL_MKWRITE, LPROCFS_TYPE_LATENCY, "page_mkwrite" },
1607 { LPROC_LL_LLSEEK, LPROCFS_TYPE_LATENCY, "seek" },
1608 { LPROC_LL_FSYNC, LPROCFS_TYPE_LATENCY, "fsync" },
1609 { LPROC_LL_READDIR, LPROCFS_TYPE_LATENCY, "readdir" },
1610 /* inode operation */
1611 { LPROC_LL_SETATTR, LPROCFS_TYPE_LATENCY, "setattr" },
1612 { LPROC_LL_TRUNC, LPROCFS_TYPE_LATENCY, "truncate" },
1613 { LPROC_LL_FLOCK, LPROCFS_TYPE_LATENCY, "flock" },
1614 { LPROC_LL_GETATTR, LPROCFS_TYPE_LATENCY, "getattr" },
1615 { LPROC_LL_FALLOCATE, LPROCFS_TYPE_LATENCY, "fallocate"},
1616 /* dir inode operation */
1617 { LPROC_LL_CREATE, LPROCFS_TYPE_LATENCY, "create" },
1618 { LPROC_LL_LINK, LPROCFS_TYPE_LATENCY, "link" },
1619 { LPROC_LL_UNLINK, LPROCFS_TYPE_LATENCY, "unlink" },
1620 { LPROC_LL_SYMLINK, LPROCFS_TYPE_LATENCY, "symlink" },
1621 { LPROC_LL_MKDIR, LPROCFS_TYPE_LATENCY, "mkdir" },
1622 { LPROC_LL_RMDIR, LPROCFS_TYPE_LATENCY, "rmdir" },
1623 { LPROC_LL_MKNOD, LPROCFS_TYPE_LATENCY, "mknod" },
1624 { LPROC_LL_RENAME, LPROCFS_TYPE_LATENCY, "rename" },
1625 /* special inode operation */
1626 { LPROC_LL_STATFS, LPROCFS_TYPE_LATENCY, "statfs" },
1627 { LPROC_LL_SETXATTR, LPROCFS_TYPE_LATENCY, "setxattr" },
1628 { LPROC_LL_GETXATTR, LPROCFS_TYPE_LATENCY, "getxattr" },
1629 { LPROC_LL_GETXATTR_HITS, LPROCFS_TYPE_REQS, "getxattr_hits" },
1630 { LPROC_LL_LISTXATTR, LPROCFS_TYPE_LATENCY, "listxattr" },
1631 { LPROC_LL_REMOVEXATTR, LPROCFS_TYPE_LATENCY, "removexattr" },
1632 { LPROC_LL_INODE_PERM, LPROCFS_TYPE_LATENCY, "inode_permission" },
1635 void ll_stats_ops_tally(struct ll_sb_info *sbi, int op, long count)
1640 if (sbi->ll_stats_track_type == STATS_TRACK_ALL)
1641 lprocfs_counter_add(sbi->ll_stats, op, count);
1642 else if (sbi->ll_stats_track_type == STATS_TRACK_PID &&
1643 sbi->ll_stats_track_id == current->pid)
1644 lprocfs_counter_add(sbi->ll_stats, op, count);
1645 else if (sbi->ll_stats_track_type == STATS_TRACK_PPID &&
1646 sbi->ll_stats_track_id == current->parent->pid)
1647 lprocfs_counter_add(sbi->ll_stats, op, count);
1648 else if (sbi->ll_stats_track_type == STATS_TRACK_GID &&
1649 sbi->ll_stats_track_id ==
1650 from_kgid(&init_user_ns, current_gid()))
1651 lprocfs_counter_add(sbi->ll_stats, op, count);
1653 EXPORT_SYMBOL(ll_stats_ops_tally);
1655 static const char *const ra_stat_string[] = {
1656 [RA_STAT_HIT] = "hits",
1657 [RA_STAT_MISS] = "misses",
1658 [RA_STAT_DISTANT_READPAGE] = "readpage_not_consecutive",
1659 [RA_STAT_MISS_IN_WINDOW] = "miss_inside_window",
1660 [RA_STAT_FAILED_GRAB_PAGE] = "failed_grab_cache_page",
1661 [RA_STAT_FAILED_MATCH] = "failed_lock_match",
1662 [RA_STAT_DISCARDED] = "read_but_discarded",
1663 [RA_STAT_ZERO_LEN] = "zero_length_file",
1664 [RA_STAT_ZERO_WINDOW] = "zero_size_window",
1665 [RA_STAT_EOF] = "readahead_to_eof",
1666 [RA_STAT_MAX_IN_FLIGHT] = "hit_max_readahead_issue",
1667 [RA_STAT_WRONG_GRAB_PAGE] = "wrong_page_from_grab_cache_page",
1668 [RA_STAT_FAILED_REACH_END] = "failed_to_reach_end",
1669 [RA_STAT_ASYNC] = "async_readahead",
1670 [RA_STAT_FAILED_FAST_READ] = "failed_to_fast_read",
1671 [RA_STAT_MMAP_RANGE_READ] = "mmap_range_read",
1674 int ll_debugfs_register_super(struct super_block *sb, const char *name)
1676 struct lustre_sb_info *lsi = s2lsi(sb);
1677 struct ll_sb_info *sbi = ll_s2sbi(sb);
1683 if (IS_ERR_OR_NULL(llite_root))
1686 sbi->ll_debugfs_entry = debugfs_create_dir(name, llite_root);
1687 ldebugfs_add_vars(sbi->ll_debugfs_entry, lprocfs_llite_obd_vars, sb);
1689 debugfs_create_file("dump_page_cache", 0444, sbi->ll_debugfs_entry, sbi,
1690 &vvp_dump_pgcache_file_ops);
1692 debugfs_create_file("extents_stats", 0644, sbi->ll_debugfs_entry, sbi,
1693 &ll_rw_extents_stats_fops);
1695 debugfs_create_file("extents_stats_per_process", 0644,
1696 sbi->ll_debugfs_entry, sbi,
1697 &ll_rw_extents_stats_pp_fops);
1699 debugfs_create_file("offset_stats", 0644, sbi->ll_debugfs_entry, sbi,
1700 &ll_rw_offset_stats_fops);
1702 /* File operations stats */
1703 sbi->ll_stats = lprocfs_alloc_stats(LPROC_LL_FILE_OPCODES,
1704 LPROCFS_STATS_FLAG_NONE);
1705 if (sbi->ll_stats == NULL)
1706 GOTO(out_debugfs, err = -ENOMEM);
1708 /* do counter init */
1709 for (id = 0; id < LPROC_LL_FILE_OPCODES; id++) {
1710 u32 type = llite_opcode_table[id].type;
1711 void *ptr = "unknown";
1713 if (type & LPROCFS_TYPE_REQS)
1715 else if (type & LPROCFS_TYPE_BYTES)
1717 else if (type & LPROCFS_TYPE_USEC)
1719 lprocfs_counter_init(sbi->ll_stats,
1720 llite_opcode_table[id].opcode, type,
1721 llite_opcode_table[id].opname, ptr);
1724 debugfs_create_file("stats", 0644, sbi->ll_debugfs_entry,
1725 sbi->ll_stats, &ldebugfs_stats_seq_fops);
1727 sbi->ll_ra_stats = lprocfs_alloc_stats(ARRAY_SIZE(ra_stat_string),
1728 LPROCFS_STATS_FLAG_NONE);
1729 if (sbi->ll_ra_stats == NULL)
1730 GOTO(out_stats, err = -ENOMEM);
1732 for (id = 0; id < ARRAY_SIZE(ra_stat_string); id++)
1733 lprocfs_counter_init(sbi->ll_ra_stats, id, 0,
1734 ra_stat_string[id], "pages");
1736 debugfs_create_file("read_ahead_stats", 0644, sbi->ll_debugfs_entry,
1737 sbi->ll_ra_stats, &ldebugfs_stats_seq_fops);
1740 /* Yes we also register sysfs mount kset here as well */
1741 sbi->ll_kset.kobj.parent = llite_kobj;
1742 sbi->ll_kset.kobj.ktype = &sbi_ktype;
1743 init_completion(&sbi->ll_kobj_unregister);
1744 err = kobject_set_name(&sbi->ll_kset.kobj, "%s", name);
1746 GOTO(out_ra_stats, err);
1748 err = kset_register(&sbi->ll_kset);
1750 GOTO(out_ra_stats, err);
1752 lsi->lsi_kobj = kobject_get(&sbi->ll_kset.kobj);
1756 lprocfs_free_stats(&sbi->ll_ra_stats);
1758 lprocfs_free_stats(&sbi->ll_stats);
1760 debugfs_remove_recursive(sbi->ll_debugfs_entry);
1765 void ll_debugfs_unregister_super(struct super_block *sb)
1767 struct lustre_sb_info *lsi = s2lsi(sb);
1768 struct ll_sb_info *sbi = ll_s2sbi(sb);
1770 debugfs_remove_recursive(sbi->ll_debugfs_entry);
1773 sysfs_remove_link(&sbi->ll_kset.kobj,
1774 sbi->ll_dt_obd->obd_type->typ_name);
1777 sysfs_remove_link(&sbi->ll_kset.kobj,
1778 sbi->ll_md_obd->obd_type->typ_name);
1780 kobject_put(lsi->lsi_kobj);
1782 kset_unregister(&sbi->ll_kset);
1783 wait_for_completion(&sbi->ll_kobj_unregister);
1785 lprocfs_free_stats(&sbi->ll_ra_stats);
1786 lprocfs_free_stats(&sbi->ll_stats);
1788 #undef MAX_STRING_SIZE
1790 static void ll_display_extents_info(struct ll_rw_extents_info *io_extents,
1791 struct seq_file *seq, int which)
1793 unsigned long read_tot = 0, write_tot = 0, read_cum, write_cum;
1794 unsigned long start, end, r, w;
1795 char *unitp = "KMGTPEZY";
1797 struct per_process_info *pp_info = &io_extents->pp_extents[which];
1803 for(i = 0; i < LL_HIST_MAX; i++) {
1804 read_tot += pp_info->pp_r_hist.oh_buckets[i];
1805 write_tot += pp_info->pp_w_hist.oh_buckets[i];
1808 for(i = 0; i < LL_HIST_MAX; i++) {
1809 r = pp_info->pp_r_hist.oh_buckets[i];
1810 w = pp_info->pp_w_hist.oh_buckets[i];
1813 end = 1 << (i + LL_HIST_START - units);
1814 seq_printf(seq, "%4lu%c - %4lu%c%c: %14lu %4u %4u | "
1815 "%14lu %4u %4u\n", start, *unitp, end, *unitp,
1816 (i == LL_HIST_MAX - 1) ? '+' : ' ',
1817 r, pct(r, read_tot), pct(read_cum, read_tot),
1818 w, pct(w, write_tot), pct(write_cum, write_tot));
1820 if (start == (1 << 10)) {
1825 if (read_cum == read_tot && write_cum == write_tot)
1830 static int ll_rw_extents_stats_pp_seq_show(struct seq_file *seq, void *v)
1832 struct timespec64 now;
1833 struct ll_sb_info *sbi = seq->private;
1834 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1837 ktime_get_real_ts64(&now);
1839 if (!sbi->ll_rw_stats_on) {
1840 seq_puts(seq, "disabled\n write anything to this file to activate, then '0' or 'disable' to deactivate\n");
1843 seq_printf(seq, "snapshot_time: %llu.%09lu (secs.nsecs)\n",
1844 (s64)now.tv_sec, now.tv_nsec);
1845 seq_printf(seq, "%15s %19s | %20s\n", " ", "read", "write");
1846 seq_printf(seq, "%13s %14s %4s %4s | %14s %4s %4s\n",
1847 "extents", "calls", "%", "cum%",
1848 "calls", "%", "cum%");
1849 spin_lock(&sbi->ll_pp_extent_lock);
1850 for (k = 0; k < LL_PROCESS_HIST_MAX; k++) {
1851 if (io_extents->pp_extents[k].pid != 0) {
1852 seq_printf(seq, "\nPID: %d\n",
1853 io_extents->pp_extents[k].pid);
1854 ll_display_extents_info(io_extents, seq, k);
1857 spin_unlock(&sbi->ll_pp_extent_lock);
1861 static ssize_t ll_rw_extents_stats_pp_seq_write(struct file *file,
1862 const char __user *buf,
1866 struct seq_file *seq = file->private_data;
1867 struct ll_sb_info *sbi = seq->private;
1868 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1875 value = ll_stats_pid_write(buf, len);
1878 sbi->ll_rw_stats_on = 0;
1880 sbi->ll_rw_stats_on = 1;
1882 spin_lock(&sbi->ll_pp_extent_lock);
1883 for (i = 0; i < LL_PROCESS_HIST_MAX; i++) {
1884 io_extents->pp_extents[i].pid = 0;
1885 lprocfs_oh_clear(&io_extents->pp_extents[i].pp_r_hist);
1886 lprocfs_oh_clear(&io_extents->pp_extents[i].pp_w_hist);
1888 spin_unlock(&sbi->ll_pp_extent_lock);
1892 LDEBUGFS_SEQ_FOPS(ll_rw_extents_stats_pp);
1894 static int ll_rw_extents_stats_seq_show(struct seq_file *seq, void *v)
1896 struct timespec64 now;
1897 struct ll_sb_info *sbi = seq->private;
1898 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1900 ktime_get_real_ts64(&now);
1902 if (!sbi->ll_rw_stats_on) {
1903 seq_puts(seq, "disabled\n write anything to this file to activate, then '0' or 'disable' to deactivate\n");
1906 seq_printf(seq, "snapshot_time: %llu.%09lu (secs.nsecs)\n",
1907 (s64)now.tv_sec, now.tv_nsec);
1909 seq_printf(seq, "%15s %19s | %20s\n", " ", "read", "write");
1910 seq_printf(seq, "%13s %14s %4s %4s | %14s %4s %4s\n",
1911 "extents", "calls", "%", "cum%",
1912 "calls", "%", "cum%");
1913 spin_lock(&sbi->ll_lock);
1914 ll_display_extents_info(io_extents, seq, LL_PROCESS_HIST_MAX);
1915 spin_unlock(&sbi->ll_lock);
1920 static ssize_t ll_rw_extents_stats_seq_write(struct file *file,
1921 const char __user *buf,
1922 size_t len, loff_t *off)
1924 struct seq_file *seq = file->private_data;
1925 struct ll_sb_info *sbi = seq->private;
1926 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1933 value = ll_stats_pid_write(buf, len);
1936 sbi->ll_rw_stats_on = 0;
1938 sbi->ll_rw_stats_on = 1;
1940 spin_lock(&sbi->ll_pp_extent_lock);
1941 for (i = 0; i <= LL_PROCESS_HIST_MAX; i++) {
1942 io_extents->pp_extents[i].pid = 0;
1943 lprocfs_oh_clear(&io_extents->pp_extents[i].pp_r_hist);
1944 lprocfs_oh_clear(&io_extents->pp_extents[i].pp_w_hist);
1946 spin_unlock(&sbi->ll_pp_extent_lock);
1951 LDEBUGFS_SEQ_FOPS(ll_rw_extents_stats);
1953 void ll_rw_stats_tally(struct ll_sb_info *sbi, pid_t pid,
1954 struct ll_file_data *file, loff_t pos,
1955 size_t count, int rw)
1958 struct ll_rw_process_info *process;
1959 struct ll_rw_process_info *offset;
1960 int *off_count = &sbi->ll_rw_offset_entry_count;
1961 int *process_count = &sbi->ll_offset_process_count;
1962 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1964 if(!sbi->ll_rw_stats_on)
1966 process = sbi->ll_rw_process_info;
1967 offset = sbi->ll_rw_offset_info;
1969 spin_lock(&sbi->ll_pp_extent_lock);
1970 /* Extent statistics */
1971 for(i = 0; i < LL_PROCESS_HIST_MAX; i++) {
1972 if(io_extents->pp_extents[i].pid == pid) {
1980 sbi->ll_extent_process_count =
1981 (sbi->ll_extent_process_count + 1) % LL_PROCESS_HIST_MAX;
1982 cur = sbi->ll_extent_process_count;
1983 io_extents->pp_extents[cur].pid = pid;
1984 lprocfs_oh_clear(&io_extents->pp_extents[cur].pp_r_hist);
1985 lprocfs_oh_clear(&io_extents->pp_extents[cur].pp_w_hist);
1988 for (i = 0; (count >= 1 << (LL_HIST_START + i)) &&
1989 (i < (LL_HIST_MAX - 1)); i++);
1991 io_extents->pp_extents[cur].pp_r_hist.oh_buckets[i]++;
1992 io_extents->pp_extents[LL_PROCESS_HIST_MAX].pp_r_hist.oh_buckets[i]++;
1994 io_extents->pp_extents[cur].pp_w_hist.oh_buckets[i]++;
1995 io_extents->pp_extents[LL_PROCESS_HIST_MAX].pp_w_hist.oh_buckets[i]++;
1997 spin_unlock(&sbi->ll_pp_extent_lock);
1999 spin_lock(&sbi->ll_process_lock);
2000 /* Offset statistics */
2001 for (i = 0; i < LL_PROCESS_HIST_MAX; i++) {
2002 if (process[i].rw_pid == pid) {
2003 if (process[i].rw_last_file != file) {
2004 process[i].rw_range_start = pos;
2005 process[i].rw_last_file_pos = pos + count;
2006 process[i].rw_smallest_extent = count;
2007 process[i].rw_largest_extent = count;
2008 process[i].rw_offset = 0;
2009 process[i].rw_last_file = file;
2010 spin_unlock(&sbi->ll_process_lock);
2013 if (process[i].rw_last_file_pos != pos) {
2015 (*off_count + 1) % LL_OFFSET_HIST_MAX;
2016 offset[*off_count].rw_op = process[i].rw_op;
2017 offset[*off_count].rw_pid = pid;
2018 offset[*off_count].rw_range_start =
2019 process[i].rw_range_start;
2020 offset[*off_count].rw_range_end =
2021 process[i].rw_last_file_pos;
2022 offset[*off_count].rw_smallest_extent =
2023 process[i].rw_smallest_extent;
2024 offset[*off_count].rw_largest_extent =
2025 process[i].rw_largest_extent;
2026 offset[*off_count].rw_offset =
2027 process[i].rw_offset;
2028 process[i].rw_op = rw;
2029 process[i].rw_range_start = pos;
2030 process[i].rw_smallest_extent = count;
2031 process[i].rw_largest_extent = count;
2032 process[i].rw_offset = pos -
2033 process[i].rw_last_file_pos;
2035 if(process[i].rw_smallest_extent > count)
2036 process[i].rw_smallest_extent = count;
2037 if(process[i].rw_largest_extent < count)
2038 process[i].rw_largest_extent = count;
2039 process[i].rw_last_file_pos = pos + count;
2040 spin_unlock(&sbi->ll_process_lock);
2044 *process_count = (*process_count + 1) % LL_PROCESS_HIST_MAX;
2045 process[*process_count].rw_pid = pid;
2046 process[*process_count].rw_op = rw;
2047 process[*process_count].rw_range_start = pos;
2048 process[*process_count].rw_last_file_pos = pos + count;
2049 process[*process_count].rw_smallest_extent = count;
2050 process[*process_count].rw_largest_extent = count;
2051 process[*process_count].rw_offset = 0;
2052 process[*process_count].rw_last_file = file;
2053 spin_unlock(&sbi->ll_process_lock);
2056 static int ll_rw_offset_stats_seq_show(struct seq_file *seq, void *v)
2058 struct timespec64 now;
2059 struct ll_sb_info *sbi = seq->private;
2060 struct ll_rw_process_info *offset = sbi->ll_rw_offset_info;
2061 struct ll_rw_process_info *process = sbi->ll_rw_process_info;
2064 ktime_get_real_ts64(&now);
2066 if (!sbi->ll_rw_stats_on) {
2067 seq_puts(seq, "disabled\n write anything to this file to activate, then '0' or 'disable' to deactivate\n");
2070 spin_lock(&sbi->ll_process_lock);
2072 seq_printf(seq, "snapshot_time: %llu.%09lu (secs.nsecs)\n",
2073 (s64)now.tv_sec, now.tv_nsec);
2074 seq_printf(seq, "%3s %10s %14s %14s %17s %17s %14s\n",
2075 "R/W", "PID", "RANGE START", "RANGE END",
2076 "SMALLEST EXTENT", "LARGEST EXTENT", "OFFSET");
2078 /* We stored the discontiguous offsets here; print them first */
2079 for (i = 0; i < LL_OFFSET_HIST_MAX; i++) {
2080 if (offset[i].rw_pid != 0)
2082 "%3c %10d %14llu %14llu %17lu %17lu %14lld\n",
2083 offset[i].rw_op == READ ? 'R' : 'W',
2085 offset[i].rw_range_start,
2086 offset[i].rw_range_end,
2087 (unsigned long)offset[i].rw_smallest_extent,
2088 (unsigned long)offset[i].rw_largest_extent,
2089 offset[i].rw_offset);
2092 /* Then print the current offsets for each process */
2093 for (i = 0; i < LL_PROCESS_HIST_MAX; i++) {
2094 if (process[i].rw_pid != 0)
2096 "%3c %10d %14llu %14llu %17lu %17lu %14lld\n",
2097 process[i].rw_op == READ ? 'R' : 'W',
2099 process[i].rw_range_start,
2100 process[i].rw_last_file_pos,
2101 (unsigned long)process[i].rw_smallest_extent,
2102 (unsigned long)process[i].rw_largest_extent,
2103 process[i].rw_offset);
2105 spin_unlock(&sbi->ll_process_lock);
2110 static ssize_t ll_rw_offset_stats_seq_write(struct file *file,
2111 const char __user *buf,
2112 size_t len, loff_t *off)
2114 struct seq_file *seq = file->private_data;
2115 struct ll_sb_info *sbi = seq->private;
2116 struct ll_rw_process_info *process_info = sbi->ll_rw_process_info;
2117 struct ll_rw_process_info *offset_info = sbi->ll_rw_offset_info;
2123 value = ll_stats_pid_write(buf, len);
2126 sbi->ll_rw_stats_on = 0;
2128 sbi->ll_rw_stats_on = 1;
2130 spin_lock(&sbi->ll_process_lock);
2131 sbi->ll_offset_process_count = 0;
2132 sbi->ll_rw_offset_entry_count = 0;
2133 memset(process_info, 0, sizeof(struct ll_rw_process_info) *
2134 LL_PROCESS_HIST_MAX);
2135 memset(offset_info, 0, sizeof(struct ll_rw_process_info) *
2136 LL_OFFSET_HIST_MAX);
2137 spin_unlock(&sbi->ll_process_lock);
2142 LDEBUGFS_SEQ_FOPS(ll_rw_offset_stats);