Bug 1398033 - Free dirty pages on memory pressure. r?njn draft
authorMike Hommey <mh+mozilla@glandium.org>
Fri, 08 Sep 2017 14:50:42 +0900
changeset 661211 3c9e74f844793a8249195c57c1671f9f2a431d6e
parent 661103 b4c1ad9565ee9d00d96501c4a83083daf25c1413
child 730495 142109aafd4c81defa34010409340b5bc3314ad3
push id78676
push userbmo:mh+mozilla@glandium.org
push dateFri, 08 Sep 2017 05:54:30 +0000
reviewersnjn
bugs1398033
milestone57.0a1
Bug 1398033 - Free dirty pages on memory pressure. r?njn Free dirty pages appear as "page-cache" in about:memory reports, but when minimizing memory, and more generally, on memory pressure, they're currently not force-free()ed on desktop, while they are on mobile. There doesn't seem to be much reason not to do it on desktop as well, and it should help reduce the noise in "explicit" allocations measurements on CI, too.
mobile/android/app/mobile.js
modules/libpref/init/all.js
xpcom/base/AvailableMemoryTracker.cpp
--- a/mobile/android/app/mobile.js
+++ b/mobile/android/app/mobile.js
@@ -734,20 +734,16 @@ pref("media.plugins.enabled", true);
 //  0 = Let Stagefright choose hardware or software decoding (default)
 //  8 = Force software decoding
 // 16 = Force hardware decoding
 pref("media.stagefright.omxcodec.flags", 0);
 
 // Coalesce touch events to prevent them from flooding the event queue
 pref("dom.event.touch.coalescing.enabled", false);
 
-// On memory pressure, release dirty but unused pages held by jemalloc
-// back to the system.
-pref("memory.free_dirty_pages", true);
-
 pref("layout.framevisibility.numscrollportwidths", 1);
 pref("layout.framevisibility.numscrollportheights", 1);
 
 pref("layers.enable-tiles", true);
 
 // Enable the dynamic toolbar
 pref("browser.chrome.dynamictoolbar", true);
 
--- a/modules/libpref/init/all.js
+++ b/modules/libpref/init/all.js
@@ -5201,18 +5201,19 @@ pref("memory.low_physical_memory_thresho
 pref("memory.low_memory_notification_interval_ms", 10000);
 #endif
 
 // How long must we wait before declaring that a window is a "ghost" (i.e., a
 // likely leak)?  This should be longer than it usually takes for an eligible
 // window to be collected via the GC/CC.
 pref("memory.ghost_window_timeout_seconds", 60);
 
-// Disable freeing dirty pages when minimizing memory.
-pref("memory.free_dirty_pages", false);
+// On memory pressure, release dirty but unused pages held by jemalloc
+// back to the system.
+pref("memory.free_dirty_pages", true);
 
 // Disable the Linux-specific, system-wide memory reporter.
 #ifdef XP_LINUX
 pref("memory.system_memory_reporter", false);
 #endif
 
 // Don't dump memory reports on OOM, by default.
 pref("memory.dump_reports_on_oom", false);
--- a/xpcom/base/AvailableMemoryTracker.cpp
+++ b/xpcom/base/AvailableMemoryTracker.cpp
@@ -328,34 +328,34 @@ public:
   void Init();
 
 private:
   static bool sFreeDirtyPages;
 };
 
 NS_IMPL_ISUPPORTS(nsMemoryPressureWatcher, nsIObserver)
 
-bool nsMemoryPressureWatcher::sFreeDirtyPages = false;
+bool nsMemoryPressureWatcher::sFreeDirtyPages = true;
 
 /**
  * Initialize and subscribe to the memory-pressure events. We subscribe to the
  * observer service in this method and not in the constructor because we need
  * to hold a strong reference to 'this' before calling the observer service.
  */
 void
 nsMemoryPressureWatcher::Init()
 {
   nsCOMPtr<nsIObserverService> os = services::GetObserverService();
 
   if (os) {
     os->AddObserver(this, "memory-pressure", /* ownsWeak */ false);
   }
 
   Preferences::AddBoolVarCache(&sFreeDirtyPages, "memory.free_dirty_pages",
-                               false);
+                               true);
 }
 
 /**
  * Reacts to all types of memory-pressure events, launches a runnable to
  * free dirty pages held by jemalloc.
  */
 NS_IMETHODIMP
 nsMemoryPressureWatcher::Observe(nsISupports* aSubject, const char* aTopic,