Reimplement EWebContext::NotifyLowMemory method.
authorAntonio Gomes <a1.gomes@samsung.com>
Mon, 25 Jan 2016 18:52:50 +0000 (14:52 -0400)
committerYoungsoo Choi <kenshin.choi@samsung.com>
Tue, 10 Jul 2018 07:55:23 +0000 (07:55 +0000)
MemoryPurger class is a fork of the obsolete files
chrome/browser/memory_purger.cc/h, removed in [1].
In [2], it is advised for callers of this API to use
RenderThreadImpl::OnMemoryPressure instead.

Patch provides an implementation of EWebContext::NotifyLowMemory
based on MemoryPressureController class that calls out to
MemoryPressureListener and down to RenderThreadImpl::OnMemoryPressure.

ewk/efl_integration/memory_purger.cc/h are also removed, as well
as message EwkViewMsg_PurgeMemory and its associated handler
RenderProcessObserverEfl::OnPurgeMemory.

Experiments with this API shows that it frees up to 40Mb of RAM
when browsing facebook.com.

[1] https://codereview.chromium.org/192573010
[2] https://code.google.com/p/chromium/issues/detail?id=350455#c13

Original beta/m47 patch: http://165.213.202.130/gerrit/#/c/105433/

Bug: http://107.108.218.239/bugzilla/show_bug.cgi?id=4822

Reviewed by: g.czajkowski

Change-Id: I437046a02b4486422dfd2913b1c2b51e405e8e2c
Signed-off-by: Antonio Gomes <a1.gomes@samsung.com>
tizen_src/ewk/efl_integration/common/render_messages_ewk.h
tizen_src/ewk/efl_integration/efl_integration.gypi
tizen_src/ewk/efl_integration/eweb_context.cc
tizen_src/ewk/efl_integration/memory_purger.cc [deleted file]
tizen_src/ewk/efl_integration/memory_purger.h [deleted file]
tizen_src/ewk/efl_integration/renderer/render_process_observer_efl.cc
tizen_src/ewk/efl_integration/renderer/render_process_observer_efl.h

index 999e627..becdcc0 100644 (file)
@@ -180,12 +180,6 @@ IPC_MESSAGE_CONTROL0(EflViewMsg_ClearCache)
 IPC_MESSAGE_CONTROL1(EflViewMsg_SetCache,
                      CacheParamsEfl)
 
