Bug 1414150 - Remove the "memory.low_*" prefs. r=erahm,dmajor.
authorNicholas Nethercote <nnethercote@mozilla.com>
Wed, 08 Nov 2017 07:49:46 +1100
changeset 443961 99a32740c0588f68bc391a3ae24fe478782134ac
parent 443960 b84d87e9fa100abe4f3aa073d2e169d3392d9b4c
child 443962 242b1157a36a8fbe769179a630c8457562d9568f
push id1618
push userCallek@gmail.com
push dateThu, 11 Jan 2018 17:45:48 +0000
treeherdermozilla-release@882ca853e05a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerserahm, dmajor
bugs1414150
milestone58.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 1414150 - Remove the "memory.low_*" prefs. r=erahm,dmajor. There's no good reason why these should't just be constants. The patch also appends "MiB" to some of the C++ values to make their meaning clearer. This patch fixes one outright bug, and one inconsistency. The bug is due to a prefname mismatch: - ContentPrefs.cpp and AvailableMemoryTracker.cpp use "memory.low_virtual_mem_threshold_mb". - all.js uses "memory.low_virtual_memory_threshold_mb". Which means that "memory.low_virtual_memory_threshold_mb" showed up in about:config, but if you changed it nothing would happen because the callback listened for changes to to "memory.low_virtual_mem_threshold_mb"! Now for the inconsistency. The above means we actually use a value of 256 for the virtual memory threshold, even though all.js says 128. But we *do* use a value of 128 for the commit space threshold, because that's what all.js says and that prefname is used correctly everywhere. The patch changes the commit space threshold to 256 for consistency with the virtual memory threshold. What a mess!
dom/ipc/ContentPrefs.cpp
modules/libpref/init/all.js
xpcom/base/AvailableMemoryTracker.cpp
--- a/dom/ipc/ContentPrefs.cpp
+++ b/dom/ipc/ContentPrefs.cpp
@@ -176,20 +176,16 @@ const char* mozilla::dom::ContentPrefs::
   "media.webspeech.test.enable",
   "media.webspeech.test.fake_fsm_events",
   "media.webspeech.test.fake_recognition_service",
   "media.wmf.allow-unsupported-resolutions",
   "media.wmf.decoder.thread-count",
   "media.wmf.enabled",
   "media.wmf.skip-blacklist",
   "media.wmf.vp9.enabled",
-  "memory.low_commit_space_threshold_mb",
-  "memory.low_memory_notification_interval_ms",
-  "memory.low_physical_memory_threshold_mb",
-  "memory.low_virtual_mem_threshold_mb",
   "network.IDN.blacklist_chars",
   "network.IDN.restriction_profile",
   "network.IDN.use_whitelist",
   "network.IDN_show_punycode",
   "network.buffer.cache.count",
   "network.buffer.cache.size",
   "network.captive-portal-service.enabled",
   "network.cookie.cookieBehavior",
--- a/modules/libpref/init/all.js
+++ b/modules/libpref/init/all.js
@@ -5205,35 +5205,16 @@ pref("layout.css.expensive-style-struct-
 
 #if defined(MOZ_WIDGET_ANDROID)
 // Network Information API
 pref("dom.netinfo.enabled", true);
 #else
 pref("dom.netinfo.enabled", false);
 #endif
 
-#ifdef XP_WIN
-// On 32-bit Windows, fire a low-memory notification if we have less than this
-// many mb of virtual address space available.
-pref("memory.low_virtual_memory_threshold_mb", 128);
-
-// On Windows 32-bit, fire a low-memory notification if we have less
-// than this many mb of commit space (physical memory plus page file) left.
-pref("memory.low_commit_space_threshold_mb", 128);
-
-// On Windows 32-bit, fire a low-memory notification if we have less
-// than this many mb of physical memory available on the whole machine.
-pref("memory.low_physical_memory_threshold_mb", 0);
-
-// On Windows 32-bit, don't fire a low-memory notification because of
-// low available physical memory or low commit space more than once every
-// low_memory_notification_interval_ms.
-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);
 
 // 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
