Beispiel #1
0
// Cpu
void TCpuSubsystem::InitializeSubsystem() {
    TCgroup cg = RootCgroup();

    HasShares = cg.Has("cpu.shares");
    if (HasShares && cg.GetUint64("cpu.shares", BaseShares))
        BaseShares = 1024;

    HasQuota = cg.Has("cpu.cfs_quota_us") &&
               cg.Has("cpu.cfs_period_us");

    HasReserve = HasShares && HasQuota &&
                 cg.Has("cpu.cfs_reserve_us") &&
                 cg.Has("cpu.cfs_reserve_shares");

    if (HasQuota && cg.GetUint64("cpu.cfs_period_us", BasePeriod))
        BasePeriod = 100000;

    HasSmart = cg.Has("cpu.smart");

    L_SYS() << GetNumCores() << " cores" << std::endl;
    if (HasShares)
        L_SYS() << "base shares " << BaseShares << std::endl;
    if (HasQuota)
        L_SYS() << "quota period " << BasePeriod << std::endl;
    if (HasReserve)
        L_SYS() << "support reserves" << std::endl;
    if (HasSmart)
        L_SYS() << "support smart" << std::endl;
}
Beispiel #2
0
TError TMemorySubsystem::GetAnonUsage(TCgroup &cg, uint64_t &usage) const {
    if (cg.Has(ANON_USAGE))
        return cg.GetUint64(ANON_USAGE, usage);

    TUintMap stat;
    TError error = Statistics(cg, stat);
    if (!error)
        usage = stat["total_inactive_anon"] +
                stat["total_active_anon"] +
                stat["unevictable"] +
                stat["total_swap"];
    return error;
}
Beispiel #3
0
// Memory
TError TMemorySubsystem::SetLimit(TCgroup &cg, uint64_t limit) {
    std::string str_limit = limit ? std::to_string(limit) : "-1";
    uint64_t memswap;

    /* Memory limit cannot be bigger than Memory+Swap limit. */
    if (SupportSwap() && !cg.GetUint64(MEM_SWAP_LIMIT, memswap) &&
            (!limit || memswap < limit))
        (void)cg.Set(MEM_SWAP_LIMIT, str_limit);

    /*
     * Maxumum value depends on arch, kernel version and bugs
     * "-1" works everywhere since 2.6.31
     */
    TError error = cg.Set(LIMIT, str_limit);

    if (!error && SupportSwap())
        cg.Set(MEM_SWAP_LIMIT, str_limit);

    return error;
}
Beispiel #4
0
 TError GetFailCnt(TCgroup &cg, uint64_t &cnt) {
     return cg.GetUint64(FAIL_CNT, cnt);
 }
Beispiel #5
0
 TError GetSoftLimit(TCgroup &cg, uint64_t &limit) const {
     return cg.GetUint64(SOFT_LIMIT, limit);
 }
Beispiel #6
0
 TError Usage(TCgroup &cg, uint64_t &value) const {
     return cg.GetUint64(USAGE, value);
 }
Beispiel #7
0
 TError GetHugeUsage(TCgroup &cg, uint64_t &usage) const {
     return cg.GetUint64(HUGE_USAGE, usage);
 }