Commit Graph

628 Commits

Author SHA1 Message Date
zhanghongyu 0216224260 iob_alloc: change sem_post to count++
if there are two throttled wait, when iob_free occurs, one of wait
will be awakened to execute iob_alloc_committed, but it will fail
to execute, sem will be posted at this time, then another wait will
be awakened. after the other wait thread is awakened, This step is
repeated. the two threads are in the critical_section state and
cannot be switched to other threads. then cpu will busy util timeout.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2023-08-11 08:54:05 -06:00
anjiahao 6eabacf304 mempool:change mutex to rmutex avoid deadlock
If malloc chunk fails, and if malloc fails to dump all memory,
it will cause deadlock in multiple_mempool_info
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2023-08-10 13:43:32 +02:00
pengyiqiang 8c19fc547d mm_heap: check heap member in advance
Block wrong address in advance before entering mempool.

Signed-off-by: pengyiqiang <pengyiqiang@xiaomi.com>
2023-08-07 01:06:05 -07:00
fangxinyong 43b0421b2a mm/map: limit the count of memory mapping for the task
No memory map count limit that will exhaust memory and cause
the system hang. Also that fix pass LTP posix case mmap/24-1.c

Signed-off-by: fangxinyong <fangxinyong@xiaomi.com>
2023-08-02 22:57:28 -07:00
Bowen Wang 477602e657 mm_heap: mm dump and panic only valid for the heap own by OS
When other code use nuttx memory manager by call mm_xx api directly,
it better to let other code to control weather dump or panic when
malloc failed.

Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
2023-08-02 06:11:59 -07:00
yintao e503f86256 mm/cirbuf: Fix cannot continue read when tail > head
when head=0, tail has not yet rolled back, and at this time tail>head still has data to read

Signed-off-by: yintao <yintao@xiaomi.com>
2023-08-01 23:09:46 -07:00
dongjiuzhu1 33bd797bb3 mm/circbuf: skip buffer content according position in circbuf_peekat
The circbuf_peekat should copy valid content from the specfied position
of buffer, so skip the area from this position to the tail.

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2023-08-01 23:09:46 -07:00
yangyalei 6a5cf6d3ff ltp: fix review questions
Signed-off-by: yangyalei <yangyalei@xiaomi.com>
2023-08-01 09:35:36 -07:00
yangyalei a551be4ee2 malloc: set errno to ENOMEM when malloc fail
fix LTP case ltp_threads_pthread_cond_init_s_c error:
"Test ltp_threads_pthread_cond_init_s_c unresolved: got 38
(Invalid system call number) on line 236 (Memory not full)"

Signed-off-by: yangyalei <yangyalei@xiaomi.com>

ltp: fix review questions

Signed-off-by: yangyalei <yangyalei@xiaomi.com>
2023-07-31 07:50:10 -07: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
Xiang Xiao abfe082a6f Kconfig: Simplify the conditional default statement
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-07-16 14:39:20 -03:00
chao an f10b54a081 cmake: fix CMake build break
Signed-off-by: chao an <anchao@xiaomi.com>
2023-07-15 23:32:36 +08:00
chao an 8ef5f02b66 libs: fix visual studio Compiler Error C2036
D:\code\nuttx\include\nuttx\net\netfilter\ip_tables.h(288,42): error C2036: "void *" : unknown size

Reference:
https://learn.microsoft.com/en-us/cpp/error-messages/compiler-errors-1/compiler-error-c2036?view=msvc-170

Signed-off-by: chao an <anchao@xiaomi.com>
2023-07-14 01:23:16 +08:00
chao an 6ee9ec7656 build: add initial cmake build system
1. Update all CMakeLists.txt to adapt to new layout
2. Fix cmake build break
3. Update all new file license
4. Fully compatible with current compilation environment(use configure.sh or cmake as you choose)

------------------

How to test

From within nuttx/. Configure:

cmake -B build -DBOARD_CONFIG=sim/nsh -GNinja
cmake -B build -DBOARD_CONFIG=sim:nsh -GNinja
cmake -B build -DBOARD_CONFIG=sabre-6quad/smp -GNinja
cmake -B build -DBOARD_CONFIG=lm3s6965-ek/qemu-flat -GNinja

