Commit Graph

574 Commits

Author SHA1 Message Date
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
df2925cf13 mempool:fix bug, use incorrect free in mempool init
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2023-04-27 00:28:09 +08:00
chao an
2be18a8b24 makefile: fix libc/mm files can not be compiled incrementally
Use double delim to fix windows native build and give an error:
makefile:132: *** target mode do not include“%”. stop.

In Windows environment DELIM := $(strip \) but \ has two role:
first: \ as directory, and second \ as Escape character, Reference:

https://github.com/apache/nuttx/pull/7572#discussion_r1028219229

Signed-off-by: chao an <anchao@xiaomi.com>
2023-04-24 12:43:10 +03:00
anjiahao
9971dfd0c1 circbuf support write or read buffer direct
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2023-04-23 23:32:00 +08: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
Zhe Weng
44a04733d4 mm/iob: Don't return NULL in iob_pack
We don't want to get a NULL pointer after iob_pack on an IOB chain with
several iobs with length 0, it should return one IOB with length 0.
Otherwise each place calls iob_pack needs to check the result.

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2023-04-22 19:26:22 +08:00
Xiang Xiao
149cafe450 procfs: Add g_ prefix to all procfs_operations
to conform the coding style

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-04-22 03:33:50 -04:00
Ville Juven
53d4b9ed54 mm/mm_map: Give the mm_map as parameter to the mm_map functions
This way the mappings can be modified for any vm area, not only the
process that is running.

Why? This allows mapping pages to kernel dynamically, this functionality
will be presented later.
2023-04-22 00:40:37 +08:00
zhangyuan21
c239d19df0 nuttx: add more dependent header file
Signed-off-by: zhangyuan21 <zhangyuan21@xiaomi.com>
2023-04-11 09:13:32 +03:00
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