7.1-r1 on Intel: media.coder seems to leak memory

278 views
Skip to first unread message

Luigi Capriotti

unread,
Apr 5, 2018, 6:53:42 AM4/5/18
to Android-x86
I have been running a digital signage client (xibo) on the latest stable nougat out of an Intel i3 machine, where the xibo client constantly shows different video clips, among other things.
As time passes, the process media.coder keeps on using more and more memory, until the system halts.

The system log contains endless repetitions of the these lines:

(....)
04-03 13:38:13.950  1214 12935 D SoftFFmpegVideo: drainOneOutputBuffer: frame_width=1920 frame_height=1080 buffer_width=1920 buffer_height=1080 ctx_width=1920 ctx_height=1080 mIsAdaptive=0
04-03 13:38:13.985  1214 12935 D SoftFFmpegVideo: drainOneOutputBuffer: frame_width=1920 frame_height=1080 buffer_width=1920 buffer_height=1080 ctx_width=1920 ctx_height=1080 mIsAdaptive=0
04-03 13:38:14.008 13067 13067 I su      : type=1400 audit(0.0:3935): avc: denied { execute_no_trans } for path="/system/xbin/supolicy" dev="loop1" ino=6991 scontext=u:r:init:s0 tcontext=u:object_r:system_file:s0 tclass=file permissive=1
04-03 13:38:14.014 13067 13067 I supolicy: type=1400 audit(0.0:3936): avc: denied { read_policy } for scontext=u:r:init:s0 tcontext=u:object_r:kernel:s0 tclass=security permissive=1
04-03 13:38:14.034  1214 12935 D SoftFFmpegVideo: drainOneOutputBuffer: frame_width=1920 frame_height=1080 buffer_width=1920 buffer_height=1080 ctx_width=1920 ctx_height=1080 mIsAdaptive=0
04-03 13:38:14.066  1214 12935 D SoftFFmpegVideo: drainOneOutputBuffer: frame_width=1920 frame_height=1080 buffer_width=1920 buffer_height=1080 ctx_width=1920 ctx_height=1080 mIsAdaptive=0
04-03 13:38:14.097 13067 13067 I supolicy: --- SELinux policy patch start ---
04-03 13:38:14.097 13067 13067 I supolicy: --- SELinux policy patch end ---
04-03 13:38:14.097 13067 13067 I supolicy: type=1400 audit(0.0:3937): avc: denied { load_policy } for scontext=u:r:init:s0 tcontext=u:object_r:kernel:s0 tclass=security permissive=1
04-03 13:38:14.104  1217  1217 I NPDecoder-CL: type=1400 audit(0.0:3938): avc: denied { ioctl } for path="/dev/dri/card0" dev="tmpfs" ino=5102 ioctlcmd=645f scontext=u:r:mediaserver:s0 tcontext=u:object_r:device:s0 tclass=chr_file permissive=1
04-03 13:38:14.107  1214  1214 I eg.h264.decoder: type=1400 audit(0.0:3939): avc: denied { ioctl } for path="/dev/dri/renderD128" dev="tmpfs" ino=5101 ioctlcmd=6457 scontext=u:r:mediacodec:s0 tcontext=u:object_r:device:s0 tclass=chr_file permissive=1
04-03 13:38:14.111  1152  1152 I auditd  : type=1403 audit(0.0:3940): policy loaded auid=4294967295 ses=4294967295
04-03 13:38:14.116  1214 12935 D SoftFFmpegVideo: drainOneOutputBuffer: frame_width=1920 frame_height=1080 buffer_width=1920 buffer_height=1080 ctx_width=1920 ctx_height=1080 mIsAdaptive=0
04-03 13:38:14.130  1201  1201 I surfaceflinger: type=1400 audit(0.0:3941): avc: denied { ioctl } for path="/dev/dri/card0" dev="tmpfs" ino=5102 ioctlcmd=640b scontext=u:r:surfaceflinger:s0 tcontext=u:object_r:device:s0 tclass=chr_file permissive=1
04-03 13:38:14.130  1201  1201 I surfaceflinger: type=1400 audit(0.0:3942): avc: denied { read } for path="/dev/dri/card0" dev="tmpfs" ino=5102 scontext=u:r:surfaceflinger:s0 tcontext=u:object_r:device:s0 tclass=chr_file permissive=1
04-03 13:38:14.150  1214 12935 D SoftFFmpegVideo: drainOneOutputBuffer: frame_width=1920 frame_height=1080 buffer_width=1920 buffer_height=1080 ctx_width=1920 ctx_height=1080 mIsAdaptive=0
04-03 13:38:14.178 13084 13084 I toybox  : type=1400 audit(0.0:3943): avc: denied { associate } for name="tmp-mksh" dev="tmpfs" ino=8060 scontext=u:object_r:rootfs:s0 tcontext=u:object_r:tmpfs:s0 tclass=filesystem permissive=1
04-03 13:38:14.182  1214 12935 D SoftFFmpegVideo: drainOneOutputBuffer: frame_width=1920 frame_height=1080 buffer_width=1920 buffer_height=1080 ctx_width=1920 ctx_height=1080 mIsAdaptive=0
04-03 13:38:14.202 12921 12921 I wget    : type=1400 audit(0.0:3944): avc: denied { read } for path="socket:[125336]" dev="sockfs" ino=125336 scontext=u:r:init:s0 tcontext=u:r:init:s0 tclass=tcp_socket permissive=1
04-03 13:38:14.234  1214 12935 D SoftFFmpegVideo: drainOneOutputBuffer: frame_width=1920 frame_height=1080 buffer_width=1920 buffer_height=1080 ctx_width=1920 ctx_height=1080 mIsAdaptive=0
04-03 13:38:14.267  1214 12935 D SoftFFmpegVideo: drainOneOutputBuffer: frame_width=1920 frame_height=1080 buffer_width=1920 buffer_height=1080 ctx_width=1920 ctx_height=1080 mIsAdaptive=0
04-03 13:38:14.318  1214 12935 D SoftFFmpegVideo: drainOneOutputBuffer: frame_width=1920 frame_height=1080 buffer_width=1920 buffer_height=1080 ctx_width=1920 ctx_height=1080 mIsAdaptive=0
(....)

