Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit 3eb58021 authored by Jia Cheng She's avatar Jia Cheng She Committed by GitHub
Browse files

Merge pull request #1 from TALUAtGitHub/lineage-17.1

Fix the massive memory leaks and make some improvements
parents 4b6a269a 8d0b1a37
Loading
Loading
Loading
Loading
+22 −6
Original line number Diff line number Diff line
@@ -11,9 +11,7 @@ with the difference that the orphan objects are not freed but only
reported via /sys/kernel/debug/kmemleak. A similar method is used by the
Valgrind tool (memcheck --leak-check) to detect the memory leaks in
user-space applications.

Please check DEBUG_KMEMLEAK dependencies in lib/Kconfig.debug for supported
architectures.
Kmemleak is supported on x86, arm, powerpc, sparc, sh, microblaze, ppc, mips, s390, metag and tile.

Usage
-----
@@ -53,7 +51,8 @@ Memory scanning parameters can be modified at run-time by writing to the
		  (default 600, 0 to stop the automatic scanning)
  scan		- trigger a memory scan
  clear		- clear list of current memory leak suspects, done by
		  marking all current reported unreferenced objects grey
		  marking all current reported unreferenced objects grey,
		  or free all kmemleak objects if kmemleak has been disabled.
  dump=<addr>	- dump information about the object found at <addr>

Kmemleak can also be disabled at boot-time by passing "kmemleak=off" on
@@ -63,12 +62,16 @@ Memory may be allocated or freed before kmemleak is initialised and
these actions are stored in an early log buffer. The size of this buffer
is configured via the CONFIG_DEBUG_KMEMLEAK_EARLY_LOG_SIZE option.

If CONFIG_DEBUG_KMEMLEAK_DEFAULT_OFF are enabled, the kmemleak is
disabled by default. Passing "kmemleak=on" on the kernel command
line enables the function. 

Basic Algorithm
---------------

The memory allocations via kmalloc, vmalloc, kmem_cache_alloc and
friends are traced and the pointers, together with additional
information like size and stack trace, are stored in a prio search tree.
information like size and stack trace, are stored in a rbtree.
The corresponding freeing function calls are tracked and the pointers
removed from the kmemleak data structures.

@@ -84,7 +87,7 @@ The scanning algorithm steps:
  1. mark all objects as white (remaining white objects will later be
     considered orphan)
  2. scan the memory starting with the data section and stacks, checking
     the values against the addresses stored in the prio search tree. If
     the values against the addresses stored in the rbtree. If
     a pointer to a white object is found, the object is added to the
     gray list
  3. scan the gray objects for matching addresses (some white objects
@@ -120,6 +123,18 @@ Then as usual to get your report with:

  # cat /sys/kernel/debug/kmemleak

Freeing kmemleak internal objects
---------------------------------

To allow access to previously found memory leaks after kmemleak has been
disabled by the user or due to an fatal error, internal kmemleak objects
won't be freed when kmemleak is disabled, and those objects may occupy
a large part of physical memory.

In this situation, you may reclaim memory with:

  # echo clear > /sys/kernel/debug/kmemleak

Kmemleak API
------------

@@ -131,6 +146,7 @@ kmemleak_alloc_percpu - notify of a percpu memory block allocation
kmemleak_free		 - notify of a memory block freeing
kmemleak_free_part	 - notify of a partial memory block freeing
kmemleak_free_percpu	 - notify of a percpu memory block freeing
kmemleak_update_trace	 - update object allocation stack trace
kmemleak_not_leak	 - mark an object as not a leak
kmemleak_ignore		 - do not scan or report an object as leak
kmemleak_scan_area	 - add scan areas inside a memory block
+21 −0
Original line number Diff line number Diff line
@@ -594,6 +594,27 @@ ifneq ($(CONFIG_FRAME_WARN),0)
KBUILD_CFLAGS += $(call cc-option,-Wframe-larger-than=${CONFIG_FRAME_WARN})
endif

# Handle stack protector mode.
ifdef CONFIG_CC_STACKPROTECTOR_REGULAR
  stackp-flag := -fstack-protector
  ifeq ($(call cc-option, $(stackp-flag)),)
    $(warning Cannot use CONFIG_CC_STACKPROTECTOR_REGULAR: \
             -fstack-protector not supported by compiler)
  endif
else
ifdef CONFIG_CC_STACKPROTECTOR_STRONG
  stackp-flag := -fstack-protector-strong
  ifeq ($(call cc-option, $(stackp-flag)),)
    $(warning Cannot use CONFIG_CC_STACKPROTECTOR_STRONG: \
	      -fstack-protector-strong not supported by compiler)
  endif
else
  # Force off for distro compilers that enable stack protector by default.
  stackp-flag := $(call cc-option, -fno-stack-protector)
endif
endif
KBUILD_CFLAGS += $(stackp-flag)

# This warning generated too much noise in a regular build.
# Use make W=1 to enable this warning (see scripts/Makefile.build)
KBUILD_CFLAGS += $(call cc-disable-warning, unused-but-set-variable)
+2 −2
Original line number Diff line number Diff line
@@ -63,12 +63,12 @@
do {									\
	compiletime_assert_atomic_type(*p);				\
	smp_mb();							\
	ACCESS_ONCE(*p) = (v);						\
	WRITE_ONCE(*p, v);						\
} while (0)

#define smp_load_acquire(p)						\
({									\
	typeof(*p) ___p1 = ACCESS_ONCE(*p);				\
	typeof(*p) ___p1 = READ_ONCE(*p);				\
	compiletime_assert_atomic_type(*p);				\
	smp_mb();							\
	___p1;								\
+1 −0
Original line number Diff line number Diff line
@@ -675,3 +675,4 @@ CONFIG_CRYPTO_DEV_SOMC_FIPS_KSCL=y
CONFIG_MISC_FILESYSTEMS=y
CONFIG_ECRYPT_FS=y
CONFIG_WTL_ENCRYPTION_FILTER=y
CONFIG_MSM8994_CPU_VOLTAGE_CONTROL=y
+1 −0
Original line number Diff line number Diff line
@@ -674,3 +674,4 @@ CONFIG_CRYPTO_DEV_SOMC_FIPS_KSCL=y
CONFIG_MISC_FILESYSTEMS=y
CONFIG_ECRYPT_FS=y
CONFIG_WTL_ENCRYPTION_FILTER=y
CONFIG_MSM8994_CPU_VOLTAGE_CONTROL=y
Loading