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>
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 */
'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',
#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"
#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"
}
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) {
+++ /dev/null
-// 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
-}
+++ /dev/null
-// 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_
#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;
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;
webkit_initialized_ = true;
OnSetCache(pending_cache_params_);
}
+
void RenderProcessObserverEfl::OnClearCache()
{
WebCache::clear();
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();
-}
bool OnControlMessageReceived(const IPC::Message& message) override;
void WebKitInitialized() override;
void OnClearCache();
- void OnPurgeMemory();
private:
void OnSetCache(const CacheParamsEfl& params);