Whamcloud - gitweb
LU-12142 readahead: limit over reservation
[fs/lustre-release.git] / lustre / llite / lproc_llite.c
index 6f90377..23b67d4 100644 (file)
@@ -289,6 +289,14 @@ static ssize_t client_type_show(struct kobject *kobj, struct attribute *attr,
 }
 LUSTRE_RO_ATTR(client_type);
 
+LUSTRE_RW_ATTR(foreign_symlink_enable);
+
+LUSTRE_RW_ATTR(foreign_symlink_prefix);
+
+LUSTRE_RW_ATTR(foreign_symlink_upcall);
+
+LUSTRE_WO_ATTR(foreign_symlink_upcall_info);
+
 static ssize_t fstype_show(struct kobject *kobj, struct attribute *attr,
                           char *buf)
 {
@@ -324,13 +332,9 @@ static ssize_t max_read_ahead_mb_show(struct kobject *kobj,
 {
        struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
                                              ll_kset.kobj);
-       unsigned long ra_max_mb;
-
-       spin_lock(&sbi->ll_lock);
-       ra_max_mb = PAGES_TO_MiB(sbi->ll_ra_info.ra_max_pages);
-       spin_unlock(&sbi->ll_lock);
 
-       return snprintf(buf, PAGE_SIZE, "%lu\n", ra_max_mb);
+       return scnprintf(buf, PAGE_SIZE, "%lu\n",
+                       PAGES_TO_MiB(sbi->ll_ra_info.ra_max_pages));
 }
 
 static ssize_t max_read_ahead_mb_store(struct kobject *kobj,
@@ -371,13 +375,9 @@ static ssize_t max_read_ahead_per_file_mb_show(struct kobject *kobj,
 {
        struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
                                              ll_kset.kobj);
-       unsigned long ra_max_file_mb;
-
-       spin_lock(&sbi->ll_lock);
-       ra_max_file_mb = PAGES_TO_MiB(sbi->ll_ra_info.ra_max_pages_per_file);
-       spin_unlock(&sbi->ll_lock);
 
-       return snprintf(buf, PAGE_SIZE, "%lu\n", ra_max_file_mb);
+       return scnprintf(buf, PAGE_SIZE, "%lu\n",
+                        PAGES_TO_MiB(sbi->ll_ra_info.ra_max_pages_per_file));
 }
 
 static ssize_t max_read_ahead_per_file_mb_store(struct kobject *kobj,
@@ -415,13 +415,9 @@ static ssize_t max_read_ahead_whole_mb_show(struct kobject *kobj,
 {
        struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
                                              ll_kset.kobj);
-       unsigned long ra_max_whole_mb;
 
-       spin_lock(&sbi->ll_lock);
-       ra_max_whole_mb = PAGES_TO_MiB(sbi->ll_ra_info.ra_max_read_ahead_whole_pages);
-       spin_unlock(&sbi->ll_lock);
-
-       return snprintf(buf, PAGE_SIZE, "%lu\n", ra_max_whole_mb);
+       return scnprintf(buf, PAGE_SIZE, "%lu\n",
+                        PAGES_TO_MiB(sbi->ll_ra_info.ra_max_read_ahead_whole_pages));
 }
 
 static ssize_t max_read_ahead_whole_mb_store(struct kobject *kobj,
@@ -462,6 +458,7 @@ static int ll_max_cached_mb_seq_show(struct seq_file *m, void *v)
        struct super_block     *sb    = m->private;
        struct ll_sb_info      *sbi   = ll_s2sbi(sb);
        struct cl_client_cache *cache = sbi->ll_cache;
+       struct ll_ra_info *ra = &sbi->ll_ra_info;
        long max_cached_mb;
        long unused_mb;
 
@@ -469,16 +466,21 @@ static int ll_max_cached_mb_seq_show(struct seq_file *m, void *v)
        max_cached_mb = PAGES_TO_MiB(cache->ccc_lru_max);
        unused_mb = PAGES_TO_MiB(atomic_long_read(&cache->ccc_lru_left));
        mutex_unlock(&cache->ccc_max_cache_mb_lock);
+
        seq_printf(m, "users: %d\n"
                      "max_cached_mb: %ld\n"
                      "used_mb: %ld\n"
                      "unused_mb: %ld\n"
-                     "reclaim_count: %u\n",
+                     "reclaim_count: %u\n"
+                     "max_read_ahead_mb: %lu\n"
+                     "used_read_ahead_mb: %d\n",
                   atomic_read(&cache->ccc_users),
                   max_cached_mb,
                   max_cached_mb - unused_mb,
                   unused_mb,
-                  cache->ccc_lru_shrinkers);
+                  cache->ccc_lru_shrinkers,
+                  PAGES_TO_MiB(ra->ra_max_pages),
+                  PAGES_TO_MiB(atomic_read(&ra->ra_cur_pages)));
        return 0;
 }
 
@@ -727,7 +729,7 @@ static ssize_t statahead_running_max_show(struct kobject *kobj,
        struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
                                              ll_kset.kobj);
 
-       return snprintf(buf, 16, "%u\n", sbi->ll_sa_running_max);
+       return scnprintf(buf, PAGE_SIZE, "%u\n", sbi->ll_sa_running_max);
 }
 
 static ssize_t statahead_running_max_store(struct kobject *kobj,
@@ -878,7 +880,7 @@ static ssize_t statfs_max_age_show(struct kobject *kobj, struct attribute *attr,
        struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
                                              ll_kset.kobj);
 
-       return snprintf(buf, PAGE_SIZE, "%u\n", sbi->ll_statfs_max_age);
+       return scnprintf(buf, PAGE_SIZE, "%u\n", sbi->ll_statfs_max_age);
 }
 
 static ssize_t statfs_max_age_store(struct kobject *kobj,
@@ -916,8 +918,8 @@ static ssize_t max_easize_show(struct kobject *kobj,
                return rc;
 
        /* Limit xattr size returned to userspace based on kernel maximum */
-       return snprintf(buf, PAGE_SIZE, "%u\n",
-                       ealen > XATTR_SIZE_MAX ? XATTR_SIZE_MAX : ealen);
+       return scnprintf(buf, PAGE_SIZE, "%u\n",
+                        ealen > XATTR_SIZE_MAX ? XATTR_SIZE_MAX : ealen);
 }
 LUSTRE_RO_ATTR(max_easize);
 
@@ -946,8 +948,8 @@ static ssize_t default_easize_show(struct kobject *kobj,
                return rc;
 
        /* Limit xattr size returned to userspace based on kernel maximum */
-       return snprintf(buf, PAGE_SIZE, "%u\n",
-                       ealen > XATTR_SIZE_MAX ? XATTR_SIZE_MAX : ealen);
+       return scnprintf(buf, PAGE_SIZE, "%u\n",
+                        ealen > XATTR_SIZE_MAX ? XATTR_SIZE_MAX : ealen);
 }
 
 /**
@@ -993,7 +995,7 @@ LUSTRE_RW_ATTR(default_easize);
 
 static int ll_sbi_flags_seq_show(struct seq_file *m, void *v)
 {
-       const char *str[] = LL_SBI_FLAGS;
+       const char *const str[] = LL_SBI_FLAGS;
        struct super_block *sb = m->private;
        int flags = ll_s2sbi(sb)->ll_flags;
        int i = 0;
@@ -1092,8 +1094,8 @@ static ssize_t max_read_ahead_async_active_show(struct kobject *kobj,
        struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
                                              ll_kset.kobj);
 
-       return snprintf(buf, PAGE_SIZE, "%u\n",
-                       sbi->ll_ra_info.ra_async_max_active);
+       return scnprintf(buf, PAGE_SIZE, "%u\n",
+                        sbi->ll_ra_info.ra_async_max_active);
 }
 
 static ssize_t max_read_ahead_async_active_store(struct kobject *kobj,
@@ -1137,8 +1139,8 @@ static ssize_t read_ahead_async_file_threshold_mb_show(struct kobject *kobj,
        struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
                                              ll_kset.kobj);
 
-       return snprintf(buf, PAGE_SIZE, "%lu\n",
-            PAGES_TO_MiB(sbi->ll_ra_info.ra_async_pages_per_file_threshold));
+       return scnprintf(buf, PAGE_SIZE, "%lu\n", PAGES_TO_MiB(
+                        sbi->ll_ra_info.ra_async_pages_per_file_threshold));
 }
 
 static ssize_t
@@ -1171,6 +1173,51 @@ read_ahead_async_file_threshold_mb_store(struct kobject *kobj,
 }
 LUSTRE_RW_ATTR(read_ahead_async_file_threshold_mb);
 
+static ssize_t read_ahead_range_kb_show(struct kobject *kobj,
+                                       struct attribute *attr,char *buf)
+{
+       struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
+                                             ll_kset.kobj);
+
+       return snprintf(buf, PAGE_SIZE, "%lu\n",
+                       sbi->ll_ra_info.ra_range_pages << (PAGE_SHIFT - 10));
+}
+
+static ssize_t
+read_ahead_range_kb_store(struct kobject *kobj,
+                              struct attribute *attr,
+                              const char *buffer, size_t count)
+{
+       unsigned long pages_number;
+       unsigned long max_ra_per_file;
+       u64 val;
+       struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
+                                             ll_kset.kobj);
+       int rc;
+
+       rc = sysfs_memparse(buffer, count, &val, "KiB");
+       if (rc < 0)
+               return rc;
+
+       pages_number = val >> PAGE_SHIFT;
+       /* Disable mmap range read */
+       if (pages_number == 0)
+               goto out;
+
+       max_ra_per_file = sbi->ll_ra_info.ra_max_pages_per_file;
+       if (pages_number > max_ra_per_file ||
+           pages_number < RA_MIN_MMAP_RANGE_PAGES)
+               return -ERANGE;
+
+out:
+       spin_lock(&sbi->ll_lock);
+       sbi->ll_ra_info.ra_range_pages = pages_number;
+       spin_unlock(&sbi->ll_lock);
+
+       return count;
+}
+LUSTRE_RW_ATTR(read_ahead_range_kb);
+
 static ssize_t fast_read_show(struct kobject *kobj,
                              struct attribute *attr,
                              char *buf)
@@ -1213,8 +1260,8 @@ static ssize_t file_heat_show(struct kobject *kobj,
        struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
                                              ll_kset.kobj);
 
-       return snprintf(buf, PAGE_SIZE, "%u\n",
-                       !!(sbi->ll_flags & LL_SBI_FILE_HEAT));
+       return scnprintf(buf, PAGE_SIZE, "%u\n",
+                        !!(sbi->ll_flags & LL_SBI_FILE_HEAT));
 }
 
 static ssize_t file_heat_store(struct kobject *kobj,
@@ -1249,8 +1296,8 @@ static ssize_t heat_decay_percentage_show(struct kobject *kobj,
        struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
                                              ll_kset.kobj);
 
-       return snprintf(buf, PAGE_SIZE, "%u\n",
-                      (sbi->ll_heat_decay_weight * 100 + 128) / 256);
+       return scnprintf(buf, PAGE_SIZE, "%u\n",
+                        (sbi->ll_heat_decay_weight * 100 + 128) / 256);
 }
 
 static ssize_t heat_decay_percentage_store(struct kobject *kobj,
@@ -1283,7 +1330,7 @@ static ssize_t heat_period_second_show(struct kobject *kobj,
        struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
                                              ll_kset.kobj);
 
-       return snprintf(buf, PAGE_SIZE, "%u\n", sbi->ll_heat_period_second);
+       return scnprintf(buf, PAGE_SIZE, "%u\n", sbi->ll_heat_period_second);
 }
 
 static ssize_t heat_period_second_store(struct kobject *kobj,
@@ -1463,9 +1510,9 @@ out_free_kernbuff:
        OBD_FREE(kernbuf, count + 1);
        return rc ? rc : count;
 }
