Memory Management in TIZEN - Samsung SW Platform Team

4,377 views

Published on

Memory Management in TIZEN - Samsung Software Platform Team (Samsung Software R&D Center)

Published in: Technology

Memory Management in TIZEN - Samsung SW Platform Team

  1. 1. Memory Management in TizenSW Platform Team,SW R&D Center
  2. 2. tizen.org2Contents• Tizen Kernel Overview• Memory Management in Tizen Kernel• Memory Size Optimization
  3. 3. tizen.org3Tizen Kernel Overview
  4. 4. tizen.org4Tizen Kernel OverviewKernelKernelOAL (OEM Adaptation Layer)TelephonyPlug-insGStreamerPlug-insSensorPlug-insSystemPlug-insOpenGL ES/EGLGraphics DriverGraphicsMemoryManagementIOMMUDMABUFMultimedia Power ManagementCPUfreqDevfreqThermal…DRMLink1 Link2V4L2StorageBlock LayerMMC/FlashInput, Sensor,…PeripheralCMAOpenGL ES1.0/2.0X11 GStreamerEFL . . .MultimediaFWTelephonyFW. . .Sensor FW System FW. . .More at http://source.tizen.org/documentation/porting-guideCoreDRM Link1: http:// elinux.org/images/7/71/Elce11_dae.pdfDRM Link2: http://download.tizen.org/misc/media/conference2012/wednesday/ballroom-c/2012-05-09-1330-1410-the_drm_(direct_rendering_manager)_of_tizen_kernel.pdf
  5. 5. tizen.org5Tizen Kernel OverviewKernelKernelOAL (OEM Adaptation Layer)TelephonyPlug-insGStreamerPlug-insSensorPlug-insSystemPlug-insOpenGL ES/EGLGraphics DriverGraphicsMemoryManagementIOMMUDMABUFMultimedia Power ManagementCPUfreqDevfreqThermal…DRMLink1 Link2V4L2StorageBlock LayerMMC/FlashInput, Sensor,…PeripheralCMAOpenGL ES1.0/2.0X11 GStreamerEFL . . .MultimediaFWTelephonyFW. . .Sensor FW System FW. . .More at http://source.tizen.org/documentation/porting-guideCore Service LayerDRM Link1: http:// elinux.org/images/7/71/Elce11_dae.pdfDRM Link2: http://download.tizen.org/misc/media/conference2012/wednesday/ballroom-c/2012-05-09-1330-1410-the_drm_(direct_rendering_manager)_of_tizen_kernel.pdf• Memory Management in Tizen– Coupled with Graphics & Multimedia devices.• Graphics & Multimedia devices = DMA devices with HUGE buffers
  6. 6. tizen.org6Tizen Kernel OverviewKernel / Device Drivers (BSP)Kernel / Core & SubsystemX ServerDRM FrameworkGEMDisplay HDMIVirtualDisplayPostProcessorG2DEFLEvas2D GPUbackendX Video DriversUserptrNEON2D GPUbackendPIXMANEXAV4L2VB2Codec CameraGStreamerOpenMAXLibdrmXV ExtensionUMMOpenGLMultimedia FWXvImageSinkCore ExternalLibraryCoreFrameworkOEMAdaptationKernelKernelGPUDDK(G3D)Radio* Images from MS Office clipart and SamsungGstreamer-CameraSrcDMABUF
  7. 7. tizen.org7Contents• Tizen Kernel Overview• Memory Management in Tizen Kernel– To Run Tizen OS.• Basic Memory Management Components• Buffer Sharing (UMM/DMABUF)• Buffer Allocation (UMM/DMAAPI)• Buffer Synchronization• Memory Size Optimization
  8. 8. tizen.org8Tizen Kernel MM, Graphics (DRM)Kernel / Device Drivers (BSP)Kernel / Core & SubsystemX ServerDRM FrameworkGEMDisplay HDMIVirtualDisplayPostProcessorG2DEFLEvas2D GPUbackendX Video DriversUserptrNEON2D GPUbackendPIXMANEXAV4L2VB2Codec CameraGStreamerOpenMAXLibdrmXV ExtensionUMMOpenGLMultimedia FWXvImageSinkCore ExternalLibraryCoreFrameworkOEMAdaptationKernelKernelGPUDDK(G3D)Radio* Images from MS Office clipart and SamsungGstreamer-CameraSrcDMABUF
  9. 9. tizen.org9Graphics:DRM/GEM (Graphics Execution Manager)drm_fb_helperdrm_mode_configLinuxDRM Common FrameworkGEMdrm_framebuffer fb_infoCrtcConnectorEncoderGEMAllocatorPlaneCommonSpecificdrm_framebufferCrtcConnectorEncoderPlane
  10. 10. tizen.org10Graphics:DRM/GEM (Graphics Execution Manager)drm_fb_helperdrm_mode_configLinuxDRM Common FrameworkGEMdrm_framebuffer fb_infoCrtcConnectorEncoderGEMAllocatorPlaneCommonSpecificdrm_framebufferCrtcConnectorEncoderPlaneGraphics Execution Manager• Framework developed by Intel• To manage graphics memory• Framework for buffer management.• Allocation and sharing.
  11. 11. tizen.org11Graphics: DRM/GEM Allocation• GEM Allocation steps @ Tizen (Generic)1. DRM_IOCTL_MODE_CREATE_DUMB• Create GEM object(global) & user GEM handle(per process)• dumb_create() of struct drm_driver• No physical memory allocated.2. DRM_IOCTL_MODE_MAP_DUMB• Create fake mmap offset of a gem object and relay the object to user• A hash key of the gem object.• dumb_map_offset() of struct drm_driver3. MMAP• Request mmap based on the hash key as the offset• Create user address space• Setup cache attribute.• Not mapped to physical memory, yet
  12. 12. tizen.org12Graphics: DRM/GEM Allocation• GEM Allocation steps @ Tizen (Generic)4. On-demand Paging– Implement & Register a fault handler that• With a page fault, allocate a page and map the page.– vma->vm_ops->fault = xxx_drm_gem_fault5. Use!6. DRM_IOCTL_MODE_DESTROY_DUMB– Remove GEM handle & object– Free memory– Implement dumb_destroy() of struct drm_driver
  13. 13. tizen.org13Graphics: DRM/GEM Allocation• GEM Allocation steps @ Tizen (Exynos Only)1. DRM_IOCTL_EXYNOS_GEM_CREATE• Only use user-desired size and buffer types.• Create gem object(global) & user gem handle(per process)• physical memory allocated.2. DRM_IOCTL_EXYNOS_GEM_MMAP• Create user address space• Map the user address space to physical memory• LIBDRM of Exynos uses these APIs, not the generic.
  14. 14. tizen.org14Graphics: DRM/GEM Sharing• GEM Sharing @ Tizen• DRM_IOCTL_GEM_FLINK– “I will share this GEM to others.”– Create GEM object name for the given GEM handle• Global key vaue for sharing• DRM_IOCTL_GEM_OPEN– “I want to use the shared GEM.”– Create GEM handle based on the given GEM object name• DRM_IOCTL_GEM_CLOSE• You don’t need to implement. It’s already there with DRM.GEMCreateGEMFLINKGEMOPENgem handle gem object name gem handleProcess 1 Process 2
  15. 15. tizen.org15Tizen Kernel MM, Multimedia (V4L2/VB2)Kernel / Device Drivers (BSP)Kernel / Core & SubsystemX ServerDRM FrameworkGEMDisplay HDMIVirtualDisplayPostProcessorG2DEFLEvas2D GPUbackendX Video DriversUserptrNEON2D GPUbackendPIXMANEXAV4L2VB2Codec CameraGStreamerOpenMAXLibdrmXV ExtensionUMMOpenGLMultimedia FWXvImageSinkCore ExternalLibraryCoreFrameworkOEMAdaptationKernelKernelGPUDDK(G3D)Radio* Images from MS Office clipart and SamsungGstreamer-CameraSrcDMABUF
  16. 16. tizen.org16Multimedia: V4L2/VB2• Tizen recommends to use V4L2 at Tizen kernel for Multimediadevices• Video input (codec & camera) & Radio• However, as long as the kernel has:– Gstreamer/OpenMAX plugins– A method to share with other F/W via DMABUF of UMM,• Tizen multimedia works.• If V4L2/VB2 is used, things get easier.
  17. 17. tizen.org17Tizen Kernel MM, OpenGL/G3D-GPUKernel / Device Drivers (BSP)Kernel / Core & SubsystemX ServerDRM FrameworkGEMDisplay HDMIVirtualDisplayPostProcessorG2DEFLEvas2D GPUbackendX Video DriversUserptrNEON2D GPUbackendPIXMANEXAV4L2VB2Codec CameraGStreamerOpenMAXLibdrmXV ExtensionUMMOpenGLMultimedia FWXvImageSinkCore ExternalLibraryCoreFrameworkOEMAdaptationKernelKernelGPUDDK(G3D)Radio* Images from MS Office clipart and SamsungGstreamer-CameraSrcDMABUF
  18. 18. tizen.org18OpenGL / G3D-GPU• Most ARM SoC GPUs (MALI, SGX, …) use their own memorymanager• E.g., Exynos4412/4210 Tizen Reference Kernel has Mali w/ UMP.– Mali DDK modified to be compatible with UMM-DMABUF.• If GPU drivers use DRM, it would be great.• (and make them GPL)
  19. 19. tizen.org19Contents• Tizen Kernel Overview• Memory Management in Tizen Kernel– To Run Tizen OS.• Basic Memory Management Components• Buffer Sharing (UMM/DMABUF)• Buffer Allocation (UMM/DMAAPI)• Buffer Synchronization• Memory Size Optimization
  20. 20. tizen.org20NEED FOR SOMETHING, A ScenarioKernel / Device Drivers (BSP)Kernel / Core & SubsystemX ServerDRM FrameworkGEMDisplay HDMIVirtualDisplayPostProcessorG2DEFLEvas2D GPUbackendX Video DriversUserptrNEON2D GPUbackendPIXMANEXAV4L2VB2Codec CameraGStreamerOpenMAXLibdrmXV ExtensionOpenGLMultimedia FWXvImageSinkCore ExternalLibraryCoreFrameworkOEMAdaptationKernelKernelGPUDDK(G3D)Radio* Images from MS Office clipart and SamsungGstreamer-CameraSrcCamera fetches a video streamThis scenario is simplified for presentation.Not an actual example of Tizen
  21. 21. tizen.org21NEED FOR SOMETHING, A ScenarioKernel / Device Drivers (BSP)Kernel / Core & SubsystemX ServerDRM FrameworkGEMDisplay HDMIVirtualDisplayPostProcessorG2DEFLEvas2D GPUbackendX Video DriversUserptrNEON2D GPUbackendPIXMANEXAV4L2VB2Codec CameraGStreamerOpenMAXLibdrmXV ExtensionOpenGLMultimedia FWXvImageSinkCore ExternalLibraryCoreFrameworkOEMAdaptationKernelKernelGPUDDK(G3D)Radio* Images from MS Office clipart and SamsungGstreamer-CameraSrcCamera fetches a video streamDraws its own imagesThis scenario is simplified for presentation.Not an actual example of Tizen
  22. 22. tizen.org22NEED FOR SOMETHING, A ScenarioKernel / Device Drivers (BSP)Kernel / Core & SubsystemX ServerDRM FrameworkGEMDisplay HDMIVirtualDisplayPostProcessorG2DEFLEvas2D GPUbackendX Video DriversUserptrNEON2D GPUbackendPIXMANEXAV4L2VB2Codec CameraGStreamerOpenMAXLibdrmXV ExtensionOpenGLMultimedia FWXvImageSinkCore ExternalLibraryCoreFrameworkOEMAdaptationKernelKernelGPUDDK(G3D)Radio* Images from MS Office clipart and SamsungGstreamer-CameraSrcCamera fetches a video streamDraws its own imagesGPU Merges the two/ Puts the merged imageThis scenario is simplified for presentation.Not an actual example of Tizen
  23. 23. tizen.org23NEED FOR SOMETHING, A ScenarioKernel / Device Drivers (BSP)Kernel / Core & SubsystemX ServerDRM FrameworkGEMDisplay HDMIVirtualDisplayPostProcessorG2DEFLEvas2D GPUbackendX Video DriversUserptrNEON2D GPUbackendPIXMANEXAV4L2VB2Codec CameraGStreamerOpenMAXLibdrmXV ExtensionOpenGLMultimedia FWXvImageSinkCore ExternalLibraryCoreFrameworkOEMAdaptationKernelKernelGPUDDK(G3D)Radio* Images from MS Office clipart and SamsungGstreamer-CameraSrcCamera fetches a video streamDraws its own imagesDRM-FIMD(display) OutputThis scenario is simplified for presentation.Not an actual example of TizenGPU Merges the two/ Puts the merged image
  24. 24. tizen.org24NEED FOR SOMETHING, A ScenarioKernel / Device Drivers (BSP)Kernel / Core & SubsystemX ServerDRM FrameworkGEMDisplay HDMIVirtualDisplayPostProcessorG2DEFLEvas2D GPUbackendX Video DriversUserptrNEON2D GPUbackendPIXMANEXAV4L2VB2Codec CameraGStreamerOpenMAXLibdrmXV ExtensionOpenGLMultimedia FWXvImageSinkCore ExternalLibraryCoreFrameworkOEMAdaptationKernelKernelGPUDDK(G3D)Radio* Images from MS Office clipart and SamsungGstreamer-CameraSrcCamera fetches a video streamDraws its own imagesDRM-FIMD(display) OutputAt a VB2 bufferAt a GEM bufferGEM bufferThis scenario is simplified for presentation.Not an actual example of TizenGPU Merges the two/ Puts the merged imageFrom GEM + VB2 into its own (e.g., UMP)
  25. 25. tizen.org25Tizen Kernel MM, UMMKernel / Device Drivers (BSP)Kernel / Core & SubsystemX ServerDRM FrameworkGEMDisplay HDMIVirtualDisplayPostProcessorG2DEFLEvas2D GPUbackendX Video DriversUserptrNEON2D GPUbackendPIXMANEXAV4L2VB2Codec CameraGStreamerOpenMAXLibdrmXV ExtensionUMMOpenGLMultimedia FWXvImageSinkCore ExternalLibraryCoreFrameworkOEMAdaptationKernelKernelGPUDDK(G3D)Radio* Images from MS Office clipart and SamsungGstreamer-CameraSrcDMABUFA mechanism to share betweenDRM, V4L2, and othersw/o memcpy
  26. 26. tizen.org26Tizen Kernel MM, UMMKernel / Device Drivers (BSP)Kernel / Core & SubsystemX ServerDRM FrameworkGEMDisplay HDMIVirtualDisplayPostProcessorG2DEFLEvas2D GPUbackendX Video DriversUserptrNEON2D GPUbackendPIXMANEXAV4L2VB2Codec CameraGStreamerOpenMAXLibdrmXV ExtensionUMMOpenGLMultimedia FWXvImageSinkCore ExternalLibraryCoreFrameworkOEMAdaptationKernelKernelGPUDDK(G3D)Radio* Images from MS Office clipart and SamsungGstreamer-CameraSrcDMABUFRequirement from Tizen platform and hardware• Different Memory Managers: GEM, VB2, GPU-adhoc, …• Share buffers• w/o memcpy• From and to users• Never expose directly to users (e.g., physical address) UMM DMABUF!
  27. 27. tizen.org27Tizen Kernel Memory ManagementUnified Memory Management (UMM)• Introduced by Jesse Barker, 2011• Includes– DMABUF (sharing buffer)– DMA Mapping API for Allocation.– CMA (Contiguous Memory Allocator)IOMMU (MMU for I/O devs)
  28. 28. tizen.org28Tizen Kernel MM, UMMDMA Buffer Sharing: DMABUF• Export– GEM/VB2/… object  DMABUF• Import– DMABUF  GEM/VB2/… object• Userspace sees DMABUF as a File Descriptor
  29. 29. tizen.org29DMA Buffer Sharing: DMABUF, ExampleCamera  DisplayX serverVideo encoderXvsinkCamera srcUser spaceKernel space DRM KMSGEM Codec CameraV4L2 V4L2struct dma_bufDisplay Codec CameraMemoryCamera AppFDHW
  30. 30. tizen.org30DMA Buffer Sharing: DMABUF, ExampleConceptual Data FlowX serverVideo encoderXvsinkCamera srcUser spaceKernel space DRM KMSGEM Codec CameraV4L2 V4L2struct dma_bufDisplay Codec CameraMemoryCamera AppFDHW
  31. 31. tizen.org31DMABUF Usage Example 1/4Camera App1) Request V4L2 camera buffer (U)2) Allocate CMA buffer (K)3) Request a camera frame at theV4L2 buffer (U)4) Store the camera frame &Notify user (K)5) Request DMABUF export for theV4L2 camera buffer (U)6) dma_buf_exporter() (K)- Create DMABUF from V4L2 buffer7) dma_buf_fd() (K)- Provide FD of the DMABUF touserX serverVideo encoderXvsinkCamera srcUser spaceKernel space DRMKMSGEMCodec CameraV4L2 V4L2struct dma_bufDisplay Codec CameraMemoryCamera AppFDHW
  32. 32. tizen.org32DMABUF Usage Example 1/4Camera App1) Request V4L2 camera buffer (U)2) Allocate CMA buffer (K)3) Request a camera frame at theV4L2 buffer (U)4) Store the camera frame &Notify user (K)5) Request DMABUF export for theV4L2 camera buffer (U)6) dma_buf_exporter() (K)- Create DMABUF from V4L2 buffer7) dma_buf_fd() (K)- Provide FD of the DMABUF touserX serverVideo encoderXvsinkCamera srcUser spaceKernel space DRMKMSGEMCodec CameraV4L2 V4L2struct dma_bufDisplay Codec CameraMemoryCamera AppFDHW
  33. 33. tizen.org33DMABUF Usage Example 1/4Camera App1) Request V4L2 camera buffer (U)2) Allocate CMA buffer (K)3) Request a camera frame at theV4L2 buffer (U)4) Store the camera frame &Notify user (K)5) Request DMABUF export for theV4L2 camera buffer (U)6) dma_buf_exporter() (K)- Create DMABUF from V4L2 buffer7) dma_buf_fd() (K)- Provide FD of the DMABUF touserX serverVideo encoderXvsinkCamera srcUser spaceKernel space DRMKMSGEMCodec CameraV4L2 V4L2struct dma_bufDisplay Codec CameraMemoryCamera AppFDHW
  34. 34. tizen.org34DMABUF Usage Example 2/4Camera App8) Request FD->GEM conversion (U)9) dma_buf_get(fd) (K)- Get DMABUF from FD10)dma_buf_attach(dma-buf) /dma_buf_map_attachment() (K)- Get Buffer from DMABUF11) Import as GEM, send user (K)12) Request GEM object name (U)13) Return GEM object name (K)14) Send GEM object name to X (U)X serverVideo encoderXvsinkCamera srcUser spaceKernel space DRMKMSGEMCodec CameraV4L2 V4L2struct dma_bufDisplay Codec CameraMemoryCamera AppFDHW
  35. 35. tizen.org35DMABUF Usage Example 2/4Camera App8) Request FD->GEM conversion (U)9) dma_buf_get(fd) (K)- Get DMABUF from FD10) dma_buf_attach(dma-buf) /dma_buf_map_attachment() (K)- Get Buffer from DMABUF11) Import as GEM, send user (K)12) Request GEM object name (U)13) Return GEM object name (K)14) Send GEM object name to X (U)X serverVideo encoderXvsinkCamera srcUser spaceKernel space DRMKMSGEMCodec CameraV4L2 V4L2struct dma_bufDisplay Codec CameraMemoryCamera AppFDHW
  36. 36. tizen.org36DMABUF Usage Example 3/4X server15) Convert given GEM object nameto GEM. Display its content.(U & K)X serverVideo encoderXvsinkCamera srcUser spaceKernel space DRMKMSGEMCodec CameraV4L2 V4L2struct dma_bufDisplay Codec CameraMemoryCamera AppFDHW
  37. 37. tizen.org37DMABUF Usage Example 3/4X server15) Convert given GEM object nameto GEM. Display its content.(U & K)X serverVideo encoderXvsinkCamera srcUser spaceKernel space DRMKMSGEMCodec CameraV4L2 V4L2struct dma_bufDisplay Codec CameraMemoryCamera AppFDHW
  38. 38. tizen.org38DMABUF Usage Example 4/4Close after usage1) “Free” the GEM object (U)2) Remove reference from theDMABUF (K)3) Close(DMABUF-FD) at cam app (U)4) (No more reference to DMABUF)Release callback executed (K)X serverVideo encoderXvsinkCamera srcUser spaceKernel space DRMKMSGEMCodec CameraV4L2 V4L2struct dma_bufDisplay Codec CameraMemoryCamera AppFDHW
  39. 39. tizen.org39DMABUF Usage Example 4/4Close after usage1) “Free” the GEM object (U)2) Remove reference from theDMABUF3) Close(DMABUF-FD) at cam app (U)4) (No more reference to DMABUF)Release callback executed (K)X serverVideo encoderXvsinkCamera srcUser spaceKernel space DRMKMSGEMCodec CameraV4L2 V4L2struct dma_bufDisplay Codec CameraMemoryCamera AppFDHW
  40. 40. tizen.org40DMABUF Usage Example 4/4Close after usage1) “Free” the GEM object (U)2) Remove reference from theDMABUF3) Close(DMABUF-FD) at cam app (U)4) (No more reference to DMABUF)Release callback executed (K)X serverVideo encoderXvsinkCamera srcUser spaceKernel space DRMKMSGEMCodec CameraV4L2 V4L2struct dma_bufDisplay Codec CameraMemoryCamera AppFDHW
  41. 41. tizen.org41Sorry, Back to DRM/GEM…• DMABUF Import / Export needs to be added• DRM_IOCTL_PRIME_HANDLE_TO_FD• Export gem handle into dmabuf fd• DRM_IOCTL_PRIME_FD_TO_HANDLE• Import dmabuf fd into gem handle
  42. 42. tizen.org42Contents• Tizen Kernel Overview• Memory Management in Tizen Kernel– To Run Tizen OS.• Basic Memory Management Components• Buffer Sharing (UMM/DMABUF)• Buffer Allocation (UMM/DMAAPI)• Buffer Synchronization• Memory Size Optimization
  43. 43. tizen.org43Tizen Kernel Memory ManagementUnified Memory Management (UMM)• Introduced by Jesse Barker, 2011• Includes– DMABUF (sharing buffer)– DMA Mapping API for Allocation.– CMA (Contiguous Memory Allocator)IOMMU (MMU for I/O devs)
  44. 44. tizen.org44Tizen Kernel MM, UMMDMA Mapping API @ Tizen ReferenceDRM / GEMDMA Mapping FrameworkIOMMUBuddyCMAIOMMUCommonDriverSystem MemoryV4L2 / VB21 21: “Exynos-DRM” provides unified device address space for all DRM devices2: Each V4L2 device has its own device address space2 2
  45. 45. tizen.org45Contents• Tizen Kernel Overview• Memory Management in Tizen Kernel– To Run Tizen OS.• Basic Memory Management Components• Buffer Sharing (UMM/DMABUF)• Buffer Allocation (UMM/DMAAPI)• Buffer Synchronization• Memory Size Optimization
  46. 46. tizen.org46Tizen Kernel Memory ManagementWe Still Have A HUGE Problem!
  47. 47. tizen.org47Tizen Kernel MM, Buffer Sync.Kernel / Device Drivers (BSP)Kernel / Core & SubsystemX ServerDRM FrameworkGEMDisplay HDMIVirtualDisplayPostProcessorG2DEFLEvas2D GPUbackendX Video DriversUserptrNEON2D GPUbackendPIXMANEXAV4L2VB2Codec CameraGStreamerOpenMAXLibdrmXV ExtensionUMMOpenGLMultimedia FWXvImageSinkCore ExternalLibraryCoreFrameworkOEMAdaptationKernelKernelGPUDDK(G3D)Radio* Images from MS Office clipart and SamsungGstreamer-CameraSrcDMABUFSynchronization?
  48. 48. tizen.org48Tizen Kernel MM, Buffer Sync.What’s the problem?BUSDRAMDRAMDRAMCPU GPUSimple Usage Scenario1. CPU writes to buffer1.2. CPU tells GPU to do something on buffer1.3. GPU does something on buffer1.4. GPU finishes.5. CPU reads the buffer1
  49. 49. tizen.org49Tizen Kernel MM, Buffer Sync.What’s the problem?BUSDRAMDRAMDRAMCPU GPUSimple Usage Scenario1. CPU writes to buffer1.2. CPU tells GPU to do something on buffer1.3. GPU does something on buffer1.4. GPU finishes.5. CPU reads the buffer1
  50. 50. tizen.org50Tizen Kernel MM, Buffer Sync.What’s the problem?BUSDRAMDRAMDRAMCPU GPUSimple Usage Scenario1. CPU writes to buffer1.2. CPU tells GPU to do something on buffer1.3. GPU does something on buffer1.4. GPU finishes.5. CPU reads the buffer1
  51. 51. tizen.org51Tizen Kernel MM, Buffer Sync.What’s the problem?BUSDRAMDRAMDRAMCPU GPUSimple Usage Scenario1. CPU writes to buffer1.2. CPU tells GPU to do something on buffer1.3. GPU does something on buffer1.4. GPU finishes.5. CPU reads the buffer1
  52. 52. tizen.org52Tizen Kernel MM, Buffer Sync.What’s the problem?BUSDRAMDRAMDRAMCPU GPUSimple Usage Scenario1. CPU writes to buffer1.2. CPU tells GPU to do something on buffer1.3. GPU does something on buffer1.4. GPU finishes.5. CPU reads the buffer1
  53. 53. tizen.org53Tizen Kernel MM, Buffer Sync.What’s the problem?Simple Usage Scenario1. CPU writes to buffer1.2. CPU tells GPU to do something on buffer1.3. GPU does something on buffer1.4. GPU finishes.5. CPU reads the buffer1How to ensure CPU won’t use buffer 1 until step 4?(esp., a user process)
  54. 54. tizen.org54Tizen Kernel MM, Buffer Sync.What’s the problem?BUSDRAMDRAMDRAMCPU,Thread1GPU• What if there are two threads using GPU?– And if the two look at the same buffer?• Not even aware of it?CPU,Thread2
  55. 55. tizen.org55Tizen Kernel MM, Buffer Sync.What’s the problem?BUSDRAMDRAMDRAMCPU,Thread1GPU• What if the two DMA devices (GPU, FIMC) share buffer?– But hard to know it at drivers or user threads.– FIMC never knows when GPU finishes– FIMC never knows when Threads1 stops using “buffer1”– Threads2 never know when GPU stops using “buffer1”CPU,Thread2FIMC-IPP(Image Post Processing)
  56. 56. tizen.org56Tizen Kernel Memory ManagementBuffer Synchronization• TGL (Tizen Global Lock) @ Tizen 2.0– … Let userspace handle the issue …– Kernel patch required.• Sync Framework (Google)– Jun, 2012. Resources w/o DMABUF (similar with TGL)• KDS (Kernel Dependency System, ARM)– May 2012 / DMABUF-compatible• DMA Fence Framework (Canonical/TI)– Aug 2012 / DMABUF-compatible– Work-In-Progress
  57. 57. tizen.org57Contents• Tizen Kernel Overview• Memory Management in Tizen Kernel• Memory Size Optimization– To Run w/ More Devices
  58. 58. tizen.org58Memory Size Optimization: Challenge• A device with 512MB RAM• Graphics/Multimedia devices want 400MB reserved– No IOMMU.• The userspace wants to run a web browser and HTML5 app!•REALLY POSSIBLE?
  59. 59. tizen.org59Memory Size Optimization: Challenge• A device with 512MB RAM• Graphics/Multimedia devices want 400MB reserved– No IOMMU• The userspace wants to run a web browser and HTML5 app!•REALLY POSSIBLE?•WHY NOT?
  60. 60. tizen.org60Minimize H/W Reserved MemoryCMA (Contiguous Memory Allocator)• Camera wants to reserve 400MB.– No IOMMU: too primitive to use paging.• You don’t use cameras while web browsing.– Free the 400MB reserved to camera, let userspace use it.• CMA can do.
  61. 61. tizen.org61Minimize H/W Reserved Memory• (Obsolete/Low-cost) ARM SoC’s DMA devices– No IOMMU– Use physically continuous memory chunk.• No paging• Potentially, a lot of memory is wasted.BUSCPUMMUL2 CacheDRAM ControllerDRAMDRAMDRAMCPUCPUGPU
  62. 62. tizen.org62Minimize H/W Reserved MemoryIOMMU• (Modern/Mid-High-cost) ARM SoC’s DMA devices– IOMMU for DMA devices!– Use paging!• Dynamically allocate & freeBUSCPUMMUL2 CacheDRAM ControllerDRAMDRAMDRAMCPUCPUGPUIOMMU
  63. 63. tizen.org63Minimize H/W Reserved MemoryIOMMU• Exynos4210/4412-based Tizen mobile device– Achieved near-zero reserved memory.– At the “menuscreen”, only around ~40MB allocated for displayand GPU.– Unfortunately, not included in the Tizen reference kernel.• But easily supported by Vanilla kernel for Tizen reference boards
  64. 64. tizen.org64Minimize H/W Reserved MemoryResults with 1GB RAM Device-sh-4.1# freetotal used free shared buffers cachedMem: 1029428 302020 727408 0 16164 133084-/+ buffers/cache: 152772 876656Swap: 0 0 0-sh-4.1# uname -aLinux localhost 3.8.3-00841-gc1981b1 #34 SMP PREEMPT Wed Apr 10 10:24:04 KST 2013 armv7l GNU/LinuxMostly available to kernel (1005.3 of 1024MB)Even with Tizen loaded, mostly free to users (856MB of 1GB)
  65. 65. tizen.org65Memory Size Optimization:Still Hungry?• Further optimization required for low-budget devices– Running full features with 512MB?– Or even < 512MB?• What about multi-tasking or “background apps”?
  66. 66. tizen.org66Memory Size Optimization: SWAP• Swap– zRAM• Used in some Samsung mobile devices successfully– Or even swap-to-flash?
  67. 67. tizen.org67Memory Size Optimization:Multitasking / Background Apps• Limit multitasking & background-app support• Pseudo multitasking by freezing background apps
  68. 68. Thank you!

×