Bug 1234176 - Do not send memory pressure events to applications sent into the background. r=dhylands
authorGabriele Svelto <gsvelto@mozilla.com>
Tue, 29 Dec 2015 11:17:13 +0100
changeset 278461 18a588877774679207909312f39bf07614ed6eaf
parent 278460 fa2e4cde3708e3f305e87ec1f22928974b498366
child 278462 74ad280efe2502857bba394886aa3d1a0d21a0ff
push id29851
push userkwierso@gmail.com
push dateTue, 05 Jan 2016 23:37:43 +0000
treeherdermozilla-central@aaef0e7e3514 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdhylands
bugs1234176
milestone46.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 1234176 - Do not send memory pressure events to applications sent into the background. r=dhylands
b2g/app/b2g.js
dom/ipc/ProcessPriorityManager.cpp
--- a/b2g/app/b2g.js
+++ b/b2g/app/b2g.js
@@ -687,17 +687,16 @@ pref("layout.css.scroll-snap.enabled", t
 
 // Enable the ProcessPriorityManager, and give processes with no visible
 // documents a 1s grace period before they're eligible to be marked as
 // background. Background processes that are perceivable due to playing
 // media are given a longer grace period to accomodate changing tracks, etc.
 pref("dom.ipc.processPriorityManager.enabled", true);
 pref("dom.ipc.processPriorityManager.backgroundGracePeriodMS", 1000);
 pref("dom.ipc.processPriorityManager.backgroundPerceivableGracePeriodMS", 5000);
-pref("dom.ipc.processPriorityManager.memoryPressureGracePeriodMS", 3000);
 pref("dom.ipc.processPriorityManager.temporaryPriorityLockMS", 5000);
 
 // Number of different background/foreground levels for background/foreground
 // processes.  We use these different levels to force the low-memory killer to
 // kill processes in a LRU order.
 pref("dom.ipc.processPriorityManager.BACKGROUND.LRUPoolLevels", 5);
 pref("dom.ipc.processPriorityManager.BACKGROUND_PERCEIVABLE.LRUPoolLevels", 4);
 
--- a/dom/ipc/ProcessPriorityManager.cpp
+++ b/dom/ipc/ProcessPriorityManager.cpp
@@ -339,17 +339,16 @@ public:
   void Freeze();
   void Unfreeze();
 
   void ShutDown();
 
 private:
   static uint32_t sBackgroundPerceivableGracePeriodMS;
   static uint32_t sBackgroundGracePeriodMS;
-  static uint32_t sMemoryPressureGracePeriodMS;
 
   void FireTestOnlyObserverNotification(
     const char* aTopic,
     const nsACString& aData = EmptyCString());
 
   void FireTestOnlyObserverNotification(
     const char* aTopic,
     const char* aData = nullptr);
@@ -364,30 +363,28 @@ private:
   bool mFrozen;
 
   /**
    * Used to implement NameWithComma().
    */
   nsAutoCString mNameWithComma;
 
   nsCOMPtr<nsITimer> mResetPriorityTimer;
-  nsCOMPtr<nsITimer> mMemoryPressureTimer;
 };
 
 /* static */ bool ProcessPriorityManagerImpl::sInitialized = false;
 /* static */ bool ProcessPriorityManagerImpl::sPrefsEnabled = false;
 /* static */ bool ProcessPriorityManagerImpl::sRemoteTabsDisabled = true;
 /* static */ bool ProcessPriorityManagerImpl::sTestMode = false;
 /* static */ bool ProcessPriorityManagerImpl::sPrefListenersRegistered = false;
 /* static */ bool ProcessPriorityManagerImpl::sFrozen = false;
 /* static */ StaticRefPtr<ProcessPriorityManagerImpl>
   ProcessPriorityManagerImpl::sSingleton;
 /* static */ uint32_t ParticularProcessPriorityManager::sBackgroundPerceivableGracePeriodMS = 0;
 /* static */ uint32_t ParticularProcessPriorityManager::sBackgroundGracePeriodMS = 0;
