Bug 1560931 - Fire memory-pressure-stop events on Windows r=gsvelto
authorJon Coppeard <jcoppeard@mozilla.com>
Mon, 24 Jun 2019 18:22:53 +0100
changeset 543018 3ea8a293b2d1a3ad00abf170116f87ef101a975d
parent 542972 b20b355373b444b5a9a303777631f99141149a2b
child 543019 337d59cc8ed5f211f595a2451aee9731b3638e1a
push id2131
push userffxbld-merge
push dateMon, 26 Aug 2019 18:30:20 +0000
treeherdermozilla-release@b19ffb3ca153 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgsvelto
bugs1560931
milestone69.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1560931 - Fire memory-pressure-stop events on Windows r=gsvelto I'd like to rely on always getting a stop event when the system recovers from a memory pressure situation. AIUI this already happens on Android platforms but not on Windows. This adds the stop event for Windows. Differential Revision: https://phabricator.services.mozilla.com/D35679
xpcom/base/AvailableMemoryTracker.cpp
xpcom/threads/nsMemoryPressure.h
--- a/xpcom/base/AvailableMemoryTracker.cpp
+++ b/xpcom/base/AvailableMemoryTracker.cpp
@@ -89,16 +89,17 @@ class nsAvailableMemoryWatcher final : p
 
   static bool IsVirtualMemoryLow();
   static bool IsCommitSpaceLow();
 
   ~nsAvailableMemoryWatcher(){};
   bool OngoingMemoryPressure() { return mUnderMemoryPressure; }
   void AdjustPollingInterval(const bool aLowMemory);
   void SendMemoryPressureEvent();
+  void MaybeSendMemoryPressureStopEvent();
   void MaybeSaveMemoryReport();
   void Shutdown();
 
   nsCOMPtr<nsITimer> mTimer;
   bool mUnderMemoryPressure;
   bool mSavedReport;
 };
 
@@ -183,16 +184,22 @@ bool nsAvailableMemoryWatcher::IsCommitS
 }
 
 void nsAvailableMemoryWatcher::SendMemoryPressureEvent() {
   MemoryPressureState state =
       OngoingMemoryPressure() ? MemPressure_Ongoing : MemPressure_New;
   NS_DispatchEventualMemoryPressure(state);
 }
 
+void nsAvailableMemoryWatcher::MaybeSendMemoryPressureStopEvent() {
+  if (OngoingMemoryPressure()) {
+    NS_DispatchEventualMemoryPressure(MemPressure_Stopping);
+  }
+}
+
 void nsAvailableMemoryWatcher::MaybeSaveMemoryReport() {
   if (!mSavedReport && OngoingMemoryPressure()) {
     nsCOMPtr<nsICrashReporter> cr =
         do_GetService("@mozilla.org/toolkit/crash-reporter;1");
     if (cr) {
       if (NS_SUCCEEDED(cr->SaveMemoryReport())) {
         mSavedReport = true;
       }
@@ -216,16 +223,21 @@ void nsAvailableMemoryWatcher::AdjustPol
 // will send memory-pressure events if memory is running low and adjust the
 // polling interval accordingly.
 NS_IMETHODIMP
 nsAvailableMemoryWatcher::Notify(nsITimer* aTimer) {
   bool lowMemory = IsVirtualMemoryLow() || IsCommitSpaceLow();
 
   if (lowMemory) {
     SendMemoryPressureEvent();
+  } else {
+    MaybeSendMemoryPressureStopEvent();
+  }
+
+  if (lowMemory) {
     MaybeSaveMemoryReport();
   } else {
     mSavedReport = false;  // Save a new report if memory gets low again
   }
 
   AdjustPollingInterval(lowMemory);
   mUnderMemoryPressure = lowMemory;
 
--- a/xpcom/threads/nsMemoryPressure.h
+++ b/xpcom/threads/nsMemoryPressure.h
@@ -50,17 +50,20 @@ enum MemoryPressureState {
    * The priority ordering between concurrent attempts to queue both stopped
    * and ongoing memory pressure is currently not defined.
    */
   MemPressure_Stopping
 };
 
 /**
  * Return and erase the latest state of the memory pressure event set by any of
- * the corresponding dispatch function.
+ * the corresponding dispatch functions.
+ *
+ * This is called when processing events on the main thread to check whether to
+ * fire a memory pressure notification.
  */
 MemoryPressureState NS_GetPendingMemoryPressure();
 
 /**
  * This function causes the main thread to fire a memory pressure event
  * before processing the next event, but if there are no events pending in
  * the main thread's event queue, the memory pressure event would not be
  * dispatched until one is enqueued. It is infallible and does not allocate