os/mm: Add API to set custom PID for kernel module memory allocations#7277
Open
vivek1-j wants to merge 1 commit intoSamsung:masterfrom
Open
os/mm: Add API to set custom PID for kernel module memory allocations#7277vivek1-j wants to merge 1 commit intoSamsung:masterfrom
vivek1-j wants to merge 1 commit intoSamsung:masterfrom
Conversation
Problem: When CONFIG_DEBUG_MM_HEAPINFO is enabled, the memory allocation node stores the PID of the currently running task to identify the memory owner. This causes incorrect attribution when kernel modules allocate memory on behalf of other tasks. For example, when the log_dump test application runs, it triggers logging via log_dump_save() which internally calls kmm_malloc(). The allocated memory node incorrectly stores the test application's PID instead of the log_dump kernel thread's PID, causing false alerts in memory debugging. Solution: Add a new API heapinfo_set_pid() and corresponding DEBUG_SET_PID() macro that allows kernel modules to explicitly set their PID on allocated memory nodes after the allocation. Changes: 1. mm/mm_heap/mm_heapinfo_utils.c: Add heapinfo_set_pid() function 2. include/tinyara/mm/mm.h: Add DEBUG_SET_PID() macro and declaration 3. kernel/log_dump/log_dump.c: Use DEBUG_SET_PID() to set correct PID for all kmm_malloc() allocations Design Decisions: - Follow existing pattern of DEBUG_SET_CALLER_ADDR() for consistency - Use a no-op macro when CONFIG_DEBUG_MM_HEAPINFO is disabled to avoid any overhead in release builds - Store log_dump thread's PID at initialization and reuse it for all subsequent allocations - The API is generic and can be used by other kernel modules with similar requirements Impact: - Memory allocated by log_dump module is now correctly attributed to the log_dump kernel thread - No impact when CONFIG_DEBUG_MM_HEAPINFO is not enabled - API is reusable by other kernel modules that need similar functionality TC1: Flat build (rtl8730e) log Dump pid = 13 13 | 4 | 10216 | 12496 | 331808 | log_dump() 0x601755f0 | 4128 | A | 0x e025bf3 | 13 | 0x60176610 | 4128 | A | 0x e025bf3 | 13 | TC2: Loadable build (rtl8730e) log dump pid: 15 15 | 4 | 10216 | 12496 | 331808 | kernel | log_dump() 0x603a57e0 | 4128 | A | 0x e023003 | 15 | 0x603a6800 | 4128 | A | 0x e023003 | 15 | 0x603a7820 | 4128 | A | 0x e023003 | 15 | Signed-Off By: Vivek Jain (vivek1.j@samsung.com)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem:
When CONFIG_DEBUG_MM_HEAPINFO is enabled, the memory allocation node stores the PID of the currently running task to identify the memory owner. This causes incorrect attribution when kernel modules allocate memory on behalf of other tasks.
For example, when the log_dump test application runs, it triggers logging via log_dump_save() which internally calls kmm_malloc(). The allocated memory node incorrectly stores the test application's PID instead of the log_dump kernel thread's PID, causing false alerts in memory debugging.
Solution:
Add a new API heapinfo_set_pid() and corresponding DEBUG_SET_PID() macro that allows kernel modules to explicitly set their PID on allocated memory nodes after the allocation.
Changes:
Design Decisions:
Impact:
TC1: Flat build (rtl8730e)
log Dump pid = 13
13 | 4 | 10216 | 12496 | 331808 | log_dump()
0x601755f0 | 4128 | A | 0x e025bf3 | 13 |
0x60176610 | 4128 | A | 0x e025bf3 | 13 |
TC2: Loadable build (rtl8730e)
log dump pid: 15
15 | 4 | 10216 | 12496 | 331808 | kernel | log_dump()
0x603a57e0 | 4128 | A | 0x e023003 | 15 |
0x603a6800 | 4128 | A | 0x e023003 | 15 |
0x603a7820 | 4128 | A | 0x e023003 | 15 |
Signed-Off By: Vivek Jain (vivek1.j@samsung.com)