Default Camera issue in jamal2367's v11 KitKat build.

Well, since I'm new here and have less than 10 posts I unfortunately can't post in the ROM thread itself, so I suppose I'll post it here. Hopefully someone else can quote me in the real thread.

I've traced the Camera "force close" issues to a memory allocation problem. Apparently the ION memory allocation library used in this case to allocate memory for the video buffer containing the camera stream occasionally fails. The out of memory event is of course posted to the kernel log in dmesg. I've pasted the log of the event below.

I'm not sure how to address this problem. Perhaps there is some way to statically allocate memory for ION? Someone with more knowledge of this may be able to suggest a tweak to fix this problem. It may require a kernel rebuild and faux123 would need to be involved.

To be clear the one special property required for these allocations is that they be contiguous in physical memory. So the allocated chunk of pages I believe has to be mapped to a contiguous set of PFNs. This is probably to facilitate DMA with the camera hardware or something like that. Perhaps memory fragmentation leads to there being no large enough contiguous chunk of physical memory.

As mentioned earlier, here is the log of the out of memory event.

Code:
<4>[  141.939422] Binder_1: page allocation failure: order:0, mode:0xe0
<4>[  141.939453] [<c00140c4>] (unwind_backtrace+0x0/0x11c) from [<c00fbd1c>] (warn_alloc_failed+0xf4/0x11c)
<4>[  141.939483] [<c00fbd1c>] (warn_alloc_failed+0xf4/0x11c) from [<c00fe2f0>] (__alloc_pages_nodemask+0x544/0x678)
<4>[  141.939483] [<c00fe2f0>] (__alloc_pages_nodemask+0x544/0x678) from [<c00fe434>] (__get_free_pages+0x10/0x24)
<4>[  141.939514] [<c00fe434>] (__get_free_pages+0x10/0x24) from [<c02d9f70>] (__sg_alloc_table+0x58/0xf8)
<4>[  141.939544] [<c02d9f70>] (__sg_alloc_table+0x58/0xf8) from [<c02da24c>] (sg_alloc_table+0x1c/0x44)
<4>[  141.939544] [<c02da24c>] (sg_alloc_table+0x1c/0x44) from [<c03a3704>] (ion_iommu_heap_allocate+0x1f4/0x54c)
<4>[  141.939575] [<c03a3704>] (ion_iommu_heap_allocate+0x1f4/0x54c) from [<c03a02e8>] (ion_alloc+0xd4/0x354)
<4>[  141.939605] [<c03a02e8>] (ion_alloc+0xd4/0x354) from [<c03a0af0>] (ion_ioctl+0x108/0x434)
<4>[  141.939605] [<c03a0af0>] (ion_ioctl+0x108/0x434) from [<c013d844>] (vfs_ioctl+0x28/0x3c)
<4>[  141.939636] [<c013d844>] (vfs_ioctl+0x28/0x3c) from [<c013e384>] (do_vfs_ioctl+0x534/0x588)
<4>[  141.939636] [<c013e384>] (do_vfs_ioctl+0x534/0x588) from [<c013e408>] (sys_ioctl+0x30/0x58)
<4>[  141.939666] [<c013e408>] (sys_ioctl+0x30/0x58) from [<c000e7c0>] (ret_fast_syscall+0x0/0x30)
<4>[  141.939666] Mem-info:
<4>[  141.939666] Normal per-cpu:
<4>[  141.939697] CPU    0: hi:  186, btch:  31 usd: 172
<4>[  141.939697] CPU    1: hi:  186, btch:  31 usd: 126
<4>[  141.939697] CPU    2: hi:  186, btch:  31 usd: 138
<4>[  141.939697] HighMem per-cpu:
<4>[  141.939697] CPU    0: hi:  186, btch:  31 usd: 186
<4>[  141.939727] CPU    1: hi:  186, btch:  31 usd:  60
<4>[  141.939727] CPU    2: hi:  186, btch:  31 usd: 200
<4>[  141.939727] active_anon:89928 inactive_anon:120 isolated_anon:0
<4>[  141.939758]  active_file:37643 inactive_file:263349 isolated_file:0
<4>[  141.939758]  unevictable:108 dirty:10 writeback:0 unstable:0
<4>[  141.939758]  free:78 slab_reclaimable:5436 slab_unreclaimable:7292
<4>[  141.939758]  mapped:34872 shmem:138 pagetables:3025 bounce:0
<4>[  141.939758]  free_cma:0
<4>[  141.939788] Normal free:0kB min:2764kB low:3452kB high:4144kB active_anon:118260kB inactive_anon:36kB active_file:13060kB inactive_file:110556kB unevictable:0kB isolated anon):0kB isolated(file):0kB present:477696kB mlocked:0kB dirty:4kB writeback:0kB mapped:18120kB shmem:44kB slab_reclaimable:21744kB slab_unreclaimable:29168kB kernel_stack:11128kB pagetables:12100kB unstable:0kB bounce:0kB free_cma:0kB writeback_tmp:0kB pages_scanned:45 all_unreclaimable? no
<4>[  141.939788] lowmem_reserve[]: 0 5570 5570
<4>[  141.939819] HighMem free:312kB min:512kB low:2572kB high:4636kB active_anon:241452kB inactive_anon:444kB active_file:137512kB inactive_file:942840kB unevictable:432kB isolated(anon):0kB isolated(file):0kB present:1425932kB mlocked:0kB dirty:36kB writeback:0kB mapped:121368kB shmem:508kB slab_reclaimable:0kB slab_unreclaimable:0kB kernel_stack:0kB pagetables:0kB unstable:0kB bounce:0kB free_cma:0kB writeback_tmp:0kB pages_scanned:0 all_unreclaimable? no
<4>[  141.939849] lowmem_reserve[]: 0 0 0
<4>[  141.939849] Normal: 0*4kB 0*8kB 0*16kB 0*32kB 0*64kB 0*128kB 0*256kB 0*512kB 0*1024kB 0*2048kB 0*4096kB = 0kB
<4>[  141.939910] HighMem: 4*4kB (M) 3*8kB (M) 1*16kB (M) 4*32kB (M) 1*64kB (M) 0*128kB 0*256kB 0*512kB 0*1024kB 0*2048kB 0*4096kB = 248kB
<4>[  141.939941] 301248 total pagecache pages
<4>[  141.939971] 0 pages in swap cache
<4>[  141.939971] Swap cache stats: add 0, delete 0, find 0/0
<4>[  141.939971] Free swap  = 0kB
<4>[  141.939971] Total swap = 0kB
<4>[  141.981048] 514303 pages of RAM
<4>[  141.981048] 38193 free pages
<4>[  141.981048] 14186 reserved pages
<4>[  141.981048] 7389 slab pages
<4>[  141.981079] 393201 pages shared
<4>[  141.981079] 0 pages swap cached
<3>[  142.015502] videobuf2_pmem_contig_user_get ION import failed
<3>[  142.015808] msm_vb2_ops_buf_init error initializing buffer 


