Whamcloud - gitweb
LU-10499 pcc: add stats for attach|detach|auto_attach 18/54418/7
authorQian Yingjin <qian@ddn.com>
Fri, 27 Aug 2021 03:46:13 +0000 (11:46 +0800)
committerOleg Drokin <green@whamcloud.com>
Sat, 13 Jul 2024 20:52:40 +0000 (20:52 +0000)
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.

EX-bug-id: EX-3715
Signed-off-by: Qian Yingjin <qian@ddn.com>
Change-Id: Ia0c1cd6b414998e72859aaf34c125b5a4e4e743c
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/54418
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: James Simmons <jsimmons@infradead.org>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lustre/llite/llite_internal.h
lustre/llite/lproc_llite.c
lustre/llite/pcc.c
lustre/tests/sanity-pcc.sh

index 9329961..fafab4d 100644 (file)
@@ -1283,6 +1283,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_HYBRID_NOSWITCH,
        LPROC_LL_HYBRID_WRITESIZE_SWITCH,
        LPROC_LL_HYBRID_READSIZE_SWITCH,
index 5c61219..52dd9b6 100644 (file)
@@ -2341,6 +2341,10 @@ 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" },
+       /* PCC I/O statistics */
+       { 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" },
        /* hybrid IO switch from buffered I/O (BIO) to direct I/O (DIO) */
        { LPROC_LL_HYBRID_NOSWITCH, LPROCFS_TYPE_REQS, "hybrid_noswitch" },
        { LPROC_LL_HYBRID_WRITESIZE_SWITCH, LPROCFS_TYPE_REQS,
index a92080c..c80aafb 100644 (file)
@@ -1910,6 +1910,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",
@@ -2012,6 +2013,9 @@ static int pcc_try_auto_attach(struct inode *inode, bool *cached,
                                             LU_PCC_READONLY, cached);
        }
 
+       if (*cached)
+               ll_stats_ops_tally(ll_i2sbi(inode), LPROC_LL_PCC_AUTOAT, 1);
+
        RETURN(rc);
 }
 
@@ -2149,6 +2153,7 @@ static inline void pcc_inode_detach(struct inode *inode)
        pcci->pcci_type = LU_PCC_NONE;
        pcc_layout_gen_set(pcci, CL_LAYOUT_GEN_NONE);
        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)
@@ -2177,7 +2182,6 @@ void pcc_layout_invalidate(struct inode *inode)
                pcc_inode_detach_put(inode);
        }
        pcc_inode_unlock(inode);
-
        EXIT;
 }
 
@@ -3004,8 +3008,6 @@ int pcc_file_mmap(struct file *file, struct vm_area_struct *vma,
                       PFID(ll_inode2fid(inode)), vma, i_size_read(inode),
                       vma->vm_end - vma->vm_start, vma->vm_pgoff,
                       vma->vm_flags);
-       } else {
-               *cached = false;
        }
 out:
        pcc_inode_unlock(inode);
@@ -3740,6 +3742,8 @@ out_unlock:
                (void) pcc_inode_remove(inode, dentry);
                revert_creds(old_cred);
                dput(dentry);
+       } else {
+               ll_stats_ops_tally(ll_i2sbi(inode), LPROC_LL_PCC_ATTACH, 1);
        }
 out_dataset_put:
        pcc_dataset_put(dataset);
@@ -3856,8 +3860,6 @@ repeat:
                        RETURN(rc);
 
                rc = ll_layout_refresh(inode, gen);
-               if (rc)
-                       RETURN(rc);
        } else { /* Readonly layout */
                struct pcc_inode *pcci;
 
@@ -3874,6 +3876,9 @@ repeat:
                        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);
@@ -3962,6 +3967,8 @@ out_put_unlock:
                        pcc_inode_put(pcci);
                else
                        dput(dentry);
+       } else {
+               ll_stats_ops_tally(ll_i2sbi(inode), LPROC_LL_PCC_ATTACH, 1);
        }
        revert_creds(old_cred);
        pcc_inode_unlock(inode);
index 3bdc18f..1f16642 100755 (executable)
@@ -3355,6 +3355,76 @@ test_42() {
 }
 run_test 42 "PCC attach without attach ID specified"
 
+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"
+
+       $LCTL get_param -n mdc.*.connect_flags | grep -q pcc_ro ||
+               skip "Server does not support PCC-RO"
+
+       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.$((RANDOM % 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 <= 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"
@@ -3544,7 +3614,7 @@ test_98() {
        setup_pcc_mapping $SINGLEAGT \
                "projid={0}\ roid=$HSM_ARCHIVE_NUMBER\ pccro=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