Bug 1451005 - Forward all memory-pressure events to the child processes; r?njn draft
authorGabriele Svelto <gsvelto@mozilla.com>
Sat, 12 May 2018 01:21:13 +0200
changeset 796276 60f1fd814f46bb98da7a5d73e648aeac837fc8b7
parent 796275 61fbd1603f57f8a42b25d379c78643eb848e9cb8
child 796277 262d60917dbefc35aa6215913e45f7054da6d015
push id110202
push usergsvelto@mozilla.com
push dateThu, 17 May 2018 12:48:51 +0000
reviewersnjn
bugs1451005
milestone62.0a1
Bug 1451005 - Forward all memory-pressure events to the child processes; r?njn When memory-pressure events were first used in an e10s environment it was to implement memory minimization from about:memory. However when low memory detection was first introduced in Firefox OS an issue arised with this scheme: every process was using a kernel-based low-latency mechanism to detect low memory scenarios and send memory-pressure events; but the main process events were also being forwarded to all child processes causing listeners to be triggered twice. Because of this -no-forward events were introduced and used. Currently however low-memory is detected via polling, so there will always be a significant delay between the beginning of the low-memory scenario and its detection. Because of this there is no value in having content processes poll on their own and it's best to have only the main process do it and then forward the memory-pressure events to all child processes. MozReview-Commit-ID: AMQOsEgECme
dom/ipc/ContentParent.cpp
xpcom/base/nsIMemory.idl
xpcom/threads/nsThread.cpp
--- a/dom/ipc/ContentParent.cpp
+++ b/dom/ipc/ContentParent.cpp
@@ -2837,19 +2837,17 @@ ContentParent::Observe(nsISupports* aSub
     SpinEventLoopUntil([&]() { return !mIPCOpen || mCalledKillHard; });
     NS_ASSERTION(!mSubprocess, "Close should have nulled mSubprocess");
   }
 
   if (!mIsAlive || !mSubprocess)
     return NS_OK;
 
   // listening for memory pressure event
-  if (!strcmp(aTopic, "memory-pressure") &&
-      !StringEndsWith(nsDependentString(aData),
-                      NS_LITERAL_STRING("-no-forward"))) {
+  if (!strcmp(aTopic, "memory-pressure")) {
       Unused << SendFlushMemory(nsDependentString(aData));
   }
   else if (!strcmp(aTopic, "nsPref:changed")) {
     // A pref changed. If it's not on the blacklist, inform child processes.
 #define BLACKLIST_ENTRY(s) { s, (sizeof(s)/sizeof(char16_t)) - 1 }
     struct BlacklistEntry {
       const char16_t* mPrefBranch;
       size_t mLen;
--- a/xpcom/base/nsIMemory.idl
+++ b/xpcom/base/nsIMemory.idl
@@ -27,20 +27,16 @@
  * observer is being asked to flush for low-memory conditions.
  *
  * "low-memory-ongoing"
  * This will be passed when we continue to be in a low-memory
  * condition and we want to flush caches and do other cheap
  * forms of memory minimization, but heavy handed approaches like
  * a GC are unlikely to succeed.
  *
- * "-no-forward"
- * This is appended to the above two parameters when the resulting
- * notification should not be forwarded to the child processes.
- *
  * "heap-minimize"
  * This will be passed as the extra data when the pressure 
  * observer is being asked to flush because of a heap minimize 
  * call.
  */
 
 [scriptable, uuid(1e004834-6d8f-425a-bc9c-a2812ed43bb7)]
 interface nsIMemory : nsISupports
--- a/xpcom/threads/nsThread.cpp
+++ b/xpcom/threads/nsThread.cpp
@@ -1266,21 +1266,19 @@ nsThread::DoMainThreadSpecificProcessing
     MemoryPressureState mpPending = NS_GetPendingMemoryPressure();
     if (mpPending != MemPressure_None) {
       nsCOMPtr<nsIObserverService> os = services::GetObserverService();
 
       if (os) {
         if (mpPending == MemPressure_Stopping) {
           os->NotifyObservers(nullptr, "memory-pressure-stop", nullptr);
         } else {
-          // Use no-forward to prevent the notifications from being transferred to
-          // the children of this process.
           os->NotifyObservers(nullptr, "memory-pressure",
-                              mpPending == MemPressure_New ? u"low-memory-no-forward" :
-                              u"low-memory-ongoing-no-forward");
+                              mpPending == MemPressure_New ? u"low-memory" :
+                              u"low-memory-ongoing");
         }
       } else {
         NS_WARNING("Can't get observer service!");
       }
     }
   }
 
   if (!ShuttingDown()) {