Whamcloud - gitweb
New tag 2.15.63
[fs/lustre-release.git] / lustre / obdclass / lu_tgt_descs.c
index d872db4..0062ded 100644 (file)
  *
  */
 
-#define DEBUG_SUBSYSTEM S_CLASS
+#define DEBUG_SUBSYSTEM S_LOV
 
 #include <linux/module.h>
 #include <linux/list.h>
 #include <linux/random.h>
 #include <libcfs/libcfs.h>
-#include <libcfs/libcfs_hash.h> /* hash_long() */
 #include <libcfs/linux/linux-mem.h>
 #include <obd_class.h>
 #include <obd_support.h>
@@ -57,21 +56,23 @@ u64 lu_prandom_u64_max(u64 ep_ro)
        u64 rand = 0;
 
        if (ep_ro) {
-#if BITS_PER_LONG == 32
+#ifdef HAVE_GET_RANDOM_U32_AND_U64
+               rand = get_random_u64() % ep_ro;
+#elif BITS_PER_LONG == 32
                /*
                 * If ep_ro > 32-bit, first generate the high
                 * 32 bits of the random number, then add in the low
                 * 32 bits (truncated to the upper limit, if needed)
                 */
                if (ep_ro > 0xffffffffULL)
-                       rand = (u64)prandom_u32_max((u32)(ep_ro >> 32)) << 32;
+                       rand = (u64)get_random_u32_below((u32)(ep_ro >> 32)) << 32;
 
                if (rand == (ep_ro & 0xffffffff00000000ULL))
-                       rand |= prandom_u32_max((u32)ep_ro);
+                       rand |= get_random_u32_below((u32)ep_ro);
                else
-                       rand |= prandom_u32();
+                       rand |= get_random_u32();
 #else
-               rand = ((u64)prandom_u32() << 32 | prandom_u32()) % ep_ro;
+               rand = ((u64)get_random_u32() << 32 | get_random_u32()) % ep_ro;
 #endif
        }
 
@@ -175,7 +176,7 @@ EXPORT_SYMBOL(lu_qos_add_tgt);
  * \retval 0                   on success
  * \retval -ENOENT             if no server was found
  */
-static int lu_qos_del_tgt(struct lu_qos *qos, struct lu_tgt_desc *ltd)
+int lu_qos_del_tgt(struct lu_qos *qos, struct lu_tgt_desc *ltd)
 {
        struct lu_svr_qos *svr;
        int rc = 0;
@@ -187,12 +188,12 @@ static int lu_qos_del_tgt(struct lu_qos *qos, struct lu_tgt_desc *ltd)
        if (!svr)
                GOTO(out, rc = -ENOENT);
 
+       ltd->ltd_qos.ltq_svr = NULL;
        svr->lsq_tgt_count--;
        if (svr->lsq_tgt_count == 0) {
                CDEBUG(D_OTHER, "removing server %s\n",
                       obd_uuid2str(&svr->lsq_uuid));
                list_del(&svr->lsq_svr_list);
-               ltd->ltd_qos.ltq_svr = NULL;
                OBD_FREE_PTR(svr);
        }
 
@@ -204,35 +205,31 @@ out:
        up_write(&qos->lq_rw_sem);
        RETURN(rc);
 }
-
-static inline __u64 tgt_statfs_bavail(struct lu_tgt_desc *tgt)
-{
-       struct obd_statfs *statfs = &tgt->ltd_statfs;
-
-       return statfs->os_bavail * statfs->os_bsize;
-}
-
-static inline __u64 tgt_statfs_iavail(struct lu_tgt_desc *tgt)
-{
-       return tgt->ltd_statfs.os_ffree;
-}
+EXPORT_SYMBOL(lu_qos_del_tgt);
 
 /**
  * Calculate weight for a given tgt.
  *
- * The final tgt weight is bavail >> 16 * iavail >> 8 minus the tgt and server
- * penalties.  See ltd_qos_penalties_calc() for how penalties are calculated.
+ * The final tgt weight uses only free space for OSTs, but combines
+ * both free space and inodes for MDTs, minus tgt and server penalties.
+ * See ltd_qos_penalties_calc() for how penalties are calculated.
  *
  * \param[in] tgt      target descriptor
+ * \param[in] is_mdt   target table is for MDT selection (use inodes)
  */