"Binder_1" sysTid=962
  #00  pc 00021940  /system/lib/libc.so (__futex_syscall3+8)
  #01  pc 0000ef04  /system/lib/libc.so (__pthread_cond_timedwait_relative+48)
  #02  pc 0000ef64  /system/lib/libc.so (__pthread_cond_timedwait+64)
  #03  pc 00012fb3  /system/lib/libc.so (pthread_join+74)
  #04  pc 00008b3b  /system/lib/libmmcamera_interface.so (mm_camera_cmd_thread_stop+70)
  #05  pc 000058b9  /system/lib/libmmcamera_interface.so (mm_channel_stop_streams+156)
  #06  pc 00006a19  /system/lib/libmmcamera_interface.so (mm_channel_fsm_fn_active+124)
  #07  pc 00006cc5  /system/lib/libmmcamera_interface.so (mm_channel_fsm_fn+36)
  #08  pc 000072cb  /system/lib/libmmcamera_interface.so (mm_camera_stop_streams+48)
  #09  pc 00027ea5  /system/lib/hw/camera.msm8960.so (android::QCameraStream::streamOff(bool)+84)
  #10  pc 0001c221  /system/lib/hw/camera.msm8960.so (android::QCameraHardwareInterface::stopPreviewInternal()+304)
  #11  pc 0001ff13  /system/lib/hw/camera.msm8960.so (android::QCameraHardwareInterface::stopPreview()+118)
  #12  pc 00011033  /system/lib/libseccameracore.so (android::ShotGoogle::stopPreview()+126)
  #13  pc 0000aa67  /system/lib/libseccameracore.so (android::SecCameraCoreManager::stopPreview()+74)
  #14  pc 00044653  /system/lib/libcameraservice.so (android::CameraClient::stopPreview()+78)
  #15  pc 0002b35b  /system/lib/libcamera_client.so (android::BnCamera::onTransact(unsigned int, android::Parcel const&, android::Parcel*, unsigned int)+298)
  #16  pc 000191ad  /system/lib/libbinder.so (android::BBinder::transact(unsigned int, android::Parcel const&, android::Parcel*, unsigned int)+60)
  #17  pc 0001d721  /system/lib/libbinder.so (android::IPCThreadState::executeCommand(int)+508)
  #18  pc 0001da9f  /system/lib/libbinder.so (android::IPCThreadState::getAndExecuteCommand()+38)
  #19  pc 0001db15  /system/lib/libbinder.so (android::IPCThreadState::joinThreadPool(bool)+48)
  #20  pc 00021921  /system/lib/libbinder.so
  #21  pc 0000ea5d  /system/lib/libutils.so (android::Thread::_threadLoop(void*)+216)
  #22  pc 0000e58f  /system/lib/libutils.so
  #23  pc 0000d1b0  /system/lib/libc.so (__thread_entry+72)
  #24  pc 0000d348  /system/lib/libc.so (pthread_create+240)