-LPROC_SEQ_FOPS(ll_pcc);
+LDEBUGFS_SEQ_FOPS(ll_pcc);
 
-struct lprocfs_vars lprocfs_llite_obd_vars[] = {
+struct ldebugfs_vars lprocfs_llite_obd_vars[] = {
        { .name =       "site",
          .fops =       &ll_site_stats_fops                     },
        { .name =       "max_cached_mb",
@@ -1496,6 +1543,10 @@ static struct attribute *llite_attrs[] = {
        &lustre_attr_filestotal.attr,
        &lustre_attr_filesfree.attr,
        &lustre_attr_client_type.attr,
+       &lustre_attr_foreign_symlink_enable.attr,
+       &lustre_attr_foreign_symlink_prefix.attr,
+       &lustre_attr_foreign_symlink_upcall.attr,
+       &lustre_attr_foreign_symlink_upcall_info.attr,
        &lustre_attr_fstype.attr,
        &lustre_attr_uuid.attr,
        &lustre_attr_checksums.attr,
@@ -1505,6 +1556,7 @@ static struct attribute *llite_attrs[] = {
        &lustre_attr_max_read_ahead_whole_mb.attr,
        &lustre_attr_max_read_ahead_async_active.attr,
        &lustre_attr_read_ahead_async_file_threshold_mb.attr,
+       &lustre_attr_read_ahead_range_kb.attr,
        &lustre_attr_stats_track_pid.attr,
        &lustre_attr_stats_track_ppid.attr,
        &lustre_attr_stats_track_gid.attr,
@@ -1537,18 +1589,14 @@ static struct kobj_type sbi_ktype = {
        .release        = sbi_kobj_release,
 };
 
-#define LPROCFS_TYPE_LATENCY \
-       (LPROCFS_TYPE_USEC | LPROCFS_CNTR_AVGMINMAX | LPROCFS_CNTR_STDDEV)
 static const struct llite_file_opcode {
        __u32           opcode;
        __u32           type;
        const char      *opname;
 } llite_opcode_table[LPROC_LL_FILE_OPCODES] = {
        /* file operation */
-       { LPROC_LL_READ_BYTES,  LPROCFS_CNTR_AVGMINMAX | LPROCFS_TYPE_BYTES,
-               "read_bytes" },
-       { LPROC_LL_WRITE_BYTES, LPROCFS_CNTR_AVGMINMAX | LPROCFS_TYPE_BYTES,
-               "write_bytes" },
+       { LPROC_LL_READ_BYTES,  LPROCFS_TYPE_BYTES_FULL, "read_bytes" },
+       { LPROC_LL_WRITE_BYTES, LPROCFS_TYPE_BYTES_FULL, "write_bytes" },
        { LPROC_LL_READ,        LPROCFS_TYPE_LATENCY,   "read" },
        { LPROC_LL_WRITE,       LPROCFS_TYPE_LATENCY,   "write" },
        { LPROC_LL_IOCTL,       LPROCFS_TYPE_REQS,      "ioctl" },
@@ -1565,6 +1613,7 @@ static const struct llite_file_opcode {
        { LPROC_LL_TRUNC,       LPROCFS_TYPE_LATENCY,   "truncate" },
        { LPROC_LL_FLOCK,       LPROCFS_TYPE_LATENCY,   "flock" },
        { LPROC_LL_GETATTR,     LPROCFS_TYPE_LATENCY,   "getattr" },
+       { LPROC_LL_FALLOCATE,   LPROCFS_TYPE_LATENCY, "fallocate"},
        /* dir inode operation */
        { LPROC_LL_CREATE,      LPROCFS_TYPE_LATENCY,   "create" },
        { LPROC_LL_LINK,        LPROCFS_TYPE_LATENCY,   "link" },
@@ -1604,7 +1653,7 @@ void ll_stats_ops_tally(struct ll_sb_info *sbi, int op, long count)
 }
 EXPORT_SYMBOL(ll_stats_ops_tally);
 
-static const char *ra_stat_string[] = {
+static const char *const ra_stat_string[] = {
        [RA_STAT_HIT] = "hits",
        [RA_STAT_MISS] = "misses",
        [RA_STAT_DISTANT_READPAGE] = "readpage not consecutive",
@@ -1620,6 +1669,7 @@ static const char *ra_stat_string[] = {
        [RA_STAT_FAILED_REACH_END] = "failed to reach end",
        [RA_STAT_ASYNC] = "async readahead",
        [RA_STAT_FAILED_FAST_READ] = "failed to fast read",
+       [RA_STAT_MMAP_RANGE_READ] = "mmap range read",
 };
 
 int ll_debugfs_register_super(struct super_block *sb, const char *name)
@@ -1659,24 +1709,21 @@ int ll_debugfs_register_super(struct super_block *sb, const char *name)
        /* do counter init */
        for (id = 0; id < LPROC_LL_FILE_OPCODES; id++) {
                u32 type = llite_opcode_table[id].type;
-               void *ptr = NULL;
+               void *ptr = "unknown";
 
                if (type & LPROCFS_TYPE_REQS)
                        ptr = "reqs";
                else if (type & LPROCFS_TYPE_BYTES)
                        ptr = "bytes";
-               else if (type & LPROCFS_TYPE_PAGES)
-                       ptr = "pages";
                else if (type & LPROCFS_TYPE_USEC)
                        ptr = "usec";
                lprocfs_counter_init(sbi->ll_stats,
-                                    llite_opcode_table[id].opcode,
-                                    (type & LPROCFS_CNTR_AVGMINMAX),
+                                    llite_opcode_table[id].opcode, type,
                                     llite_opcode_table[id].opname, ptr);
        }
 
        debugfs_create_file("stats", 0644, sbi->ll_debugfs_entry,
-                           sbi->ll_stats, &lprocfs_stats_seq_fops);
+                           sbi->ll_stats, &ldebugfs_stats_seq_fops);
 
        sbi->ll_ra_stats = lprocfs_alloc_stats(ARRAY_SIZE(ra_stat_string),
                                               LPROCFS_STATS_FLAG_NONE);
@@ -1688,7 +1735,7 @@ int ll_debugfs_register_super(struct super_block *sb, const char *name)
                                     ra_stat_string[id], "pages");
 
        debugfs_create_file("read_ahead_stats", 0644, sbi->ll_debugfs_entry,
-                           sbi->ll_ra_stats, &lprocfs_stats_seq_fops);
+                           sbi->ll_ra_stats, &ldebugfs_stats_seq_fops);
 
 out_ll_kset:
        /* Yes we also register sysfs mount kset here as well */