From 4aae212bb2aa980be7a11df0543b3ad539a90912 Mon Sep 17 00:00:00 2001 From: Lai Siyao Date: Fri, 18 Sep 2020 17:53:17 +0800 Subject: [PATCH] LU-13970 llite: add option to disable Lustre inode cache A tunable option is added to disable Lustre inode cache: "llite.*.inode_cache=0" (default =1) When it's turned off, ll_drop_inode() always returns 1, then the last iput() will release inode. Add sanity test_433. Signed-off-by: Lai Siyao Change-Id: I0642bdc694dc365a05395c3fae98131e1e7723c6 Reviewed-on: https://review.whamcloud.com/39973 Reviewed-by: Andreas Dilger Tested-by: jenkins Tested-by: Maloo Reviewed-by: Olaf Faaland-LLNL --- lustre/llite/llite_internal.h | 3 ++- lustre/llite/llite_lib.c | 1 + lustre/llite/lproc_llite.c | 31 +++++++++++++++++++++++++++++++ lustre/llite/super25.c | 7 ++++++- lustre/tests/sanity.sh | 39 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 79 insertions(+), 2 deletions(-) diff --git a/lustre/llite/llite_internal.h b/lustre/llite/llite_internal.h index 1318639..796a4a8 100644 --- a/lustre/llite/llite_internal.h +++ b/lustre/llite/llite_internal.h @@ -691,7 +691,8 @@ struct ll_sb_info { unsigned int ll_xattr_cache_enabled:1, ll_xattr_cache_set:1, /* already set to 0/1 */ ll_client_common_fill_super_succeeded:1, - ll_checksum_set:1; + ll_checksum_set:1, + ll_inode_cache_enabled:1; struct lustre_client_ocd ll_lco; diff --git a/lustre/llite/llite_lib.c b/lustre/llite/llite_lib.c index 2456745..ff70403 100644 --- a/lustre/llite/llite_lib.c +++ b/lustre/llite/llite_lib.c @@ -452,6 +452,7 @@ static int client_common_fill_super(struct super_block *sb, char *md, char *dt) sb->s_blocksize_bits = log2(osfs->os_bsize); sb->s_magic = LL_SUPER_MAGIC; sb->s_maxbytes = MAX_LFS_FILESIZE; + sbi->ll_inode_cache_enabled = 1; sbi->ll_namelen = osfs->os_namelen; sbi->ll_mnt.mnt = current->fs->root.mnt; sbi->ll_mnt_ns = current->nsproxy->mnt_ns; diff --git a/lustre/llite/lproc_llite.c b/lustre/llite/lproc_llite.c index 8e972c7..abe3b93 100644 --- a/lustre/llite/lproc_llite.c +++ b/lustre/llite/lproc_llite.c @@ -1472,6 +1472,36 @@ static ssize_t opencache_max_ms_store(struct kobject *kobj, } LUSTRE_RW_ATTR(opencache_max_ms); +static ssize_t inode_cache_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, "%u\n", sbi->ll_inode_cache_enabled); +} + +static ssize_t inode_cache_store(struct kobject *kobj, + struct attribute *attr, + const char *buffer, + size_t count) +{ + struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info, + ll_kset.kobj); + bool val; + int rc; + + rc = kstrtobool(buffer, &val); + if (rc) + return rc; + + sbi->ll_inode_cache_enabled = val; + + return count; +} +LUSTRE_RW_ATTR(inode_cache); + static int ll_unstable_stats_seq_show(struct seq_file *m, void *v) { struct super_block *sb = m->private; @@ -1728,6 +1758,7 @@ static struct attribute *llite_attrs[] = { &lustre_attr_opencache_threshold_count.attr, &lustre_attr_opencache_threshold_ms.attr, &lustre_attr_opencache_max_ms.attr, + &lustre_attr_inode_cache.attr, NULL, }; diff --git a/lustre/llite/super25.c b/lustre/llite/super25.c index bf4d3ea..1cd850e 100644 --- a/lustre/llite/super25.c +++ b/lustre/llite/super25.c @@ -73,8 +73,13 @@ static void ll_destroy_inode(struct inode *inode) static int ll_drop_inode(struct inode *inode) { - int drop = generic_drop_inode(inode); + struct ll_sb_info *sbi = ll_i2sbi(inode); + int drop; + if (!sbi->ll_inode_cache_enabled) + return 1; + + drop = generic_drop_inode(inode); if (!drop) drop = llcrypt_drop_inode(inode); diff --git a/lustre/tests/sanity.sh b/lustre/tests/sanity.sh index 9a8de64..7130179 100755 --- a/lustre/tests/sanity.sh +++ b/lustre/tests/sanity.sh @@ -26859,6 +26859,45 @@ test_432() { } run_test 432 "mv dir from outside Lustre" +test_433() { + [ $PARALLEL == "yes" ] && skip "skip parallel run" + + [[ -n "$($LCTL list_param llite.*.inode_cache 2>/dev/null)" ]] || + skip "inode cache not supported" + + $LCTL set_param llite.*.inode_cache=0 + stack_trap "$LCTL set_param llite.*.inode_cache=1" + + local count=256 + local before + local after + + cancel_lru_locks mdc + test_mkdir $DIR/$tdir || error "mkdir $tdir" + createmany -m $DIR/$tdir/f $count + createmany -d $DIR/$tdir/d $count + ls -l $DIR/$tdir > /dev/null + stack_trap "rm -rf $DIR/$tdir" + + before=$(num_objects) + cancel_lru_locks mdc + after=$(num_objects) + + # sometimes even @before is less than 2 * count + while (( before - after < count )); do + sleep 1 + after=$(num_objects) + wait=$((wait + 1)) + (( wait % 5 == 0 )) && echo "wait $wait seconds objects: $after" + if (( wait > 60 )); then + error "inode slab grew from $before to $after" + fi + done + + echo "lustre_inode_cache $before objs before lock cancel, $after after" +} +run_test 433 "ldlm lock cancel releases dentries and inodes" + prep_801() { [[ $MDS1_VERSION -lt $(version_code 2.9.55) ]] || [[ $OST1_VERSION -lt $(version_code 2.9.55) ]] && -- 1.8.3.1