From: Andreas Dilger Date: Fri, 10 May 2019 21:09:41 +0000 (-0600) Subject: LU-12043 llite: move tunable params to sysfs_memparse() X-Git-Tag: 2.13.53~145 X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=commitdiff_plain;h=59a3d7237df82ac2ce14b6779577584163f9122b LU-12043 llite: move tunable params to sysfs_memparse() Move the max_read_ahead_* tunables from debugfs to sysfs, since they follow the one-value-per-file rule and should be visible to regular users. Rename the functions and constants from *readahead* to *read_ahead* or *READ_AHEAD* to match the tunable names from procfs. Deprecate usage of llprocfs_str_with_units_to_s64(), lu_str_to_s64(), llprocfs_str_with_units_to_u64(), and lu_str_to_u64(), and instead use sysfs_memparse() to parse sizes in the few remaining places where they are used. A separate patch will remove those functions. Minor fix to the "lctl set_param" man page. Fixes: adb5aca3d673 ("LU-8066 llite: Move all remaining procfs entries to debugfs") Signed-off-by: Andreas Dilger Change-Id: I2cdf5f8f0aeca458ed1989366102c33ae83ebbe5 Reviewed-on: https://review.whamcloud.com/34849 Reviewed-by: James Simmons Tested-by: jenkins Tested-by: Maloo Reviewed-by: Wang Shilong Reviewed-by: Oleg Drokin --- diff --git a/contrib/scripts/spelling.txt b/contrib/scripts/spelling.txt index c3488b1..286a2c2 100644 --- a/contrib/scripts/spelling.txt +++ b/contrib/scripts/spelling.txt @@ -134,8 +134,9 @@ LPLX||%#lx LPO64||%#llo LPPID||%d lprocfs_str_to_s64||kstrtoxxx_from_user -lprocfs_str_with_units_to_s64||sysfs_memparse -lu_str_to_s64|sysfs_memparse +lprocfs_str_with_units_to_u64||sysfs_memparse using sysfs/kernbuf +lprocfs_str_with_units_to_s64||sysfs_memparse using sysfs/kernbuf +lu_str_to_s64||sysfs_memparse LPROC_SEQ_FOPS||LUSTRE_RW_ATTR LPROC_SEQ_FOPS_RO_TYPE||LUSTRE_RO_ATTR LPROC_SEQ_FOPS_RO||LUSTRE_RO_ATTR diff --git a/lustre/doc/lctl-set_param.8 b/lustre/doc/lctl-set_param.8 index dc8f639..bb69c4e 100644 --- a/lustre/doc/lctl-set_param.8 +++ b/lustre/doc/lctl-set_param.8 @@ -40,9 +40,9 @@ Set parameters from instead of from the command-line. The contents of .I filename is YAML format, created as an output from -.BR "lctl --device MGS llog_print " < \fIfsname >- client -fR or any other valid llog configuration log as listed by -.B lctl --device MGS llog_catlist +.BR ' "lctl --device MGS llog_print " < \fIfsname\fR >- client ' +or any other valid llog configuration log as listed by +.RB ' "lctl --device MGS llog_catlist" ' .TP .B -n Disable printing of the parameter name after setting it. diff --git a/lustre/llite/llite_internal.h b/lustre/llite/llite_internal.h index 2ff0fd0..d9ec393 100644 --- a/lustre/llite/llite_internal.h +++ b/lustre/llite/llite_internal.h @@ -452,11 +452,11 @@ static inline struct pcc_inode *ll_i2pcci(struct inode *inode) /* default to use at least 16M for fast read if possible */ #define RA_REMAIN_WINDOW_MIN MiB_TO_PAGES(16UL) -/* default to about 64M of readahead on a given system. */ -#define SBI_DEFAULT_READAHEAD_MAX MiB_TO_PAGES(64UL) +/* default readahead on a given system. */ +#define SBI_DEFAULT_READ_AHEAD_MAX MiB_TO_PAGES(64UL) -/* default to read-ahead full files smaller than 2MB on the second read */ -#define SBI_DEFAULT_READAHEAD_WHOLE_MAX MiB_TO_PAGES(2UL) +/* default read-ahead full files smaller than limit on the second read */ +#define SBI_DEFAULT_READ_AHEAD_WHOLE_MAX MiB_TO_PAGES(2UL) enum ra_stat { RA_STAT_HIT = 0, diff --git a/lustre/llite/llite_lib.c b/lustre/llite/llite_lib.c index 56204a12..ce55b7f 100644 --- a/lustre/llite/llite_lib.c +++ b/lustre/llite/llite_lib.c @@ -113,7 +113,7 @@ static struct ll_sb_info *ll_init_sbi(void) GOTO(out_destroy_ra, rc = -ENOMEM); sbi->ll_ra_info.ra_max_pages_per_file = min(pages / 32, - SBI_DEFAULT_READAHEAD_MAX); + SBI_DEFAULT_READ_AHEAD_MAX); sbi->ll_ra_info.ra_async_pages_per_file_threshold = sbi->ll_ra_info.ra_max_pages_per_file; sbi->ll_ra_info.ra_max_pages = sbi->ll_ra_info.ra_max_pages_per_file; @@ -516,7 +516,7 @@ static int client_common_fill_super(struct super_block *sb, char *md, char *dt) /* Don't change value if it was specified in the config log */ if (sbi->ll_ra_info.ra_max_read_ahead_whole_pages == -1) { sbi->ll_ra_info.ra_max_read_ahead_whole_pages = - max_t(unsigned long, SBI_DEFAULT_READAHEAD_WHOLE_MAX, + max_t(unsigned long, SBI_DEFAULT_READ_AHEAD_WHOLE_MAX, (data->ocd_brw_size >> PAGE_SHIFT)); if (sbi->ll_ra_info.ra_max_read_ahead_whole_pages > sbi->ll_ra_info.ra_max_pages_per_file) diff --git a/lustre/llite/lproc_llite.c b/lustre/llite/lproc_llite.c index 65b6479..e015ba6 100644 --- a/lustre/llite/lproc_llite.c +++ b/lustre/llite/lproc_llite.c @@ -321,40 +321,41 @@ static int ll_site_stats_seq_show(struct seq_file *m, void *v) LDEBUGFS_SEQ_FOPS_RO(ll_site_stats); -static int ll_max_readahead_mb_seq_show(struct seq_file *m, void *v) +static ssize_t max_read_ahead_mb_show(struct kobject *kobj, + struct attribute *attr, char *buf) { - struct super_block *sb = m->private; - struct ll_sb_info *sbi = ll_s2sbi(sb); + 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); - seq_printf(m, "%lu\n", ra_max_mb); - return 0; + return snprintf(buf, PAGE_SIZE, "%lu\n", ra_max_mb); } -static ssize_t -ll_max_readahead_mb_seq_write(struct file *file, const char __user *buffer, - size_t count, loff_t *off) +static ssize_t max_read_ahead_mb_store(struct kobject *kobj, + struct attribute *attr, + const char *buffer, size_t count) { - struct seq_file *m = file->private_data; - struct super_block *sb = m->private; - struct ll_sb_info *sbi = ll_s2sbi(sb); - s64 ra_max_mb, pages_number; + struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info, + ll_kset.kobj); + u64 ra_max_mb, pages_number; int rc; - rc = lprocfs_str_with_units_to_s64(buffer, count, &ra_max_mb, 'M'); + rc = sysfs_memparse(buffer, count, &ra_max_mb, "MiB"); if (rc) return rc; pages_number = round_up(ra_max_mb, 1024 * 1024) >> PAGE_SHIFT; - if (pages_number < 0 || pages_number > cfs_totalram_pages() / 2) { + CDEBUG(D_INFO, "%s: set max_read_ahead_mb=%llu (%llu pages)\n", + sbi->ll_fsname, PAGES_TO_MiB(pages_number), pages_number); + if (pages_number > cfs_totalram_pages() / 2) { /* 1/2 of RAM */ - CERROR("%s: can't set max_readahead_mb=%llu > %luMB\n", + CERROR("%s: cannot set max_read_ahead_mb=%llu > totalram/2=%luMB\n", sbi->ll_fsname, PAGES_TO_MiB(pages_number), - PAGES_TO_MiB(cfs_totalram_pages())); + PAGES_TO_MiB(cfs_totalram_pages() / 2)); return -ERANGE; } @@ -364,42 +365,40 @@ ll_max_readahead_mb_seq_write(struct file *file, const char __user *buffer, return count; } +LUSTRE_RW_ATTR(max_read_ahead_mb); -LDEBUGFS_SEQ_FOPS(ll_max_readahead_mb); - -static int ll_max_readahead_per_file_mb_seq_show(struct seq_file *m, void *v) +static ssize_t max_read_ahead_per_file_mb_show(struct kobject *kobj, + struct attribute *attr, + char *buf) { - struct super_block *sb = m->private; - struct ll_sb_info *sbi = ll_s2sbi(sb); + 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); - seq_printf(m, "%lu\n", ra_max_file_mb); - return 0; + return snprintf(buf, PAGE_SIZE, "%lu\n", ra_max_file_mb); } -static ssize_t -ll_max_readahead_per_file_mb_seq_write(struct file *file, - const char __user *buffer, - size_t count, loff_t *off) +static ssize_t max_read_ahead_per_file_mb_store(struct kobject *kobj, + struct attribute *attr, + const char *buffer, + size_t count) { - struct seq_file *m = file->private_data; - struct super_block *sb = m->private; - struct ll_sb_info *sbi = ll_s2sbi(sb); - s64 ra_max_file_mb, pages_number; + struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info, + ll_kset.kobj); + u64 ra_max_file_mb, pages_number; int rc; - rc = lprocfs_str_with_units_to_s64(buffer, count, &ra_max_file_mb, - 'M'); + rc = sysfs_memparse(buffer, count, &ra_max_file_mb, "MiB"); if (rc) return rc; pages_number = round_up(ra_max_file_mb, 1024 * 1024) >> PAGE_SHIFT; - if (pages_number < 0 || pages_number > sbi->ll_ra_info.ra_max_pages) { - CERROR("%s: can't set max_readahead_per_file_mb=%llu > max_read_ahead_mb=%lu\n", + if (pages_number > sbi->ll_ra_info.ra_max_pages) { + CERROR("%s: cannot set max_read_ahead_per_file_mb=%llu > max_read_ahead_mb=%lu\n", sbi->ll_fsname, PAGES_TO_MiB(pages_number), PAGES_TO_MiB(sbi->ll_ra_info.ra_max_pages)); return -ERANGE; @@ -411,36 +410,32 @@ ll_max_readahead_per_file_mb_seq_write(struct file *file, return count; } +LUSTRE_RW_ATTR(max_read_ahead_per_file_mb); -LDEBUGFS_SEQ_FOPS(ll_max_readahead_per_file_mb); - -static int ll_max_read_ahead_whole_mb_seq_show(struct seq_file *m, void *v) +static ssize_t max_read_ahead_whole_mb_show(struct kobject *kobj, + struct attribute *attr, char *buf) { - struct super_block *sb = m->private; - struct ll_sb_info *sbi = ll_s2sbi(sb); + 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); - seq_printf(m, "%lu\n", ra_max_whole_mb); - return 0; + return snprintf(buf, PAGE_SIZE, "%lu\n", ra_max_whole_mb); } -static ssize_t -ll_max_read_ahead_whole_mb_seq_write(struct file *file, - const char __user *buffer, - size_t count, loff_t *off) +static ssize_t max_read_ahead_whole_mb_store(struct kobject *kobj, + struct attribute *attr, + const char *buffer, size_t count) { - struct seq_file *m = file->private_data; - struct super_block *sb = m->private; - struct ll_sb_info *sbi = ll_s2sbi(sb); - s64 ra_max_whole_mb, pages_number; + struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info, + ll_kset.kobj); + u64 ra_max_whole_mb, pages_number; int rc; - rc = lprocfs_str_with_units_to_s64(buffer, count, &ra_max_whole_mb, - 'M'); + rc = sysfs_memparse(buffer, count, &ra_max_whole_mb, "MiB"); if (rc) return rc; @@ -448,11 +443,11 @@ ll_max_read_ahead_whole_mb_seq_write(struct file *file, /* Cap this at the current max readahead window size, the readahead * algorithm does this anyway so it's pointless to set it larger. */ - if (pages_number < 0 || - pages_number > sbi->ll_ra_info.ra_max_pages_per_file) { - CERROR("%s: can't set max_read_ahead_whole_mb=%llu > max_read_ahead_per_file_mb=%lu\n", + if (pages_number > sbi->ll_ra_info.ra_max_pages_per_file) { + CERROR("%s: cannot set max_read_ahead_whole_mb=%llu > max_read_ahead_per_file_mb=%lu\n", sbi->ll_fsname, PAGES_TO_MiB(pages_number), PAGES_TO_MiB(sbi->ll_ra_info.ra_max_pages_per_file)); + return -ERANGE; } @@ -462,8 +457,7 @@ ll_max_read_ahead_whole_mb_seq_write(struct file *file, return count; } - -LDEBUGFS_SEQ_FOPS(ll_max_read_ahead_whole_mb); +LUSTRE_RW_ATTR(max_read_ahead_whole_mb); static int ll_max_cached_mb_seq_show(struct seq_file *m, void *v) { @@ -500,9 +494,9 @@ static ssize_t ll_max_cached_mb_seq_write(struct file *file, long diff = 0; long nrpages = 0; __u16 refcheck; - __s64 pages_number; + u64 pages_number; int rc; - char kernbuf[128]; + char kernbuf[128], *ptr; ENTRY; if (count >= sizeof(kernbuf)) @@ -510,11 +504,10 @@ static ssize_t ll_max_cached_mb_seq_write(struct file *file, if (copy_from_user(kernbuf, buffer, count)) RETURN(-EFAULT); - kernbuf[count] = 0; + kernbuf[count] = '\0'; - buffer += lprocfs_find_named_value(kernbuf, "max_cached_mb:", &count) - - kernbuf; - rc = lprocfs_str_with_units_to_s64(buffer, count, &pages_number, 'M'); + ptr = lprocfs_find_named_value(kernbuf, "max_cached_mb:", &count); + rc = sysfs_memparse(ptr, count, &pages_number, "MiB"); if (rc) RETURN(rc); @@ -595,7 +588,6 @@ out: } return rc; } - LDEBUGFS_SEQ_FOPS(ll_max_cached_mb); static ssize_t checksums_show(struct kobject *kobj, struct attribute *attr, @@ -1100,14 +1092,14 @@ static ssize_t max_read_ahead_async_active_show(struct kobject *kobj, } static ssize_t max_read_ahead_async_active_store(struct kobject *kobj, - struct attribute *attr, - const char *buffer, - size_t count) + struct attribute *attr, + const char *buffer, + size_t count) { - unsigned int val; - int rc; struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info, ll_kset.kobj); + unsigned int val; + int rc; rc = kstrtouint(buffer, 10, &val); if (rc) @@ -1121,7 +1113,9 @@ static ssize_t max_read_ahead_async_active_store(struct kobject *kobj, return -ERANGE; } + spin_lock(&sbi->ll_lock); sbi->ll_ra_info.ra_async_max_active = val; + spin_unlock(&sbi->ll_lock); workqueue_set_max_active(sbi->ll_ra_info.ll_readahead_wq, val); return count; @@ -1466,12 +1460,6 @@ LPROC_SEQ_FOPS(ll_pcc); struct lprocfs_vars lprocfs_llite_obd_vars[] = { { .name = "site", .fops = &ll_site_stats_fops }, - { .name = "max_read_ahead_mb", - .fops = &ll_max_readahead_mb_fops }, - { .name = "max_read_ahead_per_file_mb", - .fops = &ll_max_readahead_per_file_mb_fops }, - { .name = "max_read_ahead_whole_mb", - .fops = &ll_max_read_ahead_whole_mb_fops }, { .name = "max_cached_mb", .fops = &ll_max_cached_mb_fops }, { .name = "statahead_stats", @@ -1504,6 +1492,11 @@ static struct attribute *llite_attrs[] = { &lustre_attr_uuid.attr, &lustre_attr_checksums.attr, &lustre_attr_checksum_pages.attr, + &lustre_attr_max_read_ahead_mb.attr, + &lustre_attr_max_read_ahead_per_file_mb.attr, + &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_stats_track_pid.attr, &lustre_attr_stats_track_ppid.attr, &lustre_attr_stats_track_gid.attr, @@ -1520,8 +1513,6 @@ static struct attribute *llite_attrs[] = { &lustre_attr_file_heat.attr, &lustre_attr_heat_decay_percentage.attr, &lustre_attr_heat_period_second.attr, - &lustre_attr_max_read_ahead_async_active.attr, - &lustre_attr_read_ahead_async_file_threshold_mb.attr, NULL, }; diff --git a/lustre/obdclass/lprocfs_status.c b/lustre/obdclass/lprocfs_status.c index 9399453..2b9214f 100644 --- a/lustre/obdclass/lprocfs_status.c +++ b/lustre/obdclass/lprocfs_status.c @@ -2360,13 +2360,20 @@ ssize_t lprocfs_obd_max_pages_per_rpc_seq_write(struct file *file, struct obd_import *imp; struct obd_connect_data *ocd; int chunk_mask, rc; - s64 val; + char kernbuf[22]; + u64 val; + + if (count > sizeof(kernbuf) - 1) + return -EINVAL; - rc = lprocfs_str_with_units_to_s64(buffer, count, &val, '1'); + if (copy_from_user(kernbuf, buffer, count)) + return -EFAULT; + + kernbuf[count] = '\0'; + + rc = sysfs_memparse(kernbuf, count, &val, "B"); if (rc) return rc; - if (val < 0) - return -ERANGE; /* if the max_pages is specified in bytes, convert to pages */ if (val >= ONE_MB_BRW_SIZE) @@ -2416,21 +2423,16 @@ ssize_t short_io_bytes_store(struct kobject *kobj, struct attribute *attr, struct obd_device *dev = container_of(kobj, struct obd_device, obd_kset.kobj); struct client_obd *cli = &dev->u.cli; - char kernbuf[32]; - s64 val; + u64 val; int rc; - if (count >= sizeof(kernbuf)) - return -EINVAL; - - memcpy(kernbuf, buffer, count); - kernbuf[count] = '\0'; - rc = lu_str_to_s64(kernbuf, count, &val, '1'); - if (rc) - GOTO(out, rc); - - if (val == -1) + if (strcmp(buffer, "-1") == 0) { val = OBD_DEF_SHORT_IO_BYTES; + } else { + rc = sysfs_memparse(buffer, count, &val, "B"); + if (rc) + GOTO(out, rc); + } if (val && (val < MIN_SHORT_IO_BYTES || val > LNET_MTU)) GOTO(out, rc = -ERANGE); diff --git a/lustre/tests/sanity.sh b/lustre/tests/sanity.sh index af8fcdc..541fae3 100755 --- a/lustre/tests/sanity.sh +++ b/lustre/tests/sanity.sh @@ -8932,11 +8932,6 @@ test_101c() { } run_test 101c "check stripe_size aligned read-ahead =================" -set_read_ahead() { - $LCTL get_param -n llite.*.max_read_ahead_mb | head -n 1 - $LCTL set_param -n llite.*.max_read_ahead_mb $1 > /dev/null 2>&1 -} - test_101d() { [ $PARALLEL == "yes" ] && skip "skip parallel run" @@ -8956,7 +8951,10 @@ test_101d() { cancel_lru_locks osc echo Disable read-ahead - local old_READAHEAD=$(set_read_ahead 0) + local old_RA=$($LCTL get_param -n llite.*.max_read_ahead_mb | head -n 1) + $LCTL set_param -n llite.*.max_read_ahead_mb=0 + stack_trap "$LCTL set_param -n llite.*.max_read_ahead_mb $old_RA" EXIT + $LCTL get_param -n llite.*.max_read_ahead_mb echo Reading the test file $file with read-ahead disabled local raOFF=$(do_and_time "dd if=$file of=/dev/null bs=1M count=$sz_MB") @@ -8964,7 +8962,7 @@ test_101d() { echo Cancel LRU locks on lustre client to flush the client cache cancel_lru_locks osc echo Enable read-ahead with ${ra_MB}MB - set_read_ahead $ra_MB + $LCTL set_param -n llite.*.max_read_ahead_mb=$ra_MB echo Reading the test file $file with read-ahead enabled local raON=$(do_and_time "dd if=$file of=/dev/null bs=1M count=$sz_MB") @@ -8972,7 +8970,6 @@ test_101d() { echo "read-ahead disabled time read $raOFF" echo "read-ahead enabled time read $raON" - set_read_ahead $old_READAHEAD rm -f $file wait_delete_completed @@ -16196,8 +16193,7 @@ test_224c() { # LU-6441 save_writethrough $p set_cache writethrough on - local pages_per_rpc=$($LCTL get_param \ - osc.*.max_pages_per_rpc) + local pages_per_rpc=$($LCTL get_param osc.*.max_pages_per_rpc) local at_max=$($LCTL get_param -n at_max) local timeout=$($LCTL get_param -n timeout) local test_at="at_max"