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 scnprintf(buf, PAGE_SIZE, "%u\n",
606 test_bit(LL_SBI_CHECKSUM, sbi->ll_flags));
609 static ssize_t checksums_store(struct kobject *kobj, struct attribute *attr,
610 const char *buffer, size_t count)
612 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
622 rc = kstrtobool(buffer, &val);
626 set_bit(LL_SBI_CHECKSUM, sbi->ll_flags);
628 clear_bit(LL_SBI_CHECKSUM, sbi->ll_flags);
631 rc = obd_set_info_async(NULL, sbi->ll_dt_exp, sizeof(KEY_CHECKSUM),
632 KEY_CHECKSUM, sizeof(tmp), &tmp, NULL);
634 CWARN("Failed to set OSC checksum flags: %d\n", rc);
638 LUSTRE_RW_ATTR(checksums);
640 LUSTRE_ATTR(checksum_pages, 0644, checksums_show, checksums_store);
642 static ssize_t ll_rd_track_id(struct kobject *kobj, char *buf,
643 enum stats_track_type type)
645 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
648 if (sbi->ll_stats_track_type == type)
649 return sprintf(buf, "%d\n", sbi->ll_stats_track_id);
650 else if (sbi->ll_stats_track_type == STATS_TRACK_ALL)
651 return sprintf(buf, "0 (all)\n");
653 return sprintf(buf, "untracked\n");
656 static ssize_t ll_wr_track_id(struct kobject *kobj, const char *buffer,
657 size_t count, enum stats_track_type type)
659 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
664 rc = kstrtoul(buffer, 10, &pid);
668 sbi->ll_stats_track_id = pid;
670 sbi->ll_stats_track_type = STATS_TRACK_ALL;
672 sbi->ll_stats_track_type = type;
673 lprocfs_clear_stats(sbi->ll_stats);
677 static ssize_t stats_track_pid_show(struct kobject *kobj,
678 struct attribute *attr,
681 return ll_rd_track_id(kobj, buf, STATS_TRACK_PID);
684 static ssize_t stats_track_pid_store(struct kobject *kobj,
685 struct attribute *attr,
689 return ll_wr_track_id(kobj, buffer, count, STATS_TRACK_PID);
691 LUSTRE_RW_ATTR(stats_track_pid);
693 static ssize_t stats_track_ppid_show(struct kobject *kobj,
694 struct attribute *attr,
697 return ll_rd_track_id(kobj, buf, STATS_TRACK_PPID);
700 static ssize_t stats_track_ppid_store(struct kobject *kobj,
701 struct attribute *attr,
705 return ll_wr_track_id(kobj, buffer, count, STATS_TRACK_PPID);
707 LUSTRE_RW_ATTR(stats_track_ppid);
709 static ssize_t stats_track_gid_show(struct kobject *kobj,
710 struct attribute *attr,
713 return ll_rd_track_id(kobj, buf, STATS_TRACK_GID);
716 static ssize_t stats_track_gid_store(struct kobject *kobj,
717 struct attribute *attr,
721 return ll_wr_track_id(kobj, buffer, count, STATS_TRACK_GID);
723 LUSTRE_RW_ATTR(stats_track_gid);
725 static ssize_t statahead_running_max_show(struct kobject *kobj,
726 struct attribute *attr,
729 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
732 return scnprintf(buf, PAGE_SIZE, "%u\n", sbi->ll_sa_running_max);
735 static ssize_t statahead_running_max_store(struct kobject *kobj,
736 struct attribute *attr,
740 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
745 rc = kstrtoul(buffer, 0, &val);
749 if (val <= LL_SA_RUNNING_MAX) {
750 sbi->ll_sa_running_max = val;
754 CERROR("Bad statahead_running_max value %lu. Valid values "
755 "are in the range [0, %d]\n", val, LL_SA_RUNNING_MAX);
759 LUSTRE_RW_ATTR(statahead_running_max);
761 static ssize_t statahead_max_show(struct kobject *kobj,
762 struct attribute *attr,
765 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
768 return sprintf(buf, "%u\n", sbi->ll_sa_max);
771 static ssize_t statahead_max_store(struct kobject *kobj,
772 struct attribute *attr,
776 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
781 rc = kstrtoul(buffer, 0, &val);
785 if (val <= LL_SA_RPC_MAX)
786 sbi->ll_sa_max = val;
788 CERROR("Bad statahead_max value %lu. Valid values are in the range [0, %d]\n",
793 LUSTRE_RW_ATTR(statahead_max);
795 static ssize_t statahead_agl_show(struct kobject *kobj,
796 struct attribute *attr,
799 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
802 return scnprintf(buf, PAGE_SIZE, "%u\n",
803 test_bit(LL_SBI_AGL_ENABLED, sbi->ll_flags));
806 static ssize_t statahead_agl_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 set_bit(LL_SBI_AGL_ENABLED, sbi->ll_flags);
823 clear_bit(LL_SBI_AGL_ENABLED, sbi->ll_flags);
827 LUSTRE_RW_ATTR(statahead_agl);
829 static int ll_statahead_stats_seq_show(struct seq_file *m, void *v)
831 struct super_block *sb = m->private;
832 struct ll_sb_info *sbi = ll_s2sbi(sb);
834 seq_printf(m, "statahead total: %u\n"
835 "statahead wrong: %u\n"
837 atomic_read(&sbi->ll_sa_total),
838 atomic_read(&sbi->ll_sa_wrong),
839 atomic_read(&sbi->ll_agl_total));
843 LDEBUGFS_SEQ_FOPS_RO(ll_statahead_stats);
845 static ssize_t lazystatfs_show(struct kobject *kobj,
846 struct attribute *attr,
849 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
852 return scnprintf(buf, PAGE_SIZE, "%u\n",
853 test_bit(LL_SBI_LAZYSTATFS, sbi->ll_flags));
856 static ssize_t lazystatfs_store(struct kobject *kobj,
857 struct attribute *attr,
861 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
866 rc = kstrtobool(buffer, &val);
871 set_bit(LL_SBI_LAZYSTATFS, sbi->ll_flags);
873 clear_bit(LL_SBI_LAZYSTATFS, sbi->ll_flags);
877 LUSTRE_RW_ATTR(lazystatfs);
879 static ssize_t statfs_max_age_show(struct kobject *kobj, struct attribute *attr,
882 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
885 return scnprintf(buf, PAGE_SIZE, "%u\n", sbi->ll_statfs_max_age);
888 static ssize_t statfs_max_age_store(struct kobject *kobj,
889 struct attribute *attr, const char *buffer,
892 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
897 rc = kstrtouint(buffer, 10, &val);
900 if (val > OBD_STATFS_CACHE_MAX_AGE)
903 sbi->ll_statfs_max_age = val;
907 LUSTRE_RW_ATTR(statfs_max_age);
909 static ssize_t max_easize_show(struct kobject *kobj,
910 struct attribute *attr,
913 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
918 rc = ll_get_max_mdsize(sbi, &ealen);
922 /* Limit xattr size returned to userspace based on kernel maximum */
923 return scnprintf(buf, PAGE_SIZE, "%u\n",
924 ealen > XATTR_SIZE_MAX ? XATTR_SIZE_MAX : ealen);
926 LUSTRE_RO_ATTR(max_easize);
929 * Get default_easize.
931 * \see client_obd::cl_default_mds_easize
933 * \param[in] m seq_file handle
934 * \param[in] v unused for single entry
936 * \retval 0 on success
937 * \retval negative negated errno on failure
939 static ssize_t default_easize_show(struct kobject *kobj,
940 struct attribute *attr,
943 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
948 rc = ll_get_default_mdsize(sbi, &ealen);
952 /* Limit xattr size returned to userspace based on kernel maximum */
953 return scnprintf(buf, PAGE_SIZE, "%u\n",
954 ealen > XATTR_SIZE_MAX ? XATTR_SIZE_MAX : ealen);
958 * Set default_easize.
960 * Range checking on the passed value is handled by
961 * ll_set_default_mdsize().
963 * \see client_obd::cl_default_mds_easize
965 * \param[in] file proc file
966 * \param[in] buffer string passed from user space
967 * \param[in] count \a buffer length
968 * \param[in] off unused for single entry
970 * \retval positive \a count on success
971 * \retval negative negated errno on failure
973 static ssize_t default_easize_store(struct kobject *kobj,
974 struct attribute *attr,
978 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
986 rc = kstrtouint(buffer, 10, &val);
990 rc = ll_set_default_mdsize(sbi, val);
996 LUSTRE_RW_ATTR(default_easize);
998 LDEBUGFS_SEQ_FOPS_RO(ll_sbi_flags);
1000 static ssize_t xattr_cache_show(struct kobject *kobj,
1001 struct attribute *attr,
1004 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
1007 return sprintf(buf, "%u\n", sbi->ll_xattr_cache_enabled);
1010 static ssize_t xattr_cache_store(struct kobject *kobj,
1011 struct attribute *attr,
1015 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
1020 rc = kstrtobool(buffer, &val);
1024 if (val && !test_bit(LL_SBI_XATTR_CACHE, sbi->ll_flags))
1027 sbi->ll_xattr_cache_enabled = val;
1028 sbi->ll_xattr_cache_set = 1;
1032 LUSTRE_RW_ATTR(xattr_cache);
1034 static ssize_t tiny_write_show(struct kobject *kobj,
1035 struct attribute *attr,
1038 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
1041 return scnprintf(buf, PAGE_SIZE, "%u\n",
1042 test_bit(LL_SBI_TINY_WRITE, sbi->ll_flags));
1045 static ssize_t tiny_write_store(struct kobject *kobj,
1046 struct attribute *attr,
1050 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
1055 rc = kstrtobool(buffer, &val);
1059 spin_lock(&sbi->ll_lock);
1061 set_bit(LL_SBI_TINY_WRITE, sbi->ll_flags);
1063 clear_bit(LL_SBI_TINY_WRITE, sbi->ll_flags);
1064 spin_unlock(&sbi->ll_lock);
1068 LUSTRE_RW_ATTR(tiny_write);
1070 static ssize_t parallel_dio_show(struct kobject *kobj,
1071 struct attribute *attr,
1074 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
1077 return snprintf(buf, PAGE_SIZE, "%u\n",
1078 test_bit(LL_SBI_PARALLEL_DIO, sbi->ll_flags));
1081 static ssize_t parallel_dio_store(struct kobject *kobj,
1082 struct attribute *attr,
1086 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
1091 rc = kstrtobool(buffer, &val);
1095 spin_lock(&sbi->ll_lock);
1097 set_bit(LL_SBI_PARALLEL_DIO, sbi->ll_flags);
1099 clear_bit(LL_SBI_PARALLEL_DIO, sbi->ll_flags);
1100 spin_unlock(&sbi->ll_lock);
1104 LUSTRE_RW_ATTR(parallel_dio);
1106 static ssize_t max_read_ahead_async_active_show(struct kobject *kobj,
1107 struct attribute *attr,
1110 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
1113 return scnprintf(buf, PAGE_SIZE, "%u\n",
1114 sbi->ll_ra_info.ra_async_max_active);
1117 static ssize_t max_read_ahead_async_active_store(struct kobject *kobj,
1118 struct attribute *attr,
1122 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
1127 rc = kstrtouint(buffer, 10, &val);
1132 * It doesn't make any sense to make it exceed what
1133 * workqueue could acutally support. This can easily
1134 * over subscripe the cores but Lustre internally
1135 * throttles to avoid those impacts.
1137 if (val > WQ_UNBOUND_MAX_ACTIVE) {
1138 CERROR("%s: cannot set max_read_ahead_async_active=%u larger than %u\n",
1139 sbi->ll_fsname, val, WQ_UNBOUND_MAX_ACTIVE);
1143 spin_lock(&sbi->ll_lock);
1144 sbi->ll_ra_info.ra_async_max_active = val;
1145 spin_unlock(&sbi->ll_lock);
1149 LUSTRE_RW_ATTR(max_read_ahead_async_active);
1151 static ssize_t read_ahead_async_file_threshold_mb_show(struct kobject *kobj,
1152 struct attribute *attr,
1155 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
1158 return scnprintf(buf, PAGE_SIZE, "%lu\n", PAGES_TO_MiB(
1159 sbi->ll_ra_info.ra_async_pages_per_file_threshold));
1163 read_ahead_async_file_threshold_mb_store(struct kobject *kobj,
1164 struct attribute *attr,
1165 const char *buffer, size_t count)
1167 unsigned long pages_number;
1168 unsigned long max_ra_per_file;
1169 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
1173 rc = kstrtoul(buffer, 10, &pages_number);
1177 pages_number = MiB_TO_PAGES(pages_number);
1178 max_ra_per_file = sbi->ll_ra_info.ra_max_pages_per_file;
1179 if (pages_number < 0 || pages_number > max_ra_per_file) {
1180 CERROR("%s: can't set read_ahead_async_file_threshold_mb=%lu > "
1181 "max_read_readahead_per_file_mb=%lu\n", sbi->ll_fsname,
1182 PAGES_TO_MiB(pages_number),
1183 PAGES_TO_MiB(max_ra_per_file));
1186 sbi->ll_ra_info.ra_async_pages_per_file_threshold = pages_number;
1190 LUSTRE_RW_ATTR(read_ahead_async_file_threshold_mb);
1192 static ssize_t read_ahead_range_kb_show(struct kobject *kobj,
1193 struct attribute *attr,char *buf)
1195 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
1198 return snprintf(buf, PAGE_SIZE, "%lu\n",
1199 sbi->ll_ra_info.ra_range_pages << (PAGE_SHIFT - 10));
1203 read_ahead_range_kb_store(struct kobject *kobj,
1204 struct attribute *attr,
1205 const char *buffer, size_t count)
1207 unsigned long pages_number;
1208 unsigned long max_ra_per_file;
1210 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
1214 rc = sysfs_memparse(buffer, count, &val, "KiB");
1218 pages_number = val >> PAGE_SHIFT;
1219 /* Disable mmap range read */
1220 if (pages_number == 0)
1223 max_ra_per_file = sbi->ll_ra_info.ra_max_pages_per_file;
1224 if (pages_number > max_ra_per_file ||
1225 pages_number < RA_MIN_MMAP_RANGE_PAGES)
1229 spin_lock(&sbi->ll_lock);
1230 sbi->ll_ra_info.ra_range_pages = pages_number;
1231 spin_unlock(&sbi->ll_lock);
1235 LUSTRE_RW_ATTR(read_ahead_range_kb);
1237 static ssize_t fast_read_show(struct kobject *kobj,
1238 struct attribute *attr,
1241 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
1244 return scnprintf(buf, PAGE_SIZE, "%u\n",
1245 test_bit(LL_SBI_FAST_READ, sbi->ll_flags));
1248 static ssize_t fast_read_store(struct kobject *kobj,
1249 struct attribute *attr,
1253 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
1258 rc = kstrtobool(buffer, &val);
1262 spin_lock(&sbi->ll_lock);
1264 set_bit(LL_SBI_FAST_READ, sbi->ll_flags);
1266 clear_bit(LL_SBI_FAST_READ, sbi->ll_flags);
1267 spin_unlock(&sbi->ll_lock);
1271 LUSTRE_RW_ATTR(fast_read);
1273 static ssize_t file_heat_show(struct kobject *kobj,
1274 struct attribute *attr,
1277 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
1280 return scnprintf(buf, PAGE_SIZE, "%u\n",
1281 test_bit(LL_SBI_FILE_HEAT, sbi->ll_flags));
1284 static ssize_t file_heat_store(struct kobject *kobj,
1285 struct attribute *attr,
1289 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
1294 rc = kstrtobool(buffer, &val);
1298 spin_lock(&sbi->ll_lock);
1300 set_bit(LL_SBI_FILE_HEAT, sbi->ll_flags);
1302 clear_bit(LL_SBI_FILE_HEAT, sbi->ll_flags);
1303 spin_unlock(&sbi->ll_lock);
1307 LUSTRE_RW_ATTR(file_heat);
1309 static ssize_t heat_decay_percentage_show(struct kobject *kobj,
1310 struct attribute *attr,
1313 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
1316 return scnprintf(buf, PAGE_SIZE, "%u\n",
1317 (sbi->ll_heat_decay_weight * 100 + 128) / 256);
1320 static ssize_t heat_decay_percentage_store(struct kobject *kobj,
1321 struct attribute *attr,
1325 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
1330 rc = kstrtoul(buffer, 10, &val);
1334 if (val < 0 || val > 100)
1337 sbi->ll_heat_decay_weight = (val * 256 + 50) / 100;
1341 LUSTRE_RW_ATTR(heat_decay_percentage);
1343 static ssize_t heat_period_second_show(struct kobject *kobj,
1344 struct attribute *attr,
1347 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
1350 return scnprintf(buf, PAGE_SIZE, "%u\n", sbi->ll_heat_period_second);
1353 static ssize_t heat_period_second_store(struct kobject *kobj,
1354 struct attribute *attr,
1358 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
1363 rc = kstrtoul(buffer, 10, &val);
1370 sbi->ll_heat_period_second = val;
1374 LUSTRE_RW_ATTR(heat_period_second);
1376 static ssize_t opencache_threshold_count_show(struct kobject *kobj,
1377 struct attribute *attr,
1380 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
1383 if (sbi->ll_oc_thrsh_count)
1384 return snprintf(buf, PAGE_SIZE, "%u\n",
1385 sbi->ll_oc_thrsh_count);
1387 return snprintf(buf, PAGE_SIZE, "off\n");
1390 static ssize_t opencache_threshold_count_store(struct kobject *kobj,
1391 struct attribute *attr,
1395 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
1400 rc = kstrtouint(buffer, 10, &val);
1403 /* also accept "off" to disable and "on" to always cache */
1404 rc = kstrtobool(buffer, &enable);
1409 sbi->ll_oc_thrsh_count = val;
1413 LUSTRE_RW_ATTR(opencache_threshold_count);
1415 static ssize_t opencache_threshold_ms_show(struct kobject *kobj,
1416 struct attribute *attr,
1419 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
1422 return snprintf(buf, PAGE_SIZE, "%u\n", sbi->ll_oc_thrsh_ms);
1425 static ssize_t opencache_threshold_ms_store(struct kobject *kobj,
1426 struct attribute *attr,
1430 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
1435 rc = kstrtouint(buffer, 10, &val);
1439 sbi->ll_oc_thrsh_ms = val;
1443 LUSTRE_RW_ATTR(opencache_threshold_ms);
1445 static ssize_t opencache_max_ms_show(struct kobject *kobj,
1446 struct attribute *attr,
1449 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
1452 return snprintf(buf, PAGE_SIZE, "%u\n", sbi->ll_oc_max_ms);
1455 static ssize_t opencache_max_ms_store(struct kobject *kobj,
1456 struct attribute *attr,
1460 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
1465 rc = kstrtouint(buffer, 10, &val);
1469 sbi->ll_oc_max_ms = val;
1473 LUSTRE_RW_ATTR(opencache_max_ms);
1475 static ssize_t inode_cache_show(struct kobject *kobj,
1476 struct attribute *attr,
1479 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
1482 return snprintf(buf, PAGE_SIZE, "%u\n", sbi->ll_inode_cache_enabled);
1485 static ssize_t inode_cache_store(struct kobject *kobj,
1486 struct attribute *attr,
1490 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
1495 rc = kstrtobool(buffer, &val);
1499 sbi->ll_inode_cache_enabled = val;
1503 LUSTRE_RW_ATTR(inode_cache);
1505 static int ll_unstable_stats_seq_show(struct seq_file *m, void *v)
1507 struct super_block *sb = m->private;
1508 struct ll_sb_info *sbi = ll_s2sbi(sb);
1509 struct cl_client_cache *cache = sbi->ll_cache;
1513 pages = atomic_long_read(&cache->ccc_unstable_nr);
1514 mb = (pages * PAGE_SIZE) >> 20;
1516 seq_printf(m, "unstable_check: %8d\n"
1517 "unstable_pages: %12ld\n"
1518 "unstable_mb: %8d\n",
1519 cache->ccc_unstable_check, pages, mb);
1523 static ssize_t ll_unstable_stats_seq_write(struct file *file,
1524 const char __user *buffer,
1525 size_t count, loff_t *unused)
1527 struct seq_file *seq = file->private_data;
1528 struct ll_sb_info *sbi = ll_s2sbi((struct super_block *)seq->private);
1535 if (count >= sizeof(kernbuf))
1538 if (copy_from_user(kernbuf, buffer, count))
1542 buffer += lprocfs_find_named_value(kernbuf, "unstable_check:", &count) -
1544 rc = kstrtobool_from_user(buffer, count, &val);
1548 /* borrow lru lock to set the value */
1549 spin_lock(&sbi->ll_cache->ccc_lru_lock);
1550 sbi->ll_cache->ccc_unstable_check = val;
1551 spin_unlock(&sbi->ll_cache->ccc_lru_lock);
1556 LDEBUGFS_SEQ_FOPS(ll_unstable_stats);
1558 static int ll_root_squash_seq_show(struct seq_file *m, void *v)
1560 struct super_block *sb = m->private;
1561 struct ll_sb_info *sbi = ll_s2sbi(sb);
1562 struct root_squash_info *squash = &sbi->ll_squash;
1564 seq_printf(m, "%u:%u\n", squash->rsi_uid, squash->rsi_gid);
1568 static ssize_t ll_root_squash_seq_write(struct file *file,
1569 const char __user *buffer,
1570 size_t count, loff_t *off)
1572 struct seq_file *m = file->private_data;
1573 struct super_block *sb = m->private;
1574 struct ll_sb_info *sbi = ll_s2sbi(sb);
1575 struct root_squash_info *squash = &sbi->ll_squash;
1577 return lprocfs_wr_root_squash(buffer, count, squash, sbi->ll_fsname);
1580 LDEBUGFS_SEQ_FOPS(ll_root_squash);
1582 static int ll_nosquash_nids_seq_show(struct seq_file *m, void *v)
1584 struct super_block *sb = m->private;
1585 struct ll_sb_info *sbi = ll_s2sbi(sb);
1586 struct root_squash_info *squash = &sbi->ll_squash;
1589 spin_lock(&squash->rsi_lock);
1590 if (!list_empty(&squash->rsi_nosquash_nids)) {
1591 len = cfs_print_nidlist(m->buf + m->count, m->size - m->count,
1592 &squash->rsi_nosquash_nids);
1596 seq_puts(m, "NONE\n");
1598 spin_unlock(&squash->rsi_lock);
1603 static ssize_t ll_nosquash_nids_seq_write(struct file *file,
1604 const char __user *buffer,
1605 size_t count, loff_t *off)
1607 struct seq_file *m = file->private_data;
1608 struct super_block *sb = m->private;
1609 struct ll_sb_info *sbi = ll_s2sbi(sb);
1610 struct root_squash_info *squash = &sbi->ll_squash;
1613 rc = lprocfs_wr_nosquash_nids(buffer, count, squash, sbi->ll_fsname);
1617 ll_compute_rootsquash_state(sbi);
1622 LDEBUGFS_SEQ_FOPS(ll_nosquash_nids);
1624 static int ll_filename_enc_seq_show(struct seq_file *m, void *v)
1626 struct super_block *sb = m->private;
1627 struct lustre_sb_info *lsi = s2lsi(sb);
1629 seq_printf(m, "%u\n", lsi->lsi_flags & LSI_FILENAME_ENC ? 1 : 0);
1633 static ssize_t ll_filename_enc_seq_write(struct file *file,
1634 const char __user *buffer,
1635 size_t count, loff_t *off)
1637 struct seq_file *m = file->private_data;
1638 struct super_block *sb = m->private;
1639 struct lustre_sb_info *lsi = s2lsi(sb);
1643 rc = kstrtobool_from_user(buffer, count, &val);
1648 lsi->lsi_flags |= LSI_FILENAME_ENC;
1650 lsi->lsi_flags &= ~LSI_FILENAME_ENC;
1655 LDEBUGFS_SEQ_FOPS(ll_filename_enc);
1657 static int ll_pcc_seq_show(struct seq_file *m, void *v)
1659 struct super_block *sb = m->private;
1660 struct ll_sb_info *sbi = ll_s2sbi(sb);
1662 return pcc_super_dump(&sbi->ll_pcc_super, m);
1665 static ssize_t ll_pcc_seq_write(struct file *file, const char __user *buffer,
1666 size_t count, loff_t *off)
1668 struct seq_file *m = file->private_data;
1669 struct super_block *sb = m->private;
1670 struct ll_sb_info *sbi = ll_s2sbi(sb);
1674 if (count >= LPROCFS_WR_PCC_MAX_CMD)
1677 if (!(exp_connect_flags2(sbi->ll_md_exp) & OBD_CONNECT2_PCC))
1680 OBD_ALLOC(kernbuf, count + 1);
1681 if (kernbuf == NULL)
1684 if (copy_from_user(kernbuf, buffer, count))
1685 GOTO(out_free_kernbuff, rc = -EFAULT);
1687 rc = pcc_cmd_handle(kernbuf, count, &sbi->ll_pcc_super);
1689 OBD_FREE(kernbuf, count + 1);
1690 return rc ? rc : count;
1692 LDEBUGFS_SEQ_FOPS(ll_pcc);
1694 struct ldebugfs_vars lprocfs_llite_obd_vars[] = {
1696 .fops = &ll_site_stats_fops },
1697 { .name = "max_cached_mb",
1698 .fops = &ll_max_cached_mb_fops },
1699 { .name = "statahead_stats",
1700 .fops = &ll_statahead_stats_fops },
1701 { .name = "unstable_stats",
1702 .fops = &ll_unstable_stats_fops },
1703 { .name = "sbi_flags",
1704 .fops = &ll_sbi_flags_fops },
1705 { .name = "root_squash",
1706 .fops = &ll_root_squash_fops },
1707 { .name = "nosquash_nids",
1708 .fops = &ll_nosquash_nids_fops },
1710 .fops = &ll_pcc_fops, },
1711 { .name = "enable_filename_encryption",
1712 .fops = &ll_filename_enc_fops, },
1716 #define MAX_STRING_SIZE 128
1718 static struct attribute *llite_attrs[] = {
1719 &lustre_attr_blocksize.attr,
1720 &lustre_attr_stat_blocksize.attr,
1721 &lustre_attr_kbytestotal.attr,
1722 &lustre_attr_kbytesfree.attr,
1723 &lustre_attr_kbytesavail.attr,
1724 &lustre_attr_filestotal.attr,
1725 &lustre_attr_filesfree.attr,
1726 &lustre_attr_client_type.attr,
1727 &lustre_attr_foreign_symlink_enable.attr,
1728 &lustre_attr_foreign_symlink_prefix.attr,
1729 &lustre_attr_foreign_symlink_upcall.attr,
1730 &lustre_attr_foreign_symlink_upcall_info.attr,
1731 &lustre_attr_fstype.attr,
1732 &lustre_attr_uuid.attr,
1733 &lustre_attr_checksums.attr,
1734 &lustre_attr_checksum_pages.attr,
1735 &lustre_attr_max_read_ahead_mb.attr,
1736 &lustre_attr_max_read_ahead_per_file_mb.attr,
1737 &lustre_attr_max_read_ahead_whole_mb.attr,
1738 &lustre_attr_max_read_ahead_async_active.attr,
1739 &lustre_attr_read_ahead_async_file_threshold_mb.attr,
1740 &lustre_attr_read_ahead_range_kb.attr,
1741 &lustre_attr_stats_track_pid.attr,
1742 &lustre_attr_stats_track_ppid.attr,
1743 &lustre_attr_stats_track_gid.attr,
1744 &lustre_attr_statahead_running_max.attr,
1745 &lustre_attr_statahead_max.attr,
1746 &lustre_attr_statahead_agl.attr,
1747 &lustre_attr_lazystatfs.attr,
1748 &lustre_attr_statfs_max_age.attr,
1749 &lustre_attr_max_easize.attr,
1750 &lustre_attr_default_easize.attr,
1751 &lustre_attr_xattr_cache.attr,
1752 &lustre_attr_fast_read.attr,
1753 &lustre_attr_tiny_write.attr,
1754 &lustre_attr_parallel_dio.attr,
1755 &lustre_attr_file_heat.attr,
1756 &lustre_attr_heat_decay_percentage.attr,
1757 &lustre_attr_heat_period_second.attr,
1758 &lustre_attr_opencache_threshold_count.attr,
1759 &lustre_attr_opencache_threshold_ms.attr,
1760 &lustre_attr_opencache_max_ms.attr,
1761 &lustre_attr_inode_cache.attr,
1765 static void sbi_kobj_release(struct kobject *kobj)
1767 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
1769 complete(&sbi->ll_kobj_unregister);
1772 static struct kobj_type sbi_ktype = {
1773 .default_attrs = llite_attrs,
1774 .sysfs_ops = &lustre_sysfs_ops,
1775 .release = sbi_kobj_release,
1778 static const struct llite_file_opcode {
1782 } llite_opcode_table[LPROC_LL_FILE_OPCODES] = {
1783 /* file operation */
1784 { LPROC_LL_READ_BYTES, LPROCFS_TYPE_BYTES_FULL, "read_bytes" },
1785 { LPROC_LL_WRITE_BYTES, LPROCFS_TYPE_BYTES_FULL, "write_bytes" },
1786 { LPROC_LL_READ, LPROCFS_TYPE_LATENCY, "read" },
1787 { LPROC_LL_WRITE, LPROCFS_TYPE_LATENCY, "write" },
1788 { LPROC_LL_IOCTL, LPROCFS_TYPE_REQS, "ioctl" },
1789 { LPROC_LL_OPEN, LPROCFS_TYPE_LATENCY, "open" },
1790 { LPROC_LL_RELEASE, LPROCFS_TYPE_LATENCY, "close" },
1791 { LPROC_LL_MMAP, LPROCFS_TYPE_LATENCY, "mmap" },
1792 { LPROC_LL_FAULT, LPROCFS_TYPE_LATENCY, "page_fault" },
1793 { LPROC_LL_MKWRITE, LPROCFS_TYPE_LATENCY, "page_mkwrite" },
1794 { LPROC_LL_LLSEEK, LPROCFS_TYPE_LATENCY, "seek" },
1795 { LPROC_LL_FSYNC, LPROCFS_TYPE_LATENCY, "fsync" },
1796 { LPROC_LL_READDIR, LPROCFS_TYPE_LATENCY, "readdir" },
1797 { LPROC_LL_INODE_OCOUNT,LPROCFS_TYPE_REQS |
1798 LPROCFS_CNTR_AVGMINMAX |
1799 LPROCFS_CNTR_STDDEV, "opencount" },
1800 { LPROC_LL_INODE_OPCLTM,LPROCFS_TYPE_LATENCY, "openclosetime" },
1801 /* inode operation */
1802 { LPROC_LL_SETATTR, LPROCFS_TYPE_LATENCY, "setattr" },
1803 { LPROC_LL_TRUNC, LPROCFS_TYPE_LATENCY, "truncate" },
1804 { LPROC_LL_FLOCK, LPROCFS_TYPE_LATENCY, "flock" },
1805 { LPROC_LL_GETATTR, LPROCFS_TYPE_LATENCY, "getattr" },
1806 { LPROC_LL_FALLOCATE, LPROCFS_TYPE_LATENCY, "fallocate"},
1807 /* dir inode operation */
1808 { LPROC_LL_CREATE, LPROCFS_TYPE_LATENCY, "create" },
1809 { LPROC_LL_LINK, LPROCFS_TYPE_LATENCY, "link" },
1810 { LPROC_LL_UNLINK, LPROCFS_TYPE_LATENCY, "unlink" },
1811 { LPROC_LL_SYMLINK, LPROCFS_TYPE_LATENCY, "symlink" },
1812 { LPROC_LL_MKDIR, LPROCFS_TYPE_LATENCY, "mkdir" },
1813 { LPROC_LL_RMDIR, LPROCFS_TYPE_LATENCY, "rmdir" },
1814 { LPROC_LL_MKNOD, LPROCFS_TYPE_LATENCY, "mknod" },
1815 { LPROC_LL_RENAME, LPROCFS_TYPE_LATENCY, "rename" },
1816 /* special inode operation */
1817 { LPROC_LL_STATFS, LPROCFS_TYPE_LATENCY, "statfs" },
1818 { LPROC_LL_SETXATTR, LPROCFS_TYPE_LATENCY, "setxattr" },
1819 { LPROC_LL_GETXATTR, LPROCFS_TYPE_LATENCY, "getxattr" },
1820 { LPROC_LL_GETXATTR_HITS, LPROCFS_TYPE_REQS, "getxattr_hits" },
1821 { LPROC_LL_LISTXATTR, LPROCFS_TYPE_LATENCY, "listxattr" },
1822 { LPROC_LL_REMOVEXATTR, LPROCFS_TYPE_LATENCY, "removexattr" },
1823 { LPROC_LL_INODE_PERM, LPROCFS_TYPE_LATENCY, "inode_permission" },
1826 void ll_stats_ops_tally(struct ll_sb_info *sbi, int op, long count)
1831 if (sbi->ll_stats_track_type == STATS_TRACK_ALL)
1832 lprocfs_counter_add(sbi->ll_stats, op, count);
1833 else if (sbi->ll_stats_track_type == STATS_TRACK_PID &&
1834 sbi->ll_stats_track_id == current->pid)
1835 lprocfs_counter_add(sbi->ll_stats, op, count);
1836 else if (sbi->ll_stats_track_type == STATS_TRACK_PPID &&
1837 sbi->ll_stats_track_id == current->real_parent->pid)
1838 lprocfs_counter_add(sbi->ll_stats, op, count);
1839 else if (sbi->ll_stats_track_type == STATS_TRACK_GID &&
1840 sbi->ll_stats_track_id ==
1841 from_kgid(&init_user_ns, current_gid()))
1842 lprocfs_counter_add(sbi->ll_stats, op, count);
1844 EXPORT_SYMBOL(ll_stats_ops_tally);
1846 static const char *const ra_stat_string[] = {
1847 [RA_STAT_HIT] = "hits",
1848 [RA_STAT_MISS] = "misses",
1849 [RA_STAT_DISTANT_READPAGE] = "readpage_not_consecutive",
1850 [RA_STAT_MISS_IN_WINDOW] = "miss_inside_window",
1851 [RA_STAT_FAILED_GRAB_PAGE] = "failed_grab_cache_page",
1852 [RA_STAT_FAILED_MATCH] = "failed_lock_match",
1853 [RA_STAT_DISCARDED] = "read_but_discarded",
1854 [RA_STAT_ZERO_LEN] = "zero_length_file",
1855 [RA_STAT_ZERO_WINDOW] = "zero_size_window",
1856 [RA_STAT_EOF] = "readahead_to_eof",
1857 [RA_STAT_MAX_IN_FLIGHT] = "hit_max_readahead_issue",
1858 [RA_STAT_WRONG_GRAB_PAGE] = "wrong_page_from_grab_cache_page",
1859 [RA_STAT_FAILED_REACH_END] = "failed_to_reach_end",
1860 [RA_STAT_ASYNC] = "async_readahead",
1861 [RA_STAT_FAILED_FAST_READ] = "failed_to_fast_read",
1862 [RA_STAT_MMAP_RANGE_READ] = "mmap_range_read",
1865 int ll_debugfs_register_super(struct super_block *sb, const char *name)
1867 struct lustre_sb_info *lsi = s2lsi(sb);
1868 struct ll_sb_info *sbi = ll_s2sbi(sb);
1874 if (IS_ERR_OR_NULL(llite_root))
1877 sbi->ll_debugfs_entry = debugfs_create_dir(name, llite_root);
1878 ldebugfs_add_vars(sbi->ll_debugfs_entry, lprocfs_llite_obd_vars, sb);
1880 debugfs_create_file("dump_page_cache", 0444, sbi->ll_debugfs_entry, sbi,
1881 &vvp_dump_pgcache_file_ops);
1883 debugfs_create_file("extents_stats", 0644, sbi->ll_debugfs_entry, sbi,
1884 &ll_rw_extents_stats_fops);
1886 debugfs_create_file("extents_stats_per_process", 0644,
1887 sbi->ll_debugfs_entry, sbi,
1888 &ll_rw_extents_stats_pp_fops);
1890 debugfs_create_file("offset_stats", 0644, sbi->ll_debugfs_entry, sbi,
1891 &ll_rw_offset_stats_fops);
1893 /* File operations stats */
1894 sbi->ll_stats = lprocfs_alloc_stats(LPROC_LL_FILE_OPCODES,
1895 LPROCFS_STATS_FLAG_NONE);
1896 if (sbi->ll_stats == NULL)
1897 GOTO(out_debugfs, err = -ENOMEM);
1899 /* do counter init */
1900 for (id = 0; id < LPROC_LL_FILE_OPCODES; id++) {
1901 u32 type = llite_opcode_table[id].type;
1902 void *ptr = "unknown";
1904 if (type & LPROCFS_TYPE_REQS)
1906 else if (type & LPROCFS_TYPE_BYTES)
1908 else if (type & LPROCFS_TYPE_USEC)
1910 lprocfs_counter_init(sbi->ll_stats,
1911 llite_opcode_table[id].opcode, type,
1912 llite_opcode_table[id].opname, ptr);
1915 debugfs_create_file("stats", 0644, sbi->ll_debugfs_entry,
1916 sbi->ll_stats, &ldebugfs_stats_seq_fops);
1918 sbi->ll_ra_stats = lprocfs_alloc_stats(ARRAY_SIZE(ra_stat_string),
1919 LPROCFS_STATS_FLAG_NONE);
1920 if (sbi->ll_ra_stats == NULL)
1921 GOTO(out_stats, err = -ENOMEM);
1923 for (id = 0; id < ARRAY_SIZE(ra_stat_string); id++)
1924 lprocfs_counter_init(sbi->ll_ra_stats, id, 0,
1925 ra_stat_string[id], "pages");
1927 debugfs_create_file("read_ahead_stats", 0644, sbi->ll_debugfs_entry,
1928 sbi->ll_ra_stats, &ldebugfs_stats_seq_fops);
1931 /* Yes we also register sysfs mount kset here as well */
1932 sbi->ll_kset.kobj.parent = llite_kobj;
1933 sbi->ll_kset.kobj.ktype = &sbi_ktype;
1934 init_completion(&sbi->ll_kobj_unregister);
1935 err = kobject_set_name(&sbi->ll_kset.kobj, "%s", name);
1937 GOTO(out_ra_stats, err);
1939 err = kset_register(&sbi->ll_kset);
1941 GOTO(out_ra_stats, err);
1943 lsi->lsi_kobj = kobject_get(&sbi->ll_kset.kobj);
1947 lprocfs_free_stats(&sbi->ll_ra_stats);
1949 lprocfs_free_stats(&sbi->ll_stats);
1951 debugfs_remove_recursive(sbi->ll_debugfs_entry);
1956 void ll_debugfs_unregister_super(struct super_block *sb)
1958 struct lustre_sb_info *lsi = s2lsi(sb);
1959 struct ll_sb_info *sbi = ll_s2sbi(sb);
1961 debugfs_remove_recursive(sbi->ll_debugfs_entry);
1964 sysfs_remove_link(&sbi->ll_kset.kobj,
1965 sbi->ll_dt_obd->obd_type->typ_name);
1968 sysfs_remove_link(&sbi->ll_kset.kobj,
1969 sbi->ll_md_obd->obd_type->typ_name);
1971 kobject_put(lsi->lsi_kobj);
1973 kset_unregister(&sbi->ll_kset);
1974 wait_for_completion(&sbi->ll_kobj_unregister);
1976 lprocfs_free_stats(&sbi->ll_ra_stats);
1977 lprocfs_free_stats(&sbi->ll_stats);
1979 #undef MAX_STRING_SIZE
1981 static void ll_display_extents_info(struct ll_rw_extents_info *rw_extents,
1982 struct seq_file *seq, int which)
1984 unsigned long read_tot = 0, write_tot = 0, read_cum, write_cum;
1985 unsigned long start, end, r, w;
1986 char *unitp = "KMGTPEZY";
1988 struct per_process_info *pp_info;
1990 pp_info = &rw_extents->pp_extents[which];
1995 for (i = 0; i < LL_HIST_MAX; i++) {
1996 read_tot += pp_info->pp_r_hist.oh_buckets[i];
1997 write_tot += pp_info->pp_w_hist.oh_buckets[i];
2000 for (i = 0; i < LL_HIST_MAX; i++) {
2001 r = pp_info->pp_r_hist.oh_buckets[i];
2002 w = pp_info->pp_w_hist.oh_buckets[i];
2005 end = 1 << (i + LL_HIST_START - units);
2006 seq_printf(seq, "%4lu%c - %4lu%c%c: %14lu %4u %4u | "
2007 "%14lu %4u %4u\n", start, *unitp, end, *unitp,
2008 (i == LL_HIST_MAX - 1) ? '+' : ' ',
2009 r, pct(r, read_tot), pct(read_cum, read_tot),
2010 w, pct(w, write_tot), pct(write_cum, write_tot));
2012 if (start == (1 << 10)) {
2017 if (read_cum == read_tot && write_cum == write_tot)
2022 static int ll_rw_extents_stats_pp_seq_show(struct seq_file *seq, void *v)
2024 struct ll_sb_info *sbi = seq->private;
2025 struct ll_rw_extents_info *rw_extents = sbi->ll_rw_extents_info;
2028 if (!sbi->ll_rw_stats_on || !rw_extents) {
2029 seq_puts(seq, "disabled\n write anything to this file to activate, then '0' or 'disable' to deactivate\n");
2033 spin_lock(&sbi->ll_pp_extent_lock);
2034 lprocfs_stats_header(seq, ktime_get(), rw_extents->pp_init, 25, ":", 1);
2035 seq_printf(seq, "%15s %19s | %20s\n", " ", "read", "write");
2036 seq_printf(seq, "%13s %14s %4s %4s | %14s %4s %4s\n",
2037 "extents", "calls", "%", "cum%", "calls", "%", "cum%");
2039 for (k = 0; k < LL_PROCESS_HIST_MAX; k++) {
2040 if (rw_extents->pp_extents[k].pid != 0) {
2041 seq_printf(seq, "\nPID: %d\n",
2042 rw_extents->pp_extents[k].pid);
2043 ll_display_extents_info(rw_extents, seq, k);
2046 spin_unlock(&sbi->ll_pp_extent_lock);
2050 static int alloc_rw_stats_info(struct ll_sb_info *sbi)
2052 struct ll_rw_extents_info *rw_extents;
2053 struct ll_rw_process_info *offset;
2054 struct ll_rw_process_info *process;
2057 OBD_ALLOC(rw_extents, sizeof(*rw_extents));
2061 for (i = 0; i <= LL_PROCESS_HIST_MAX; i++) {
2062 spin_lock_init(&rw_extents->pp_extents[i].pp_r_hist.oh_lock);
2063 spin_lock_init(&rw_extents->pp_extents[i].pp_w_hist.oh_lock);
2066 spin_lock(&sbi->ll_pp_extent_lock);
2067 if (!sbi->ll_rw_extents_info)
2068 sbi->ll_rw_extents_info = rw_extents;
2069 spin_unlock(&sbi->ll_pp_extent_lock);
2070 /* another writer allocated the struct before we got the lock */
2071 if (sbi->ll_rw_extents_info != rw_extents)
2072 OBD_FREE(rw_extents, sizeof(*rw_extents));
2074 OBD_ALLOC(process, sizeof(*process) * LL_PROCESS_HIST_MAX);
2076 GOTO(out, rc = -ENOMEM);
2077 OBD_ALLOC(offset, sizeof(*offset) * LL_OFFSET_HIST_MAX);
2079 GOTO(out_free, rc = -ENOMEM);
2081 spin_lock(&sbi->ll_process_lock);
2082 if (!sbi->ll_rw_process_info)
2083 sbi->ll_rw_process_info = process;
2084 if (!sbi->ll_rw_offset_info)
2085 sbi->ll_rw_offset_info = offset;
2086 spin_unlock(&sbi->ll_process_lock);
2088 /* another writer allocated the structs before we got the lock */
2089 if (sbi->ll_rw_offset_info != offset)
2090 OBD_FREE(offset, sizeof(*offset) * LL_OFFSET_HIST_MAX);
2091 if (sbi->ll_rw_process_info != process) {
2093 OBD_FREE(process, sizeof(*process) * LL_PROCESS_HIST_MAX);
2100 void ll_free_rw_stats_info(struct ll_sb_info *sbi)
2102 if (sbi->ll_rw_extents_info) {
2103 OBD_FREE(sbi->ll_rw_extents_info,
2104 sizeof(*sbi->ll_rw_extents_info));
2105 sbi->ll_rw_extents_info = NULL;
2107 if (sbi->ll_rw_offset_info) {
2108 OBD_FREE(sbi->ll_rw_offset_info,
2109 sizeof(*sbi->ll_rw_offset_info) * LL_OFFSET_HIST_MAX);
2110 sbi->ll_rw_offset_info = NULL;
2112 if (sbi->ll_rw_process_info) {
2113 OBD_FREE(sbi->ll_rw_process_info,
2114 sizeof(*sbi->ll_rw_process_info) * LL_PROCESS_HIST_MAX);
2115 sbi->ll_rw_process_info = NULL;
2119 static ssize_t ll_rw_extents_stats_pp_seq_write(struct file *file,
2120 const char __user *buf,
2121 size_t len, loff_t *off)
2123 struct seq_file *seq = file->private_data;
2124 struct ll_sb_info *sbi = seq->private;
2125 struct ll_rw_extents_info *rw_extents;
2132 value = ll_stats_pid_write(buf, len);
2135 sbi->ll_rw_stats_on = 0;
2137 if (!sbi->ll_rw_extents_info) {
2138 int rc = alloc_rw_stats_info(sbi);
2143 sbi->ll_rw_stats_on = 1;
2147 spin_lock(&sbi->ll_pp_extent_lock);
2148 rw_extents = sbi->ll_rw_extents_info;
2150 rw_extents->pp_init = ktime_get();
2151 for (i = 0; i < LL_PROCESS_HIST_MAX; i++) {
2152 rw_extents->pp_extents[i].pid = 0;
2153 lprocfs_oh_clear(&rw_extents->pp_extents[i].pp_r_hist);
2154 lprocfs_oh_clear(&rw_extents->pp_extents[i].pp_w_hist);
2157 spin_unlock(&sbi->ll_pp_extent_lock);
2162 LDEBUGFS_SEQ_FOPS(ll_rw_extents_stats_pp);
2164 static int ll_rw_extents_stats_seq_show(struct seq_file *seq, void *v)
2166 struct ll_sb_info *sbi = seq->private;
2167 struct ll_rw_extents_info *rw_extents = sbi->ll_rw_extents_info;
2169 if (!sbi->ll_rw_stats_on || !rw_extents) {
2170 seq_puts(seq, "disabled\n write anything to this file to activate, then '0' or 'disable' to deactivate\n");
2174 spin_lock(&sbi->ll_lock);
2175 lprocfs_stats_header(seq, ktime_get(), rw_extents->pp_init, 25, ":", 1);
2177 seq_printf(seq, "%15s %19s | %20s\n", " ", "read", "write");
2178 seq_printf(seq, "%13s %14s %4s %4s | %14s %4s %4s\n",
2179 "extents", "calls", "%", "cum%",
2180 "calls", "%", "cum%");
2182 ll_display_extents_info(rw_extents, seq, LL_PROCESS_HIST_MAX);
2183 spin_unlock(&sbi->ll_lock);
2188 static ssize_t ll_rw_extents_stats_seq_write(struct file *file,
2189 const char __user *buf,
2190 size_t len, loff_t *off)
2192 struct seq_file *seq = file->private_data;
2193 struct ll_sb_info *sbi = seq->private;
2194 struct ll_rw_extents_info *rw_extents;
2201 value = ll_stats_pid_write(buf, len);
2204 sbi->ll_rw_stats_on = 0;
2206 if (!sbi->ll_rw_extents_info) {
2207 int rc = alloc_rw_stats_info(sbi);
2212 sbi->ll_rw_stats_on = 1;
2215 spin_lock(&sbi->ll_pp_extent_lock);
2216 rw_extents = sbi->ll_rw_extents_info;
2218 rw_extents->pp_init = ktime_get();
2219 for (i = 0; i <= LL_PROCESS_HIST_MAX; i++) {
2220 rw_extents->pp_extents[i].pid = 0;
2221 lprocfs_oh_clear(&rw_extents->pp_extents[i].pp_r_hist);
2222 lprocfs_oh_clear(&rw_extents->pp_extents[i].pp_w_hist);
2225 spin_unlock(&sbi->ll_pp_extent_lock);
2230 LDEBUGFS_SEQ_FOPS(ll_rw_extents_stats);
2232 void ll_rw_stats_tally(struct ll_sb_info *sbi, pid_t pid,
2233 struct ll_file_data *file, loff_t pos,
2234 size_t count, int rw)
2237 struct ll_rw_process_info *process;
2238 struct ll_rw_process_info *offset;
2239 int *off_count = &sbi->ll_rw_offset_entry_count;
2240 int *process_count = &sbi->ll_offset_process_count;
2241 struct ll_rw_extents_info *rw_extents;
2243 if (!sbi->ll_rw_stats_on)
2246 spin_lock(&sbi->ll_pp_extent_lock);
2247 rw_extents = sbi->ll_rw_extents_info;
2249 spin_unlock(&sbi->ll_pp_extent_lock);
2253 /* Extent statistics */
2254 for (i = 0; i < LL_PROCESS_HIST_MAX; i++) {
2255 if (rw_extents->pp_extents[i].pid == pid) {
2263 sbi->ll_extent_process_count =
2264 (sbi->ll_extent_process_count + 1) % LL_PROCESS_HIST_MAX;
2265 cur = sbi->ll_extent_process_count;
2266 rw_extents->pp_extents[cur].pid = pid;
2267 lprocfs_oh_clear(&rw_extents->pp_extents[cur].pp_r_hist);
2268 lprocfs_oh_clear(&rw_extents->pp_extents[cur].pp_w_hist);
2271 for (i = 0; (count >= 1 << (LL_HIST_START + i)) &&
2272 (i < (LL_HIST_MAX - 1)); i++);
2274 rw_extents->pp_extents[cur].pp_r_hist.oh_buckets[i]++;
2275 rw_extents->pp_extents[LL_PROCESS_HIST_MAX].pp_r_hist.oh_buckets[i]++;
2277 rw_extents->pp_extents[cur].pp_w_hist.oh_buckets[i]++;
2278 rw_extents->pp_extents[LL_PROCESS_HIST_MAX].pp_w_hist.oh_buckets[i]++;
2280 spin_unlock(&sbi->ll_pp_extent_lock);
2282 spin_lock(&sbi->ll_process_lock);
2283 process = sbi->ll_rw_process_info;
2284 offset = sbi->ll_rw_offset_info;
2285 if (!process || !offset)
2288 /* Offset statistics */
2289 for (i = 0; i < LL_PROCESS_HIST_MAX; i++) {
2290 if (process[i].rw_pid == pid) {
2291 if (process[i].rw_last_file != file) {
2292 process[i].rw_range_start = pos;
2293 process[i].rw_last_file_pos = pos + count;
2294 process[i].rw_smallest_extent = count;
2295 process[i].rw_largest_extent = count;
2296 process[i].rw_offset = 0;
2297 process[i].rw_last_file = file;
2300 if (process[i].rw_last_file_pos != pos) {
2302 (*off_count + 1) % LL_OFFSET_HIST_MAX;
2303 offset[*off_count].rw_op = process[i].rw_op;
2304 offset[*off_count].rw_pid = pid;
2305 offset[*off_count].rw_range_start =
2306 process[i].rw_range_start;
2307 offset[*off_count].rw_range_end =
2308 process[i].rw_last_file_pos;
2309 offset[*off_count].rw_smallest_extent =
2310 process[i].rw_smallest_extent;
2311 offset[*off_count].rw_largest_extent =
2312 process[i].rw_largest_extent;
2313 offset[*off_count].rw_offset =
2314 process[i].rw_offset;
2315 process[i].rw_op = rw;
2316 process[i].rw_range_start = pos;
2317 process[i].rw_smallest_extent = count;
2318 process[i].rw_largest_extent = count;
2319 process[i].rw_offset = pos -
2320 process[i].rw_last_file_pos;
2322 if (process[i].rw_smallest_extent > count)
2323 process[i].rw_smallest_extent = count;
2324 if (process[i].rw_largest_extent < count)
2325 process[i].rw_largest_extent = count;
2326 process[i].rw_last_file_pos = pos + count;
2330 *process_count = (*process_count + 1) % LL_PROCESS_HIST_MAX;
2331 process[*process_count].rw_pid = pid;
2332 process[*process_count].rw_op = rw;
2333 process[*process_count].rw_range_start = pos;
2334 process[*process_count].rw_last_file_pos = pos + count;
2335 process[*process_count].rw_smallest_extent = count;
2336 process[*process_count].rw_largest_extent = count;
2337 process[*process_count].rw_offset = 0;
2338 process[*process_count].rw_last_file = file;
2341 spin_unlock(&sbi->ll_process_lock);
2344 static int ll_rw_offset_stats_seq_show(struct seq_file *seq, void *v)
2346 struct ll_sb_info *sbi = seq->private;
2347 struct ll_rw_process_info *offset;
2348 struct ll_rw_process_info *process;
2351 if (!sbi->ll_rw_stats_on) {
2352 seq_puts(seq, "disabled\n write anything to this file to activate, then '0' or 'disable' to deactivate\n");
2356 spin_lock(&sbi->ll_process_lock);
2357 lprocfs_stats_header(seq, ktime_get(), sbi->ll_process_stats_init, 25,
2359 seq_printf(seq, "%3s %10s %14s %14s %17s %17s %14s\n",
2360 "R/W", "PID", "RANGE START", "RANGE END",
2361 "SMALLEST EXTENT", "LARGEST EXTENT", "OFFSET");
2363 /* We stored the discontiguous offsets here; print them first */
2364 offset = sbi->ll_rw_offset_info;
2365 for (i = 0; offset && i < LL_OFFSET_HIST_MAX; i++) {
2366 if (offset[i].rw_pid != 0)
2368 "%3c %10d %14llu %14llu %17lu %17lu %14lld\n",
2369 offset[i].rw_op == READ ? 'R' : 'W',
2371 offset[i].rw_range_start,
2372 offset[i].rw_range_end,
2373 (unsigned long)offset[i].rw_smallest_extent,
2374 (unsigned long)offset[i].rw_largest_extent,
2375 offset[i].rw_offset);
2378 /* Then print the current offsets for each process */
2379 process = sbi->ll_rw_process_info;
2380 for (i = 0; process && i < LL_PROCESS_HIST_MAX; i++) {
2381 if (process[i].rw_pid != 0)
2383 "%3c %10d %14llu %14llu %17lu %17lu %14lld\n",
2384 process[i].rw_op == READ ? 'R' : 'W',
2386 process[i].rw_range_start,
2387 process[i].rw_last_file_pos,
2388 (unsigned long)process[i].rw_smallest_extent,
2389 (unsigned long)process[i].rw_largest_extent,
2390 process[i].rw_offset);
2392 spin_unlock(&sbi->ll_process_lock);
2397 static ssize_t ll_rw_offset_stats_seq_write(struct file *file,
2398 const char __user *buf,
2399 size_t len, loff_t *off)
2401 struct seq_file *seq = file->private_data;
2402 struct ll_sb_info *sbi = seq->private;
2408 value = ll_stats_pid_write(buf, len);
2411 sbi->ll_rw_stats_on = 0;
2413 if (!sbi->ll_rw_process_info || !sbi->ll_rw_offset_info) {
2414 int rc = alloc_rw_stats_info(sbi);
2419 sbi->ll_rw_stats_on = 1;
2422 spin_lock(&sbi->ll_process_lock);
2423 sbi->ll_offset_process_count = 0;
2424 sbi->ll_rw_offset_entry_count = 0;
2425 sbi->ll_process_stats_init = ktime_get();
2426 if (sbi->ll_rw_process_info)
2427 memset(sbi->ll_rw_process_info, 0,
2428 sizeof(struct ll_rw_process_info) * LL_PROCESS_HIST_MAX);
2429 if (sbi->ll_rw_offset_info)
2430 memset(sbi->ll_rw_offset_info, 0,
2431 sizeof(struct ll_rw_process_info) * LL_OFFSET_HIST_MAX);
2432 spin_unlock(&sbi->ll_process_lock);
2437 LDEBUGFS_SEQ_FOPS(ll_rw_offset_stats);