Skip to content

diff: kernel dma contiguous.c

Raphaël Valyi edited this page Sep 19, 2024 · 1 revision

The diff you’ve highlighted in kernel/dma/contiguous.c between the Samsung kernel and the GKI kernel involves some custom handling of memory block tracking in Samsung's kernel. Let's break down the differences:

Key Differences in the Code:

  1. Tracking DMA CMA Memory Usage:

    • In Samsung's version, the functions memblock_memsize_disable_tracking() and memblock_memsize_enable_tracking() are used around a memory allocation section, along with a call to memblock_memsize_record() to track the allocated memory size for the DMA CMA (Contiguous Memory Allocator) memory block. This behavior is absent from the GKI kernel.
    • Original (Samsung):
      memblock_memsize_disable_tracking();
      ...
      memblock_memsize_record("dma_cma", cma_get_base(*res_cma),
                              cma_get_size(*res_cma), false, true);
      out:
      memblock_memsize_enable_tracking();
      return ret;
    • GKI Version:
      return ret;
  2. Behavior at Error or Completion:

    • Samsung Kernel:
      • The goto out; directs the code to re-enable memory block size tracking (memblock_memsize_enable_tracking()) before returning, ensuring that this tracking system is reactivated after the DMA CMA memory handling.
    • GKI Kernel:
      • In contrast, the GKI kernel simply returns the result (return ret;) without any such tracking, meaning that no additional memory size tracking or disabling is done in this part of the DMA CMA code.
  3. Return on Success:

    • The GKI version simplifies the code by returning 0 directly at the end of the function, while the Samsung kernel ensures tracking is re-enabled before returning.

What Does This Mean?

  1. Memory Tracking:

    • Samsung-Specific Memory Tracking: The Samsung kernel adds additional memory tracking functionality around the DMA CMA memory allocation. The memblock_memsize_disable_tracking() and memblock_memsize_enable_tracking() calls likely disable and re-enable a custom memory tracking feature that is unique to Samsung's kernel. The memblock_memsize_record() function records the size and base of the DMA CMA memory allocation under a custom tag "dma_cma", which is probably used for internal memory auditing or optimization purposes.
    • This suggests that Samsung has built a more detailed memory tracking system to monitor contiguous memory allocations, which is particularly important for mobile devices where memory is a constrained resource. The tracking likely helps them optimize or debug memory usage for performance or power efficiency.
  2. Error Handling:

    • In Samsung's kernel, when an error occurs (e.g., if cma_alloc fails), the code ensures that memory tracking is always re-enabled before returning, maintaining consistency in memory state management. The GKI kernel does not have this additional tracking logic, so it simply returns the error code.
  3. Why It's Not in GKI:

    • The additional memory tracking and handling introduced by Samsung is specific to their custom kernel, reflecting their optimizations for their devices. This kind of memory tracking might not be needed in the more generic GKI kernel, which is designed to work across a wide range of devices without such specific optimizations.

Summary:

Samsung's addition of memblock_memsize_disable_tracking(), memblock_memsize_enable_tracking(), and memblock_memsize_record() is part of a custom memory tracking system they use to monitor and record the size of memory allocated by the Contiguous Memory Allocator (CMA). This tracking ensures they can manage memory more effectively, likely for performance, resource optimization, and possibly debugging purposes. The GKI kernel, being more generic, does not include this specialized tracking.

Clone this wiki locally