New issue
Advanced search Search tips
Note: Color blocks (like or ) mean that a user may not be available. Tooltip shows the reason.

Issue 729335 link

Starred by 8 users

Issue metadata

Status: Assigned
Owner:
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: Chrome
Pri: 2
Type: Bug


Show other hotlists

Hotlists containing this issue:
Hotlist-1
Hotlist-2


Sign in to add a comment

Tab discarder: fine tune the killing rate

Project Member Reported by cylee@chromium.org, Jun 3 2017

Issue description

Currently when receiving a critical memory pressure, tab discarder calculates "target memory to free" using low memory margin, available memory, and estimation of memory freed by killing each candidate. However
1. Current estimation uses RSS of the renderer process when killing a tab, which is inaccurate because of a renderer process might host multiple tabs. 
2. A minor problem: in the process of killing candidate, memory level has been changed because of swap of other factors. To be more accurate, we can check available memory before each kill.

I have a CL which polls /dev/chromeos-low-mem before each kill to decide whether to continue: https://chromium-review.googlesource.com/c/523043
However as yusukes pointed out, it'll not work well because app kills are not synchronous, tab kills are potentially not either. So memory would not be freed immediately. 

It'll be better if we can find a better way to control the killing rate.
For example, is it possible to setup a second tier polling inside tab discarder? Like when receiving a critical memory pressure, poll /dev/chromeos-low-mem 5 times a second? 

 
We should be able to get a better estimation than RSS if we use PSS (proportional set size) and then putting each renderer in it's own process will help with the multiple tabs/renderer complication.

I'm not sure I understand the last paragraph.  Why poll 5x per second?

Comment 2 by zork@chromium.org, Dec 1 2017

Owner: r...@chromium.org
Since there may be activity on this bug, I'd like to add some information, which leads me as well to speculate that polling 5x per second is not going to help.

In the attached graph, blue vertical lines are the times when the kernel signals a low-memory state.  That happens at the crossing of the available memory (blue graph) and the margin (blue horizontal line).

Red lines represent tab discards.  This is a bit of an extreme situation (lots of open tabs, lots of tab switchings and reloads) but as you can see the tab discards go on for about 40 seconds after the last notification.  Also one of the tabs was very large and it either crashed or was discarded, so at t = 12 seconds there is no longer a need to discard anything, yet 20+ more tabs are discarded.

Sorry, here's the attached graph mentioned in #3.
figure_1.png
294 KB View Download

Comment 5 by r...@chromium.org, Dec 1 2017

Owner: semenzato@chromium.org
Luigi, you know way more about this than I do, so passing it over to you :)
If you feel we should just WontFix this, feel free to.

Well how kind of you.  That teaches me to keep my mouth shut. ;)

I mostly work on the kernel, and as we speak I am writing a tool to collect fine-grained memory stats.  That's why I have this information.  But I've hacked Chrome too and have no excuse for pushing back on this :/

I don't know what you're working on or what interests you, but if you like this topic, don't be intimidated, I'll be happy to collaborate.


Cc: r...@chromium.org
Please see #6 :)
Cc: cmtm@chromium.org

Comment 9 by cylee@google.com, Dec 4 2017

Hi Luigi,
  I'm kind of confused. The bug refers to the problem where when one notification comes in, the "for" loop in tab discarder would 1) Get a snapshot of current memory status and 2) Kill tabs until memory backs to normal level according to the info got from 1) and estimated memory to be freed for each tab. The whole "for" loop after getting a notification should be executed in under 1 second. How could a notification causes a tab to be discarded after ~40 seconds? It looks very strange to me. Do you have any assumption ? A new bug ? 
Hi Cheng-Yu,
yes I agree it looks strange, but I am not familiar with that code so I don't have an explanation.  I just collected the data and put it on the same graph.  If we don't trust the data, we may be able to confirm these events by looking at logs.  Bear in mind that the system was under very heavy load, with many tabs reloading.

The data is collected in a separate daemon, and Chrome notifies the daemon via DBus.  I added the tab discard signal here:

https://chromium-review.googlesource.com/c/chromium/src/+/754301/2/chrome/browser/resource_coordinator/tab_manager.cc

Could that be the problem?

Comment 11 by cylee@chromium.org, Jan 10 2018

Owner: cylee@chromium.org

Comment 12 by cylee@chromium.org, Jan 12 2018

Hi Luigi,
  Per #3, how did you get the timing of kernel signals a low-memory state (vertical blue line)? The code you showed in #10 is actually not when tab discarder happens. Instead it should be called every time when system is in low memory state. Memory coordinator polls the kernel interface for available memory periodically (like 1 second) and check whether there's room for several renderers. The new logic is like 

  int expected_renderer_count = available / kExpectedRendererSizeMB;
  if (available <= 0 || expected_renderer_count < kNewRenderersUntilCritical)
    return MemoryCondition::CRITICAL;
https://cs.chromium.org/chromium/src/content/browser/memory/memory_condition_observer.cc?rcl=4bccc9372c2644679beecf3e3a88b3630ec32132&l=78

  I'm not sure whether memory coordinator has been enabled in the Chrome version you used. But the old code did roughly the same. I have no idea why it continues to fire when there's lots of available memory.

  On the other hand, when PurgeMemoryAndDiscardTab is called, on ChromeOS we have another inner loop which reads the low memory margin and tries to kill several tabs to reclaim enough memory
https://cs.chromium.org/chromium/src/chrome/browser/resource_coordinator/tab_manager_delegate_chromeos.cc?rcl=5b0879c77d86676a28d6e4334c3bdca0f005f6cb&l=650

  If when this function is called the low memory margin is negative (enough has been reclaimed), no tab would be discarded at all. If you want to know when a tab is really discarded, you should add a log at KillTab() and KillArcProcess() in this file. 
The low-memory crossing (vertical blue line) is directly from /dev/chromeos-low-mem.

But I see what you're saying, manager->DiscardTab doesn't necessarily discard a tab.  Although the comment in DiscardTabImpl says:

  // Loop until a non-discarded tab to kill is found.

But you're right, if the kArcMemoryManagement feature is enabled then it calls LowMemoryKillImpl, which does not necessarily free tabs.

In any case, it is strange that it is called so many times when there seems to be a lot of free RAM.  Maybe the low-memory condition is computed differently?  I am not sure if these calls are expensive, but they pollute the logs.  Should I file a separate bug for this?


Comment 14 by cylee@chromium.org, Jan 13 2018

Checked the code again, MemoryCoordinator defaults to disabled so the only place where critical memory pressure occurs looks still
https://cs.chromium.org/chromium/src/base/memory/memory_pressure_monitor_chromeos.cc?rcl=7a7c695b9e11047c95c371446f0939ece09c8ac3&l=199
where /dev/chromeos-low-mem is set. 
Does the value "available' come from /sys/kernel/mm/chromeos-low_mem/available ?

