releasing background tabs
Tomeu Vizoso <[email protected]>
| Newsgroups | gmane.comp.gnome.apps.epiphany |
|---|---|
| Message-ID | <CAAObsKBv+6MFoC+AxjijYRt=K5t9xe5yjtOHzcjsEtMcBoUNSA@mail.gmail.com> |
Hello, have been giving a look at memory usage within epiphany with looks to make it work better in memory-constrained devices and have noticed that heap fragmentation will cause it to grow indefinitely as more tabs are open (and loaded, because of lazy loading of tabs at startup). This won't be such a problem once we have each webview in its own process, but for now the web process won't be able to return to the OS most of the memory allocated by its webviews. This can be easily checked with the crude patch I'm attaching. One can see that the allocated sizes of the malloc and tcmalloc heaps grow as more tabs get opened, even if the used memory decreases when closing tabs. So, similarly to what mobile browsers do, and reusing some of the code about delayed loading of tabs at startup, I'm considering keeping a maximum number of "live" tabs at any point, which would put a limit to heap grow. WebViews would be destroyed in LRU order and would be recreated when the user would come back to them. Is this something that interests upstream? Regards, Tomeu _______________________________________________ epiphany-list mailing list [email protected] https://mail.gnome.org/mailman/listinfo/epiphany-list
0001-Print-memory-usage-stats-on-F6.patch
(message/news, 3.9 KB)
From aabff742258f5a67e66a330464ca00e7d45e3598 Mon Sep 17 00:00:00 2001 From: ChangSeok Oh <[email protected]> Date: Mon, 4 Nov 2013 11:27:14 +0100 Subject: [PATCH] Print memory usage stats on F6 Co-Authored-By: Tomeu Vizoso <[email protected]> --- Source/WebCore/loader/cache/MemoryCache.cpp | 4 ++-- Source/WebCore/loader/cache/MemoryCache.h | 11 +++++++---- Source/WebKit/gtk/webkit/webkitwebview.cpp | 30 +++++++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 6 deletions(-) diff --git a/Source/WebCore/loader/cache/MemoryCache.cpp b/Source/WebCore/loader/cache/MemoryCache.cpp index 4690485..f894f96 100644 --- a/Source/WebCore/loader/cache/MemoryCache.cpp +++ b/Source/WebCore/loader/cache/MemoryCache.cpp @@ -876,7 +876,7 @@ void MemoryCache::pruneToPercentage(float targetPercentLive) } -#ifndef NDEBUG +//#ifndef NDEBUG void MemoryCache::dumpStats() { Statistics s = getStatistics(); @@ -923,6 +923,6 @@ void MemoryCache::dumpLRULists(bool includeLive) const } } } -#endif +//#endif } // namespace WebCore diff --git a/Source/WebCore/loader/cache/MemoryCache.h b/Source/WebCore/loader/cache/MemoryCache.h index 3f8b616..a5199f1 100644 --- a/Source/WebCore/loader/cache/MemoryCache.h +++ b/Source/WebCore/loader/cache/MemoryCache.h @@ -187,15 +187,18 @@ public: unsigned liveSize() const { return m_liveSize; } unsigned deadSize() const { return m_deadSize; } + void dumpStats(); + void dumpLRULists(bool includeLive) const; + private: MemoryCache(); ~MemoryCache(); // Not implemented to make sure nobody accidentally calls delete -- WebCore does not delete singletons. LRUList* lruListFor(CachedResource*); -#ifndef NDEBUG - void dumpStats(); - void dumpLRULists(bool includeLive) const; -#endif +//#ifndef NDEBUG +// void dumpStats(); +// void dumpLRULists(bool includeLive) const; +//#endif unsigned liveCapacity() const; unsigned deadCapacity() const; diff --git a/Source/WebKit/gtk/webkit/webkitwebview.cpp b/Source/WebKit/gtk/webkit/webkitwebview.cpp index fa30bc5..3736ba6 100644 --- a/Source/WebKit/gtk/webkit/webkitwebview.cpp +++ b/Source/WebKit/gtk/webkit/webkitwebview.cpp @@ -714,8 +714,38 @@ static gboolean webkit_web_view_draw(GtkWidget* widget, cairo_t* cr) } #endif // GTK_API_VERSION_2 +#include <malloc.h> + static gboolean webkit_web_view_key_press_event(GtkWidget* widget, GdkEventKey* event) { + if (event->keyval == GDK_F6) { + struct mallinfo mi; + + memoryCache()->dumpStats(); + + mi = mallinfo(); + + printf("=========================================\n"); + printf("Total non-mmapped bytes (arena): %d\n", mi.arena); + printf("# of free chunks (ordblks): %d\n", mi.ordblks); + printf("# of free fastbin blocks (smblks): %d\n", mi.smblks); + printf("# of mapped regions (hblks): %d\n", mi.hblks); + printf("Bytes in mapped regions (hblkhd): %d\n", mi.hblkhd); + printf("Total allocated space (uordblks): %d\n", mi.uordblks); + printf("Total free space (fordblks): %d\n", mi.fordblks); + printf("Topmost releasable block (keepcost): %d\n", mi.keepcost); + printf("=========================================\n"); + + WTF::FastMallocStatistics stats = WTF::fastMallocStatistics(); + printf("=========================================\n"); + printf("Reserved VM %d\n", stats.reservedVMBytes); + printf("Committed VM %d\n", stats.committedVMBytes); + printf("Free list %d\n", stats.freeListBytes); + printf("=========================================\n"); + + fflush(stdin); + } + if (WEBKIT_WEB_VIEW(widget)->priv->imFilter.filterKeyEvent(event)) return TRUE; return GTK_WIDGET_CLASS(webkit_web_view_parent_class)->key_press_event(widget, event); -- 1.8.4.2