-void lu_tgt_qos_weight_calc(struct lu_tgt_desc *tgt)
+void lu_tgt_qos_weight_calc(struct lu_tgt_desc *tgt, bool is_mdt)
 {
        struct lu_tgt_qos *ltq = &tgt->ltd_qos;
        __u64 penalty;
 
-       ltq->ltq_avail = (tgt_statfs_bavail(tgt) >> 16) *
-                        (tgt_statfs_iavail(tgt) >> 8);
+       if (is_mdt)
+               ltq->ltq_avail = (tgt_statfs_bavail(tgt) >> 16) *
+                                (tgt_statfs_iavail(tgt) >> 8);
+       else
+               ltq->ltq_avail = tgt_statfs_bavail(tgt) >> 8;
        penalty = ltq->ltq_penalty + ltq->ltq_svr->lsq_penalty;
+       CDEBUG(D_OTHER, "ltq_penalty: %llu lsq_penalty: %llu tgt_bavail: %llu\n",
+                 ltq->ltq_penalty, ltq->ltq_svr->lsq_penalty, ltq->ltq_avail);
        if (ltq->ltq_avail < penalty)
                ltq->ltq_weight = 0;
        else
@@ -283,11 +280,13 @@ int lu_tgt_descs_init(struct lu_tgt_descs *ltd, bool is_mdt)
                ltd->ltd_lmv_desc.ld_pattern = LMV_HASH_TYPE_DEFAULT;
                ltd->ltd_qos.lq_prio_free = LMV_QOS_DEF_PRIO_FREE * 256 / 100;
                ltd->ltd_qos.lq_threshold_rr =
-                       LMV_QOS_DEF_THRESHOLD_RR_PCT * 256 / 100;
+                       LMV_QOS_DEF_THRESHOLD_RR_PCT *
+                       QOS_THRESHOLD_MAX / 100;
        } else {
                ltd->ltd_qos.lq_prio_free = LOV_QOS_DEF_PRIO_FREE * 256 / 100;
                ltd->ltd_qos.lq_threshold_rr =
-                       LOV_QOS_DEF_THRESHOLD_RR_PCT * 256 / 100;
+                       LOV_QOS_DEF_THRESHOLD_RR_PCT *
+                       QOS_THRESHOLD_MAX / 100;
        }
 
        return 0;
@@ -426,7 +425,7 @@ EXPORT_SYMBOL(ltd_del_tgt);
  * Calculate penalties per-tgt and per-server
  *
  * Re-calculate penalties when the configuration changes, active targets
- * change and after statfs refresh (all these are reflected by lq_dirty flag).
+ * change and after statfs refresh (all these are reflected by LQ_DIRTY flag).
  * On every tgt and server: decay the penalty by half for every 8x the update
  * interval that the device has been idle. That gives lots of time for the
  * statfs information to be updated (which the penalty is only a proxy for),
@@ -518,14 +517,13 @@ int ltd_qos_penalties_calc(struct lu_tgt_descs *ltd)
 
                /*
                 * per-tgt penalty is
-                * prio * bavail * iavail / (num_tgt - 1) / 2
+                * prio * bavail * iavail / (num_tgt - 1) / prio_max / 2
                 */
-               tgt->ltd_qos.ltq_penalty_per_obj = prio_wide * ba * ia >> 8;
+               tgt->ltd_qos.ltq_penalty_per_obj = prio_wide * ba * ia >> 9;
                do_div(tgt->ltd_qos.ltq_penalty_per_obj, num_active);
-               tgt->ltd_qos.ltq_penalty_per_obj >>= 1;
 
                age = (now - tgt->ltd_qos.ltq_used) >> 3;