Is this a known issue with nougat on Intel GPUs or something misconfigured from my side?

Thanks in advance
Luigi

Carmen R

unread,
Apr 5, 2018, 10:51:37 AM4/5/18
to Android-x86
noticed that also, seems like a simple memory leak. it takes hours of fiddling with VLC or Youtube (in a browser) to get media.codec to ~600-800M but then backgrounded apps get killed due to low system-memory.

you can simply kill the process as root and a watchdog will restart it over with the memory freed. you can even restart it while video is playing, and the video doesn't stop! also you can upgrade to nightly Oreo builds from Mauro or Bliss. pretty sure whatever bug it was has been fixed in mainline

Luigi Capriotti

unread,
Apr 5, 2018, 11:27:06 AM4/5/18
to Android-x86
On Thursday, April 5, 2018 at 4:51:37 PM UTC+2, Carmen R wrote:
noticed that also, seems like a simple memory leak. it takes hours of fiddling with VLC or Youtube (in a browser) to get media.codec to ~600-800M but then backgrounded apps get killed due to low system-memory.

you can simply kill the process as root and a watchdog will restart it over with the memory freed. you can even restart it while video is playing, and the video doesn't stop! also you can upgrade to nightly Oreo builds from Mauro or Bliss. pretty sure whatever bug it was has been fixed in mainline

Thanks Carmen, I can confirm the latest nightly Bliss 10 works as expected. 
Any chance it will be fixed in a future "official" nougat build?

L

Michael Goffioul

unread,
Apr 5, 2018, 11:48:56 AM4/5/18
to andro...@googlegroups.com
AFAIK oreo-x86 doesn't have hw-accelerated codecs yet, so this may explain why there's no memory leak in that build.

Michael.

Luigi Capriotti

unread,
Apr 6, 2018, 2:53:47 AM4/6/18
to Android-x86
would it be possible to turn off HW-acceleration on official nougat? 
Leak-free SW-assisted decoding in my case is better than HW-accelerated but leaking decoding...

spin877

