Whamcloud - gitweb
LU-1304 mdt: cache statfs in mdt_device
authorAlex Zhuravlev <bzzz@whamcloud.com>
Thu, 16 Aug 2012 07:17:21 +0000 (11:17 +0400)
committerOleg Drokin <green@whamcloud.com>
Thu, 6 Sep 2012 14:24:48 +0000 (10:24 -0400)
... and save few cycles

Signed-off-by: Alex Zhuravlev <bzzz@whamcloud.com>
Change-Id: Ib3727c7419cfdfa393a2c1c72770ef960b1d05e6
Reviewed-on: http://review.whamcloud.com/3780
Tested-by: Hudson
Reviewed-by: Jinshan Xiong <jinshan.xiong@whamcloud.com>
Tested-by: Maloo <whamcloud.maloo@gmail.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
lustre/mdt/mdt_handler.c
lustre/mdt/mdt_internal.h

index 9d9c84d..11c7a76 100644 (file)
@@ -383,12 +383,30 @@ static int mdt_statfs(struct mdt_thread_info *info)
         if (rc)
                 RETURN(err_serious(rc));
 
         if (rc)
                 RETURN(err_serious(rc));
 
-        if (OBD_FAIL_CHECK(OBD_FAIL_MDS_STATFS_PACK)) {
-                rc = err_serious(-ENOMEM);
-        } else {
-                osfs = req_capsule_server_get(info->mti_pill, &RMF_OBD_STATFS);
-                rc = next->md_ops->mdo_statfs(info->mti_env, next, osfs);
-        }
+       if (OBD_FAIL_CHECK(OBD_FAIL_MDS_STATFS_PACK))
+               RETURN(err_serious(-ENOMEM));
+
+       osfs = req_capsule_server_get(info->mti_pill, &RMF_OBD_STATFS);
+       if (!osfs)
+               RETURN(-EPROTO);
+
+       /** statfs information are cached in the mdt_device */
+       if (cfs_time_before_64(info->mti_mdt->mdt_osfs_age,
+                              cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS))) {
+               /** statfs data is too old, get up-to-date one */
+               rc = next->md_ops->mdo_statfs(info->mti_env, next, osfs);
+               if (rc)
+                       RETURN(rc);
+               cfs_spin_lock(&info->mti_mdt->mdt_osfs_lock);
+               info->mti_mdt->mdt_osfs = *osfs;
+               info->mti_mdt->mdt_osfs_age = cfs_time_current_64();
+               cfs_spin_unlock(&info->mti_mdt->mdt_osfs_lock);
+       } else {
+               /** use cached statfs data */
+               cfs_spin_lock(&info->mti_mdt->mdt_osfs_lock);
+               *osfs = info->mti_mdt->mdt_osfs;
+               cfs_spin_unlock(&info->mti_mdt->mdt_osfs_lock);
+       }
 
         if (rc == 0)
                mdt_counter_incr(req, LPROC_MDT_STATFS);
 
         if (rc == 0)
                mdt_counter_incr(req, LPROC_MDT_STATFS);
index 410b9df..52ba781 100644 (file)
@@ -158,6 +158,11 @@ struct mdt_device {
         unsigned int               mdt_capa_conf:1,
                                    mdt_som_conf:1;
 
         unsigned int               mdt_capa_conf:1,
                                    mdt_som_conf:1;
 
+       /* statfs optimization: we cache a bit  */
+       struct obd_statfs          mdt_osfs;
+       __u64                      mdt_osfs_age;
+       cfs_spinlock_t             mdt_osfs_lock;
+
         /* root squash */
         uid_t                      mdt_squash_uid;
         gid_t                      mdt_squash_gid;
         /* root squash */
         uid_t                      mdt_squash_uid;
         gid_t                      mdt_squash_gid;
@@ -369,7 +374,7 @@ struct mdt_thread_info {
                 struct obd_uuid    uuid[2];       /* for mdt_seq_init_cli()  */
                 char               ns_name[48];   /* for mdt_init0()         */
                 struct lustre_cfg_bufs bufs;      /* for mdt_stack_fini()    */
                 struct obd_uuid    uuid[2];       /* for mdt_seq_init_cli()  */
                 char               ns_name[48];   /* for mdt_init0()         */
                 struct lustre_cfg_bufs bufs;      /* for mdt_stack_fini()    */
-                cfs_kstatfs_t      ksfs;          /* for mdt_statfs()        */
+               struct obd_statfs  osfs;          /* for mdt_statfs()        */
                 struct {
                         /* for mdt_readpage()      */
                         struct lu_rdpg     mti_rdpg;
                 struct {
                         /* for mdt_readpage()      */
                         struct lu_rdpg     mti_rdpg;