Commit Graph

57 Commits

Author SHA1 Message Date
yinshengkai 84333881d7 mm: add mm_largest api to get the current largest available memory block
Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2024-08-25 23:09:28 +08:00
yinshengkai 49d1b4198f mm: add memory pressure notification support
Add mm_heap_free interface to pass remaining memory to memory pressure

Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2024-08-25 23:09:28 +08:00
Yanfeng Liu cafee0e086 mm/mm.h: add mm_free_delaylist interface
This adds explicit `void mm_free_delaylist(heap)` interface so that
to force freeing the heap's delaylist.

Signed-off-by: Yanfeng Liu <yfliu2008@qq.com>
2024-08-03 01:30:04 +08:00
fangpeina 242b50f921 libc/execinfo: extract a common backtrace format function
Add a common method to format backtrace to buffer, so it can be used by both mm, fs and other possoble modules.

Signed-off-by: fangpeina <fangpeina@xiaomi.com>
2024-06-29 22:44:39 +08:00
buxiasen 756d9508bc mm: mm_threshold perfer from init
Signed-off-by: buxiasen <buxiasen@xiaomi.com>
2024-06-26 00:20:44 +08:00
buxiasen cf574fa466 mm: add mm_initialize_pool, make pool more flexible
now allow enable pool for extra heap, and disable umm/kmm pool.

Signed-off-by: buxiasen <buxiasen@xiaomi.com>
2024-06-25 16:42:06 +08:00
buxiasen 870d989d6c mm: seperate mm_pool and mm_pool init
make possible enable pool, but disabled in system heap.
also compatible for further extra heap use/not use pool.
Now use MM_HEAP_MEMPOOL_THRESHOLD -1 to indicate pool disabled.

Signed-off-by: buxiasen <buxiasen@xiaomi.com>
2024-06-23 11:09:39 +08:00
chao an feb6ede434 sched/cpu: replace up_cpu_index() to this_cpu()
In SMP mode, up_cpu_index()/this_cpu() are the same, both return the index of the physical core.
In AMP mode, up_cpu_index() will return the index of the physical core, and this_cpu() will always return 0

| #ifdef CONFIG_SMP
| #  define this_cpu()             up_cpu_index()
| #elif defined(CONFIG_AMP)
| #  define this_cpu()             (0)
| #else
| #  define this_cpu()             (0)
| #endif

Signed-off-by: chao an <anchao@lixiang.com>
2024-03-21 18:52:35 +08:00
wangmingrong d2fd043575 mm: Using Macros Instead of Memory to Fill Labels
Signed-off-by: wangmingrong <wangmingrong@xiaomi.com>
2024-03-14 22:48:19 +08:00
Xu Xingliang 6e7115ca09 mm: free delay list when exceeding specified count
Signed-off-by: Xu Xingliang <xuxingliang@xiaomi.com>
2023-11-15 12:05:20 +01:00
Xiang Xiao 0fbeea64d5 mm: Remove mm_spinlock
since it's enough to protect per cpu delay list by disabling interrupt

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-11-12 11:27:38 +08:00
yinshengkai bb5b5420ae mm: record the maximum system memory usage
Add the usmblks field to mallinfo to record the maximum space allocated historically in the system

https://man7.org/linux/man-pages/man3/mallinfo.3.html#:~:text=mmap(2).-,usmblks,-This%20field%20is

Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2023-11-09 09:08:49 +08:00
Xiang Xiao 0c805ca0a9 mm: Change global spinlock to per heap
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-10-30 11:18:34 +02:00
Xiang Xiao 08bae13624 mm/tlfs: Replace the critical section with spin lock
Base on discusion: https://github.com/apache/nuttx/issues/10981

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-10-30 11:18:34 +02:00
ligd 13f0051747 mm: rewrite the memdump code for more readable
Signed-off-by: ligd <liguiding1@xiaomi.com>
2023-09-24 10:39:18 +08:00
dongjiuzhu1 36e3d32740 mm/heap: add coloration after free to detect use after free issue
Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2023-09-11 15:28:34 -04:00
xuxin19 5b6488f09f cmake:complete missing changes during cmake reforming for mm
Signed-off-by: xuxin19 <xuxin19@xiaomi.com>
2023-09-08 21:20:16 +03:00
wangbowen6 b0ab41beee memdump: support dump the leak memory (malloced but task exit)
1. command "memdump leak" can dump the leacked memory node;
2. fix the leak memory stat bug in memory manager;