unread,
Apr 6, 2018, 4:03:21 AM4/6/18
to Android-x86

just the memory is saturated

echo 3 >/proc/sys/vm/drop_caches


the situation improves?
you could schedule it with tot. minutes


ciao

Luigi Capriotti

unread,
Apr 6, 2018, 6:13:32 AM4/6/18
to Android-x86
does not seem to help:

x86:/ # procrank | head
  PID       Vss      Rss      Pss      Uss  cmdline
 1231   414008K  308316K  306993K  306860K  media.codec
x86:/ # echo 3 >/proc/sys/vm/drop_caches
x86:/ # procrank | head
  PID       Vss      Rss      Pss      Uss  cmdline
 1231   414008K  307044K  305777K  305684K  media.codec

numbers are always increasing over time:
1231   178900K   85040K   70730K   64272K  media.codec
1231   198356K  100696K   86274K   79704K  media.codec
1231   246492K  144724K  130415K  123952K  media.codec


Michael Goffioul

unread,
Apr 6, 2018, 7:51:33 AM4/6/18
to andro...@googlegroups.com
Try to set property "media.sf.hwaccel" to 0.


On Fri, Apr 6, 2018 at 2:53 AM, Luigi Capriotti <l.cap...@gmail.com> wrote:
would it be possible to turn off HW-acceleration on official nougat? 
Leak-free SW-assisted decoding in my case is better than HW-accelerated but leaking decoding...

--
You received this message because you are subscribed to the Google Groups "Android-x86" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-x86+unsubscribe@googlegroups.com.
To post to this group, send email to andro...@googlegroups.com.
Visit this group at https://groups.google.com/group/android-x86.
For more options, visit https://groups.google.com/d/optout.

youling 257

unread,
Apr 7, 2018, 1:21:14 PM4/7/18
to Android-x86
android_x86:/ # cat /proc/sys/vm/drop_caches
0
android_x86:/ # echo 3 >/proc/sys/vm/drop_caches
android_x86:/ # cat /proc/sys/vm/drop_caches
3
android_x86:/ # procrank | head
  PID Vss Rss Pss Uss cmdline
 1526 386648K 237000K 235123K 234892K media.codec
28432 1247144K 180588K 105232K 83128K com.android.systemui
 1859 1950348K 157464K 102039K 92380K system_server
 2492 1538972K 141880K 86035K 75344K com.baidu.input
 2791 1238220K 80200K 39774K 34916K com.google.android.gms.persistent
 3351 1182964K 58516K 35742K 34560K com.farmerbb.taskbar.paid
 4453 1166344K 78396K 31381K 23964K jackpal.androidterm
 3131 1884360K 61360K 30967K 28744K com.schiztech.swapps
 2722 1185172K 49648K 27500K 26408K com.google.android.apps.nexuslauncher
android_x86:/ # kill -9 1526
android_x86:/ # procrank | head
  PID Vss Rss Pss Uss cmdline
 1859 1949644K 158304K 102676K 93100K system_server
28432 1245232K 173932K 98067K 76100K com.android.systemui
 2492 1537436K 150544K 94440K 83828K com.baidu.input
 2791 1238220K 80672K 39884K 35060K com.google.android.gms.persistent
 3351 1182964K 58516K 35741K 34560K com.farmerbb.taskbar.paid
 4453 1166296K 80932K 33714K 26392K jackpal.androidterm
 3131 1884360K 61360K 30942K 28744K com.schiztech.swapps
 2722 1185172K 49648K 27498K 26408K com.google.android.apps.nexuslauncher
28509 1133472K 87008K 25322K 11952K com.android.externalstorage


[ 9236.421965] init: Service 'mediacodec' (pid 1526) killed by signal 9
[ 9236.422038] init: Service 'mediacodec' (pid 1526) killing any children in process group
[ 9236.423858] init: Starting service 'mediacodec'...
[ 9236.449734] type=1400 audit(1523121121.040:5199): avc: denied { getattr } for pid=28769 comm="mediacodec" path="/vendor" dev="tmpfs" ino=386 scontext=u:r:mediacodec:s0 tcontext=u:object_r:tmpfs:s0 tclass=lnk_file permissive=1
[ 9236.450360] type=1400 audit(1523121121.040:5200): avc: denied { read } for pid=28769 comm="mediacodec" name="vendor" dev="tmpfs" ino=386 scontext=u:r:mediacodec:s0 tcontext=u:object_r:tmpfs:s0 tclass=lnk_file permissive=1

