packages/apps/Settings
Revisão | a0fc2b88f8814de735269ccc7deed1d0f5363cf8 (tree) |
---|---|
Hora | 2015-10-30 11:25:05 |
Autor | Dianne Hackborn <hackbod@goog...> |
Commiter | The Android Automerger |
Fix issue #25371736: Don't include z-ram allocations in Android OS
Just distribute them across all of the running apps, by creating
an additional fake "z-ram" process for each of them.
Change-Id: I9b4efe9c7b907779a0ec76cb8652709619e2e686
@@ -157,6 +157,9 @@ public class ProcStatsData { | ||
157 | 157 | ProcessStats.ALL_SCREEN_ADJ, mMemStates, ProcessStats.NON_CACHED_PROC_STATES); |
158 | 158 | |
159 | 159 | createPkgMap(getProcs(bgTotals, runTotals), bgTotals, runTotals); |
160 | + if (totalMem.sysMemZRamWeight > 0) { | |
161 | + distributeZRam(totalMem.sysMemZRamWeight); | |
162 | + } | |
160 | 163 | |
161 | 164 | ProcStatsPackageEntry osPkg = createOsEntry(bgTotals, runTotals, totalMem, |
162 | 165 | mMemInfo.baseCacheRam); |
@@ -180,6 +183,41 @@ public class ProcStatsData { | ||
180 | 183 | } |
181 | 184 | } |
182 | 185 | |
186 | + private void distributeZRam(double zramWeight) { | |
187 | + // Distribute kernel's Z-Ram across processes, based on how much they have been running. | |
188 | + // The idea is that the memory used by the kernel for this is not really the kernel's | |
189 | + // responsibility, but that of whoever got swapped in to it... and we will take how | |
190 | + // much a process runs for as a sign of the proportion of Z-Ram it is responsible for. | |
191 | + | |
192 | + long zramMem = (long) (zramWeight / memTotalTime); | |
193 | + long totalTime = 0; | |
194 | + for (int i = pkgEntries.size() - 1; i >= 0; i--) { | |
195 | + ProcStatsPackageEntry entry = pkgEntries.get(i); | |
196 | + for (int j = entry.mEntries.size() - 1; j >= 0; j--) { | |
197 | + ProcStatsEntry proc = entry.mEntries.get(j); | |
198 | + totalTime += proc.mRunDuration; | |
199 | + } | |
200 | + } | |
201 | + for (int i = pkgEntries.size() - 1; i >= 0 && totalTime > 0; i--) { | |
202 | + ProcStatsPackageEntry entry = pkgEntries.get(i); | |
203 | + long pkgRunTime = 0; | |
204 | + for (int j = entry.mEntries.size() - 1; j >= 0; j--) { | |
205 | + ProcStatsEntry proc = entry.mEntries.get(j); | |
206 | + pkgRunTime += proc.mRunDuration; | |
207 | + } | |
208 | + long pkgZRam = (zramMem*pkgRunTime)/totalTime; | |
209 | + if (pkgZRam > 0) { | |
210 | + zramMem -= pkgZRam; | |
211 | + totalTime -= pkgRunTime; | |
212 | + ProcStatsEntry procEntry = new ProcStatsEntry(entry.mPackage, 0, | |
213 | + mContext.getString(R.string.process_stats_os_zram), memTotalTime, | |
214 | + pkgZRam); | |
215 | + procEntry.evaluateTargetPackage(mPm, mStats, null, null, sEntryCompare, mUseUss); | |
216 | + entry.addEntry(procEntry); | |
217 | + } | |
218 | + } | |
219 | + } | |
220 | + | |
183 | 221 | private ProcStatsPackageEntry createOsEntry(ProcessDataCollection bgTotals, |
184 | 222 | ProcessDataCollection runTotals, TotalMemoryUseCollection totalMem, long baseCacheRam) { |
185 | 223 | // Add in fake entry representing the OS itself. |
@@ -199,6 +237,7 @@ public class ProcStatsData { | ||
199 | 237 | osEntry.evaluateTargetPackage(mPm, mStats, bgTotals, runTotals, sEntryCompare, mUseUss); |
200 | 238 | osPkg.addEntry(osEntry); |
201 | 239 | } |
240 | + /* Turned off now -- zram is being distributed across running apps. | |
202 | 241 | if (totalMem.sysMemZRamWeight > 0) { |
203 | 242 | osEntry = new ProcStatsEntry(Utils.OS_PKG, 0, |
204 | 243 | mContext.getString(R.string.process_stats_os_zram), memTotalTime, |
@@ -206,6 +245,7 @@ public class ProcStatsData { | ||
206 | 245 | osEntry.evaluateTargetPackage(mPm, mStats, bgTotals, runTotals, sEntryCompare, mUseUss); |
207 | 246 | osPkg.addEntry(osEntry); |
208 | 247 | } |
248 | + */ | |
209 | 249 | if (baseCacheRam > 0) { |
210 | 250 | osEntry = new ProcStatsEntry(Utils.OS_PKG, 0, |
211 | 251 | mContext.getString(R.string.process_stats_os_cache), memTotalTime, |