(or full path in custom board) :
cmake -B build -DBOARD_CONFIG=$PWD/boards/sim/sim/sim/configs/nsh -GNinja

This uses ninja generator (install with sudo apt install ninja-build). To build:

$ cmake --build build

menuconfig:

$ cmake --build build -t menuconfig

--------------------------

2. cmake/build: reformat the cmake style by cmake-format

https://github.com/cheshirekow/cmake_format

$ pip install cmakelang

$ for i in `find -name CMakeLists.txt`;do cmake-format $i -o $i;done
$ for i in `find -name *\.cmake`;do cmake-format $i -o $i;done

Co-authored-by: Matias N <matias@protobits.dev>
Signed-off-by: chao an <anchao@xiaomi.com>
2023-07-08 13:50:48 +08:00
chao an a2c4027da6 mm/kasan: replace load/store methods to marco
Signed-off-by: chao an <anchao@xiaomi.com>
2023-06-28 15:18:04 +08: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
tjwu1217 42914040de mm_lock.c: reformat preprocessor format 2023-06-24 10:54:19 -03: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 313f79d55e mm/mempool: Count the expend block overhead in mempool_info
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-06-19 11:37:34 +03:00
Xiang Xiao 0572bc4d03 mm/mempool: Count the backtrace overhead in mempool_[dump|info[_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 c76f9f9349 mm/heap: Count mm_heap_s overhead in mm_mallinfo
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-06-17 19:11:07 -03:00
Xiang Xiao 1d5ca4e809 mm/mempool: Avoid the allocation number of expend block equals zero
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-06-17 19:11:07 -03:00
wangbowen6 372fba70bb mm_heap: dump and stat the mm_heapend node also
Signed-off-by: wangbowen6 <wangbowen6@xiaomi.com>
2023-06-17 19:37:14 +08:00
Xiang Xiao 9f4da58c67 mm: Remove mempoolinfo_task macro and use mallinfo_task directly
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-06-11 19:37:04 +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
Ville Juven a41f752ecc kmm/kmm_map: Add missing FAR qualifiers 2023-06-05 12:03:37 +03:00
Xiang Xiao e98a153cb2 mm/mempool: Remove nexpend and totalsize from mempool_s
forget in the commit(https://github.com/apache/nuttx/pull/9052):
commit 781a34da94
Author: anjiahao <anjiahao@xiaomi.com>
Date:   Tue Apr 18 11:18:43 2023 +0800

    memepool:fix memory consumption double counting issue

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-06-04 11:47:51 -03:00
Ville Juven 61a46ad39e mm/kmm_map: Fix code style error
As pointed out in https://github.com/apache/nuttx/pull/9368
2023-06-02 22:40:23 +08:00
Ville Juven 0476e30a6d mm/kmm_map: Add support to dynamically map pages into kernel virtual memory
This adds functionality to map pages dynamically into kernel virtual
memory. This allows implementing I/O remap for example, which is a useful
(future) feature.

Now, the first target is to support mapping user pages for the kernel.

Why? There are some userspace structures that might be needed when the
userspace process is not running. Semaphores are one such example. Signals
and the WDT timeout both need access to the user semaphore to work
properly. Even though for this only obtaining the kernel addressable
page pool virtual address is needed, for completeness a procedure is
provided to map several pages.
2023-06-02 10:50:26 +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
anjiahao e6506619ac mempool:Fix seqnumber statistics error in memdump
The judgment of seqmin and seqmax is ignored

Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2023-05-31 23:00:16 +08:00
yinshengkai aad2f97587 mm: Dump all memory blocks on allocation failure
Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2023-05-31 15:24:25 +08:00
anjiahao 045b9ffd54 mempool:fix bug read out of bounds when realloc
fix kasan report

Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2023-05-30 23:12:07 +08:00
chao an fb9b41221d semantic/parser: fix compile warning found by sparse
Reference:
https://linux.die.net/man/1/sparse

Signed-off-by: chao an <anchao@xiaomi.com>
2023-05-30 23:00:00 +08: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 70cb62e2a3 Support when malloc failed dump mempool info
Replaced the previous implementation method to
maintain unity with the heap dump

Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2023-05-29 15:29:31 +02: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