@@ -32,21 +32,31 @@
 #endif  // MOZ_MEMORY
 
 using namespace mozilla;
 
 namespace {
 
 #if defined(_M_IX86) && defined(XP_WIN)
 
+// Fire a low-memory notification if we have less than this many MiB of virtual
+// address space available.
+static const uint32_t kLowVirtualMemoryThresholdMiB = 256;
 
-uint32_t sLowVirtualMemoryThreshold = 0;
-uint32_t sLowCommitSpaceThreshold = 0;
-uint32_t sLowPhysicalMemoryThreshold = 0;
-uint32_t sLowMemoryNotificationIntervalMS = 0;
+// Fire a low-memory notification if we have less than this many MiB of commit
+// space (physical memory plus page file) left.
+static const uint32_t kLowCommitSpaceThresholdMiB = 256;
+
+// Fire a low-memory notification if we have less than this many MiB of
+// physical memory available on the whole machine.
+static const uint32_t kLowPhysicalMemoryThresholdMiB = 0;
+
+// Don't fire a low-memory notification because of low available physical
+// memory or low commit space more often than this interval.
+static const uint32_t kLowMemoryNotificationIntervalMS = 10000;
 
 Atomic<uint32_t> sNumLowVirtualMemEvents;
 Atomic<uint32_t> sNumLowCommitSpaceEvents;
 Atomic<uint32_t> sNumLowPhysicalMemEvents;
 
 WindowsDllInterceptor sKernel32Intercept;
 WindowsDllInterceptor sGdi32Intercept;
 
@@ -80,17 +90,17 @@ HBITMAP(WINAPI* sCreateDIBSectionOrig)(H
  */
 bool
 MaybeScheduleMemoryPressureEvent()
 {
   // If this interval rolls over, we may fire an extra memory pressure
   // event, but that's not a big deal.
   PRIntervalTime interval = PR_IntervalNow() - sLastLowMemoryNotificationTime;
   if (sHasScheduledOneLowMemoryNotification &&
-      PR_IntervalToMilliseconds(interval) < sLowMemoryNotificationIntervalMS) {
+      PR_IntervalToMilliseconds(interval) < kLowMemoryNotificationIntervalMS) {
 
     return false;
   }
 
   // There's a bit of a race condition here, since an interval may be a
   // 64-bit number, and 64-bit writes aren't atomic on x86-32.  But let's
   // not worry about it -- the races only happen when we're already
   // experiencing memory pressure and firing notifications, so the worst
@@ -110,28 +120,28 @@ CheckMemAvailable()
     return;
   }
 
   MEMORYSTATUSEX stat;
   stat.dwLength = sizeof(stat);
   bool success = GlobalMemoryStatusEx(&stat);
 
   if (success) {
-    // sLowVirtualMemoryThreshold is in MB, but ullAvailVirtual is in bytes.
-    if (stat.ullAvailVirtual < sLowVirtualMemoryThreshold * 1024 * 1024) {
+    // kLowVirtualMemoryThresholdMiB is in MiB, but ullAvailVirtual is in bytes.
+    if (stat.ullAvailVirtual < kLowVirtualMemoryThresholdMiB * 1024 * 1024) {
       // If we're running low on virtual memory, unconditionally schedule the
       // notification.  We'll probably crash if we run out of virtual memory,
       // so don't worry about firing this notification too often.
       ++sNumLowVirtualMemEvents;
       NS_DispatchEventualMemoryPressure(MemPressure_New);
-    } else if (stat.ullAvailPageFile < sLowCommitSpaceThreshold * 1024 * 1024) {
+    } else if (stat.ullAvailPageFile < kLowCommitSpaceThresholdMiB * 1024 * 1024) {
       if (MaybeScheduleMemoryPressureEvent()) {
         ++sNumLowCommitSpaceEvents;
       }
-    } else if (stat.ullAvailPhys < sLowPhysicalMemoryThreshold * 1024 * 1024) {
+    } else if (stat.ullAvailPhys < kLowPhysicalMemoryThresholdMiB * 1024 * 1024) {
       if (MaybeScheduleMemoryPressureEvent()) {
         ++sNumLowPhysicalMemEvents;
       }
     }
   }
 }
 
 LPVOID WINAPI
@@ -151,18 +161,18 @@ VirtualAllocHook(LPVOID aAddress, SIZE_T
   // afterwards how much free virtual address space we have.  If we're running
   // low, we schedule a low-memory notification to run as soon as possible.
 
   LPVOID result = sVirtualAllocOrig(aAddress, aSize, aAllocationType, aProtect);
 
   // Don't call CheckMemAvailable for MEM_RESERVE if we're not tracking low
   // virtual memory.  Similarly, don't call CheckMemAvailable for MEM_COMMIT if
   // we're not tracking low physical memory.
-  if ((sLowVirtualMemoryThreshold != 0 && aAllocationType & MEM_RESERVE) ||
-      (sLowPhysicalMemoryThreshold != 0 && aAllocationType & MEM_COMMIT)) {
+  if ((kLowVirtualMemoryThresholdMiB != 0 && aAllocationType & MEM_RESERVE) ||
+      (kLowPhysicalMemoryThresholdMiB != 0 && aAllocationType & MEM_COMMIT)) {
     CheckMemAvailable();
   }
 
   return result;
 }
 
 LPVOID WINAPI
 MapViewOfFileHook(HANDLE aFileMappingObject,
@@ -369,26 +379,16 @@ namespace AvailableMemoryTracker {
 
 void
 Activate()
 {
 #if defined(_M_IX86) && defined(XP_WIN)
   MOZ_ASSERT(sInitialized);
   MOZ_ASSERT(!sHooksActive);
 
-  Preferences::AddUintVarCache(&sLowVirtualMemoryThreshold,
-                               "memory.low_virtual_mem_threshold_mb", 256);
-  Preferences::AddUintVarCache(&sLowPhysicalMemoryThreshold,
-                               "memory.low_physical_memory_threshold_mb", 0);
-  Preferences::AddUintVarCache(&sLowCommitSpaceThreshold,
-                               "memory.low_commit_space_threshold_mb", 256);
-  Preferences::AddUintVarCache(&sLowMemoryNotificationIntervalMS,
-                               "memory.low_memory_notification_interval_ms",
-                               10000);
-
   RegisterStrongMemoryReporter(new LowEventsReporter());
   RegisterLowMemoryEventsVirtualDistinguishedAmount(
     LowMemoryEventsVirtualDistinguishedAmount);
   RegisterLowMemoryEventsPhysicalDistinguishedAmount(
     LowMemoryEventsPhysicalDistinguishedAmount);
   sHooksActive = true;
 #endif