Signed-off-by: wangbowen6 <wangbowen6@xiaomi.com>
2023-07-31 05:48:33 -07:00
wangbowen6 2dedaa449b mm: use shced_backtrace and skip the first numbers in mm backatrace
beacause the first numbers backtrace in mm node is same, skip them to
show more useful backtrace.

Signed-off-by: wangbowen6 <wangbowen6@xiaomi.com>
2023-07-31 05:46:37 -07:00
anjiahao 79c0fafc06 mm:Fix the problem that the memdump statistics of blkcont are inconsistent
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2023-06-25 18:17:30 +08:00
Xiang Xiao 04e44d7d20 build: Replace "$(shell $(DEFINE) $(CC) ...)" with $(DEFINE_PREFIX)
to unify the way to define macros in Makefile

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-06-23 00:11:25 +03:00
Xiang Xiao a8e0a5faa4 sched: Remove the unnecessary cast from pid_t to int
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-06-19 11:37:34 +03:00
Xiang Xiao 07b0cd1cba mm: Simplify memdump_handler logic a little bit
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-06-19 11:37:34 +03:00
Xiang Xiao 590e968c5f mm/tlfs: Count the backtrace overhead in mm_mallinfo_task
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-06-19 11:37:34 +03:00
Xiang Xiao 9b6cd96671 mm: Rename PID_MM_INVALID to PID_MM_LEAK
to express the intent more clear

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-06-18 14:26:07 +03:00
Xiang Xiao b00237ac01 mm: Move PID_MM_MEMPOOL after PID_MM_ALLOC
so the allocation from mempool could be dumped correctly

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-06-18 09:12:14 +03:00
Xiang Xiao f01deff80f mm: Rename MM_BACKTRACE_XXX_PID to PID_MM_XXX
and move the definition to malloc.h

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-06-18 09:12:14 +03:00
Xiang Xiao ddbe9eb6ab mm: Rename mm_memdump_s to malltask
align with the naming of mallinfo_task

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-06-18 09:12:14 +03:00
Xiang Xiao d920bfba10 mm: include malloc.h in mm/mm.h
to remove the forward declaration of mallinfo and mallinfo_task

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-06-11 19:37:04 +03:00
anjiahao 7732791cd6 mempool:Add mail_info support for multiple pools
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2023-06-08 23:56:40 +08:00
anjiahao 6572081e07 mempool:Allocate a chunk for multiple mempool avoid memory fragmentation
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2023-06-08 23:56:40 +08:00
Xiang Xiao bff3c2308c mm/tlsf: git clone https instead git
to avoid ci fail with "error: cannot run ssh: No such file or directory"

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-06-01 08:19:04 +03:00
Xiang Xiao dfe583e1de Fix tlsf/mm_tlsf.c:151:28: error: ‘TCB_FLAG_HEAPDUMP’ undeclared
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-06-01 08:19:04 +03:00
Xiang Xiao 3edff9d323 mm/tlsf: Change "memdump_backtrace_s *dump" to memdump_backtrace_s *buf"
avoid the conflict with "mm_memdump_s *dump"

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-06-01 08:19:04 +03:00
ligd 1a927a6cf3 mm: add invalid pid dump when malloc failed
We can dump the memory that has exited but
has not been released

