From 0ade88c83de7f207389d2c7a8385e927604dae70 Mon Sep 17 00:00:00 2001 From: Mark Salyzyn Date: Tue, 20 Nov 2018 08:28:24 -0800 Subject: [PATCH] storaged: emplace recent_perf in load_perf_history_proto If recent_perf contains existing content, overwrite in method load_perf_history_proto. If proto of recent_perf contains a lot of history, the content would have grown with system_server crashes. Test: setprop ro.storaged.flush_proto.interval 60 while true;do sleep 5;stop;sleep 1;start;ps -A|grep storaged;done and look at value for rss should remain about 4MB over long term. Bug: 119798824 Change-Id: I50aae7d61eb791a8fcddbbd829254baf8f708186 --- storaged/storaged_info.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/storaged/storaged_info.cpp b/storaged/storaged_info.cpp index 8c0b3d191..ca2421b41 100644 --- a/storaged/storaged_info.cpp +++ b/storaged/storaged_info.cpp @@ -87,12 +87,21 @@ void storage_info_t::load_perf_history_proto(const IOPerfHistory& perf_history) day_start_tp += chrono::seconds(perf_history.day_start_sec()); nr_samples = perf_history.nr_samples(); + if (nr_samples < recent_perf.size()) { + recent_perf.erase(recent_perf.begin() + nr_samples, recent_perf.end()); + } + size_t i = 0; for (auto bw : perf_history.recent_perf()) { - recent_perf.push_back(bw); + if (i < recent_perf.size()) { + recent_perf[i] = bw; + } else { + recent_perf.push_back(bw); + } + ++i; } nr_days = perf_history.nr_days(); - int i = 0; + i = 0; for (auto bw : perf_history.daily_perf()) { daily_perf[i++] = bw; }