Commit Graph

44 Commits

Author SHA1 Message Date
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
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
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
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
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 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
Xiang Xiao 54de894e52 mm/heap: Skip memset backtrace buffer
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-01-08 01:25:18 +02:00
Xiang Xiao 70ecb4ef26 mm/heap: Changee mmchunk_handler_t to mm_node_handler_t
to unify the term usage(chunk v.s. node and mm v.s. mm_)

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-01-08 01:25:18 +02:00
anjiahao f403118647 mm:fix typos
./mm_heap/mm.h:86:27: error: expected '=', ',', ';', 'asm' or '__attribute__' before '*' token
   86 |          FAR strcut tcb_s *tcb; \
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2022-12-22 20:19:05 +08:00
anjiahao 70791af8e2 procmeminfo:support memdump can show specific task
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2022-12-19 20:43:33 +08:00
qinwei1 8021dfece6 sched/task/task_getpid: getpid should return process id not thread id
Summary:
   implement the right semantics:
1. getpid should return the main thread id
2. gettid should return the current thread id

Refer to:
 https://github.com/apache/incubator-nuttx/issues/2499
 https://github.com/apache/incubator-nuttx/pull/2518

Signed-off-by: qinwei1 <qinwei1@xiaomi.com>
2022-11-17 17:58:08 +08:00
Xiang Xiao 7dcf35cf64 mm: Remove the unused macro MM_IS_ALLOCATED
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-11-08 14:57:48 +09:00
Xiang Xiao b567e09c3c mm: Restore the return type of mm_lock from bool to int
Fix the issue reported here better:
https://github.com/apache/incubator-nuttx/pull/6995

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-11-07 10:01:52 +01:00
Xiang Xiao e08c296a8e Change the type of tg_joinlock, mm_lock and md_lock from sem_t to mutex_t
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-10-31 10:35:53 +01:00
dongjiuzhu1 579e47347e mm/mm_heap: define MM_MASK_BIT as significant bits mask
using MM_MASK_BIT to expand different bits of preceding field to store the
block status.

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2022-10-29 00:12:02 +08:00
dongjiuzhu1 5982cafbe0 mm/mm_heap: using LOG2_CEIL to generate MM_MIN_SHIFT at compile time
Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2022-10-29 00:12:02 +08:00
anjiahao d1d46335df Replace nxsem API when used as a lock with nxmutex API
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-10-17 15:59:46 +09:00
chao.an 87cb224b1c mm/kasan: node header should updated from unpoisoning memory
| (gdb) bt
| #0  up_assert (filename=0x7fffffffdc6c "\001", lineno=0) at sim/up_assert.c:75
| #1  0x00005555555e636b in _assert (filename=0x555555627225 "kasan/kasan.c", linenum=104) at assert/lib_assert.c:36
| #2  0x00005555555a388e in kasan_report (addr=140737284458088, size=1, is_write=true) at kasan/kasan.c:104
| #3  0x00005555555a40a1 in __asan_storeN_noabort (addr=140737284458088, size=1) at kasan/kasan.c:297
| #4  0x00005555555a4519 in __asan_store1_noabort (addr=140737284458088) at kasan/kasan.c:348
| #5  0x00005555555a26d7 in memset (s=0x7ffff3d8c668, c=0, n=63) at string/lib_memset.c:169
| #6  0x00005555555a46a4 in mm_addregion (heap=0x7ffff3d8c000, heapstart=0x7ffff3d8c648, heapsize=66058656) at mm_heap/mm_initialize.c:131
| #7  0x00005555555a4a00 in mm_initialize (name=0x555555627068 "Umem", heapstart=0x7ffff3d8c648, heapsize=67107256) at mm_heap/mm_initialize.c:231
| #8  0x00005555555a33b1 in umm_initialize (heap_start=0x7ffff3d8c000, heap_size=67108864) at umm_heap/umm_initialize.c:84
| #9  0x000055555558f17c in nx_start () at init/nx_start.c:469
| #10 0x0000555555589559 in main (argc=1, argv=0x7fffffffdf58, envp=0x7fffffffdf68) at sim/up_head.c:131
| (gdb)

Signed-off-by: chao.an <anchao@xiaomi.com>
2022-08-02 01:44:48 +08:00
Jiuzhu Dong 9899dd0ec0 mm/mm_heap: change CONFIG_MM_BACKTRACE to int type
Signed-off-by: Jiuzhu Dong <dongjiuzhu1@xiaomi.com>
2022-07-26 23:45:31 +08:00
Xiang Xiao 53c6789bef mm: Add mm_uninitialize to release the resource
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-06-12 19:41:14 +09:00
YAMAMOTO Takashi b05320cac2 mm: Move backtrace stuff into a separate option
The functionality has too much overhead for CONFIG_DEBUG_MM.
2022-05-21 14:28:41 +08:00
wangbowen6 1a4ccd2d70 Revert "mm_heap: heapsize align with MM_MIN_CHUNK."
This reverts commit 69e69740b5.
2022-04-11 12:46:17 +08:00
wangbowen6 69e69740b5 mm_heap: heapsize align with MM_MIN_CHUNK.
Signed-off-by: wangbowen6 <wangbowen6@xiaomi.com>
2022-03-31 19:50:25 +08:00
wangbowen6 a0bde21f0f mm/mm_heap: place alloc-bit at the LSB of node->preceeding.
Heap always allocate the memory at least 2bytes alignment.