And it should be the only code path where PurgeMemoryAndDiscardTab() is called (when critical memory pressure happens)
https://cs.chromium.org/chromium/src/chrome/browser/resource_coordinator/tab_manager.cc?rcl=7a7c695b9e11047c95c371446f0939ece09c8ac3&l=887
Have no idea why the call is not synced with /dev/chromeos-low-mem

I tried to log available memory on my cave when PurMemoryAndDiscardTab() is called and it's close to low memory margin (< ±30MB).

Can you reliably reproduce the problem? I would like to know the steps so I can look into this. It's really weird. Is there any possibility that the red lines don't align with blue lines properly?

#14 hi!  Sorry, I don't follow your reasoning on the code. But to answer your questions:

> Does the value "available' come from /sys/kernel/mm/chromeos-low_mem/available ?

I don't know.  In theory it should, but there is code to calculate it in

https://cs.chromium.org/chromium/src/base/memory/memory_pressure_monitor_chromeos.cc

I hope it's not used because it doesn't match what we do on caroline.

> Can you reliably reproduce the problem? I would like to know the steps so I can look into this.

I load a large number of CNN tabs and Google properties, multiple times, for a total of 30 to 50 tabs, and I tab-switch among them pausing 1-2 seconds on each tab.

> Is there any possibility that the red lines don't align with blue lines properly?

Well I never make mistakes, so no, it's impossible :)

But joking aside, it really seems difficult that it's wrong.  I saw this pattern many times.  The program that collects that data is here

https://chromium-review.googlesource.com/c/chromiumos/platform2/+/775478

