在Android x86 Nougat上为虚拟帧缓冲区分配缓冲区内存时,SurfaceFlinger/gralloc Out of Memory错误

pil*_*ipe 5 android linux-kernel android-source android-x86 surfaceflinger

我们正在定制Android x86 Nougat(Android v7.1)项目的分支.由于我们的系统中没有视频显示硬件,因此我们尝试设置虚拟帧缓冲区(VFB),以便我们可以自定义方式处理视频显示(例如,通过VNC服务器路由视频显示等).

我们在系统启动时SurfaceError尝试初始化它时尝试使用gralloc分配内存时失败.以下是logcat的摘录:

03-02 18:31:21.757   986   986 E gralloc : #### gralloc_alloc
03-02 18:31:21.757   986   986 E gralloc : #### gralloc_alloc_framebuffer
03-02 18:31:21.757   986   986 E gralloc : #### gralloc_alloc_framebuffer_locked
03-02 18:31:21.757   986   986 E Gralloc1On0Adapter: gralloc0 allocation failed: -12 (Out of memory)
03-02 18:31:21.757   986   986 E GraphicBufferAllocator: Failed to allocate (360 x 480) format 5 usage 6656: 5
03-02 18:31:21.757   986   986 V Gralloc1On0Adapter: Destroying descriptor 3
03-02 18:31:21.757   986   986 V Gralloc1On0Adapter: dump(0 (0xbfe341f4), 0x0
03-02 18:31:21.757   986   986 V Gralloc1On0Adapter: dump(0 (0xbfe341f4), 0x0
03-02 18:31:21.757   986   986 D GraphicBufferAllocator: Allocated buffers:
03-02 18:31:21.757   986   986 D GraphicBufferAllocator: 0xab5f60c0:  675.00 KiB |  360 ( 360) x  480 |        5 | 0x00001a00 | FramebufferSurface
03-02 18:31:21.757   986   986 D GraphicBufferAllocator: 0xab5f60f0:  675.00 KiB |  360 ( 360) x  480 |        5 | 0x00001a00 | FramebufferSurface
03-02 18:31:21.757   986   986 D GraphicBufferAllocator: Total allocated (estimate): 1350.00 KB
03-02 18:31:21.757   986   986 E         : GraphicBufferAlloc::createGraphicBuffer(w=360, h=480) failed (Out of memory), handle=0x0
03-02 18:31:21.757   986   986 E BufferQueueProducer: [FramebufferSurface] allocateBuffers: failed to allocate buffer (0 x 0, format 5, usage 0)
Run Code Online (Sandbox Code Playgroud)

这是完整日志的链接:

Init log(dmesg):http: //pastebin.com/sr1rAK43

Logcat:http://pastebin.com/SVYhvgu5

我们为了让事情运转我们做了什么:

  1. 在kernel/arch/x86/configs/android-x86_defconfig中,为VFB模块模式设置选项:CONFIG_FB_VIRTUAL为M 



  2. 在kernel/drivers/video/fbdev/vfb.c中更新的帧缓冲区大小高达64MB:#define VIDEOMEMSIZE(64*1024*1024)



  3. 在device/generic/common/init.sh中,我启动VFB并禁用UVESA帧缓冲:

函数do_init()

#init_hal_gralloc

modprobe vfb vfb_enable = 1



并且在"return 0"之前的文件末尾的init.sh中:

/ system/bin/fbset 360 480 20


我想知道:

1)我如何解决内存不足错误?


2)如何从内核命令行启用vfb?


3)在Android 7.x中让VFB在内核4.4上工作时我可能错过的任何配置/设置