-// Tells the renderer to dump as much memory as it can, perhaps because we
-// have memory pressure or the renderer is (or will be) paged out.  This
-// should only result in purging objects we can recalculate, e.g. caches or
-// JS garbage, not in purging irreplaceable objects.
-IPC_MESSAGE_CONTROL0(EwkViewMsg_PurgeMemory)
-
 IPC_MESSAGE_ROUTED3(EwkViewMsg_PrintToPdf,
                     int, /* width */
                     int, /* height */
index 5e1dc8f..6cb4970 100644 (file)
       'http_user_agent_settings_efl.h',
       'locale_efl.cc',
       'locale_efl.h',
-      'memory_purger.cc',
-      'memory_purger.h',
       'message_pump_for_ui_efl.cc',
       'message_pump_for_ui_efl.h',
       'network_delegate_efl.cc',
index a6c8541..a4fcca0 100644 (file)
@@ -6,8 +6,10 @@
 
 #include <string>
 #include <vector>
+
 #include "base/synchronization/waitable_event.h"
 #include "components/autofill/content/browser/content_autofill_driver.h"
+#include "content/browser/memory/memory_pressure_controller.h"
 #include "content/public/browser/appcache_service.h"
 #include "content/public/browser/browser_context.h"
 #include "content/public/browser/browser_thread.h"
@@ -31,7 +33,6 @@
 
 #include "browser_context_efl.h"
 #include "ewk_global_data.h"
-#include "memory_purger.h"
 #include "browser/password_manager/password_store_factory.h"
 #include "browser/browsing_data_remover_efl.h"
 #include "browser/vibration/vibration_provider_client.h"
@@ -327,7 +328,14 @@ void EWebContext::SetCertificate(const char* certificate_file) {
 }
 
 void EWebContext::NotifyLowMemory() {
-  MemoryPurger::PurgeAll(browser_context_.get());
+  // FIXME(a1.gomes): ChromeOS, Win and Mac have monitors that listen to system
+  // OOO notification, and act accordingly.
+  // Also, newer chromium rebases (m49+) have a new API for this named
+  // MemoryPressureController::SendPressureNotification. Use it when available.
+  DLOG(WARNING) << "Releasing as much memory as possible.";
+  content::MemoryPressureController::GetInstance()->
+      SimulatePressureNotificationInAllProcesses(
+          base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL);
 }
 
 bool EWebContext::HTTPCustomHeaderAdd(const std::string& name, const std::string& value) {
diff --git a/tizen_src/ewk/efl_integration/memory_purger.cc b/tizen_src/ewk/efl_integration/memory_purger.cc
deleted file mode 100644 (file)
index fafd3e3..0000000
+++ /dev/null
@@ -1,47 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Copyright 2014 Samsung Electronics. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "memory_purger.h"
-
-#include "base/allocator/allocator_extension.h"
-#include "content/public/browser/render_process_host.h"
-
-using content::BrowserContext;
-
-// static
-void MemoryPurger::PurgeAll(BrowserContext* browser_context) {
-  PurgeBrowser(browser_context);
-  PurgeRenderers();
-  // TODO(pk):
-  // * Tell the plugin processes to release their free memory?  Other stuff?
-  // * Enumerate what other processes exist and what to do for them.
-}
-
-// static
-void MemoryPurger::PurgeBrowser(BrowserContext* browser_context) {
-  // Tell our allocator to release any free pages it's still holding.
-  base::allocator::ReleaseFreeMemory();
-}
-
-// static
-void MemoryPurger::PurgeRenderers() {
-  // Direct all renderers to free everything they can.
-  //
-  // Concern: Telling a bunch of renderer processes to destroy their data may
-  // cause them to page everything in to do it, which could take a lot of time/
-  // cause jank.
-  for (content::RenderProcessHost::iterator i(
-          content::RenderProcessHost::AllHostsIterator());
-       !i.IsAtEnd(); i.Advance())
-    PurgeRendererForHost(i.GetCurrentValue());
-}
-
-// static
-void MemoryPurger::PurgeRendererForHost(content::RenderProcessHost* host) {
-#if !defined(EWK_BRINGUP)
-  // Direct the renderer to free everything it can.
-  host->Send(new EwkViewMsg_PurgeMemory());
-#endif
-}
diff --git a/tizen_src/ewk/efl_integration/memory_purger.h b/tizen_src/ewk/efl_integration/memory_purger.h
deleted file mode 100644 (file)
index 0dc22d6..0000000
+++ /dev/null
@@ -1,36 +0,0 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
-// Copyright 2014 Samsung Electronics. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// MemoryPurger provides static APIs to purge as much memory as possible from
-// all processes.  These can be hooked to various signals to try and balance
-// memory consumption, speed, page swapping, etc.
-//
-// This was implemented in an attempt to speed up suspend-to-disk by throwing
-// away any cached data that can be recomputed.  Memory use will rapidly
-// re-expand after this purge is run.
-
-#ifndef MEMORY_PURGER_H_
-#define MEMORY_PURGER_H_
-
-#include "base/basictypes.h"
-#include "content/public/browser/browser_context.h"
-
-namespace content {
-class RenderProcessHost;
-}
-
-class MemoryPurger {
- public:
-  // Call any of these on the UI thread to purge memory from the named places.
-  static void PurgeAll(content::BrowserContext* browser_context);
-  static void PurgeBrowser(content::BrowserContext* browser_context);
-  static void PurgeRenderers();
-  static void PurgeRendererForHost(content::RenderProcessHost* host);
-
- private:
-  DISALLOW_IMPLICIT_CONSTRUCTORS(MemoryPurger);
-};
-
-#endif  // MEMORY_PURGER_H_
index 95b67fe..c57c4ce 100644 (file)
@@ -20,7 +20,6 @@
 #include "third_party/WebKit/Source/config.h"
 #include "third_party/WebKit/Source/platform/fonts/FontCache.h"
 
-
 using blink::WebCache;
 using blink::WebRuntimeFeatures;
 using content::RenderThread;
@@ -38,7 +37,6 @@ bool RenderProcessObserverEfl::OnControlMessageReceived(const IPC::Message& mess
   IPC_BEGIN_MESSAGE_MAP(RenderProcessObserverEfl, message)
     IPC_MESSAGE_HANDLER(EflViewMsg_ClearCache, OnClearCache)
     IPC_MESSAGE_HANDLER(EflViewMsg_SetCache, OnSetCache)
-    IPC_MESSAGE_HANDLER(EwkViewMsg_PurgeMemory, OnPurgeMemory)
     IPC_MESSAGE_UNHANDLED(handled = false)
   IPC_END_MESSAGE_MAP()
   return handled;
@@ -49,6 +47,7 @@ void RenderProcessObserverEfl::WebKitInitialized()
   webkit_initialized_ = true;
   OnSetCache(pending_cache_params_);
 }
+
 void RenderProcessObserverEfl::OnClearCache()
 {
   WebCache::clear();
@@ -65,20 +64,3 @@ void RenderProcessObserverEfl::OnSetCache(const CacheParamsEfl& params)
     static_cast<size_t>(params.cache_total_capacity));
 }
 
-void RenderProcessObserverEfl::OnPurgeMemory()
-{
-  RenderThread::Get()->EnsureWebKitInitialized();
-  // Clear the object cache (as much as possible; some live objects cannot be
-  // freed).
-  OnClearCache();
-  // Clear the font/glyph cache.
-  blink::FontCache::fontCache()->invalidate();
-  // TODO(pk): currently web process not linking sqlite. when used this should enable
-  // Release all freeable memory from the SQLite process-global page cache (a
-  // low-level object which backs the Connection-specific page caches).
-  //while (sqlite3_release_memory(std::numeric_limits<int>::max()) > 0) {
-  //}
-  v8::Isolate::GetCurrent()->LowMemoryNotification();
-  // Tell our allocator to release any free pages it's still holding.
-  base::allocator::ReleaseFreeMemory();
-}
index af81eb3..ea7bd7a 100644 (file)
@@ -23,7 +23,6 @@ public:
   bool OnControlMessageReceived(const IPC::Message& message) override;
   void WebKitInitialized() override;
   void OnClearCache();
-  void OnPurgeMemory();
   
 private:
   void OnSetCache(const CacheParamsEfl& params);