Signed-off-by: ligd <liguiding1@xiaomi.com>
2023-05-30 02:19:59 +08:00
anjiahao c60dd72a2a Support memdump to realize incremental dump function
Add a new field to record the global on the basis of mm_backtrace.
When using alloc, the field is incremented by 1,
so that the memory usage can be dumped within the range
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2023-05-22 12:31:32 +08:00
anjiahao 97e652aed1 tlsf:fix bug invalid reference & mm_backtace need tid
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2023-05-22 12:31:32 +08:00
Xiang Xiao 7990f90915 Indent the define statement by two spaces
follow the code style convention

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-05-21 09:52:08 -03:00
Xiang Xiao 6f6fce95a2 Replace all sprintf with snprintf
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-05-08 09:57:01 +02:00
Petro Karashchenko fa07c90522 mm/tlsf: fix compilation warnings
Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com>
2023-05-02 18:29:29 -06:00
Petro Karashchenko 5a298e8685 mm: memory allocations return valid pointer when request 0 size
This change introduce 2 items:
1. If the size of the space requested is 0, the behavior is implementation-defined:
   either a null pointer shall be returned, or the behavior shall be as if the size
   were some non-zero value, except that the behavior is undefined if the returned
   pointer is used to access an object.

   Change the behavior to be similar to Linux and Android and allocates an object
   of a minimum size instead of returning null pointer.

   https://pubs.opengroup.org/onlinepubs/9699919799/functions/malloc.html
   https://pubs.opengroup.org/onlinepubs/9699919799/functions/calloc.html
   https://pubs.opengroup.org/onlinepubs/9699919799/functions/realloc.html

2. The description of realloc() has been modified from previous versions of this
   standard to align with the ISO/IEC 9899:1999 standard. Previous versions explicitly
   permitted a call to realloc (p, 0) to free the space pointed to by p and return
   a null pointer. While this behavior could be interpreted as permitted by this
   version of the standard, the C language committee have indicated that this
   interpretation is incorrect. Applications should assume that if realloc() returns
   a null pointer, the space pointed to by p has not been freed. Since this could lead
   to double-frees, implementations should also set errno if a null pointer actually
   indicates a failure, and applications should only free the space if errno was changed.

   Do not free memory of zero-length reallocation is requested

   https://pubs.opengroup.org/onlinepubs/9699919799/functions/realloc.html

Co-authored-by: fangxinyong <fangxinyong@xiaomi.com>
Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com>
2023-05-02 18:29:29 -06:00
anjiahao 781a34da94 memepool:fix memory consumption double counting issue
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2023-04-23 23:28:32 +08:00
anjiahao 49cd7a795a mm:change special pid to macro
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2023-04-23 23:28:32 +08:00
chao an 4c8d244fae sched/getpid: replace syscall getpid/tid/ppid() to kernel version
NuttX kernel should not use the syscall functions, especially after
enabling CONFIG_SCHED_INSTRUMENTATION_SYSCALL, all system functions
will be traced to backend, which will impact system performance.

Signed-off-by: chao an <anchao@xiaomi.com>
2023-02-02 10:33:01 +08:00
Gustavo Henrique Nihei e6b204f438 nuttx: Use MIN/MAX definitions from "sys/param.h"
Signed-off-by: Gustavo Henrique Nihei <gustavo.nihei@espressif.com>
2023-02-01 23:47:44 +08:00
anjiahao b362f18d6a mempool:Calibration total memory statistics
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2023-01-18 09:02:33 +01:00
anjiahao d846004533 mempool:use two-dimensional array avoid competition
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2023-01-18 09:02:33 +01:00
anjiahao 632ed0d3a4 Optimize multipe mempool memory space usage
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2023-01-18 14:12:45 +08:00
anjiahao 6b530fceae mempool:change mempool_multiple way of initialization
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2023-01-18 14:12:45 +08:00
anjiahao bc30b294aa mm:add heap args to mm_malloc_size
use malloc_size inside of where used mm_malloc_size

Signed-off-by: anjiahao <anjiahao@xiaomi.com>
Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2023-01-17 21:57:37 +08:00