📄 lov_qos.c
字号:
/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*- * vim:expandtab:shiftwidth=8:tabstop=8: * * Copyright (C) 2002, 2003 Cluster File Systems, Inc. * * This file is part of the Lustre file system, http://www.lustre.org * Lustre is a trademark of Cluster File Systems, Inc. * * You may have signed or agreed to another license before downloading * this software. If so, you are bound by the terms and conditions * of that agreement, and the following does not apply to you. See the * LICENSE file included with this distribution for more information. * * If you did not agree to a different license, then this copy of Lustre * is open source software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * In either case, Lustre is distributed in the hope that it will be * useful, but WITHOUT ANY WARRANTY; without even the implied warranty * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * license text for more details. */#ifndef EXPORT_SYMTAB# define EXPORT_SYMTAB#endif#define DEBUG_SUBSYSTEM S_LOV#ifdef __KERNEL__#include <libcfs/libcfs.h>#else#include <liblustre.h>#endif#include <obd_class.h>#include <obd_lov.h>#include "lov_internal.h"/* #define QOS_DEBUG 1 */#define D_QOS D_OTHER#define TGT_BAVAIL(i) (lov->lov_tgts[i]->ltd_exp->exp_obd->obd_osfs.os_bavail*\ lov->lov_tgts[i]->ltd_exp->exp_obd->obd_osfs.os_bsize)#define TGT_FFREE(i) (lov->lov_tgts[i]->ltd_exp->exp_obd->obd_osfs.os_ffree)int qos_add_tgt(struct obd_device *obd, __u32 index){ struct lov_obd *lov = &obd->u.lov; struct lov_qos_oss *oss, *temposs; struct obd_export *exp = lov->lov_tgts[index]->ltd_exp; int rc = 0, found = 0; ENTRY; /* We only need this QOS struct on MDT, not clients - but we may not * have registered the LOV's observer yet, so there's no way to know */ if (!exp || !exp->exp_connection) { CERROR("Missing connection\n"); RETURN(-ENOTCONN); } down_write(&lov->lov_qos.lq_rw_sem); mutex_down(&lov->lov_lock); list_for_each_entry(oss, &lov->lov_qos.lq_oss_list, lqo_oss_list) { if (obd_uuid_equals(&oss->lqo_uuid, &exp->exp_connection->c_remote_uuid)) { found++; break; } } if (!found) { OBD_ALLOC_PTR(oss); if (!oss) GOTO(out, rc = -ENOMEM); memcpy(&oss->lqo_uuid, &exp->exp_connection->c_remote_uuid, sizeof(oss->lqo_uuid)); } else { /* Assume we have to move this one */ list_del(&oss->lqo_oss_list); } oss->lqo_ost_count++; lov->lov_tgts[index]->ltd_qos.ltq_oss = oss; /* Add sorted by # of OSTs. Find the first entry that we're bigger than... */ list_for_each_entry(temposs, &lov->lov_qos.lq_oss_list, lqo_oss_list) { if (oss->lqo_ost_count > temposs->lqo_ost_count) break; } /* ...and add before it. If we're the first or smallest, temposs points to the list head, and we add to the end. */ list_add_tail(&oss->lqo_oss_list, &temposs->lqo_oss_list); lov->lov_qos.lq_dirty = 1; lov->lov_qos.lq_dirty_rr = 1; CDEBUG(D_QOS, "add tgt %s to OSS %s (%d OSTs)\n", obd_uuid2str(&lov->lov_tgts[index]->ltd_uuid), obd_uuid2str(&oss->lqo_uuid), oss->lqo_ost_count);out: mutex_up(&lov->lov_lock); up_write(&lov->lov_qos.lq_rw_sem); RETURN(rc);}int qos_del_tgt(struct obd_device *obd, __u32 index){ struct lov_obd *lov = &obd->u.lov; struct lov_qos_oss *oss; int rc = 0; ENTRY; if (!lov->lov_tgts[index]) RETURN(0); down_write(&lov->lov_qos.lq_rw_sem); oss = lov->lov_tgts[index]->ltd_qos.ltq_oss; if (!oss) GOTO(out, rc = -ENOENT); oss->lqo_ost_count--; if (oss->lqo_ost_count == 0) { CDEBUG(D_QOS, "removing OSS %s\n", obd_uuid2str(&oss->lqo_uuid)); list_del(&oss->lqo_oss_list); OBD_FREE_PTR(oss); } lov->lov_qos.lq_dirty = 1; lov->lov_qos.lq_dirty_rr = 1;out: up_write(&lov->lov_qos.lq_rw_sem); RETURN(rc);}/* Recalculate per-object penalties for OSSs and OSTs, depends on size of each ost in an oss */static int qos_calc_ppo(struct obd_device *obd){ struct lov_obd *lov = &obd->u.lov; struct lov_qos_oss *oss; __u64 ba_max, ba_min, temp; __u32 num_active; int rc, i, prio_wide; ENTRY; if (!lov->lov_qos.lq_dirty) GOTO(out, rc = 0); num_active = lov->desc.ld_active_tgt_count - 1; if (num_active < 1) GOTO(out, rc = -EAGAIN); /* find bavail on each OSS */ list_for_each_entry(oss, &lov->lov_qos.lq_oss_list, lqo_oss_list) { oss->lqo_bavail = 0; } lov->lov_qos.lq_active_oss_count = 0; /* How badly user wants to select osts "widely" (not recently chosen and not on recent oss's). As opposed to "freely" (free space avail.) 0-256. */ prio_wide = 256 - lov->lov_qos.lq_prio_free; ba_min = (__u64)(-1); ba_max = 0; /* Calculate OST penalty per object */ /* (lov ref taken in alloc_qos) */ for (i = 0; i < lov->desc.ld_tgt_count; i++) { if (!lov->lov_tgts[i] || !lov->lov_tgts[i]->ltd_active) continue; temp = TGT_BAVAIL(i); if (!temp) continue; ba_min = min(temp, ba_min); ba_max = max(temp, ba_max); /* Count the number of usable OSS's */ if (lov->lov_tgts[i]->ltd_qos.ltq_oss->lqo_bavail == 0) lov->lov_qos.lq_active_oss_count++; lov->lov_tgts[i]->ltd_qos.ltq_oss->lqo_bavail += temp; /* per-OST penalty is prio * TGT_bavail / (num_ost - 1) / 2 */ temp >>= 1; do_div(temp, num_active); lov->lov_tgts[i]->ltd_qos.ltq_penalty_per_obj = (temp * prio_wide) >> 8; if (lov->lov_qos.lq_reset == 0) lov->lov_tgts[i]->ltd_qos.ltq_penalty = 0; } num_active = lov->lov_qos.lq_active_oss_count - 1; if (num_active < 1) { /* If there's only 1 OSS, we can't penalize it, so instead we have to double the OST penalty */ num_active = 1; for (i = 0; i < lov->desc.ld_tgt_count; i++) if (lov->lov_tgts[i]) lov->lov_tgts[i]->ltd_qos.ltq_penalty_per_obj <<= 1; } /* Per-OSS penalty is prio * oss_avail / oss_osts / (num_oss - 1) / 2 */ list_for_each_entry(oss, &lov->lov_qos.lq_oss_list, lqo_oss_list) { temp = oss->lqo_bavail >> 1; do_div(temp, oss->lqo_ost_count * num_active); oss->lqo_penalty_per_obj = (temp * prio_wide) >> 8; if (lov->lov_qos.lq_reset == 0) oss->lqo_penalty = 0; } lov->lov_qos.lq_dirty = 0; lov->lov_qos.lq_reset = 0; /* If each ost has almost same free space, * do rr allocation for better creation performance */ lov->lov_qos.lq_same_space = 0; temp = ba_max - ba_min; ba_min = (ba_min * 51) >> 8; /* 51/256 = .20 */ if (temp < ba_min) { /* Difference is less than 20% */ lov->lov_qos.lq_same_space = 1; /* Reset weights for the next time we enter qos mode */ lov->lov_qos.lq_reset = 0; } rc = 0;out: if (!rc && lov->lov_qos.lq_same_space) RETURN(-EAGAIN); RETURN(rc);}static int qos_calc_weight(struct lov_obd *lov, int i){ __u64 temp, temp2; /* Final ost weight = TGT_BAVAIL - ost_penalty - oss_penalty */ temp = TGT_BAVAIL(i); temp2 = lov->lov_tgts[i]->ltd_qos.ltq_penalty + lov->lov_tgts[i]->ltd_qos.ltq_oss->lqo_penalty; if (temp < temp2) lov->lov_tgts[i]->ltd_qos.ltq_weight = 0; else lov->lov_tgts[i]->ltd_qos.ltq_weight = temp - temp2; return 0;}/* We just used this index for a stripe; adjust everyone's weights */static int qos_used(struct lov_obd *lov, __u32 index, __u64 *total_wt){ struct lov_qos_oss *oss; int i; ENTRY; /* Don't allocate from this stripe anymore, until the next alloc_qos */ lov->lov_tgts[index]->ltd_qos.ltq_usable = 0; oss = lov->lov_tgts[index]->ltd_qos.ltq_oss; /* Decay old penalty by half (we're adding max penalty, and don't want it to run away.) */ lov->lov_tgts[index]->ltd_qos.ltq_penalty >>= 1; oss->lqo_penalty >>= 1; /* Set max penalties for this OST and OSS */ lov->lov_tgts[index]->ltd_qos.ltq_penalty += lov->lov_tgts[index]->ltd_qos.ltq_penalty_per_obj * lov->desc.ld_active_tgt_count; oss->lqo_penalty += oss->lqo_penalty_per_obj * lov->lov_qos.lq_active_oss_count; /* Decrease all OSS penalties */ list_for_each_entry(oss, &lov->lov_qos.lq_oss_list, lqo_oss_list) { if (oss->lqo_penalty < oss->lqo_penalty_per_obj) oss->lqo_penalty = 0; else oss->lqo_penalty -= oss->lqo_penalty_per_obj; } *total_wt = 0; /* Decrease all OST penalties */ for (i = 0; i < lov->desc.ld_tgt_count; i++) { if (!lov->lov_tgts[i] || !lov->lov_tgts[i]->ltd_active) continue; if (lov->lov_tgts[i]->ltd_qos.ltq_penalty < lov->lov_tgts[i]->ltd_qos.ltq_penalty_per_obj) lov->lov_tgts[i]->ltd_qos.ltq_penalty = 0; else lov->lov_tgts[i]->ltd_qos.ltq_penalty -= lov->lov_tgts[i]->ltd_qos.ltq_penalty_per_obj; qos_calc_weight(lov, i); /* Recalc the total weight of usable osts */ if (lov->lov_tgts[i]->ltd_qos.ltq_usable) *total_wt += lov->lov_tgts[i]->ltd_qos.ltq_weight;#ifdef QOS_DEBUG CDEBUG(D_QOS, "recalc tgt %d avail="LPU64 " ostppo="LPU64" ostp="LPU64" ossppo="LPU64 " ossp="LPU64" wt="LPU64"\n", i, TGT_BAVAIL(i) >> 10, lov->lov_tgts[i]->ltd_qos.ltq_penalty_per_obj >> 10, lov->lov_tgts[i]->ltd_qos.ltq_penalty >> 10, lov->lov_tgts[i]->ltd_qos.ltq_oss->lqo_penalty_per_obj>>10, lov->lov_tgts[i]->ltd_qos.ltq_oss->lqo_penalty>>10, lov->lov_tgts[i]->ltd_qos.ltq_weight>>10);#endif } RETURN(0);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -