Commit Graph

563 Commits

Author SHA1 Message Date
Zhe Weng
cd1decf4a5 mm/iob: Support neg offset in iob_clone
Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2023-03-08 23:09:25 +02:00
Huang Qi
aba0a25524 ubsan: Implement __ubsan_handle_invalid_builtin
Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
2023-03-06 13:43:08 +02:00
wangbowen6
3e971d2e6d mm_heap: double malloced memory default alignment (4 -> 8, 8 -> 16)
Base on the gnu libc standard:
https://www.gnu.org/software/libc/manual/html_node/Aligned-Memory-Blocks.html

Change the default memory aligment to 8 bytes for 32-bit system and
16 bytes for 64-bit system.

Signed-off-by: wangbowen6 <wangbowen6@xiaomi.com>
2023-03-06 11:27:43 +01:00
wangbowen6
70083168f1 mm: support custom the mm alignment and default to be 8
Signed-off-by: wangbowen6 <wangbowen6@xiaomi.com>
2023-03-06 11:10:36 +08:00
dongjiuzhu1
81825bc003 mm/circbuf: fix minor issue about update buffer head
update head pointer with skip before write buffer.

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2023-02-27 22:35:00 +08:00
Xiang Xiao
2c5f653bfd Remove the tail spaces from all files except Documentation
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-02-26 13:24:24 -08:00
dongjiuzhu1
89e8409244 mm/circbuf: update buffer head according to real length of writing
Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2023-02-26 15:55:18 +08:00
anjiahao
7347684e5f mempool:fix bug when list needs to be protected by a lock
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2023-02-13 15:47:17 +08:00
anjiahao
4ced3c9642 mempool:fix bug when use MM_BACKTRACE
caculate blk address when mempool_multiple_free
have a bug. need a real blocksize to caulate the
memory address.

Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2023-02-13 15:47:17 +08:00
anjiahao
267976e5a8 mempool:fix bug for realloc when shortage of memory
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2023-02-13 01:57:41 +08:00
chao an
2d536059f0 mm/mempool: fix visual studio Compiler Warning C4098
D:\archer\code\nuttx\mm\mempool\mempool_multiple.c(180,72): warning C4098: "mempool_multiple_free_callback":"void" void function returning a value

Compiler Warning C4098:
A function declared with return type void has a return statement that returns a value. The compiler assumes the function returns a value of type int.

Reference:
https://learn.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-1-c4098?view=msvc-170

Signed-off-by: chao an <anchao@xiaomi.com>
2023-02-09 20:11:55 +08:00
Xiang Xiao
be1c84c96a mm/mempool: Initialize spinlock with spin_initialize
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-02-02 22:47:34 +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
yinshengkai
ab2b09e557 Revert "Makefile: fix redundant delimiters when using make V=1"
This reverts commit 64d39a8b7b.
2023-02-01 20:39:52 +08:00
wangbowen6
b1948a1631 mm: move preceding to previous free node to reduce the overhead
Signed-off-by: wangbowen6 <wangbowen6@xiaomi.com>
2023-02-01 11:14:02 +08:00
wangbowen6
723c6e52e2 mm: reorder the preceding and size and move MM_ALLOC_BIT to size
Signed-off-by: wangbowen6 <wangbowen6@xiaomi.com>
2023-02-01 11:14:02 +08:00
yinshengkai
64d39a8b7b Makefile: fix redundant delimiters when using make V=1
rm-none-eabi-ar rcs  libc.a    bin//lib_assert.o  bin//lib_builtin_getname.o
Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2023-01-31 15:12:36 -03:00
Zhe Weng
be89bcc044 mm/iob: Support negative offset when copyin/out.
Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2023-01-31 00:39:15 +08:00
wangbowen6
81d37d0320 mm_memalign: avoid two adjacent free nodes situation.
Original code assumes the previous node in physical must be
ALLOCED, but other thread may free the previous node between
mm_malloc() and mm_lock(), and the original code didn't condsider
this, which will cause two adjacent free nodes situation and this
should not be happened.

This commit will merge the previous node and node if the previous
node is free to avoid the situation discribed above.

Signed-off-by: wangbowen6 <wangbowen6@xiaomi.com>
2023-01-30 11:47:06 +08:00
dongjiuzhu1
a161800214 mm/mm_heap: do this check in mm_size2ndx
Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2023-01-28 23:22:20 +02:00
chao.an
ac8918345b mm/kasan: bypass link-time optimizer
To avoid lto alias with override __asan_* symbols

undefined reference to `__asan_load4_noabort'
undefined reference to `__asan_load1_noabort'
undefined reference to `__asan_store1_noabort'
undefined reference to `__asan_load1_noabort'
undefined reference to `__asan_store1_noabort'
undefined reference to `__asan_load4_noabort'
undefined reference to `__asan_store4_noabort'

Signed-off-by: chao.an <anchao@xiaomi.com>
2023-01-28 23:21:02 +02:00
Xiang Xiao
27afd0e5e3 mm/mempool: Fix the minor style issue
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-01-22 23:23:28 +02:00
Ville Juven
6c2e0b7333 mm/mm_extend: Increase total heap size accordingly
When adding more heap memory, the total heap size was not updated. This
results in a crash in mm_mallinfo:

DEBUGASSERT((size_t)info->uordblks + info->fordblks == heap->mm_heapsize);

This commit fixes this issue
2023-01-19 16:41:43 +08:00
Jukka Laitinen
5920a8b673 mm/mempool/mempool_multiple.c: Remove void * arithmetic
Cast substraction arguments to FAR char *, which gives the same result as the
gcc extension on the original void * arithmetic.

Signed-off-by: Jukka Laitinen <jukkax@ssrc.tii.ae>
2023-01-18 22:03:17 +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
288725a5f8 mempool:fix a bug when use smp on mempool backtrace
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
49ffd99eaf mempool:use single queue insdie of list
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2023-01-18 14:12:45 +08:00
anjiahao
e7d02ffac2 mempool:remove multiple fixed api
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2023-01-18 14:12:45 +08:00
anjiahao
f00d56337f mempool:remove unnecessary alignment
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
Xiang Xiao
154bb93c45 mm: Terminate the backtrace array with one NULL pointer
since one entry is enough to identify the end of back trace

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-01-17 16:48:30 +08:00
anjiahao
29404ef54e procmeminfo:support memdump can show specific task for tlsf
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2023-01-17 16:48:30 +08:00
dongjiuzhu1
c386a1a2d9 mm/mempool: support backtrace function for mempool
Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2023-01-17 16:48:30 +08:00
anjiahao
af3978c1fa adjust the contents of memdump and meminfo
memdump:just dump info
meminfo:statistics mem information

Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2023-01-17 16:48:30 +08:00
Gustavo Henrique Nihei
a3e253b4a3 mm: Enable a dedicated kernel heap on BUILD_FLAT via MM_KERNEL_HEAP
Signed-off-by: Gustavo Henrique Nihei <gustavo.nihei@espressif.com>
2023-01-17 10:30:00 +08:00
anjiahao
cb404167a7 mm/tlsf:add mempool to optimize small block perfomance
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2023-01-16 20:32:17 +08:00
anjiahao
bdcb1f6a25 fix:mmsize_t need support 64bit
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2023-01-16 20:32:17 +08:00
dongjiuzhu1
c82f44c4f3 mm/mm_heap: add mempool to optimize small block performance
There are many small memory block in NuttX system, eg: struct tcb_s,
struct inode, etc, and several disadvantages about them:
1.Their frequent allocate and free cause the system memory fragmentation.
2.Since each memory block has an overhead, the utilization of small memory
blocks is relatively low, which will cause memory waste.

So we can use mempool to alloc smallo block, to improve alloc speed
and utilization, to reduce fragmentation.

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2023-01-16 20:32:17 +08:00
dongjiuzhu1
7cd325f3be mm/mm_heap: remove kasan in MM_ADD_BACKTRACE
do simple copy to instead of memset and memcpy operation because
they have been instrumented, if you access the posion area,
the system will crash.

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2023-01-16 20:32:17 +08:00
chao an
613bfd0fde mm/tlsf: fix compile error/warning on tlsf
1.
make[1]: Entering directory '/home/archer/code/nuttx/n2/incubator-nuttx/mm'
/bin/sh: 1: Syntax error: "(" unexpected

2.
tools/Unix.mk:681: warning: overriding recipe for target 'mm_clean'
tools/Unix.mk:681: warning: ignoring old recipe for target 'mm_clean'
tools/Unix.mk:700: warning: overriding recipe for target 'mm_distclean'
tools/Unix.mk:700: warning: ignoring old recipe for target 'mm_distclean'

Signed-off-by: chao an <anchao@xiaomi.com>
2023-01-16 16:14:13 +08:00
dongjiuzhu1
5c0a5a6627 mm/mempool: support memalign about mempool and mulitple mempool
The memalign is special to multiple mempool because multiple mempool
doesn't support split and shrink chunk operate. So When you alloc a
memory block and find an aligned address in this block, you need to
occupy 8 bytes before the address to save the address of the padding
size and pool to ensure correct use in realloc and free operations.
So we will use bit1 in the previous address of the address to represent
that it is applied by memalign.

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2023-01-15 20:05:55 +08:00
dongjiuzhu1
f5ee767c46 mm/mempool: fix crash about mempool_multiple_realloc
kasan_report (addr=0xf3c68618, size=1, is_write=false) at
kasan/kasan.c:106
0x56585fbf in __asan_loadN_noabort (addr=0xf3c68618, size=1) at
kasan/kasan.c:300
0x565860ac in __asan_load1_noabort (addr=0xf3c68618) at
kasan/kasan.c:354
0x565843af in memcpy (dest=0xf3de9d6c, src=0xf3c685cc, n=3) at
string/lib_memcpy.c:44
0x56587ae8 in mempool_multiple_realloc (mpool=0xf3c670fc,
oldblk=0xf3c685cc, size=416) at mempool/mempool_multiple.c:218
0x5658707a in mm_realloc (heap=0xf3c67000, oldmem=0xf3c685cc,
size=416) at mm_heap/mm_realloc.c:98
0x5658524e in realloc (oldmem=0xf3c685cc, size=416) at
umm_heap/umm_realloc.c:97

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2023-01-15 20:05:55 +08:00
dongjiuzhu1
e5394be881 mempool/multiple_mempool: add private member delta in multiple-mempool
This delta describes the relationship between the block size of each
mempool in multiple mempool by user initialized. It is automatically
detected by the mempool_multiple_init function. If the delta is not
equal to 0, the block size of the pool in the multiple mempool is an
arithmetic progressions, otherwise it is an increasing progressions.

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2023-01-15 20:05:55 +08:00
dongjiuzhu1
cd97134c7c mm/mempool: update nexpand/ninitial/ninterrupt to xxxsize
Let's specify size instead of number, so that we can unify the size of
expansion memory in the multiple mempool.

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2023-01-15 20:05:55 +08:00
dongjiuzhu1
adaca6a5ce mm/mempool: using inline list instead of queue to avoid kasan report
the crash backtrace:
kasan_report (addr=0xf3d02fd4, size=4, is_write=false) at
kasan/kasan.c:106
0x5658518d in __asan_loadN_noabort (addr=0xf3d02fd4, size=4) at
kasan/kasan.c:300
0x565851ee in __asan_load4_noabort (addr=0xf3d02fd4) at
kasan/kasan.c:334
0x56580b02 in sq_remfirst (queue=0xf3d02b08) at
queue/sq_remfirst.c:45
0x565e0e0b in mempool_alloc (pool=0xf3d02aec) at
mempool/mempool.c:161
0x566033d2 in mempool_multiple_alloc (mpool=0xf3d02a30, size=16) at
mempool/mempool_multiple.c:147

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2023-01-15 20:05:55 +08:00
Xiang Xiao
a6428f4c27 mm: Integrate TLSF manager
can be enabled by CONFIG_MM_TLSF_MANAGER=y

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2023-01-15 03:43:37 +08:00