std::optional CgroupContext::getIoCostCumulative()

in src/oomd/CgroupContext.cpp [407:438]


std::optional<double> CgroupContext::getIoCostCumulative(Error* err) const {
  if (!io_stat(err)) {
    return std::nullopt;
  }
  const auto& params = ctx_.getParams();
  double cost = 0.0;
  // calculate the sum of cumulative io cost on all devices.
  for (const auto& stat : *io_stat()) {
    // only keep stats from devices we care
    auto dev = params.io_devs.find(stat.dev_id);
    if (dev == params.io_devs.end()) {
      continue;
    }
    IOCostCoeffs coeffs;
    switch (dev->second) {
      case DeviceType::SSD:
        coeffs = params.ssd_coeffs;
        break;
      case DeviceType::HDD:
        coeffs = params.hdd_coeffs;
        break;
    }
    // Dot product between dev io stat and io cost coeffs. A more sensible way
    // is to do dot product between rate of change (bandwidth, iops) with
    // coeffs but since the coeffs are constant, we can calculate rate of
    // change later.
    cost += stat.rios * coeffs.read_iops + stat.rbytes * coeffs.readbw +
        stat.wios * coeffs.write_iops + stat.wbytes * coeffs.writebw +
        stat.dios * coeffs.trim_iops + stat.dbytes * coeffs.trimbw;
  }
  return cost;
}