cog icon indicating copy to clipboard operation
cog copied to clipboard

Cog memory leak

Open lilveg opened this issue 7 years ago • 7 comments

Hello!

I am experiencing a memory leak in Cog. It's memory usage grows by about 25 MB/hour. The attached graph shows the available system memory along with with the memory consumed by Cog, WPEWebProcess and WPENetworkProcess individually, over a period of about 20 hours.

cog-memory

I am running a Qualcomm Snapdragon SD-410, with the latest Cog and WPE from meta-webkit as of yesterday (b12d42). This means commit 063df1 of Cog and version 2.22.0-r0 of WPEWebKit.

I am starting cog with these variables and arguments

[Service]
Environment=XDG_RUNTIME_DIR=/data/xdg_runtime_dir
Environment=COG_PLATFORM_FDO_VIEW_FULLSCREEN=1
Environment=WEBKIT_INSPECTOR_SERVER=0.0.0.0:2999
Environment=WPE_RAM_SIZE=128m
Environment=WPE_POLL_MAX_MEMORY=databaseprocess:50m,networkprocess:100m,webprocess:300m,rpcprocess:50m
Environment=MSE_MAX_BUFFER_SIZE=audio:2m,video:15m,text:1m
ExecStart=/usr/bin/cog -P fdo --enable-write-console-messages-to-stdout=true <url>

The page being displayed is of relatively low-resolution images scrolling horizontally using canvas, but the issue has also been observed when using css transforms.

Any help in finding the source of this problem is greatly appreciated!

lilveg avatar Oct 11 '18 08:10 lilveg

There's definitely something fishy going on here. Given that you are experiencing this when new frames are constantly being rendered and displayed (i.e. the image carousel, the transforms) what comes to my mind is something related to the code that runs on ever frame update.

Which resolution does your screen have, and how fast your animations are? I see from you graph that memory usage increases by 100 MiB in ~4 hours (that is: ~25 MiB/hour, ~420 KiB/minute, or ~7 KiB/second), so it does not look like buffers with rendered frames are being leaked (because for example a 960x540 screen in true color would take a bit inder 2 MiB per rendered frame) — but I would like to confirm my suspicion.

aperezdc avatar Oct 11 '18 19:10 aperezdc

Hello Adrian,

The screen is 1280x1024. The canvas-based carousel runs at between 20 and 30 FPS, depending on how many images are on the screen.

lilveg avatar Oct 12 '18 08:10 lilveg

I ran a test over the weekend, on the site that uses CSS transformations. Curiously, Cog consumes memory in a steep curve until it reaches 300 MB, then flattens out. This flattening corresponds with the system running very low on available memory, yet the fact that the memory consumption becomes so flat leads me to wonder if some kind of memory limit has been reached in Cog.

cog

Near the end of the graph, WPEWebProcss seems to crash, and the screen was blank this morning. I assume this happened to due lack of memory.

lilveg avatar Oct 15 '18 10:10 lilveg

A small leak was fixed in the FDO backend recently (see https://github.com/Igalia/WPEBackend-fdo/pull/31), I wonder if it might be related :thinking:

@lilveg Is there any chance you could re-run your test with the patch applied? Note that the fix is also available in the wpebackend-fdo-1.0 branch, which I think is the version you were (are?) probably using.

aperezdc avatar Feb 26 '19 10:02 aperezdc

I am going to close this issue for now, as it looks like the issue is gone—or at least nobody has been able to reproduce it anymore. If @lilveg or someone else can still hit the problem with current versions, we can always reopen this issue later :smiley_cat:

aperezdc avatar Aug 25 '20 14:08 aperezdc

There's a memory leak during video playback with recent cog/wpewebkit on i.MX6DL platform: https://github.com/WebPlatformForEmbedded/WPEWebKit/issues/1191

(not sure which project is better suited for opening that issue, so just referencing it here)

vnd avatar Sep 21 '23 09:09 vnd

Hi @aperezdc!

We are experiencing (most likely) the same issue: we can reproduce it with the following transform

.scrolling-text {
    animation: scroll-left 200 linear infinite;
    transform: translate3d(0, 0, 0);
}

@keyframes scroll-left {
    0% {
        transform: translate3d(1600px, 0, 0);
    }
    100% {
        transform: translate3d(-100%, 0, 0);
    }
}

Could the issue be re-opened?

stfnzl avatar Jan 08 '25 20:01 stfnzl