releasing background tabs



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
--- Begin Message ---
Co-Authored-By: Tomeu Vizoso <tomeu vizoso collabora com>
---
 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


--- End Message ---


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]