Linux Kernel Memory Leak Detection via Slab Tracking

Resolve Bottlenecks,
Find Innovative Solutions
Generate Solutions

Solution Overview

Problem

Existing memory leak detection methods in Linux systems require periodic scanning, leading to increased CPU consumption and reduced efficiency in memory allocation and release, due to slab allocation and high memory usage by the kmemleak slab.

Innovation Solution

A method that creates nodes to track return addresses and memory page allocations, allowing for efficient detection of memory leaks by comparing allocation counts, using a data structure with address return identifiers and allocation order flags, and reducing memory consumption by minimizing slab allocation.

Engineering Contradictions & Design Principles

VSEngineering Contradiction Analysis

1Reliability

If periodic scanning is performed to detect memory leaks, then memory leak detection capability is improved, but CPU consumption increases

Engineering Contradiction:
Improvememory leak detection capabilityVSAvoidCPU consumption
Core Design Contradiction:
ReliabilityVSUse of energy by moving object

Solution Approach 1:

The patent applies preliminary action by pre-allocating and initializing slab objects with tracking structures before memory allocation occurs. The slab allocation mechanism is prepared in advance with embedded trace information structures, eliminating the need for periodic scanning and reducing CPU consumption during runtime detection.

Inventive Principle:
Principle #10Preliminary action

Solution Approach 2:

The patent implements self-service through automatic tracking of memory allocation and release operations. The slab allocation system automatically records trace information (pointer, size, stack trace) when memory is allocated and automatically updates or deletes records when memory is released, enabling continuous monitoring without external scanning intervention.

Inventive Principle:
Principle #25Self-service

2Measurement precision

If slab allocation is performed to record memory object information, then memory leak detection accuracy is improved, but memory allocation and release time increases

Engineering Contradiction:
Improvememory leak detection accuracyVSAvoidmemory allocation and release time
Core Design Contradiction:
Measurement precisionVSLoss of time

Solution Approach 1:

The patent merges the memory allocation tracking function with the existing slab allocation mechanism. By integrating trace information recording into the slab allocation process itself, the system achieves accurate memory leak detection without adding separate tracking operations, thus avoiding time penalties in allocation and release cycles.

Inventive Principle:
Principle #5Merging (Combining)

Solution Approach 2:

The patent makes the slab allocation structure multi-functional by enabling it to simultaneously perform memory allocation and trace information recording. The same slab infrastructure that manages memory blocks also tracks allocation details (pointer, size, stack trace), eliminating redundant data structures and reducing overhead.

Inventive Principle:
Principle #6Universality (Multi-functionality)

3Reliability

If kmemleak slab is used for tracking, then memory leak detection capability is improved, but system memory consumption increases

Engineering Contradiction:
Improvememory leak detection capabilityVSAvoidsystem memory consumption
Core Design Contradiction:
ReliabilityVSQuantity of substance

Solution Approach 1:

The patent extracts only the essential tracking information (pointer, size, stack trace) needed for memory leak detection and stores it within the slab allocation structure itself. By taking out only the necessary trace data rather than maintaining separate comprehensive tracking structures, the system reduces overall memory consumption while preserving detection capability.

Inventive Principle:
Principle #2Taking out (Extraction)

Data Source

PatentUS20210334192A1Method for detecting memory leak based on linux kernel
Publication Date: 2021.10.28 AMLOGIC (SHANGHAI) CO LTD
  • US20210334192A1 patent drawing
  • US20210334192A1 patent drawing
  • US20210334192A1 patent drawing

AI summary

A method for detecting a memory leak based on Linux kernel, applied to an detection of the memory leak, comprises: reading a node, acquiring the return addresses of the allocation functions of each of the plurality of memory pages and the number of the memory pages thereof; releasing the return addresses of the allocation functions and the number of the memory pages counted by the node; reading the node again, acquiring the return address of each of the allocation functions and the number of the memory pages thereof; comparing the number in each case to calculate a difference value, if the difference value is a positive value and monotonically increases, it's determined that the memory leak occurs in the memory pages allocated correspondingly by the allocation functions. During the detection of the memory leak, the detection method consumes less memory without affecting the efficiency in allocating and releasing the memory.