From: Alex Zhuravlev Date: Thu, 16 Aug 2012 07:17:21 +0000 (+0400) Subject: LU-1304 mdt: cache statfs in mdt_device X-Git-Tag: 2.3.51~141 X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=commitdiff_plain;h=368e1b74310b98769c524909838a8eb6ab81dc5e LU-1304 mdt: cache statfs in mdt_device ... and save few cycles Signed-off-by: Alex Zhuravlev Change-Id: Ib3727c7419cfdfa393a2c1c72770ef960b1d05e6 Reviewed-on: http://review.whamcloud.com/3780 Tested-by: Hudson Reviewed-by: Jinshan Xiong Tested-by: Maloo Reviewed-by: Andreas Dilger --- diff --git a/lustre/mdt/mdt_handler.c b/lustre/mdt/mdt_handler.c index 9d9c84d..11c7a76 100644 --- a/lustre/mdt/mdt_handler.c +++ b/lustre/mdt/mdt_handler.c @@ -383,12 +383,30 @@ static int mdt_statfs(struct mdt_thread_info *info) 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); diff --git a/lustre/mdt/mdt_internal.h b/lustre/mdt/mdt_internal.h index 410b9df..52ba781 100644 --- a/lustre/mdt/mdt_internal.h +++ b/lustre/mdt/mdt_internal.h @@ -158,6 +158,11 @@ struct mdt_device { 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; @@ -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() */ - cfs_kstatfs_t ksfs; /* for mdt_statfs() */ + struct obd_statfs osfs; /* for mdt_statfs() */ struct { /* for mdt_readpage() */ struct lu_rdpg mti_rdpg;