Tme "memd" program listens for low-memory notifications as well as dbus signals from Chrome (as discussed in #10).  Those events (plus timer events) are added to a circular buffer and each is time-stamped with the current time.  (There is one exception for kernel trace events, which provide their own time, but it does not apply here.)


Comment 16 by cylee@chromium.org, Jan 19 2018

I read the code before and checked again. When /dev/chromeos-low-mem is present, the calculation logic in this memory_pressure_monitor_chromeos.cc is never used to fire critical memory pressure:
   if (low_mem_file_.is_valid() &&
        current_memory_pressure_level_ ==
        MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL) {
      current_memory_pressure_level_ =
          MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE;

Also in #14 I mean that it looks the only place where PurgeMemoryAndDiscardTab() (and thus your tab-discard DBus signal) is called is when memory pressure is critical. So it's really hard to imagine why a tab-discard event in the graph doesn't come with a low-mem signal. A possibility is that MemoryPressureListener is overridden by the new component "MemoryCoordinator", where critical memory pressures doesn't look to respect /dev/chromeos-low-mem . However afaik MemoryCoordinator is not enabled by default. 

I've added a log at PurgeMemoryAndDiscardTab() like
// static
void TabManager::PurgeMemoryAndDiscardTab(DiscardReason reason) {
  TabManager* manager = g_browser_process->GetTabManager();
  manager->PurgeBrowserMemory();
  manager->DiscardTab(reason);
  LOG(ERROR) << "PurgeMemoryAndDiscardTab() " << TargetMemoryToFreeKB();
}
where TargetMemoryToFreeKB() prints current available memory (from /sys/kernel/mm/chromeos-low_mem/available)
The setting should be able to catch the situation where your "tab-discard" signal is raised, but available is fairly high.
However I played on my cave for a while, opening dozens of tabs and switching around. The value of (available - low_mem_margin) never exceeds 150M (usually <100M). I believe in my case low mem signal is indeed raised but some memory is reclaimed when the chrome code is executed. In your graph it's obviously not the case. What device are you using ? 

I tried to patch https://chromium-review.googlesource.com/c/chromium/src/+/754301
 but there's some missing file
../../chromeos/dbus/event_logger_client.cc:12:10: fatal error: 'third_party/cros_system_api/dbus/event_logger/dbus-constants.h' file not found
#include "third_party/cros_system_api/dbus/event_logger/dbus-constants.h"
so I can't try it by myself yet.

Sorry---that file is not in the chromium source.  I am including here for reference.

semenzato@luigi:~/chromium/src$ cat third_party/cros_system_api/dbus/event_logger/dbus-constants.h
// Copyright 2017 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef SYSTEM_API_DBUS_EVENT_LOGGER_DBUS_CONSTANTS_H_
#define SYSTEM_API_DBUS_EVENT_LOGGER_DBUS_CONSTANTS_H_

namespace event_logger {
// powerd
const char kEventLoggerInterface[] = "org.chromium.EventLogger";
const char kEventLoggerServicePath[] = "/org/chromium/EventLogger";
const char kEventLoggerServiceName[] = "org.chromium.EventLogger";

// Signal emitted for chrome events of interest for the purpose of logging
// related information (such as kernel memory manager activity at the time of a
// tab discard).
const char kChromeEvent[] = "ChromeEvent";

}  // namespace event_logger

#endif  // SYSTEM_API_DBUS_EVENT_LOGGER_DBUS_CONSTANTS_H_

Components: UI>Browser>TabStrip
Cc: -bccheng@chromium.org cywang@chromium.org
Project Member

Comment 20 by bugdroid1@chromium.org, May 11 2018

The following revision refers to this bug:
  https://chromium.googlesource.com/chromiumos/platform2/+/54df2464f3fa5aa7344553e715dcd435c6b69c96

commit 54df2464f3fa5aa7344553e715dcd435c6b69c96
Author: Luigi Semenzato <semenzato@chromium.org>
Date: Fri May 11 19:10:56 2018

metrics: memd: a fine-grain memory stat collection daemon

Memd collects fine-grained memory stats around events of interest
(such as browser tab discards) and saves them in a queue of "clip
files", to be uploaded with other logs.

It has two modes of operation.  When memory pressure is low, it
wakes up every 2 seconds and checks that pressure is still low.
If not, it goes into fast-poll mode, where it collects stats in
a circular buffer 10 times per second.  When an "interesting"
event happens, it dumps those stats into a file, limited to 5
seconds before and 5 seconds after the event.

The output files (called "clip files") are also rotated, so only
the most recent 20 are kept.  They are stored in /var/log/memd
and are uploaded (in a later CL) together with other logs in
feedback reports.

The daemon minimizes the number of syscalls by keeping system
files open and using pread() instead of seek() + read().
Here are some performance stats in fast-poll mode:

device				caroline	cyan
cpu time/elapsed time (ratio)	0.00207846	0.00558685
user/system time (ticks)	71/335		546/4248

Since syscalls are already optimized, and user time is a
small fraction of system time, further optimization is
unlikely to help.  If this is too high, the sampling rate
could be reduced to 5 samples/second.

The power_Idle autotest was used to measure times spent
in various C states with and without the daemon running
in fast-poll mode.  This is the result on a cyan.

Without memd:

cpuidle_C0	5.733226548
cpuidle_C1-CHT	2.161165429
cpuidle_C6N-CHT	1.312466693
cpuidle_C6S-CHT	11.53713899
cpuidle_C7-CHT	22.70593436
cpuidle_C7S-CHT	56.55006798
cpupkg_C0_C1	17.49514512
cpupkg_C6	82.50485488

With memd:

cpuidle_C0      5.826605515
cpuidle_C1-CHT  1.304592293
cpuidle_C6N-CHT 1.146455368
cpuidle_C6S-CHT 11.89613166
cpuidle_C7-CHT  28.10783807
cpuidle_C7S-CHT 51.7183771
cpupkg_C0_C1    17.12395914
cpupkg_C6       82.87604086

These numbers suggest that the impact on power will be minimal.

For a functional test, run integ/memd-tester.sh from the top
directory (metrics/memd).

BUG=chromium:729335
TEST=integ/memd-tester on workstation

Change-Id: I12a01e73efed2d845cce9567c0a5d832bd4534c5
Reviewed-on: https://chromium-review.googlesource.com/990434
Commit-Ready: Luigi Semenzato <semenzato@chromium.org>
Tested-by: Luigi Semenzato <semenzato@chromium.org>
Reviewed-by: Sonny Rao <sonnyrao@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>

[add] https://crrev.com/54df2464f3fa5aa7344553e715dcd435c6b69c96/metrics/memd/src/main.rs
[add] https://crrev.com/54df2464f3fa5aa7344553e715dcd435c6b69c96/metrics/memd/Cargo.lock
[add] https://crrev.com/54df2464f3fa5aa7344553e715dcd435c6b69c96/metrics/memd/integ/memd-tester.sh
[add] https://crrev.com/54df2464f3fa5aa7344553e715dcd435c6b69c96/metrics/memd/Cargo.toml

Project Member

Comment 21 by bugdroid1@chromium.org, May 23 2018

The following revision refers to this bug:
  https://chromium.googlesource.com/chromiumos/platform2/+/76520b498bce019c8243c90eb03b9a9651859feb

commit 76520b498bce019c8243c90eb03b9a9651859feb
Author: Luigi Semenzato <semenzato@chromium.org>
Date: Wed May 23 01:45:32 2018

metrics: memd: remove regex dependency

env_logger by default depends on regex, which depends on
a lot of other packages.  This reduces the size of the executable
from 1.4 to 0.6 MB.

This also accidentally bumped the version number for a number
of other dependencies.  Maybe I should freeze them all in Cargo.toml.

BUG=chromium:729335
TEST=tested upstart with start/stop/reboot

Change-Id: I3d94c35c50e4cae1b2853b06665fc6415b2a9166
Reviewed-on: https://chromium-review.googlesource.com/1063041
Commit-Ready: Luigi Semenzato <semenzato@chromium.org>
Tested-by: Luigi Semenzato <semenzato@chromium.org>
Reviewed-by: Luigi Semenzato <semenzato@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>

[modify] https://crrev.com/76520b498bce019c8243c90eb03b9a9651859feb/metrics/memd/Cargo.lock
[modify] https://crrev.com/76520b498bce019c8243c90eb03b9a9651859feb/metrics/memd/Cargo.toml

Project Member

Comment 22 by bugdroid1@chromium.org, May 23 2018

The following revision refers to this bug:
  https://chromium.googlesource.com/chromiumos/platform2/+/e56894fea6e462d503749b8c8df15dc204cd81c6

commit e56894fea6e462d503749b8c8df15dc204cd81c6
Author: Luigi Semenzato <semenzato@chromium.org>
Date: Wed May 23 01:45:32 2018

metrics: memd: treat low-memory notifications as "interesting"

This ensures that a clip is collected whenever a low-mem notification
fires even if no tab is subsequently discarded (if, for instance,
by the time the tab discarder is running, enough memory has been
freed, by swapping or other means).

BUG=chromium:729335
TEST=memd-tester still passes

Change-Id: If00d8cd491d4567b70a60519fcdf6446716b8ddc
Reviewed-on: https://chromium-review.googlesource.com/1063169
Commit-Ready: Luigi Semenzato <semenzato@chromium.org>
Tested-by: Luigi Semenzato <semenzato@chromium.org>
Reviewed-by: Luigi Semenzato <semenzato@chromium.org>
Reviewed-by: Sonny Rao <sonnyrao@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>

[modify] https://crrev.com/e56894fea6e462d503749b8c8df15dc204cd81c6/metrics/memd/src/main.rs

Project Member

Comment 23 by bugdroid1@chromium.org, May 23 2018

The following revision refers to this bug:
  https://chromium.googlesource.com/chromiumos/platform2/+/9cdc79abeb2b75bb8ecc24c503beb8b937e3a379

commit 9cdc79abeb2b75bb8ecc24c503beb8b937e3a379
Author: Luigi Semenzato <semenzato@chromium.org>
Date: Wed May 23 01:45:33 2018

metrics: memd: correctly convert timeval fields

Don't make assumptions on the size of the timeval
fields (which is different on different platforms)
and instead convert directly to their types.

BUG=chromium:729335
TEST=compiles for kevin and caroline

Change-Id: I51877ef1a0c94c817bfc3dbbb77e783172297a2b
Reviewed-on: https://chromium-review.googlesource.com/1064314
Commit-Ready: Luigi Semenzato <semenzato@chromium.org>
Tested-by: Luigi Semenzato <semenzato@chromium.org>
Reviewed-by: Luigi Semenzato <semenzato@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>

[modify] https://crrev.com/9cdc79abeb2b75bb8ecc24c503beb8b937e3a379/metrics/memd/src/main.rs

Project Member

Comment 24 by bugdroid1@chromium.org, May 23 2018

The following revision refers to this bug:
  https://chromium.googlesource.com/chromiumos/platform2/+/f1320cb1f286178d0d7642e85b0e0866b8304fe2

commit f1320cb1f286178d0d7642e85b0e0866b8304fe2
Author: Luigi Semenzato <semenzato@chromium.org>
Date: Wed May 23 01:45:33 2018

metrics: memd: use syslog crate

Logging via syslog adds about 100k to the binary size (330k to 440k
on x86 and 290k to 380k on arm).

BUG=chromium:729335
TEST=none

Change-Id: I94268a20eb89471a1b6dd49d33a644372fef28d2
Reviewed-on: https://chromium-review.googlesource.com/1064691
Commit-Ready: Luigi Semenzato <semenzato@chromium.org>
Tested-by: Luigi Semenzato <semenzato@chromium.org>
Reviewed-by: Luigi Semenzato <semenzato@chromium.org>

[modify] https://crrev.com/f1320cb1f286178d0d7642e85b0e0866b8304fe2/metrics/memd/Cargo.lock
[modify] https://crrev.com/f1320cb1f286178d0d7642e85b0e0866b8304fe2/metrics/memd/src/main.rs
[modify] https://crrev.com/f1320cb1f286178d0d7642e85b0e0866b8304fe2/metrics/memd/Cargo.toml

Project Member

Comment 25 by bugdroid1@chromium.org, May 23 2018

The following revision refers to this bug:
  https://chromium.googlesource.com/chromiumos/platform2/+/2672924102bd51bf7f5897651e5854eec91a24ea

commit 2672924102bd51bf7f5897651e5854eec91a24ea
Author: Luigi Semenzato <semenzato@chromium.org>
Date: Wed May 23 01:45:34 2018

metrics: memd: fix parsing bug

Parsing of /proc/loadavg was broken because the input could contain
extra spaces.  This makes the parser more lenient.  Also provides
more info on errors.

BUG=chromium:729335
TEST=ran integration test and ran on device

Change-Id: I51a5b25dc9c84cce8494bccd9ca10f4798d6bc00
Reviewed-on: https://chromium-review.googlesource.com/1066453
Commit-Ready: Luigi Semenzato <semenzato@chromium.org>
Tested-by: Luigi Semenzato <semenzato@chromium.org>
Reviewed-by: Luigi Semenzato <semenzato@chromium.org>

[modify] https://crrev.com/2672924102bd51bf7f5897651e5854eec91a24ea/metrics/memd/src/main.rs

Project Member

Comment 26 by bugdroid1@chromium.org, May 23 2018

The following revision refers to this bug:
  https://chromium.googlesource.com/chromiumos/platform2/+/98ebc58fa5cfd33cc439233bbf45e0f45b6f5bab

commit 98ebc58fa5cfd33cc439233bbf45e0f45b6f5bab
Author: Luigi Semenzato <semenzato@chromium.org>
Date: Wed May 23 04:56:59 2018

metrics: memd: fix unwraps

I noticed I still had a couple of incorrect unwrap() calls.
I changed one to ?, the others to expect().  There are still
another couple of unwraps left, but those should be OK because
they are expected to succeed---it's an internal bug if they fail.

BUG=chromium:729335
TEST=none

Change-Id: I93ceb611fb82ff862bec08b59d69dcffe863a222
Reviewed-on: https://chromium-review.googlesource.com/1068129
Commit-Ready: Luigi Semenzato <semenzato@chromium.org>
Tested-by: Luigi Semenzato <semenzato@chromium.org>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>

[modify] https://crrev.com/98ebc58fa5cfd33cc439233bbf45e0f45b6f5bab/metrics/memd/src/main.rs

Project Member

Comment 27 by bugdroid1@chromium.org, May 23 2018

The following revision refers to this bug:
  https://chromium.googlesource.com/chromiumos/platform2/+/c6f9303a421bf01e286a363a4ca68d19880dc7e0

commit c6f9303a421bf01e286a363a4ca68d19880dc7e0
Author: Luigi Semenzato <semenzato@chromium.org>
Date: Wed May 23 04:56:59 2018

metrics: memd: refactor file open and add filename to errors

For performance, std::fs::File does not include path names
in errors.  But this program DIES on any error, so we don't
need no stinking performance.

BUG=chromium:729335
TEST=compiled, run on target device with minijail-induced errors

Change-Id: I71b9c7fa318b034c147de2ec06dff4780af210be
Reviewed-on: https://chromium-review.googlesource.com/1068130
Commit-Ready: Luigi Semenzato <semenzato@chromium.org>
Tested-by: Luigi Semenzato <semenzato@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>

[modify] https://crrev.com/c6f9303a421bf01e286a363a4ca68d19880dc7e0/metrics/memd/src/main.rs

Hi Luigi,
  We just found that a problem in TabManager could be the root cause of what you observed in at #3 (crbug/850545).
Oh yes, I saw that!  It's very exciting.  Well done!
Project Member

Comment 30 by bugdroid1@chromium.org, Jun 19 2018

The following revision refers to this bug:
  https://chromium.googlesource.com/chromiumos/platform2/+/d46f95c2baaaeb0305478f6bd46476e50c216c95

commit d46f95c2baaaeb0305478f6bd46476e50c216c95
Author: Luigi Semenzato <semenzato@chromium.org>
Date: Tue Jun 19 21:38:38 2018

metrics: memd: boot script

This adds /etc/init/memd.conf and two seccomp files.

The seccomp policies were generated by running the daemon on
all code paths (except the error paths) while recording
syscalls with strace, then removing spurious entries.

BUG=chromium:729335
TEST=start/stop memd on caroline and kevin

Change-Id: I58a7a3ffe35049c24fbc42b502db0514fa967641
Reviewed-on: https://chromium-review.googlesource.com/1069729
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Tested-by: Luigi Semenzato <semenzato@chromium.org>
Reviewed-by: Mike Frysinger <vapier@chromium.org>

[add] https://crrev.com/d46f95c2baaaeb0305478f6bd46476e50c216c95/metrics/memd/init/memd-seccomp-amd64.policy
[add] https://crrev.com/d46f95c2baaaeb0305478f6bd46476e50c216c95/metrics/memd/init/memd.conf
[add] https://crrev.com/d46f95c2baaaeb0305478f6bd46476e50c216c95/metrics/memd/init/memd-seccomp-arm.policy

Project Member

Comment 31 by bugdroid1@chromium.org, Jun 19 2018

The following revision refers to this bug:
  https://chromium.googlesource.com/chromiumos/platform2/+/31de6f01db4851fd27823158035466b40d3441c4

commit 31de6f01db4851fd27823158035466b40d3441c4
Author: Luigi Semenzato <semenzato@chromium.org>
Date: Tue Jun 19 21:38:39 2018

metrics: memd: integrate and robustify testing

These tests exercise the entire event loop by mocking time,
which guarantees reproducibility and makes the test run
faster (i.e. the mocked sleep() and select() with timeout
don't actually do any waiting).

Time is mocked by a "timer" trait which implements select(),
sleep(), and now().  The "mock timer" implementation manages
a list of "external" events that must be delivered at specified
times.  Infinite CPU speed is assumed, so the events are
delivered only during sleep() or select() with a timeout.

Piggy-back a small bug fix: clip files need to be truncated
when clobbered.  Also add ftruncate() to the seccomp whitelist
and clean up a bit.

BUG=chromium:729335
TEST=run "memd test", pass the tests.  Also start on x86 and arm.

Change-Id: I4b10c0a63e4c1c62446afbbef61a405c0c3153fb
Reviewed-on: https://chromium-review.googlesource.com/1097950
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Tested-by: Luigi Semenzato <semenzato@chromium.org>
Reviewed-by: Luigi Semenzato <semenzato@chromium.org>

[delete] https://crrev.com/d46f95c2baaaeb0305478f6bd46476e50c216c95/metrics/memd/integ/memd-tester.sh
[modify] https://crrev.com/31de6f01db4851fd27823158035466b40d3441c4/metrics/memd/init/memd-seccomp-amd64.policy
[modify] https://crrev.com/31de6f01db4851fd27823158035466b40d3441c4/metrics/memd/src/main.rs
[modify] https://crrev.com/31de6f01db4851fd27823158035466b40d3441c4/metrics/memd/init/memd-seccomp-arm.policy

Project Member

Comment 32 by bugdroid1@chromium.org, Jun 23 2018

The following revision refers to this bug:
  https://chromium.googlesource.com/chromiumos/overlays/chromiumos-overlay/+/2c1f0bbff7768cb4d13cc0af9288ae9fc39e3dc2

commit 2c1f0bbff7768cb4d13cc0af9288ae9fc39e3dc2
Author: Luigi Semenzato <semenzato@chromium.org>
Date: Sat Jun 23 03:19:31 2018

chromeos-base/memd: add memd ebuild

This adds an ebuild for memd.
I have also uploaded the needed crates to chromeos-localmirror.

BUG=chromium:729335
TEST={FEATURES=test,}emerge-cyan memd; emerge-kevin memd; ran on both devices
CQ-DEPEND=CL:1097950

Change-Id: I26af9f5bbf81ca1fa0141bc20f66e7a0eaea7ca2
Reviewed-on: https://chromium-review.googlesource.com/1063256
Commit-Ready: Luigi Semenzato <semenzato@chromium.org>
Tested-by: Luigi Semenzato <semenzato@chromium.org>
Reviewed-by: Mike Frysinger <vapier@chromium.org>

[add] https://crrev.com/2c1f0bbff7768cb4d13cc0af9288ae9fc39e3dc2/chromeos-base/memd/memd-9999.ebuild

Project Member

Comment 33 by bugdroid1@chromium.org, Jun 26 2018

The following revision refers to this bug:
  https://chromium.googlesource.com/chromiumos/platform2/+/379e01218b601b03d8febf7870855f23c1140128

commit 379e01218b601b03d8febf7870855f23c1140128
Author: Luigi Semenzato <semenzato@chromium.org>
Date: Tue Jun 26 00:20:23 2018

metrics: memd: split test code into separate module

Moving the test code into a separate file helps achieve two goals:
the main program file becomes smaller and more readable, and the
test code is compiled only when running the unit tests.

The separation is not perfect: the main program code still has some
knowledge of testing (for instance when building the Paths object),
but it's better than before.

BUG=chromium:729335
TEST=ran "cargo build" and "cargo test"

Change-Id: I2f3515243a0a7959005677d11c34bffdc0b4d3ce
Reviewed-on: https://chromium-review.googlesource.com/1112669
Commit-Ready: Luigi Semenzato <semenzato@chromium.org>
Tested-by: Luigi Semenzato <semenzato@chromium.org>
Reviewed-by: Luigi Semenzato <semenzato@chromium.org>

[add] https://crrev.com/379e01218b601b03d8febf7870855f23c1140128/metrics/memd/src/vmstat_content
[add] https://crrev.com/379e01218b601b03d8febf7870855f23c1140128/metrics/memd/src/zoneinfo_content
[add] https://crrev.com/379e01218b601b03d8febf7870855f23c1140128/metrics/memd/src/test.rs
[modify] https://crrev.com/379e01218b601b03d8febf7870855f23c1140128/metrics/memd/src/main.rs

Project Member

Comment 34 by bugdroid1@chromium.org, Jun 26 2018

The following revision refers to this bug:
  https://chromium.googlesource.com/chromiumos/overlays/chromiumos-overlay/+/5687887ea07d39aae1b51f99563684c4b23c930e

commit 5687887ea07d39aae1b51f99563684c4b23c930e
Author: Luigi Semenzato <semenzato@chromium.org>
Date: Tue Jun 26 04:00:55 2018

metrics: memd: add missing Manifest

BUG=chromium:729335
TEST=none

Change-Id: I8806e70d81b51df2beda2dbb7afc0e5f0edbcb8a
Reviewed-on: https://chromium-review.googlesource.com/1114190
Commit-Ready: Luigi Semenzato <semenzato@chromium.org>
Tested-by: Luigi Semenzato <semenzato@chromium.org>
Reviewed-by: Mike Frysinger <vapier@chromium.org>

[add] https://crrev.com/5687887ea07d39aae1b51f99563684c4b23c930e/chromeos-base/memd/Manifest

Project Member

Comment 35 by bugdroid1@chromium.org, Jun 28 2018

The following revision refers to this bug:
  https://chromium.googlesource.com/chromiumos/third_party/autotest/+/45a0694044bfed0ec0964cb746cff1ae503777c5

commit 45a0694044bfed0ec0964cb746cff1ae503777c5
Author: Luigi Semenzato <semenzato@chromium.org>
Date: Thu Jun 28 05:06:59 2018

platform_ToolchainOptions: whitelist /usr/bin/memd

BUG=chromium:729335
TEST=none

Change-Id: Ia8878a50463b07a2a87ef2c4e7523befef25baf0
Reviewed-on: https://chromium-review.googlesource.com/1116353
Commit-Ready: Luigi Semenzato <semenzato@chromium.org>
Tested-by: Luigi Semenzato <semenzato@chromium.org>
Reviewed-by: Mike Frysinger <vapier@chromium.org>

[modify] https://crrev.com/45a0694044bfed0ec0964cb746cff1ae503777c5/client/site_tests/platform_ToolchainOptions/libgcc_whitelist

Project Member

Comment 37 by bugdroid1@chromium.org, Jun 28 2018

The following revision refers to this bug:
  https://chromium.googlesource.com/chromiumos/overlays/chromiumos-overlay/+/39cc371b22066adbf0e6c5f4054c84941b4a5483

commit 39cc371b22066adbf0e6c5f4054c84941b4a5483
Author: Luigi Semenzato <semenzato@chromium.org>
Date: Thu Jun 28 05:06:58 2018

memd: do not run unit tests in non-x86 builds

BUG=chromium:729335
TEST=FEATURES=test emerge-kevin memd

Change-Id: Ibe531d1cc38d9294d958ae4d63dcf7659c985037
Reviewed-on: https://chromium-review.googlesource.com/1115339
Commit-Ready: Luigi Semenzato <semenzato@chromium.org>
Tested-by: Luigi Semenzato <semenzato@chromium.org>
Reviewed-by: Mike Frysinger <vapier@chromium.org>

[modify] https://crrev.com/39cc371b22066adbf0e6c5f4054c84941b4a5483/chromeos-base/memd/memd-9999.ebuild

Project Member

Comment 38 by bugdroid1@chromium.org, Jun 28 2018

The following revision refers to this bug:
  https://chromium.googlesource.com/chromiumos/platform2/+/7f00dfb8d2eb69e76c95199ced094a776a60b26f

commit 7f00dfb8d2eb69e76c95199ced094a776a60b26f
Author: Luigi Semenzato <semenzato@chromium.org>
Date: Thu Jun 28 05:07:12 2018

debugd: add collection of memd logs

BUG=chromium:729335
TEST=none

Change-Id: Ie78613c1f5404efce61e5bf38f3559ec5f3fcc21
Reviewed-on: https://chromium-review.googlesource.com/1115703
Commit-Ready: Luigi Semenzato <semenzato@chromium.org>
Tested-by: Luigi Semenzato <semenzato@chromium.org>
Reviewed-by: Ben Chan <benchan@chromium.org>
Reviewed-by: Mike Frysinger <vapier@chromium.org>

[modify] https://crrev.com/7f00dfb8d2eb69e76c95199ced094a776a60b26f/debugd/src/log_tool.cc

Project Member

Comment 39 by bugdroid1@chromium.org, Jul 10

The following revision refers to this bug:
  https://chromium.googlesource.com/chromiumos/third_party/autotest/+/b70dd180671bf0651921b926427b8372b4126478

commit b70dd180671bf0651921b926427b8372b4126478
Author: Luigi Semenzato <semenzato@chromium.org>
Date: Tue Jul 10 00:59:30 2018

security_SandboxedServices: add memd to baseline

BUG=chromium:729335
TEST=./bin/autotest_client tests/security_SandboxedServices/control

Change-Id: I31fb6e5ef5255e26ed50efb3c5a5105d336d768f
Reviewed-on: https://chromium-review.googlesource.com/1128500
Commit-Ready: Luigi Semenzato <semenzato@chromium.org>
Tested-by: Luigi Semenzato <semenzato@chromium.org>
Reviewed-by: Mike Frysinger <vapier@chromium.org>

[modify] https://crrev.com/b70dd180671bf0651921b926427b8372b4126478/client/site_tests/security_SandboxedServices/baseline

Project Member

Comment 40 by bugdroid1@chromium.org, Jul 15

The following revision refers to this bug:
  https://chromium.googlesource.com/chromiumos/overlays/chromiumos-overlay/+/f4efe08ab35905cde61ec77c1f47b85e7864b40d

commit f4efe08ab35905cde61ec77c1f47b85e7864b40d
Author: Mike Frysinger <vapier@chromium.org>
Date: Sun Jul 15 01:11:43 2018

memd: disable for R69

It's pretty late in the branch cycle, so pull memd out as it hasn't
had enough testing just yet.  We can re-enable for R70.

BUG= chromium:860034 ,chromium:729335
TEST=precq passes

Change-Id: Ib8f97c57689ce5d14bf24120643df419412dc7e0
Reviewed-on: https://chromium-review.googlesource.com/1136874
Commit-Ready: Mike Frysinger <vapier@chromium.org>
Tested-by: Mike Frysinger <vapier@chromium.org>
Reviewed-by: Sonny Rao <sonnyrao@chromium.org>

[modify] https://crrev.com/f4efe08ab35905cde61ec77c1f47b85e7864b40d/profiles/targets/chromeos/make.defaults

Status: Assigned (was: Untriaged)
This bug has an owner, thus, it's been triaged. Changing status to "assigned".
Owner: semenzato@chromium.org
I should probably own this at least for now.
Project Member

Comment 43 by bugdroid1@chromium.org, Aug 30

The following revision refers to this bug:
  https://chromium.googlesource.com/chromiumos/platform/system_api/+/a71cda985de20c747a6525de0fac2dc95766bd6d

commit a71cda985de20c747a6525de0fac2dc95766bd6d
Author: Luigi Semenzato <semenzato@chromium.org>
Date: Thu Aug 30 04:05:46 2018

system_api: dbus: add metrics_event protobuffer

This is used for signaling memory pressure events from Chrome to
memd (or other interested party).

BUG=chromium:729335
TEST=compiles and runs correctly with chromium changes that use it

Change-Id: I00aee977045977d606e3f09eb8a4215c54ea5ee2
Reviewed-on: https://chromium-review.googlesource.com/1186024
Commit-Ready: Luigi Semenzato <semenzato@chromium.org>
Tested-by: Luigi Semenzato <semenzato@chromium.org>
Reviewed-by: Dan Erat <derat@chromium.org>

[add] https://crrev.com/a71cda985de20c747a6525de0fac2dc95766bd6d/dbus/metrics_event/service.proto

Project Member

Comment 44 by bugdroid1@chromium.org, Aug 31

The following revision refers to this bug:
  https://chromium.googlesource.com/chromiumos/overlays/chromiumos-overlay/+/e15256b1402e6bf98c3490b96745fbc1aa5b748c

commit e15256b1402e6bf98c3490b96745fbc1aa5b748c
Author: Luigi Semenzato <semenzato@chromium.org>
Date: Fri Aug 31 12:23:47 2018

chromeos-base/memd: adjust ebuild for use of protobufs.

These changes are needed after adding the use of
protobufs to memd, for parsing metrics event signals
from Chrome.

BUG=chromium:729335
TEST=compiles

Change-Id: Ie608b2a052efa61d67e7200816df44669c452990
Reviewed-on: https://chromium-review.googlesource.com/1194651
Commit-Ready: Luigi Semenzato <semenzato@chromium.org>
Tested-by: Luigi Semenzato <semenzato@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>

[modify] https://crrev.com/e15256b1402e6bf98c3490b96745fbc1aa5b748c/chromeos-base/memd/memd-9999.ebuild
[modify] https://crrev.com/e15256b1402e6bf98c3490b96745fbc1aa5b748c/chromeos-base/memd/Manifest

Project Member

Comment 45 by bugdroid1@chromium.org, Sep 1

The following revision refers to this bug:
  https://chromium.googlesource.com/chromiumos/platform/system_api/+/ac2aa599abbd9bb353914648e83de934a15b3682

commit ac2aa599abbd9bb353914648e83de934a15b3682
Author: Luigi Semenzato <semenzato@chromium.org>
Date: Sat Sep 01 21:43:34 2018

system_api: dbus: rename metrics_event proto file

Naming the protobuf specification "service.proto" causes conflicts
in the chrome build.  This may be related to

https://github.com/protocolbuffers/protobuf/issues/2520

namespace protobuf_service_2eproto {
void InitDefaults() {

Naming the file "service.proto" makes the namespace contain the word
"service", which happens to be used by another protobuf for vm_concierge.
So I get a link-time multiple definition.

BUG=chromium:729335
TEST=compiles and runs correctly with chromium changes that use it

Change-Id: Ic83489d3bab15f627288e44c323e5032da76d874
Reviewed-on: https://chromium-review.googlesource.com/1199965
Commit-Ready: Luigi Semenzato <semenzato@chromium.org>
Tested-by: Luigi Semenzato <semenzato@chromium.org>
Reviewed-by: Dan Erat <derat@chromium.org>

[rename] https://crrev.com/ac2aa599abbd9bb353914648e83de934a15b3682/dbus/metrics_event/metrics_event.proto

(Pardon me. Doing a bulk audit for CLs that missed R70  for nocturne: 
https://crosland.corp.google.com/log/11021.0.0..11035.0.0
This CL was found in the "might be helpful for nocturne" list). 

CL in #43 went in before R70 branch point, but #44 and #45 came later.
Is this intended for a Merge-Request to M70? 

Cc: kirtika@chromium.org
Project Member

Comment 48 by bugdroid1@chromium.org, Sep 5

The following revision refers to this bug:
  https://chromium.googlesource.com/chromiumos/platform/system_api/+/41fa3011067832b0b4341de834cd7cd341099738

commit 41fa3011067832b0b4341de834cd7cd341099738
Author: Luigi Semenzato <semenzato@chromium.org>
Date: Wed Sep 05 12:11:43 2018

system_api: service_constants.h: add MetricsEvent

This adds constants for the MetricsEventService.
Ideally this would have gone in with the addition
of metrics_event.proto, but I had my chrome and cros
sources out of sync.

BUG=chromium:729335
TEST=chromium compiles (cros clones these in Rust code)

Change-Id: I2407619196dd6fe75e3143caa932bb443ad5fffc
Reviewed-on: https://chromium-review.googlesource.com/1204910
Commit-Ready: Luigi Semenzato <semenzato@chromium.org>
Tested-by: Luigi Semenzato <semenzato@chromium.org>
Reviewed-by: Dan Erat <derat@chromium.org>

[modify] https://crrev.com/41fa3011067832b0b4341de834cd7cd341099738/dbus/service_constants.h

Project Member

Comment 49 by bugdroid1@chromium.org, Sep 5

The following revision refers to this bug:
  https://chromium.googlesource.com/chromiumos/overlays/chromiumos-overlay/+/1f38337baf092db94acc789741efaa243a1fb836

commit 1f38337baf092db94acc789741efaa243a1fb836
Author: Luigi Semenzato <semenzato@chromium.org>
Date: Wed Sep 05 23:11:12 2018

chromeos-base/memd: add dependency on chromeos-base/system_api

BUG=chromium:729335
TEST=none

Change-Id: I3231a8e08db5e4f2ccbdd2de57033bcb8b30463a
Reviewed-on: https://chromium-review.googlesource.com/1199445
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Tested-by: Luigi Semenzato <semenzato@chromium.org>
Reviewed-by: Mike Frysinger <vapier@chromium.org>

[modify] https://crrev.com/1f38337baf092db94acc789741efaa243a1fb836/chromeos-base/memd/memd-9999.ebuild

Project Member

Comment 50 by bugdroid1@chromium.org, Sep 7

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/a179f27585302bacbcca81263479ba3e9c28ce36

commit a179f27585302bacbcca81263479ba3e9c28ce36
Author: Luigi Semenzato <semenzato@chromium.org>
Date: Fri Sep 07 21:06:41 2018

Add metrics event reporting for Chrome OS

This adds a mechanism to report statistically-interesting
events to Chrome OS listeners.  A Chrome OS daemon (such
as the memory daemon "memd") can register as a client
of the Metrics Event Service, and receive signals on the
occurrence of related events (for instance, a tab discard).

This CL adds the supporting machinery and its first use,
signaling of a tab discard.

CQ-DEPEND=CL:1199965
BUG=chromium:729335
TEST=ran on DUT, verified that D-Bus signal is sent as expected

Change-Id: I6eddf4b0d18aa4c8a3fd4aab7f0770d87ddc7aeb
Reviewed-on: https://chromium-review.googlesource.com/1062078
Commit-Queue: Luigi Semenzato <semenzato@chromium.org>
Reviewed-by: Steven Bennetts <stevenjb@chromium.org>
Reviewed-by: Dan Erat <derat@chromium.org>
Cr-Commit-Position: refs/heads/master@{#589639}
[modify] https://crrev.com/a179f27585302bacbcca81263479ba3e9c28ce36/DEPS
[modify] https://crrev.com/a179f27585302bacbcca81263479ba3e9c28ce36/chrome/browser/chromeos/BUILD.gn
[modify] https://crrev.com/a179f27585302bacbcca81263479ba3e9c28ce36/chrome/browser/chromeos/chrome_browser_main_chromeos.cc
[add] https://crrev.com/a179f27585302bacbcca81263479ba3e9c28ce36/chrome/browser/chromeos/dbus/metrics_event_service_provider.cc
[add] https://crrev.com/a179f27585302bacbcca81263479ba3e9c28ce36/chrome/browser/chromeos/dbus/metrics_event_service_provider.h
[add] https://crrev.com/a179f27585302bacbcca81263479ba3e9c28ce36/chrome/browser/chromeos/dbus/org.chromium.MetricsEventService.conf
[modify] https://crrev.com/a179f27585302bacbcca81263479ba3e9c28ce36/chromeos/BUILD.gn

Project Member

Comment 51 by bugdroid1@chromium.org, Sep 8

The following revision refers to this bug:
  https://chromium.googlesource.com/chromiumos/platform2/+/22f4b09a56a133a476e13eb71a58cd3de356b844

commit 22f4b09a56a133a476e13eb71a58cd3de356b844
Author: Luigi Semenzato <semenzato@chromium.org>
Date: Sat Sep 08 05:27:45 2018

metrics: memd: plumbing D-Bus event notifications from Chrome

Register for notifications from the Metrics Event Service
provided by Chrome.  This service offers no methods,
only sends signals for events that have a large impact
on memory usage, such as tab discards and tab switches.

The changes include:
- adding build.rs to generate Rust for protobuf;
- parsing D-Bus payload using protobuf code;
- changing process_chrome_events to return a list of events (each
with its own timestamp) rather than only a count;
- fixing the unit tests to include time stamps in the mock chrome events.
- making the output routine ignore possibly incorrect time stamps
from external sources

CQ-DEPEND=CL:1194651,CL:1199445,CL:1199965
BUG=chromium:729335
TEST=unit test, ran on device, verified tab discards work as expected

Change-Id: Ica9805ec134d40d44984de3d5276b9fae9257a86
Reviewed-on: https://chromium-review.googlesource.com/1188796
Commit-Ready: Luigi Semenzato <semenzato@chromium.org>
Tested-by: Luigi Semenzato <semenzato@chromium.org>
Reviewed-by: Luigi Semenzato <semenzato@chromium.org>

[add] https://crrev.com/22f4b09a56a133a476e13eb71a58cd3de356b844/metrics/memd/build.rs
[modify] https://crrev.com/22f4b09a56a133a476e13eb71a58cd3de356b844/metrics/memd/Cargo.lock
[modify] https://crrev.com/22f4b09a56a133a476e13eb71a58cd3de356b844/metrics/memd/src/main.rs
[modify] https://crrev.com/22f4b09a56a133a476e13eb71a58cd3de356b844/metrics/memd/src/test.rs
[modify] https://crrev.com/22f4b09a56a133a476e13eb71a58cd3de356b844/metrics/memd/Cargo.toml

Project Member

Comment 52 by bugdroid1@chromium.org, Sep 24

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/3d29b40bd87d3adf42730d2dbd4822f21e0cdaea

commit 3d29b40bd87d3adf42730d2dbd4822f21e0cdaea
Author: Luigi Semenzato <semenzato@chromium.org>
Date: Mon Sep 24 17:20:55 2018

histograms.xml: add Network.Shill.CumulativeTimeOnLine.*

Implementation CL:
https://chromium-review.googlesource.com/c/aosp/platform/system/connectivity/shill/+/1220430

BUG=chromium:729335
TEST=none

Change-Id: I00fe89328d9ec0f910b354733fb1914838c5d75c
Reviewed-on: https://chromium-review.googlesource.com/1234696
Commit-Queue: Luigi Semenzato <semenzato@chromium.org>
Reviewed-by: Ilya Sherman <isherman@chromium.org>
Reviewed-by: Robert Kaplow (sloooow) <rkaplow@chromium.org>
Cr-Commit-Position: refs/heads/master@{#593579}
[modify] https://crrev.com/3d29b40bd87d3adf42730d2dbd4822f21e0cdaea/tools/metrics/histograms/histograms.xml

Project Member

Comment 53 by bugdroid1@chromium.org, Sep 26

The following revision refers to this bug:
  https://chromium.googlesource.com/chromiumos/platform/system_api/+/98bc2a6d4b6c83b6dcae8fe50101aef1b75d1a13

commit 98bc2a6d4b6c83b6dcae8fe50101aef1b75d1a13
Author: Luigi Semenzato <semenzato@chromium.org>
Date: Wed Sep 26 17:32:14 2018

system_api: add anomaly event service interface

This also adds new event types to the metrics event protobuf,
and adds generation of C++ sources for use by the anomaly
collector.

BUG=chromium:729335
TEST=compiles, links, and runs with anomaly_collector

Change-Id: I330d9103752c9db58c6db824f69e25d5cc6bd180
Reviewed-on: https://chromium-review.googlesource.com/1239736
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Tested-by: Luigi Semenzato <semenzato@chromium.org>
Reviewed-by: Luigi Semenzato <semenzato@chromium.org>

[modify] https://crrev.com/98bc2a6d4b6c83b6dcae8fe50101aef1b75d1a13/dbus/metrics_event/metrics_event.proto
[modify] https://crrev.com/98bc2a6d4b6c83b6dcae8fe50101aef1b75d1a13/dbus/service_constants.h
[modify] https://crrev.com/98bc2a6d4b6c83b6dcae8fe50101aef1b75d1a13/system_api.gyp

Project Member

Comment 54 by bugdroid1@chromium.org, Sep 26

The following revision refers to this bug:
  https://chromium.googlesource.com/chromiumos/overlays/chromiumos-overlay/+/21a9b57ba39bb8010f891284680081957dfe415d

commit 21a9b57ba39bb8010f891284680081957dfe415d
Author: Luigi Semenzato <semenzato@chromium.org>
Date: Wed Sep 26 17:32:14 2018

chromeos-base/system_api: add metrics_event protobuf.

The metrics_event protobuf is used by the anomaly detector
to send a D-Bus signal when it detects that the kernel has
attempted an Out-of-memory kill (OOM kill).

CQ-DEPEND=CL:1239736
BUG=chromium:729335
TEST=compiled

Change-Id: I9722752c1a28076535cf69d465bc03a990a564a5
Reviewed-on: https://chromium-review.googlesource.com/1236995
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Tested-by: Luigi Semenzato <semenzato@chromium.org>
Reviewed-by: Luigi Semenzato <semenzato@chromium.org>

[modify] https://crrev.com/21a9b57ba39bb8010f891284680081957dfe415d/chromeos-base/system_api/system_api-9999.ebuild

Project Member

Comment 55 by bugdroid1@chromium.org, Oct 2

The following revision refers to this bug:
  https://chromium.googlesource.com/chromiumos/platform2/+/a457cc7a65c8cd23572df023e7eaf88e3f219a4e

commit a457cc7a65c8cd23572df023e7eaf88e3f219a4e
Author: Luigi Semenzato <semenzato@chromium.org>
Date: Tue Oct 02 16:17:40 2018

crash: add detection and reporting of OOM kills

Enhance the anomaly collector so that it detects kernel OOM kills,
ahd correspondingly sends D-Bus signals.  This is mainly for memd,
which collects and correlates such events.

BUG=chromium:729335
TEST=ran on DUT, verified content of emitted signals

Change-Id: I1f1055ff255892f646edc81d39c3bce14b2acc0e
Reviewed-on: https://chromium-review.googlesource.com/1224637
Commit-Ready: Luigi Semenzato <semenzato@chromium.org>
Tested-by: Luigi Semenzato <semenzato@chromium.org>
Reviewed-by: Dan Erat <derat@chromium.org>

[modify] https://crrev.com/a457cc7a65c8cd23572df023e7eaf88e3f219a4e/crash-reporter/anomaly_collector_test.sh
[modify] https://crrev.com/a457cc7a65c8cd23572df023e7eaf88e3f219a4e/crash-reporter/README.md
[modify] https://crrev.com/a457cc7a65c8cd23572df023e7eaf88e3f219a4e/crash-reporter/anomaly_collector.l
[modify] https://crrev.com/a457cc7a65c8cd23572df023e7eaf88e3f219a4e/crash-reporter/anomaly_collector.h
[modify] https://crrev.com/a457cc7a65c8cd23572df023e7eaf88e3f219a4e/crash-reporter/anomaly_collector.cc
[modify] https://crrev.com/a457cc7a65c8cd23572df023e7eaf88e3f219a4e/crash-reporter/BUILD.gn
[modify] https://crrev.com/a457cc7a65c8cd23572df023e7eaf88e3f219a4e/metrics/memd/src/main.rs
[modify] https://crrev.com/a457cc7a65c8cd23572df023e7eaf88e3f219a4e/crash-reporter/docs/collectors.md

Cc: chinglinyu@chromium.org
Cc: yuzhao@chromium.org cros-perf-detectives@google.com
 Issue 896142  has been merged into this issue.
(Continue the discussion of  bug 896142  since it's merged into this bug)

Conclusion: we should not invoke memory pressure handler if the previous invocation hasn't finished.

If, for any reason, the previous dispatch of TabManager::OnMemoryPressure() hasn't finished its job (e.g. will take 5 sec to finish), the memory pressure monitor will almost certainly dispatch another 4. When the first finishes its job, the other 4 dispatches will run in a bursty manner *right after* the first one and will either:
1. still find some app/tab to kill. 
  1.1 This could be either another tab/app is still quickly allocating memory.
  1.2 The app/tab killed in the first dispatch hasn't taken effect in system memory statistics. If this is the case, we will see several dispatches has the same number of "Target memory to free". Because the later dispatches doesn't know previous kill in action, we will overkill. This will be bad for user because more than necessary tabs/apps will be discarded in a sudden.
2. cannot find some app/tab to kill. We will see from the log of listing of candidates, but no app/tab is killed because target memory to free is already negative. It just wastes a lot of cycles on the UI thread.

This also has a side effect of the first-kill latency metric: if 1.1 happens, we will send out first-kill latencies ike 5, 4, 3, 2, 1 seconds, but these latencies actually overlap in time, which doesn't make much sense.
Cc: vovoy@chromium.org

Sign in to add a comment