-               if (test_bit(LQ_RESET, &qos->lq_flags) || 
+               if (test_bit(LQ_RESET, &qos->lq_flags) ||
                    age > 32 * desc->ld_qos_maxage)
                        tgt->ltd_qos.ltq_penalty = 0;
                else if (age > desc->ld_qos_maxage)
@@ -561,7 +559,7 @@ int ltd_qos_penalties_calc(struct lu_tgt_descs *ltd)
                svr->lsq_penalty_per_obj >>= 1;
 
                age = (now - svr->lsq_used) >> 3;
-               if (test_bit(LQ_RESET, &qos->lq_flags) || 
+               if (test_bit(LQ_RESET, &qos->lq_flags) ||
                    age > 32 * desc->ld_qos_maxage)
                        svr->lsq_penalty = 0;
                else if (age > desc->ld_qos_maxage)
@@ -569,20 +567,23 @@ int ltd_qos_penalties_calc(struct lu_tgt_descs *ltd)
                        svr->lsq_penalty >>= age / desc->ld_qos_maxage;
        }
 
-       clear_bit(LQ_DIRTY, &qos->lq_flags);
-       clear_bit(LQ_RESET, &qos->lq_flags);
 
        /*
         * If each tgt has almost same free space, do rr allocation for better
         * creation performance
         */
-       clear_bit(LQ_SAME_SPACE, &qos->lq_flags);
-       if ((ba_max * (256 - qos->lq_threshold_rr)) >> 8 < ba_min &&
-           (ia_max * (256 - qos->lq_threshold_rr)) >> 8 < ia_min) {
+       if (((ba_max * (QOS_THRESHOLD_MAX - qos->lq_threshold_rr)) /
+           QOS_THRESHOLD_MAX) < ba_min &&
+           ((ia_max * (QOS_THRESHOLD_MAX - qos->lq_threshold_rr)) /
+           QOS_THRESHOLD_MAX) < ia_min) {
                set_bit(LQ_SAME_SPACE, &qos->lq_flags);
                /* Reset weights for the next time we enter qos mode */
                set_bit(LQ_RESET, &qos->lq_flags);
+       } else {
+               clear_bit(LQ_SAME_SPACE, &qos->lq_flags);
+               clear_bit(LQ_RESET, &qos->lq_flags);
        }
+       clear_bit(LQ_DIRTY, &qos->lq_flags);
        rc = 0;
 
 out:
@@ -636,8 +637,15 @@ int ltd_qos_update(struct lu_tgt_descs *ltd, struct lu_tgt_desc *tgt,
        /* Set max penalties for this tgt and server */
        ltq->ltq_penalty += ltq->ltq_penalty_per_obj *
                            ltd->ltd_lov_desc.ld_active_tgt_count;
+       CDEBUG(D_OTHER, "ltq_penalty: %llu per_obj: %llu tgt_count: %d\n",
+              ltq->ltq_penalty, ltq->ltq_penalty_per_obj,
+              ltd->ltd_lov_desc.ld_active_tgt_count);
        svr->lsq_penalty += svr->lsq_penalty_per_obj *
                            qos->lq_active_svr_count;
+       CDEBUG(D_OTHER, "lsq_penalty: %llu per_obj: %llu srv_count: %d\n",
+              svr->lsq_penalty, svr->lsq_penalty_per_obj,
+              qos->lq_active_svr_count);
+
 
        /* Decrease all MDS penalties */
        list_for_each_entry(svr, &qos->lq_svr_list, lsq_svr_list) {
@@ -659,7 +667,7 @@ int ltd_qos_update(struct lu_tgt_descs *ltd, struct lu_tgt_desc *tgt,
                else
                        ltq->ltq_penalty -= ltq->ltq_penalty_per_obj;
 
-               lu_tgt_qos_weight_calc(tgt);
+               lu_tgt_qos_weight_calc(tgt, ltd->ltd_is_mdt);
 
                /* Recalc the total weight of usable osts */
                if (ltq->ltq_usable)