Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 56c414e8 authored by Sandeep Patil's avatar Sandeep Patil
Browse files

meminfo: Remove unnecessary working set stats



The Vma and ProcMemInfo objects do not need separate stats
objects for storing working set. The Vma either has working set
or memory usage information and never both.

Bug: 111694435
Test: libmeminfo_test 1

Change-Id: I2df05f7e750bbba4325474633e705d6d68dd2ccb
Merged-In: I2df05f7e750bbba4325474633e705d6d68dd2ccb
Signed-off-by: default avatarSandeep Patil <sspatil@google.com>
parent 002f02ea
Loading
Loading
Loading
Loading
+1 −6
Original line number Original line Diff line number Diff line
@@ -72,15 +72,10 @@ struct Vma {
        : start(s), end(e), offset(off), flags(f), name(n) {}
        : start(s), end(e), offset(off), flags(f), name(n) {}
    ~Vma() = default;
    ~Vma() = default;


    void clear() {
    void clear() { memset(&usage, 0, sizeof(usage)); }
        memset(&usage, 0, sizeof(usage));
        memset(&wss, 0, sizeof(wss));
    }


    // Memory usage of this mapping.
    // Memory usage of this mapping.
    MemUsage usage;
    MemUsage usage;
    // Working set within this mapping.
    MemUsage wss;
};
};


}  // namespace meminfo
}  // namespace meminfo
+0 −1
Original line number Original line Diff line number Diff line
@@ -82,7 +82,6 @@ class ProcMemInfo final {
    std::vector<Vma> maps_;
    std::vector<Vma> maps_;


    MemUsage usage_;
    MemUsage usage_;
    MemUsage wss_;
    std::vector<uint16_t> swap_offsets_;
    std::vector<uint16_t> swap_offsets_;
};
};


+14 −29
Original line number Original line Diff line number Diff line
@@ -157,14 +157,14 @@ const MemUsage& ProcMemInfo::Wss() {
    if (!get_wss_) {
    if (!get_wss_) {
        LOG(WARNING) << "Trying to read process working set for " << pid_
        LOG(WARNING) << "Trying to read process working set for " << pid_
                     << " using invalid object";
                     << " using invalid object";
        return wss_;
        return usage_;
    }
    }


    if (maps_.empty() && !ReadMaps(get_wss_)) {
    if (maps_.empty() && !ReadMaps(get_wss_)) {
        LOG(ERROR) << "Failed to get working set for Process " << pid_;
        LOG(ERROR) << "Failed to get working set for Process " << pid_;
    }
    }


    return wss_;
    return usage_;
}
}


bool ProcMemInfo::ForEachVma(const VmaCallback& callback) {
bool ProcMemInfo::ForEachVma(const VmaCallback& callback) {
@@ -228,12 +228,8 @@ bool ProcMemInfo::ReadMaps(bool get_wss) {
            maps_.clear();
            maps_.clear();
            return false;
            return false;
        }
        }
        if (get_wss) {
            add_mem_usage(&wss_, vma.wss);
        } else {
        add_mem_usage(&usage_, vma.usage);
        add_mem_usage(&usage_, vma.usage);
    }
    }
    }


    return true;
    return true;
}
}
@@ -300,18 +296,9 @@ bool ProcMemInfo::ReadVmaStats(int pagemap_fd, Vma& vma, bool get_wss) {
            // This effectively makes vss = rss for the working set is requested.
            // This effectively makes vss = rss for the working set is requested.
            // The libpagemap implementation returns vss > rss for
            // The libpagemap implementation returns vss > rss for
            // working set, which doesn't make sense.
            // working set, which doesn't make sense.
            vma.wss.vss += pagesz;
            vma.usage.vss += pagesz;
            vma.wss.rss += pagesz;
            vma.wss.uss += is_private ? pagesz : 0;
            vma.wss.pss += pagesz / pg_counts[i];
            if (is_private) {
                vma.wss.private_dirty += is_dirty ? pagesz : 0;
                vma.wss.private_clean += is_dirty ? 0 : pagesz;
            } else {
                vma.wss.shared_dirty += is_dirty ? pagesz : 0;
                vma.wss.shared_clean += is_dirty ? 0 : pagesz;
        }
        }
        } else {

        vma.usage.rss += pagesz;
        vma.usage.rss += pagesz;
        vma.usage.uss += is_private ? pagesz : 0;
        vma.usage.uss += is_private ? pagesz : 0;
        vma.usage.pss += pagesz / pg_counts[i];
        vma.usage.pss += pagesz / pg_counts[i];
@@ -323,8 +310,6 @@ bool ProcMemInfo::ReadVmaStats(int pagemap_fd, Vma& vma, bool get_wss) {
            vma.usage.shared_clean += is_dirty ? 0 : pagesz;
            vma.usage.shared_clean += is_dirty ? 0 : pagesz;
        }
        }
    }
    }
    }

    return true;
    return true;
}
}


