From: Qian Yingjin Date: Fri, 27 Aug 2021 03:46:13 +0000 (+0800) Subject: EX-3715 pcc: add stats for attach|detach|auto_attach X-Git-Url: https://git.whamcloud.com/?a=commitdiff_plain;h=a8674b29dc661d44b51433c7b308abd2b6053b45;p=fs%2Flustre-release.git EX-3715 pcc: add stats for attach|detach|auto_attach In this patch, we add stats for PCC attach, detach and auto_attach. With this feature, we verify that PCC can auto-attach the file into PCC cache without having to re-fetch the data of the whole file. Add sanity-pcc test_44. Signed-off-by: Qian Yingjin Change-Id: Ia0c1cd6b414998e72859aaf34c125b5a4e4e743c Reviewed-on: https://review.whamcloud.com/44764 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Yang Sheng Reviewed-by: Andreas Dilger --- diff --git a/lustre/llite/llite_internal.h b/lustre/llite/llite_internal.h index 2ae186d..793aa6f 100644 --- a/lustre/llite/llite_internal.h +++ b/lustre/llite/llite_internal.h @@ -1062,6 +1062,9 @@ enum { LPROC_LL_FALLOCATE, LPROC_LL_INODE_OCOUNT, LPROC_LL_INODE_OPCLTM, + LPROC_LL_PCC_ATTACH, + LPROC_LL_PCC_DETACH, + LPROC_LL_PCC_AUTOAT, LPROC_LL_FILE_OPCODES }; diff --git a/lustre/llite/lproc_llite.c b/lustre/llite/lproc_llite.c index ff47947..9ab644a 100644 --- a/lustre/llite/lproc_llite.c +++ b/lustre/llite/lproc_llite.c @@ -1824,6 +1824,9 @@ static const struct llite_file_opcode { { LPROC_LL_LISTXATTR, LPROCFS_TYPE_LATENCY, "listxattr" }, { LPROC_LL_REMOVEXATTR, LPROCFS_TYPE_LATENCY, "removexattr" }, { LPROC_LL_INODE_PERM, LPROCFS_TYPE_LATENCY, "inode_permission" }, + { LPROC_LL_PCC_ATTACH, LPROCFS_TYPE_REQS, "pcc_attach" }, + { LPROC_LL_PCC_DETACH, LPROCFS_TYPE_REQS, "pcc_detach" }, + { LPROC_LL_PCC_AUTOAT, LPROCFS_TYPE_REQS, "pcc_auto_attach" }, }; void ll_stats_ops_tally(struct ll_sb_info *sbi, int op, long count) diff --git a/lustre/llite/pcc.c b/lustre/llite/pcc.c index 4ff9de9..4fe7b34 100644 --- a/lustre/llite/pcc.c +++ b/lustre/llite/pcc.c @@ -1877,6 +1877,7 @@ static int pcc_try_readonly_open_attach(struct inode *inode, struct file *file, pcci = ll_i2pcci(inode); if (pcci && pcc_inode_has_layout(pcci)) *cached = true; + if (rc) { CDEBUG(D_CACHE, "Failed to try PCC-RO attach "DFID", rc = %d\n", @@ -1974,6 +1975,9 @@ static int pcc_try_auto_attach(struct inode *inode, bool *cached, rc = pcc_try_datasets_attach(inode, iot, clt.cl_layout_gen, LU_PCC_READONLY, cached); + if (*cached) + ll_stats_ops_tally(ll_i2sbi(inode), LPROC_LL_PCC_AUTOAT, 1); + RETURN(rc); } @@ -2097,6 +2101,7 @@ static inline void pcc_inode_detach(struct inode *inode) { __pcc_layout_invalidate(ll_i2pcci(inode)); pcc_inode_mapping_reset(inode); + ll_stats_ops_tally(ll_i2sbi(inode), LPROC_LL_PCC_DETACH, 1); } static inline void pcc_inode_detach_put(struct inode *inode) @@ -2125,7 +2130,6 @@ void pcc_layout_invalidate(struct inode *inode) pcc_inode_detach_put(inode); } pcc_inode_unlock(inode); - EXIT; } @@ -3579,6 +3583,8 @@ out_dentry: if (rc) { pcc_inode_remove(inode, *dentry); dput(*dentry); + } else { + ll_stats_ops_tally(ll_i2sbi(inode), LPROC_LL_PCC_ATTACH, 1); } out_cred: revert_creds(old_cred); @@ -3693,7 +3699,7 @@ out_unlock: RETURN(rc); } -static int pcc_layout_rdonly_set(struct inode *inode, __u32 *gen) +static int pcc_layout_rdonly_set(struct inode *inode, __u32 *gen, bool *cached) { struct ll_inode_info *lli = ll_i2info(inode); @@ -3747,10 +3753,25 @@ repeat: RETURN(rc); rc = ll_layout_refresh(inode, gen); - if (rc) - RETURN(rc); } else { /* Readonly layout */ + struct pcc_inode *pcci; + *gen = clt.cl_layout_gen; + /* + * The file is already in readonly state, give a chance to + * try auto attach. + */ + pcc_inode_lock(inode); + pcci = ll_i2pcci(inode); + if (pcci && pcc_inode_has_layout(pcci)) + *cached = true; + else + rc = pcc_try_datasets_attach(inode, PIT_OPEN, *gen, + LU_PCC_READONLY, cached); + pcc_inode_unlock(inode); + if (*cached) + ll_stats_ops_tally(ll_i2sbi(inode), + LPROC_LL_PCC_AUTOAT, 1); } RETURN(rc); @@ -3763,16 +3784,19 @@ static int pcc_readonly_attach(struct file *file, struct ll_inode_info *lli = ll_i2info(inode); const struct cred *old_cred; struct pcc_dataset *dataset; - struct pcc_inode *pcci; + struct pcc_inode *pcci = NULL; struct dentry *dentry; bool attached = false; bool unlinked = false; + bool cached = false; __u32 gen; int rc; ENTRY; - rc = pcc_layout_rdonly_set(inode, &gen); + rc = pcc_layout_rdonly_set(inode, &gen, &cached); + if (cached) + RETURN(0); if (rc) RETURN(rc); @@ -3801,6 +3825,15 @@ static int pcc_readonly_attach(struct file *file, pcc_inode_attach_set(super, dataset, lli, pcci, dentry, LU_PCC_READONLY); + } else if (pcc_inode_has_layout(pcci)) { + /* + * There may be a gap between auto attach and auto open cache: + * ->pcc_file_open() + * ->pcc_try_auto_attach() + * The file is re-attach into PCC by other thread. + * ->pcc_try_readonly_open_attach() + */ + GOTO(out_put_unlock, rc = -EEXIST); } else { atomic_inc(&pcci->pcci_refcount); path_put(&pcci->pcci_path); diff --git a/lustre/tests/sanity-pcc.sh b/lustre/tests/sanity-pcc.sh index a1d73b7..106b526 100644 --- a/lustre/tests/sanity-pcc.sh +++ b/lustre/tests/sanity-pcc.sh @@ -3346,6 +3346,73 @@ test_43() { } run_test 43 "Auto attach at open() should add capacity owner check" +test_44() { + local loopfile="$TMP/$tfile" + local mntpt="/mnt/pcc.$tdir" + local hsm_root="$mntpt/$tdir" + local file=$DIR/$tfile + local count=50 + local bs="1M" + + setup_loopdev client $loopfile $mntpt 60 + mkdir $hsm_root || error "mkdir $hsm_root failed" + setup_pcc_mapping client \ + "projid={0}\ roid=$HSM_ARCHIVE_NUMBER\ ropcc=1\ mmap_conv=0" + $LCTL pcc list $MOUNT + $LCTL set_param llite.*.pcc_async_threshold=1G + + dd if=/dev/zero of=$file bs=$bs count=$count || + error "Write $file failed" + + local n=16 + local lpid + local -a rpids + + $LFS getstripe -v $file + clear_stats llite.*.stats + + for ((i = 0; i < $n; i++)); do + ( + while [ ! -e $DIR/$tfile.lck ]; do + dd if=$file of=/dev/null bs=$bs count=$count || + error "Read $file failed" + sleep 0.$((RANDON % 4 + 1)) + done + )& + rpids[$i]=$! + done + + ( + while [ ! -e $DIR/$tfile.lck ]; do + $LCTL set_param -n ldlm.namespaces.*mdc*.lru_size=clear || + error "cancel_lru_locks mdc failed" + sleep 0.2 + done + )& + lpid=$! + + sleep 60 + touch $DIR/$tfile.lck + + for ((i = 0; i < $n; i++)); do + wait ${rpids[$i]} || error "$?: read failed" + done + wait $lpid || error "$?: lock cancel failed" + + echo "Finish ========" + $LFS getstripe -v $file + $LCTL get_param llite.*.stats + + local attach_num=$(calc_stats llite.*.stats pcc_attach) + local detach_num=$(calc_stats llite.*.stats pcc_detach) + local autoat_num=$(calc_stats llite.*.stats pcc_auto_attach) + + echo "attach $attach_num detach $detach_num auto_attach $autoat_num" + [ $attach_num -eq 1 ] || error "attach more than 1 time: $attach_num" + rm -f $DIR/$tfile.lck +} +run_test 44 "Verify valid auto attach without re-fetching the whole files" + test_96() { local loopfile="$TMP/$tfile" local mntpt="/mnt/pcc.$tdir" @@ -3525,7 +3592,7 @@ test_98() { setup_pcc_mapping $SINGLEAGT \ "projid={0}\ roid=$HSM_ARCHIVE_NUMBER\ ropcc=1\ mmap_conv=0" do_facet $SINGLEAGT $LCTL pcc list $MOUNT - do_facet $SINGLEAGT $LCTL set_param llite.*.pcc_async_threshold=1G + do_facet $SINGLEAGT $LCTL set_param llite.*.pcc_async_threshold=0 local rpid1 local rpid2