-
Notifications
You must be signed in to change notification settings - Fork 14
diff: kernel dma contiguous.c
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:
-
Tracking DMA CMA Memory Usage:
- In Samsung's version, the functions
memblock_memsize_disable_tracking()andmemblock_memsize_enable_tracking()are used around a memory allocation section, along with a call tomemblock_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;
- In Samsung's version, the functions
-
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.
- The
-
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.
- In contrast, the GKI kernel simply returns the result (
-
Samsung Kernel:
-
Return on Success:
- The GKI version simplifies the code by returning
0directly at the end of the function, while the Samsung kernel ensures tracking is re-enabled before returning.
- The GKI version simplifies the code by returning
-
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()andmemblock_memsize_enable_tracking()calls likely disable and re-enable a custom memory tracking feature that is unique to Samsung's kernel. Thememblock_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.
-
Samsung-Specific Memory Tracking: The Samsung kernel adds additional memory tracking functionality around the DMA CMA memory allocation. The
-
Error Handling:
- In Samsung's kernel, when an error occurs (e.g., if
cma_allocfails), 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.
- In Samsung's kernel, when an error occurs (e.g., if
-
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.
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.