android_x86:/ # procrank | head
  PID Vss Rss Pss Uss cmdline
 1859 1954188K 178696K 109925K 97796K system_server
28432 1252780K 181288K 89381K 69400K com.android.systemui
 2492 1528640K 143840K 81374K 73268K com.baidu.input
 2791 1238220K 85996K 39173K 34900K com.google.android.gms.persistent
 2722 1185172K 99672K 38192K 29504K com.google.android.apps.nexuslauncher
 3351 1182964K 58516K 35624K 34560K com.farmerbb.taskbar.paid
 4453 1166480K 90216K 34048K 27808K jackpal.androidterm
 3131 1884360K 61384K 30578K 28764K com.schiztech.swapps
 4360 1153900K 97912K 30375K 21832K org.uguess.android.sysinfo.pre
android_x86:/ # procrank | head
  PID Vss Rss Pss Uss cmdline
29115 1402032K 270400K 127074K 111360K com.chrome.canary
29554 1414260K 258064K 126358K 117540K com.chrome.canary:sandboxed_process1
 1859 1953024K 175088K 101083K 94124K system_server
 2492 1534784K 131784K 68670K 64712K com.baidu.input
29310 1321440K 191312K 60972K 52516K com.chrome.canary:sandboxed_process0
28432 1248208K 154404K 60528K 51940K com.android.systemui
 3131 1887916K 131520K 58815K 53516K com.schiztech.swapps
29832 1241872K 169692K 39183K 30936K com.chrome.canary:sandboxed_process3
 2791 1239260K 100720K 38957K 35240K com.google.android.gms.persistent
android_x86:/ #

Michael Goffioul