Signed-off-by: wangbowen6 <wangbowen6@xiaomi.com>
2022-03-31 14:43:56 +03:00
Jiuzhu Dong 709207b8d3 mm/memdump: dynamic turn on backtrace in heap when enable DEBUG_MM
default turn off.
turn on: echo on > /proc/memdump
turn off: echo off > proc/memdump

Signed-off-by: Jiuzhu Dong <dongjiuzhu1@xiaomi.com>
2022-03-27 13:21:48 +08:00
Petro Karashchenko 68902d8732 pid_t: unify usage of special task IDs
Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com>
2022-03-22 21:22:32 +08:00
Jiuzhu Dong 2dcc4a359d mm/dump: add pid and backtrace for every memory node
usage:
echo <pid/used/free> trace > /proc/memdump
echo used > /proc/memdump //output all used memory info with backtrace
echo free > /proc/memdump //output all free memory info
echo 22 > /proc/memdump //output used memory info for task pid is 22 with backtrace

Signed-off-by: Jiuzhu Dong <dongjiuzhu1@xiaomi.com>
2022-02-26 14:32:42 +08:00
Jiuzhu Dong 39eaeefb78 mm/mm_heap: remove the unnecessary check for memory node size
Signed-off-by: Jiuzhu Dong <dongjiuzhu1@xiaomi.com>
2022-02-26 14:32:42 +08:00
Jiuzhu Dong eba0323eae mm/mm_heap: add mm_foreach to run handler for every memory node
Signed-off-by: Jiuzhu Dong <dongjiuzhu1@xiaomi.com>
2022-02-13 03:20:31 +08:00
Xiang Xiao 77792a1598 sched: Define CONFIG_SMP_NCPUS to 1 in no SMP case
to simplify the SMP related code logic

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-01-20 23:21:21 +08:00
ligd 5b369c5cec libs/lbc: remove CHAR_BIT = 16 support
For CEVA platform CHAR_BIT is 16, and will do lots of extra work
when use IPC.
We will not support this platform anymore, so remove all the b2c operations.

Signed-off-by: ligd <liguiding1@xiaomi.com>
2021-12-13 11:08:28 -06:00
Abdelatif Guettouche f86ceea099 mm/mm_heap/mm.h: Fix some typos.
Signed-off-by: Abdelatif Guettouche <abdelatif.guettouche@espressif.com>
2021-08-03 10:11:26 -07:00
Xiang Xiao 5fe51b923a mm: Simplify the semaphore handling
1.Move all special process to mm_takesemaphore
2.Remove the support of recurive lock
3.Remove mm_trysemaphore function

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
Change-Id: Ie216a6294ab67c5d427f31b089beb15c532f08fe
2021-07-10 16:10:32 -03:00
Xiang Xiao 76cdd5c329 mm: Remove mm_heap_impl_s struct
it's more simple to make mm_heap_s opaque outside of mm

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
Change-Id: I5c8e435f6baba6d22b10c5f7e8d9191104fb5af2
2021-07-07 04:25:15 -07:00
Xiang Xiao b1f711f790 mm: Move procfs_register_meminfo into common place
to avoid the code duplication and ensure the consistent behaviour

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2021-07-03 09:39:32 -07:00
ligd aa43a0215d mm: fix memory corruption when loop create/exit thread in SMP mode
Root casue:
when do thread exit, need add free stack operation to mm_delaylist,
but in SMP mode, CPU0 thread1 exit, at this time, CPU1 call malloc
and free mm_delaylist.

Fix:
Divide mm_delaylist for per CPU in SMP mode.

Change-Id: Ibf7d04614ea2f99fb5b506356b7346a0d94f0590
Signed-off-by: ligd <liguiding1@xiaomi.com>
2021-07-02 04:55:46 -05:00
Xiang Xiao e14c458747 mm/heap: Move semaphore related declaration to private header
since other subsystem doesn't need call these function anymore

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
Change-Id: Idfb217c412db62d9f17f427310b75bb78785dc50
2021-03-22 15:35:32 +01:00
Xiang Xiao 473bacd7a2 mm/heap: Add FAR to the pointer type
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2021-03-21 10:11:43 +01:00
mage1 635cfadc25 mm: Move mm_heap_s related stuff to private header file
since it will improve the modularity and reduce the inforamtion explosion

Change-Id: I085b36adb38993a979625a1f4c252d364a15afa1
2021-03-19 09:56:39 -07:00