-/* static */ uint32_t ParticularProcessPriorityManager::sMemoryPressureGracePeriodMS = 0;
 
 NS_IMPL_ISUPPORTS(ProcessPriorityManagerImpl,
                   nsIObserver,
                   nsISupportsWeakReference);
 
 /* static */ void
 ProcessPriorityManagerImpl::PrefChangedCallback(const char* aPref,
                                                 void* aClosure)
@@ -697,18 +694,16 @@ ParticularProcessPriorityManager::Partic
 
 void
 ParticularProcessPriorityManager::StaticInit()
 {
   Preferences::AddUintVarCache(&sBackgroundPerceivableGracePeriodMS,
                                "dom.ipc.processPriorityManager.backgroundPerceivableGracePeriodMS");
   Preferences::AddUintVarCache(&sBackgroundGracePeriodMS,
                                "dom.ipc.processPriorityManager.backgroundGracePeriodMS");
-  Preferences::AddUintVarCache(&sMemoryPressureGracePeriodMS,
-                               "dom.ipc.processPriorityManager.memoryPressureGracePeriodMS");
 }
 
 void
 ParticularProcessPriorityManager::Init()
 {
   RegisterWakeLockObserver(this);
 
   nsCOMPtr<nsIObserverService> os = services::GetObserverService();
@@ -1005,38 +1000,27 @@ ParticularProcessPriorityManager::Schedu
       timeout = sBackgroundGracePeriodMS;
       break;
     default:
       MOZ_ASSERT(false, "Unrecognized timeout pref");
       break;
   }
 
   LOGP("Scheduling reset timer to fire in %dms.", timeout);
-  mResetPriorityTimer = do_CreateInstance("@mozilla.org/timer;1");
+  mResetPriorityTimer = do_CreateInstance(NS_TIMER_CONTRACTID);
   mResetPriorityTimer->InitWithCallback(this, timeout, nsITimer::TYPE_ONE_SHOT);
 }
 
 NS_IMETHODIMP
 ParticularProcessPriorityManager::Notify(nsITimer* aTimer)
 {
-  if (mResetPriorityTimer == aTimer) {
-    LOGP("Reset priority timer callback; about to ResetPriorityNow.");
-    ResetPriorityNow();
-    mResetPriorityTimer = nullptr;
-    return NS_OK;
-  }
-
-  if (mContentParent && mMemoryPressureTimer == aTimer) {
-    Unused << mContentParent->SendFlushMemory(NS_LITERAL_STRING("lowering-priority"));
-    mMemoryPressureTimer = nullptr;
-    return NS_OK;
-  }
-
-  NS_WARNING("Unexpected timer!");
-  return NS_ERROR_INVALID_POINTER;
+  LOGP("Reset priority timer callback; about to ResetPriorityNow.");
+  ResetPriorityNow();
+  mResetPriorityTimer = nullptr;
+  return NS_OK;
 }
 
 bool
 ParticularProcessPriorityManager::HasAppType(const char* aAppType)
 {
   const ManagedContainer<PBrowserParent>& browsers =
     mContentParent->ManagedPBrowserParent();
   for (auto iter = browsers.ConstIter(); !iter.Done(); iter.Next()) {
@@ -1151,28 +1135,16 @@ ParticularProcessPriorityManager::SetPri
   mPriority = aPriority;
   hal::SetProcessPriority(Pid(), mPriority);
 
   if (oldPriority != mPriority) {
     ProcessPriorityManagerImpl::GetSingleton()->
       NotifyProcessPriorityChanged(this, oldPriority);
 
     Unused << mContentParent->SendNotifyProcessPriorityChanged(mPriority);
-
-    if (mMemoryPressureTimer) {
-      mMemoryPressureTimer->Cancel();
-      mMemoryPressureTimer = nullptr;
-    }
-
-    if (aPriority < PROCESS_PRIORITY_FOREGROUND) {
-      mMemoryPressureTimer = do_CreateInstance(NS_TIMER_CONTRACTID);
-      mMemoryPressureTimer->InitWithCallback(this,
-                                             sMemoryPressureGracePeriodMS,
-                                             nsITimer::TYPE_ONE_SHOT);
-    }
   }
 
   FireTestOnlyObserverNotification("process-priority-set",
     ProcessPriorityToString(mPriority));
 }
 
 void
 ParticularProcessPriorityManager::Freeze()