unread,
Apr 26, 2018, 2:47:05 PM4/26/18
to Android-x86
I think I found one source of leakage (I'm not ruling out the possibility that there are others) in the hw-acceleration layer: it's missing some cleanup when uninitializing the decoder. This patch solves it:

diff --git a/external/stagefright-plugins/omx/ffmpeg_hwaccel.c.orig b/external/stagefright-plugins/omx/ffmpeg_hwaccel.c
index 229fcb1..33c84fb 100644
--- a/external/stagefright-plugins/omx/ffmpeg_hwaccel.c.orig
+++ b/external/stagefright-plugins/omx/ffmpeg_hwaccel.c
@@ -162,8 +162,10 @@ int ffmpeg_hwaccel_init(AVCodecContext *avctx)
 void ffmpeg_hwaccel_deinit(AVCodecContext *avctx)
 {
     if (avctx->opaque) {
-#ifdef LIBAV_CONFIG_H
         InputStream *ist = avctx->opaque;
+        if (ist->hwaccel_uninit)
+            ist->hwaccel_uninit(avctx);
+#ifdef LIBAV_CONFIG_H
         avcodec_free_context(&ist->dec_ctx);
 #endif
         av_freep(&avctx->opaque);


Michael.



On Thursday, April 5, 2018 at 11:48:56 AM UTC-4, Michael Goffioul wrote:

Luigi Capriotti

unread,
Apr 27, 2018, 2:37:09 AM4/27/18
to Android-x86
if you could provide me with a build I'd be glad to repeat the tests.
Tks

Chih-Wei Huang

unread,
Apr 27, 2018, 2:57:13 AM4/27/18
to Android-x86
2018-04-27 2:47 GMT+08:00 Michael Goffioul <michael....@gmail.com>:
> I think I found one source of leakage (I'm not ruling out the possibility
> that there are others) in the hw-acceleration layer: it's missing some
> cleanup when uninitializing the decoder. This patch solves it:
>
> diff --git a/external/stagefright-plugins/omx/ffmpeg_hwaccel.c.orig
> b/external/stagefright-plugins/omx/ffmpeg_hwaccel.c
> index 229fcb1..33c84fb 100644
> --- a/external/stagefright-plugins/omx/ffmpeg_hwaccel.c.orig
> +++ b/external/stagefright-plugins/omx/ffmpeg_hwaccel.c
> @@ -162,8 +162,10 @@ int ffmpeg_hwaccel_init(AVCodecContext *avctx)
> void ffmpeg_hwaccel_deinit(AVCodecContext *avctx)
> {
> if (avctx->opaque) {
> -#ifdef LIBAV_CONFIG_H
> InputStream *ist = avctx->opaque;
> + if (ist->hwaccel_uninit)
> + ist->hwaccel_uninit(avctx);
> +#ifdef LIBAV_CONFIG_H
> avcodec_free_context(&ist->dec_ctx);
> #endif
> av_freep(&avctx->opaque);

Great! Thank you for the fix.
I've pushed it.


--
Chih-Wei
Android-x86 project
http://www.android-x86.org

Michael Goffioul

unread,
Apr 27, 2018, 6:24:12 AM4/27/18
to andro...@googlegroups.com
I think another tiny small source of leakage is the 'strdup' call in SoftFFmpegVideo::createSoftOMXComponent() to create componentRole. AFAIK, this is never freed.

Michael.


Michael Goffioul

unread,
Apr 27, 2018, 11:22:29 AM4/27/18
to andro...@googlegroups.com
The attached patch should solve it.
omx-memleak.diff

Chih-Wei Huang

unread,
Apr 29, 2018, 12:18:30 AM4/29/18
to Android-x86
2018-04-27 23:22 GMT+08:00 Michael Goffioul <michael....@gmail.com>:
> The attached patch should solve it.

Thank you for the fix.
Indeed the 'strdup' is unnecessary.


> On Fri, Apr 27, 2018 at 6:23 AM, Michael Goffioul
> <michael....@gmail.com> wrote:
>>
>> I think another tiny small source of leakage is the 'strdup' call in
>> SoftFFmpegVideo::createSoftOMXComponent() to create componentRole. AFAIK,
>> this is never freed.


Luigi Capriotti

unread,
May 18, 2018, 3:26:51 AM5/18/18
to Android-x86
I'm happy to report that the official r2 release works like a charm, no more leaks. 
Kudos!

youli...@gmail.com

unread,
May 16, 2022, 11:46:01 PM5/16/22
to Android-x86
I have mediacodec memory leak on amdgpu, amdgpu HW-acceleration working.
android_x86:/ $ su
android_x86:/ # procrank | head
Error allocating proportional swap offset array.
  PID Vss Rss Pss Uss cmdline
 6880 717828K 519972K 476512K 471964K media.codec
 2271 1890280K 376644K 196004K 183360K com.baidu.input
 1280 2152624K 310660K 126668K 106056K system_server
 5223 1472244K 316228K 122164K 101428K com.android.systemui
 2577 2105916K 272460K 100462K 88588K com.schiztech.swapps
 2997 2113464K 258832K 81756K 70104K fi.rojekti.clipper
 6233 2068552K 262328K 81380K 68984K com.sonelli.juicessh
 2065 1404116K 266504K 80695K 66272K com.google.android.apps.nexuslauncher
 4715 1385956K 236824K 65619K 55444K com.termoneplus
android_x86:/ #

setprop media.sf.hwaccel 0, not have memory leak.

android_x86:/ $ su
android_x86:/ # vainfo
libva info: VA-API version 1.14.0
libva info: Trying to open /system/vendor/lib/dri/radeonsi_drv_video.so
libva info: Found init function __vaDriverInit_1_14
libva info: va_openDriver() returns 0
vainfo: VA-API version: 1.14 (libva 2.14.0)
vainfo: Driver version: Mesa Gallium driver 22.1.0-rc5 for AMD Radeon Vega 11 Graphics (raven, LLVM 14.0.1, DRM 3.46, 5.18.0-rc7-android-x86_64+)
vainfo: Supported profile and entrypoints
      VAProfileMPEG2Simple : VAEntrypointVLD
      VAProfileMPEG2Main : VAEntrypointVLD
      VAProfileVC1Simple : VAEntrypointVLD
      VAProfileVC1Main : VAEntrypointVLD
      VAProfileVC1Advanced : VAEntrypointVLD
      VAProfileH264ConstrainedBaseline: VAEntrypointVLD
      VAProfileH264ConstrainedBaseline: VAEntrypointEncSlice
      VAProfileH264Main : VAEntrypointVLD
      VAProfileH264Main : VAEntrypointEncSlice
      VAProfileH264High : VAEntrypointVLD
      VAProfileH264High : VAEntrypointEncSlice
      VAProfileHEVCMain : VAEntrypointVLD
      VAProfileHEVCMain : VAEntrypointEncSlice
      VAProfileHEVCMain10 : VAEntrypointVLD
      VAProfileJPEGBaseline : VAEntrypointVLD
      VAProfileVP9Profile0 : VAEntrypointVLD
      VAProfileVP9Profile2 : VAEntrypointVLD
      VAProfileNone : VAEntrypointVideoProc
android_x86:/ #

Michael Goffioul

unread,
May 17, 2022, 3:51:19 AM5/17/22
to Android-x86
If you look at the history of external/stagefright-plugins in nougat-x86, you'll see that there were 2 fixes after 7.1-r1 related to memory leaks:
https://osdn.net/projects/android-x86/scm/git/external-stagefright-plugins/commits/?branch=nougat-x86

Michael.


--
You received this message because you are subscribed to the Google Groups "Android-x86" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-x86...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-x86/985aa702-cb4b-466d-8b9e-c8d68f97480fn%40googlegroups.com.

youli...@gmail.com

unread,
Oct 20, 2022, 2:38:55 PM10/20/22
to Android-x86
when i used my stagefright-plugin(https://github.com/youling257/stagefright-plugins/commits/e49db02) and ndk build ffmpeg, no memory leak, that because CONFIG_VAAPI_1=y? https://github.com/supremegamers/android_external_ffmpeg/commit/4844471cc379ea4a77639c487e9f70c7ecda6dde
I check my ndk build ffmpeg config.mak already CONFIG_VAAPI_1=y.

but now, i test "Use new HW accel API from FFMPEG", have memory leak, https://github.com/youling257/stagefright-plugins/commits/cm-14.1
10-21 02:21:45.843 5536 5537 I FFMPEG : FFMPEG initialized: n3.4.11-5-g9aaf5bed56
10-21 02:21:45.843 5536 5537 D SoftFFmpegVideo: 0xf6c86200 initDecoder: 0xf6cb1000
10-21 02:21:45.845 5536 5537 W OMXNodeInstance: [15a00001:ffmpeg.hevc.decoder] component does not support metadata mode; using fallback
10-21 02:21:45.845 5536 5537 I SoftFFmpegVideo: OMX_IndexParamPortDefinition (input) width=3840 height=2160
10-21 02:21:45.845 5536 5537 I SoftFFmpegVideo: OMX_IndexParamPortDefinition (output) width=3840 height=2160
10-21 02:21:45.848 5536 5581 D SoftFFmpegVideo: ffmpeg got codecconfig buffer
10-21 02:21:45.858 5536 5581 D SoftFFmpegVideo: begin to open ffmpeg decoder(hevc) now
10-21 02:21:45.860 5536 5581 D SoftFFmpegVideo: open ffmpeg video decoder(hevc) success
10-21 02:21:45.884 5536 5581 I HWACCEL : hw codec hevc enabled: s=0xf6cb3800 pix_fmts=53
10-21 02:21:46.205 5536 5581 D SoftFFmpegVideo: drainOneOutputBuffer: frame_width=3840 frame_height=2160 buffer_width=3840 buffer_height=2160 ctx_width=3840 ctx_height=2160 mIsAdaptive=0
10-21 02:21:46.247 5536 5581 D SoftFFmpegVideo: drainOneOutputBuffer: frame_width=3840 frame_height=2160 buffer_width=3840 buffer_height=2160 ctx_width=3840 ctx_height=2160 mIsAdaptive=0

youli...@gmail.com

unread,
Oct 20, 2022, 2:41:56 PM10/20/22
to Android-x86
Reply all
Reply to author
Forward
0 new messages