Skip to content
Snippets Groups Projects
  • Edward Wu's avatar
    memleak: Add workaround to alleviate misjudgments when free is missing · cd81f13c
    Edward Wu authored
    Profiling in memory part is hard to be accurate because of BPF infrastructure.
    memleak keeps misjudging memory leak on the complicated environment which has
    the action of free in hard/soft irq.
    
    For example, in my misjudged case:
    
    640 bytes in 10 allocations from stack
    --
    __kmalloc+0x178 [kernel]
    __kmalloc+0x178 [kernel]
    xhci_urb_enqueue+0x140 [kernel]
    usb_hcd_submit_urb+0x5e0 [kernel]
    
    This result looks like kernel doesn't free urb_priv. However, it's not true.
    The reason for this leak is because xhci hw irq interrupts during the BPF program.
    BPF program is not finished on that CPU, and xhci_irq() will call xhci_urb_free_priv()
    before the end. But the kernel doesn't permit this isr to go into BPF program again.
    Because BPF infrastructure(trace_call_bpf) denied this action.
    So we miss this free action and cause memory leak misjudgment.
    
    Side-effect:
    - Increase overhead for each memory allocation.
    - A higher chance to be interrupted at the allocation part causes ignore more allocations.
    
    This workaround doesn't solve all misjudgments, the improvement in BPF infrastructure
    is the only solution.
    cd81f13c