+6 −6
Original line number Original line Diff line number Diff line
@@ -98,7 +98,7 @@ static int show(const MemUsage& proc_stats, const std::vector<Vma>& maps) {
    std::stringstream ss;
    std::stringstream ss;
    print_header(ss);
    print_header(ss);
    for (auto& vma : maps) {
    for (auto& vma : maps) {
        const MemUsage& vma_stats = show_wss ? vma.wss : vma.usage;
        const MemUsage& vma_stats = vma.usage;
        if (hide_zeroes && vma_stats.rss == 0) {
        if (hide_zeroes && vma_stats.rss == 0) {
            continue;
            continue;
        }
        }
@@ -116,14 +116,14 @@ static int show(const MemUsage& proc_stats, const std::vector<Vma>& maps) {
int main(int argc, char* argv[]) {
int main(int argc, char* argv[]) {
    int opt;
    int opt;
    auto pss_sort = [](const Vma& a, const Vma& b) {
    auto pss_sort = [](const Vma& a, const Vma& b) {
        uint64_t pss_a = show_wss ? a.wss.pss : a.usage.pss;
        uint64_t pss_a = a.usage.pss;
        uint64_t pss_b = show_wss ? b.wss.pss : b.usage.pss;
        uint64_t pss_b = b.usage.pss;
        return pss_a > pss_b;
        return pss_a > pss_b;
    };
    };


    auto uss_sort = [](const Vma& a, const Vma& b) {
    auto uss_sort = [](const Vma& a, const Vma& b) {
        uint64_t uss_a = show_wss ? a.wss.uss : a.usage.uss;
        uint64_t uss_a = a.usage.uss;
        uint64_t uss_b = show_wss ? b.wss.uss : b.usage.uss;
        uint64_t uss_b = b.usage.uss;
        return uss_a > uss_b;
        return uss_a > uss_b;
    };
    };


@@ -182,7 +182,7 @@ int main(int argc, char* argv[]) {
    }
    }


    ProcMemInfo proc(pid, show_wss);
    ProcMemInfo proc(pid, show_wss);
    const MemUsage& proc_stats = show_wss ? proc.Wss() : proc.Usage();
    const MemUsage& proc_stats = proc.Usage();
    std::vector<Vma> maps(proc.Maps());
    std::vector<Vma> maps(proc.Maps());
    if (sort_func != nullptr) {
    if (sort_func != nullptr) {
        std::sort(maps.begin(), maps.end(), sort_func);
        std::sort(maps.begin(), maps.end(), sort_func);
+1 −1
Original line number Original line Diff line number Diff line
@@ -465,7 +465,7 @@ int main(int argc, char* argv[]) {
        }
        }


        // Skip processes with no memory mappings
        // Skip processes with no memory mappings
        uint64_t vss = show_wss ? proc.Wss().vss : proc.Usage().vss;
        uint64_t vss = proc.Usage().vss;
        if (vss == 0) return true;
        if (vss == 0) return true;


        // collect swap_offset counts from all processes in 1st pass
        // collect swap_offset counts from all processes in 1st pass