jingfei195887 opened a new pull request, #22540:
URL: https://github.com/apache/nuttx/pull/22540
## Summary
Allow an independent filesystem heap to select the size of its first
memory-pool backing chunk. With a 64 KiB normal chunk, that first reservation
can leave less contiguous space for larger allocations even when most of the
pool is unused. `CONFIG_FS_HEAP_MEMPOOL_INIT_CHUNK_SIZE` makes the first chunk
configurable while retaining the allocator's default pool sizes and later
growth policy.
Keep the existing initializers and configuration structures. Add
initial-size variants of `mm_initialize_pool()` and `mempool_multiple_init()`;
the original entries pass zero to retain the normal chunk size. A positive
first size is aligned and raised to fit the first request. Direct-allocation
mode ignores it. Both the standard allocator and TLSF support the option.
Document the policy and its tradeoffs.
## Impact
- Functionality/configuration: YES, optional first backing-chunk size for a
separate FS heap. Default is zero; pool geometry, later chunk size and existing
callers retain their policies.
- API: two additive entry points; existing signatures and public
configuration structures are unchanged.
- Memory: a smaller first chunk can leave more contiguous space, but can
require earlier growth. Multiple-pool metadata gains one `size_t`; this is not
a promise of lower total/peak RAM or faster allocations.
- Build system and hardware interfaces: NO changes.
- Documentation: updated memory-management reference.
## Testing
I confirm that the first-chunk policy is verified on the local setup.
Host: Linux x86_64; gcc (Ubuntu 13.1.0-8ubuntu1~22.04) 13.1.0. Runtime:
`sim:nsh`, standard and TLSF allocators, 32/64-bit. Baseline `f9d3eb13c3f4`,
branch `f66392dfdb95`.
| Configuration | Checks | Failures |
|---|---:|---:|
| baseline | 11023 | 4 |
| branch | 11027 | 0 |
| baseline32 | 11023 | 4 |
| branch32 | 11027 | 0 |
| baseline-tlsf | 11023 | 4 |
| branch-tlsf | 11027 | 0 |
| branch-zero | 11027 | 0 |
| branch32-tlsf | 11027 | 0 |
The three baseline runs have four expected mismatches: the existing API
always requests the normal chunk, so the requested small, unaligned, tiny and
larger first chunks are unavailable. Branch runs pass. The same fixture uses
weak references to the new APIs and falls back to the original ones on
baseline. It checks real backing callbacks, default/zero behavior, rounded
initial sizes, first-request clamping, unchanged later growth,
direct-allocation mode, metadata/first-backing allocation failure, live
contents of 192 objects and complete release. Overflow rejection runs only when
the new API exists. Separate heap cases exercise default, custom and explicitly
empty pool configurations, and the real FS heap allocates and frees duplicated
strings.
Paired baseline/branch configurations are identical except for the newly
available FS option. For the same aligned 256 KiB standard heap on the branch,
a normal 64 KiB first chunk leaves a maximum contiguous free block of 192464
bytes; an 8 KiB first chunk leaves 249808 bytes, a 57344-byte increase. The
reported used total stays 5944 bytes in those two branch cases; baseline used
is 5928 bytes. These are allocator statistics for that fixture, not a claim
that callback request sizes equal total heap overhead. No throughput benchmark
was performed.
Small `sim:nsh` image sizes, without the regression application or coverage
instrumentation:
| Configuration | text | data | bss |
|---|---:|---:|---:|
| size-default-base | 551285 | 2800 | 13056 |
| size-default-branch | 551285 | 2800 | 13056 |
| size-pool-base | 561069 | 2800 | 13056 |
| size-pool-zero | 561261 | 2800 | 13056 |
| size-pool-initial | 561277 | 2800 | 13056 |
Default small configuration: text/data/bss delta +0/+0/+0 bytes.
Pools enabled, first size zero: text/data/bss delta +192/+0/+0 bytes.
Changing FS first size from zero to 8192: text/data/bss delta +16/+0/+0
bytes.
Kernel `qemu-armv8a:knsh` whole-image builds pass with the FS option
enabled, using both allocators. Symbol checks confirm that the new FS and pool
initializer paths are linked. Protected `qemu-armv7r:pnsh` fails to link its
user image on both baseline and branch, with both allocators: five unresolved
references to `nxsem_tickwait_uninterruptible`, `procfs_snprintf` and
`procfs_memcpy`. Paired configurations are identical except for the new FS
option, and the linker errors match exactly. The FS, kernel-MM and user-MM
libraries compile, including the new initializer paths; this does not count as
a passing protected whole-image build. Make/CMake builds and OSTest pass. No
physical hardware, SMP runtime, protected/kernel runtime, or exhaustive failure
injection after initialization was tested.
<details>
<summary>baseline: actual build and runner status</summary>
```text
rev f9d3eb13c3f arch/arm/pp502x: Finish start-up in the common no-MMU entry.
build rc=0
run rc=0
log=/home/mi/test/nuttx_apache/fs-upstream/pr-fs-heap-initial/baseline/run.log
```
</details>
<details>
<summary>baseline: actual runtime log</summary>
```text
nsh> cat /proc/meminfo
total used free maxused maxfree nused nfree name
524280 19360 504920 76288 452480 26 1 heapfs
67108856 2392176 64716680 2442768 64602752 21 3 Umem
nsh> fspoolcheck
FSPOOL APIs multiple=0 heap=0 pointer_bits=64
MULTI legacy initial=0 first_bytes=8232 backing_calls=4 live=0
MULTI zero initial=0 first_bytes=8232 backing_calls=4 live=0
FAIL initial backing size
MULTI small initial=1024 first_bytes=8232 backing_calls=4 live=0
FAIL initial backing size
MULTI odd initial=1025 first_bytes=8232 backing_calls=4 live=0
FAIL initial backing size
MULTI tiny initial=8 first_bytes=8232 backing_calls=4 live=0
FAIL initial backing size
MULTI large initial=16384 first_bytes=8232 backing_calls=4 live=0
MULTI direct initial=1024 first_bytes=128 backing_calls=44 live=0
MULTI metadata-fail calls=1 live=0
MULTI first-fail calls=2 live=0
SKIP new API overflow rejection: interface unavailable
HEAP heap-legacy initial=0 arena=262136 used=5928 free=256208 largest=192464
HEAP heap-zero initial=0 arena=262136 used=5928 free=256208 largest=192464
HEAP heap-small initial=8192 arena=262136 used=5928 free=256208
largest=192464
HEAP custom-legacy initial=0 arena=262136 used=1752 free=260384
largest=251856
HEAP custom-small initial=1024 arena=262136 used=1752 free=260384
largest=251856
HEAP empty-legacy initial=0 arena=262136 used=744 free=261392 largest=261392
HEAP empty-small initial=1024 arena=262136 used=744 free=261392
largest=261392
FSPOOL RESULT checks=11023 failures=4
nsh> echo status=$?
status=1
nsh> cat /proc/meminfo
total used free maxused maxfree nused nfree name
524280 19360 504920 76288 452480 26 1 heapfs
67108856 2392176 64716680 2787488 64602752 21 3 Umem
nsh> poweroff
```
</details>
<details>
<summary>branch: actual build and runner status</summary>
```text
rev f66392dfdb9 fs_heap: fix fs_heap mempool init_chunksize build rc=0
run rc=0
log=/home/mi/test/nuttx_apache/fs-upstream/pr-fs-heap-initial/branch/run.log
```
</details>
<details>
<summary>branch: actual runtime log</summary>
```text
nsh> cat /proc/meminfo
total used free maxused maxfree nused nfree name
524280 19408 504872 85664 442368 27 2 heapfs
67108856 2392192 64716664 2442784 64602752 21 3 Umem
nsh> fspoolcheck
FSPOOL APIs multiple=1 heap=1 pointer_bits=64
MULTI legacy initial=0 first_bytes=8232 backing_calls=4 live=0
MULTI zero initial=0 first_bytes=8232 backing_calls=4 live=0
MULTI small initial=1024 first_bytes=1064 backing_calls=5 live=0
MULTI odd initial=1025 first_bytes=1072 backing_calls=5 live=0
MULTI tiny initial=8 first_bytes=168 backing_calls=5 live=0
MULTI large initial=16384 first_bytes=16424 backing_calls=3 live=0
MULTI direct initial=1024 first_bytes=128 backing_calls=44 live=0
MULTI metadata-fail calls=1 live=0
MULTI first-fail calls=2 live=0
HEAP heap-legacy initial=0 arena=262136 used=5944 free=256192 largest=192464
HEAP heap-zero initial=0 arena=262136 used=5944 free=256192 largest=192464
HEAP heap-small initial=8192 arena=262136 used=5944 free=256192
largest=249808
HEAP custom-legacy initial=0 arena=262136 used=1752 free=260384
largest=251856
HEAP custom-small initial=1024 arena=262136 used=1752 free=260384
largest=259024
HEAP empty-legacy initial=0 arena=262136 used=744 free=261392 largest=261392
HEAP empty-small initial=1024 arena=262136 used=744 free=261392
largest=261392
FSPOOL RESULT checks=11027 failures=0
nsh> echo status=$?
status=0
nsh> cat /proc/meminfo
total used free maxused maxfree nused nfree name
524280 19408 504872 85664 442368 27 2 heapfs
67108856 2392192 64716664 2787504 64602752 21 3 Umem
nsh> poweroff
```
</details>
<details>
<summary>baseline32: actual build and runner status</summary>
```text
rev f9d3eb13c3f arch/arm/pp502x: Finish start-up in the common no-MMU entry.
build rc=0
run rc=0
log=/home/mi/test/nuttx_apache/fs-upstream/pr-fs-heap-initial/baseline32/run.log
```
</details>
<details>
<summary>baseline32: actual runtime log</summary>
```text
nsh> cat /proc/meminfo
total used free maxused maxfree nused nfree name
524280 17468 506812 75536 454656 7 2 heapfs
67108856 2388508 64720348 2439936 64669248 19 2 Umem
nsh> fspoolcheck
FSPOOL APIs multiple=0 heap=0 pointer_bits=32
MULTI legacy initial=0 first_bytes=8212 backing_calls=4 live=0
MULTI zero initial=0 first_bytes=8212 backing_calls=4 live=0
FAIL initial backing size
MULTI small initial=1024 first_bytes=8212 backing_calls=4 live=0
FAIL initial backing size
MULTI odd initial=1025 first_bytes=8212 backing_calls=4 live=0
FAIL initial backing size
MULTI tiny initial=8 first_bytes=8212 backing_calls=4 live=0
FAIL initial backing size
MULTI large initial=16384 first_bytes=8212 backing_calls=4 live=0
MULTI direct initial=1024 first_bytes=128 backing_calls=42 live=0
MULTI metadata-fail calls=1 live=0
MULTI first-fail calls=2 live=0
SKIP new API overflow rejection: interface unavailable
HEAP heap-legacy initial=0 arena=262136 used=5512 free=256624 largest=192480
HEAP heap-zero initial=0 arena=262136 used=5512 free=256624 largest=192480
HEAP heap-small initial=8192 arena=262136 used=5512 free=256624
largest=192480
HEAP custom-legacy initial=0 arena=262136 used=984 free=261152 largest=252896
HEAP custom-small initial=1024 arena=262136 used=984 free=261152
largest=252896
HEAP empty-legacy initial=0 arena=262136 used=392 free=261744 largest=261744
HEAP empty-small initial=1024 arena=262136 used=392 free=261744
largest=261744
FSPOOL RESULT checks=11023 failures=4
nsh> echo status=$?
status=1
nsh> cat /proc/meminfo
total used free maxused maxfree nused nfree name
524280 17468 506812 75536 454656 7 2 heapfs
67108856 2388508 64720348 2784064 64669248 19 2 Umem
nsh> poweroff
```
</details>
<details>
<summary>branch32: actual build and runner status</summary>
```text
rev f66392dfdb9 fs_heap: fix fs_heap mempool init_chunksize build rc=0
run rc=0
log=/home/mi/test/nuttx_apache/fs-upstream/pr-fs-heap-initial/branch32/run.log
```
</details>
<details>
<summary>branch32: actual runtime log</summary>
```text
nsh> cat /proc/meminfo
total used free maxused maxfree nused nfree name
524280 17500 506780 83760 442368 8 3 heapfs
67108856 2388508 64720348 2439936 64669248 19 2 Umem
nsh> fspoolcheck
FSPOOL APIs multiple=1 heap=1 pointer_bits=32
MULTI legacy initial=0 first_bytes=8212 backing_calls=4 live=0
MULTI zero initial=0 first_bytes=8212 backing_calls=4 live=0
MULTI small initial=1024 first_bytes=1044 backing_calls=5 live=0
MULTI odd initial=1025 first_bytes=1048 backing_calls=5 live=0
MULTI tiny initial=8 first_bytes=148 backing_calls=5 live=0
MULTI large initial=16384 first_bytes=16404 backing_calls=3 live=0
MULTI direct initial=1024 first_bytes=128 backing_calls=42 live=0
MULTI metadata-fail calls=1 live=0
MULTI first-fail calls=2 live=0
HEAP heap-legacy initial=0 arena=262136 used=5512 free=256624 largest=192480
HEAP heap-zero initial=0 arena=262136 used=5512 free=256624 largest=192480
HEAP heap-small initial=8192 arena=262136 used=5512 free=256624
largest=249824
HEAP custom-legacy initial=0 arena=262136 used=984 free=261152 largest=252896
HEAP custom-small initial=1024 arena=262136 used=984 free=261152
largest=260064
HEAP empty-legacy initial=0 arena=262136 used=392 free=261744 largest=261744
HEAP empty-small initial=1024 arena=262136 used=392 free=261744
largest=261744
FSPOOL RESULT checks=11027 failures=0
nsh> echo status=$?
status=0
nsh> cat /proc/meminfo
total used free maxused maxfree nused nfree name
524280 17500 506780 83760 442368 8 3 heapfs
67108856 2388508 64720348 2784064 64669248 19 2 Umem
nsh> poweroff
```
</details>
<details>
<summary>baseline-tlsf: actual build and runner status</summary>
```text
rev f9d3eb13c3f arch/arm/pp502x: Finish start-up in the common no-MMU entry.
build rc=0
run rc=0
log=/home/mi/test/nuttx_apache/fs-upstream/pr-fs-heap-initial/baseline-tlsf/run.log
```
</details>
<details>
<summary>baseline-tlsf: actual runtime log</summary>
```text
nsh> cat /proc/meminfo
total used free maxused maxfree nused nfree name
517608 20672 496936 73208 444336 24 1 heapfs
67102184 2393304 64708880 2443560 64594624 19 3 Umem
nsh> fspoolcheck
FSPOOL APIs multiple=0 heap=0 pointer_bits=64
MULTI legacy initial=0 first_bytes=8232 backing_calls=4 live=0
MULTI zero initial=0 first_bytes=8232 backing_calls=4 live=0
FAIL initial backing size
MULTI small initial=1024 first_bytes=8232 backing_calls=4 live=0
FAIL initial backing size
MULTI odd initial=1025 first_bytes=8232 backing_calls=4 live=0
FAIL initial backing size
MULTI tiny initial=8 first_bytes=8232 backing_calls=4 live=0
FAIL initial backing size
MULTI large initial=16384 first_bytes=8232 backing_calls=4 live=0
MULTI direct initial=1024 first_bytes=128 backing_calls=44 live=0
MULTI metadata-fail calls=1 live=0
MULTI first-fail calls=2 live=0
SKIP new API overflow rejection: interface unavailable
HEAP heap-legacy initial=0 arena=255464 used=7584 free=247880 largest=184264
HEAP heap-zero initial=0 arena=255464 used=7584 free=247880 largest=184264
HEAP heap-small initial=8192 arena=255464 used=7584 free=247880
largest=184264
HEAP custom-legacy initial=0 arena=255464 used=1024 free=254440
largest=246216
HEAP custom-small initial=1024 arena=255464 used=1024 free=254440
largest=246216
HEAP empty-legacy initial=0 arena=255464 used=16 free=255448 largest=255448
HEAP empty-small initial=1024 arena=255464 used=16 free=255448 largest=255448
FSPOOL RESULT checks=11023 failures=4
nsh> echo status=$?
status=1
nsh> cat /proc/meminfo
total used free maxused maxfree nused nfree name
517608 20808 496800 73208 444336 24 1 heapfs
67102184 2393304 64708880 2780040 64594624 19 3 Umem
nsh> poweroff
```
</details>
<details>
<summary>branch-tlsf: actual build and runner status</summary>
```text
rev f66392dfdb9 fs_heap: fix fs_heap mempool init_chunksize build rc=0
run rc=0
log=/home/mi/test/nuttx_apache/fs-upstream/pr-fs-heap-initial/branch-tlsf/run.log
```
</details>
<details>
<summary>branch-tlsf: actual runtime log</summary>
```text
nsh> cat /proc/meminfo
total used free maxused maxfree nused nfree name
517608 20728 496880 81440 434168 25 2 heapfs
67102184 2393312 64708872 2443568 64594624 19 3 Umem
nsh> fspoolcheck
FSPOOL APIs multiple=1 heap=1 pointer_bits=64
MULTI legacy initial=0 first_bytes=8232 backing_calls=4 live=0
MULTI zero initial=0 first_bytes=8232 backing_calls=4 live=0
MULTI small initial=1024 first_bytes=1064 backing_calls=5 live=0
MULTI odd initial=1025 first_bytes=1072 backing_calls=5 live=0
MULTI tiny initial=8 first_bytes=168 backing_calls=5 live=0
MULTI large initial=16384 first_bytes=16424 backing_calls=3 live=0
MULTI direct initial=1024 first_bytes=128 backing_calls=44 live=0
MULTI metadata-fail calls=1 live=0
MULTI first-fail calls=2 live=0
HEAP heap-legacy initial=0 arena=255464 used=7592 free=247872 largest=184264
HEAP heap-zero initial=0 arena=255464 used=7592 free=247872 largest=184264
HEAP heap-small initial=8192 arena=255464 used=7592 free=247872
largest=241608
HEAP custom-legacy initial=0 arena=255464 used=1032 free=254432
largest=246216
HEAP custom-small initial=1024 arena=255464 used=1032 free=254432
largest=253384
HEAP empty-legacy initial=0 arena=255464 used=16 free=255448 largest=255448
HEAP empty-small initial=1024 arena=255464 used=16 free=255448 largest=255448
FSPOOL RESULT checks=11027 failures=0
nsh> echo status=$?
status=0
nsh> cat /proc/meminfo
total used free maxused maxfree nused nfree name
517608 20864 496744 81440 434168 25 2 heapfs
67102184 2393312 64708872 2780048 64594624 19 3 Umem
nsh> poweroff
```
</details>
<details>
<summary>branch-zero: actual build and runner status</summary>
```text
rev f66392dfdb9 fs_heap: fix fs_heap mempool init_chunksize build rc=0
run rc=0
log=/home/mi/test/nuttx_apache/fs-upstream/pr-fs-heap-initial/branch-zero/run.log
```
</details>
<details>
<summary>branch-zero: actual runtime log</summary>
```text
nsh> cat /proc/meminfo
total used free maxused maxfree nused nfree name
524280 19360 504920 76304 452480 26 1 heapfs
67108856 2392192 64716664 2442784 64602752 21 3 Umem
nsh> fspoolcheck
FSPOOL APIs multiple=1 heap=1 pointer_bits=64
MULTI legacy initial=0 first_bytes=8232 backing_calls=4 live=0
MULTI zero initial=0 first_bytes=8232 backing_calls=4 live=0
MULTI small initial=1024 first_bytes=1064 backing_calls=5 live=0
MULTI odd initial=1025 first_bytes=1072 backing_calls=5 live=0
MULTI tiny initial=8 first_bytes=168 backing_calls=5 live=0
MULTI large initial=16384 first_bytes=16424 backing_calls=3 live=0
MULTI direct initial=1024 first_bytes=128 backing_calls=44 live=0
MULTI metadata-fail calls=1 live=0
MULTI first-fail calls=2 live=0
HEAP heap-legacy initial=0 arena=262136 used=5944 free=256192 largest=192464
HEAP heap-zero initial=0 arena=262136 used=5944 free=256192 largest=192464
HEAP heap-small initial=8192 arena=262136 used=5944 free=256192
largest=249808
HEAP custom-legacy initial=0 arena=262136 used=1752 free=260384
largest=251856
HEAP custom-small initial=1024 arena=262136 used=1752 free=260384
largest=259024
HEAP empty-legacy initial=0 arena=262136 used=744 free=261392 largest=261392
HEAP empty-small initial=1024 arena=262136 used=744 free=261392
largest=261392
FSPOOL RESULT checks=11027 failures=0
nsh> echo status=$?
status=0
nsh> cat /proc/meminfo
total used free maxused maxfree nused nfree name
524280 19360 504920 76304 452480 26 1 heapfs
67108856 2392192 64716664 2787504 64602752 21 3 Umem
nsh> poweroff
```
</details>
<details>
<summary>branch32-tlsf: actual build and runner status</summary>
```text
rev f66392dfdb9 fs_heap: fix fs_heap mempool init_chunksize build rc=0
run rc=0
log=/home/mi/test/nuttx_apache/fs-upstream/pr-fs-heap-initial/branch32-tlsf/run.log
```
</details>
<details>
<summary>branch32-tlsf: actual runtime log</summary>
```text
nsh> cat /proc/meminfo
total used free maxused maxfree nused nfree name
521024 19664 501360 78728 438268 6 2 heapfs
67105600 2390436 64715164 2507152 64597984 18 3 Umem
nsh> fspoolcheck
FSPOOL APIs multiple=1 heap=1 pointer_bits=32
MULTI legacy initial=0 first_bytes=8212 backing_calls=4 live=0
MULTI zero initial=0 first_bytes=8212 backing_calls=4 live=0
MULTI small initial=1024 first_bytes=1044 backing_calls=5 live=0
MULTI odd initial=1025 first_bytes=1048 backing_calls=5 live=0
MULTI tiny initial=8 first_bytes=148 backing_calls=5 live=0
MULTI large initial=16384 first_bytes=16404 backing_calls=3 live=0
MULTI direct initial=1024 first_bytes=128 backing_calls=42 live=0
MULTI metadata-fail calls=1 live=0
MULTI first-fail calls=2 live=0
HEAP heap-legacy initial=0 arena=258880 used=7700 free=251180 largest=188388
HEAP heap-zero initial=0 arena=258880 used=7700 free=251180 largest=188388
HEAP heap-small initial=8192 arena=258880 used=7700 free=251180
largest=245732
HEAP custom-legacy initial=0 arena=258880 used=596 free=258284 largest=249828
HEAP custom-small initial=1024 arena=258880 used=596 free=258284
largest=256996
HEAP empty-legacy initial=0 arena=258880 used=8 free=258872 largest=258872
HEAP empty-small initial=1024 arena=258880 used=8 free=258872 largest=258872
FSPOOL RESULT checks=11027 failures=0
nsh> echo status=$?
status=0
nsh> cat /proc/meminfo
total used free maxused maxfree nused nfree name
521024 19664 501360 78728 438268 6 2 heapfs
67105600 2390436 64715164 2843052 64597984 18 3 Umem
nsh> poweroff
```
</details>
<details>
<summary>Local build/runtime gate</summary>
```text
target : nuttx
branch : fs/heap-initial-chunk
head : f66392dfdb954b4d9b34bae5b023f84bcdc0c784
subject : fs_heap: fix fs_heap mempool init_chunksize
commits : 1
base : f9d3eb13c3 (merge-base with upstream/master)
behind : 0 commits of upstream/master
nuttx : f66392dfdb
apps : 0a37af9866
options : CONFIG_FS_TMPFS CONFIG_FS_HEAPSIZE=524288
CONFIG_MM_HEAP_MEMPOOL_THRESHOLD=128 CONFIG_MM_HEAP_MEMPOOL_CHUNK_SIZE=65536
CONFIG_MM_HEAP_MEMPOOL_EXPAND_SIZE=4096
CONFIG_MM_HEAP_MEMPOOL_DICTIONARY_EXPAND_SIZE=4096
CONFIG_FS_HEAP_MEMPOOL_INIT_CHUNK_SIZE=8192 CONFIG_DEBUG_ASSERTIONS
host : Linux x86_64, gcc (Ubuntu 13.1.0-8ubuntu1~22.04) 13.1.0
checkpatch: rc=0
signer : jingfei <[email protected]>
commits missing your Signed-off-by: 0
make build: rc=0
warnings in changed files: 0
ostest: Exiting with status 0
cmake reconfigure: rc=0
cmake build: rc=0
worktree tracked changes after: 0
RESULT: PASS
```
</details>
<details>
<summary>Kernel build results</summary>
```text
qemu-armv8a:knsh kernel whole-image build PASS
qemu-armv8a:knsh kernel-tlsf whole-image build PASS
```
</details>
<details>
<summary>protected-baseline: actual whole-image link failure</summary>
```text
qemu-armv7r:pnsh protected-baseline whole-image build FAIL rc=2
/home/mi/test/nuttx_apache/fs-upstream/nuttx/mm/mempool/mempool.c:530:(.text.mempool_allocate+0x15c):
undefined reference to `nxsem_tickwait_uninterruptible'
/home/mi/test/nuttx_apache/fs-upstream/nuttx/mm/mempool/mempool_procfs.c:144:(.text.mempool_read+0x70):
undefined reference to `procfs_snprintf'
arm-none-eabi-ld:
/home/mi/test/nuttx_apache/fs-upstream/nuttx/mm/mempool/mempool_procfs.c:149:(.text.mempool_read+0x8c):
undefined reference to `procfs_memcpy'
arm-none-eabi-ld:
/home/mi/test/nuttx_apache/fs-upstream/nuttx/mm/mempool/mempool_procfs.c:165:(.text.mempool_read+0x120):
undefined reference to `procfs_snprintf'
arm-none-eabi-ld:
/home/mi/test/nuttx_apache/fs-upstream/nuttx/mm/mempool/mempool_procfs.c:171:(.text.mempool_read+0x138):
undefined reference to `procfs_memcpy'
```
</details>
<details>
<summary>protected-branch: actual whole-image link failure</summary>
```text
qemu-armv7r:pnsh protected whole-image build FAIL rc=2 (user image link)
/home/mi/test/nuttx_apache/fs-upstream/nuttx/mm/mempool/mempool.c:530:(.text.mempool_allocate+0x15c):
undefined reference to `nxsem_tickwait_uninterruptible'
/home/mi/test/nuttx_apache/fs-upstream/nuttx/mm/mempool/mempool_procfs.c:144:(.text.mempool_read+0x70):
undefined reference to `procfs_snprintf'
arm-none-eabi-ld:
/home/mi/test/nuttx_apache/fs-upstream/nuttx/mm/mempool/mempool_procfs.c:149:(.text.mempool_read+0x8c):
undefined reference to `procfs_memcpy'
arm-none-eabi-ld:
/home/mi/test/nuttx_apache/fs-upstream/nuttx/mm/mempool/mempool_procfs.c:165:(.text.mempool_read+0x120):
undefined reference to `procfs_snprintf'
arm-none-eabi-ld:
/home/mi/test/nuttx_apache/fs-upstream/nuttx/mm/mempool/mempool_procfs.c:171:(.text.mempool_read+0x138):
undefined reference to `procfs_memcpy'
```
</details>
<details>
<summary>protected-tlsf-baseline: actual whole-image link failure</summary>
```text
qemu-armv7r:pnsh protected-tlsf-baseline whole-image build FAIL rc=2
/home/mi/test/nuttx_apache/fs-upstream/nuttx/mm/mempool/mempool.c:530:(.text.mempool_allocate+0x15c):
undefined reference to `nxsem_tickwait_uninterruptible'
/home/mi/test/nuttx_apache/fs-upstream/nuttx/mm/mempool/mempool_procfs.c:144:(.text.mempool_read+0x70):
undefined reference to `procfs_snprintf'
arm-none-eabi-ld:
/home/mi/test/nuttx_apache/fs-upstream/nuttx/mm/mempool/mempool_procfs.c:149:(.text.mempool_read+0x8c):
undefined reference to `procfs_memcpy'
arm-none-eabi-ld:
/home/mi/test/nuttx_apache/fs-upstream/nuttx/mm/mempool/mempool_procfs.c:165:(.text.mempool_read+0x120):
undefined reference to `procfs_snprintf'
arm-none-eabi-ld:
/home/mi/test/nuttx_apache/fs-upstream/nuttx/mm/mempool/mempool_procfs.c:171:(.text.mempool_read+0x138):
undefined reference to `procfs_memcpy'
```
</details>
<details>
<summary>protected-tlsf-branch: actual whole-image link failure</summary>
```text
qemu-armv7r:pnsh protected-tlsf-branch whole-image build FAIL rc=2
/home/mi/test/nuttx_apache/fs-upstream/nuttx/mm/mempool/mempool.c:530:(.text.mempool_allocate+0x15c):
undefined reference to `nxsem_tickwait_uninterruptible'
/home/mi/test/nuttx_apache/fs-upstream/nuttx/mm/mempool/mempool_procfs.c:144:(.text.mempool_read+0x70):
undefined reference to `procfs_snprintf'
arm-none-eabi-ld:
/home/mi/test/nuttx_apache/fs-upstream/nuttx/mm/mempool/mempool_procfs.c:149:(.text.mempool_read+0x8c):
undefined reference to `procfs_memcpy'
arm-none-eabi-ld:
/home/mi/test/nuttx_apache/fs-upstream/nuttx/mm/mempool/mempool_procfs.c:165:(.text.mempool_read+0x120):
undefined reference to `procfs_snprintf'
arm-none-eabi-ld:
/home/mi/test/nuttx_apache/fs-upstream/nuttx/mm/mempool/mempool_procfs.c:171:(.text.mempool_read+0x138):
undefined reference to `procfs_memcpy'
```
</details>
Regression fixture: place the following files under
`apps/examples/fspoolcheck/`, enable `CONFIG_EXAMPLES_FSPOOLCHECK`,
`CONFIG_FS_HEAPSIZE=524288`, `CONFIG_MM_HEAP_MEMPOOL_THRESHOLD=128`,
`CONFIG_MM_HEAP_MEMPOOL_CHUNK_SIZE=65536`,
`CONFIG_MM_HEAP_MEMPOOL_EXPAND_SIZE=4096`, and
`CONFIG_MM_HEAP_MEMPOOL_DICTIONARY_EXPAND_SIZE=4096` in `sim:nsh`. On the
branch set `CONFIG_FS_HEAP_MEMPOOL_INIT_CHUNK_SIZE=8192`. Build and run
`fspoolcheck`. This local regression source is attached here; it is not
installed by the production patch.
<details>
<summary>Regression source: Kconfig</summary>
```text
config EXAMPLES_FSPOOLCHECK
tristate "FS heap initial chunk regression"
default n
depends on MM_HEAP_MEMPOOL_THRESHOLD >= 0
```
</details>
<details>
<summary>Regression source: Make.defs</summary>
```text
ifneq ($(CONFIG_EXAMPLES_FSPOOLCHECK),)
CONFIGURED_APPS += $(APPDIR)/examples/fspoolcheck
endif
```
</details>
<details>
<summary>Regression source: Makefile</summary>
```text
include $(APPDIR)/Make.defs
PROGNAME = fspoolcheck
PRIORITY = SCHED_PRIORITY_DEFAULT
STACKSIZE = 8192
MODULE = $(CONFIG_EXAMPLES_FSPOOLCHECK)
MAINSRC = fspoolcheck_main.c
CFLAGS += ${INCDIR_PREFIX}$(TOPDIR)/fs
include $(APPDIR)/Application.mk
```
</details>
<details>
<summary>Regression source: fspoolcheck_main.c</summary>
```c
/****************************************************************************
* apps/examples/fspoolcheck/fspoolcheck_main.c
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <nuttx/compiler.h>
#include <nuttx/mm/mm.h>
#include <nuttx/mm/mempool.h>
#include <malloc.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "fs_heap.h"
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#define NOBJECTS 192
#define NHISTORY 256
#define CHUNKSIZE 8192
#define EXPANDSIZE 512
#define DICTSIZE 128
/****************************************************************************
* Private Function Prototypes
****************************************************************************/
extern FAR struct mempool_multiple_s *mempool_multiple_init_initial(
FAR const char *name, FAR const size_t *poolsize, size_t npools,
mempool_multiple_alloc_t alloc,
mempool_multiple_alloc_size_t alloc_size,
mempool_multiple_free_t freecb, FAR void *arg, size_t chunksize,
size_t expandsize, size_t dict_expendsize,
size_t initialsize) weak_function;
extern FAR struct mm_heap_s *mm_initialize_pool_initial(
FAR const struct mm_heap_config_s *config,
FAR const struct mempool_init_s *init,
size_t initialsize) weak_function;
/****************************************************************************
* Private Types
****************************************************************************/
struct history_s
{
FAR void *addr;
size_t size;
bool freed;
};
struct context_s
{
struct history_s history[NHISTORY];
unsigned int calls;
unsigned int count;
unsigned int live;
unsigned int fail_call;
};
/****************************************************************************
* Private Data
****************************************************************************/
static struct context_s g_context;
static FAR void *g_objects[NOBJECTS];
static unsigned int g_checks;
static unsigned int g_failures;
static size_t g_chunk_overhead;
/****************************************************************************
* Private Functions
****************************************************************************/
static void check(bool value, FAR const char *name)
{
g_checks++;
if (!value)
{
g_failures++;
printf("FAIL %s\n", name);
}
}
static FAR void *backing_alloc(FAR void *arg, size_t align, size_t size)
{
FAR struct context_s *ctx = arg;
FAR void *addr;
ctx->calls++;
if (ctx->calls == ctx->fail_call || ctx->count == NHISTORY)
{
return NULL;
}
addr = memalign(align, size);
if (addr != NULL)
{
ctx->history[ctx->count].addr = addr;
ctx->history[ctx->count].size = size;
ctx->history[ctx->count].freed = false;
ctx->count++;
ctx->live++;
}
return addr;
}
static size_t backing_size(FAR void *arg, FAR void *addr)
{
FAR struct context_s *ctx = arg;
unsigned int i;
for (i = 0; i < ctx->count; i++)
{
if (ctx->history[i].addr == addr && !ctx->history[i].freed)
{
return ctx->history[i].size;
}
}
check(false, "backing size ownership");
return 0;
}
static void backing_free(FAR void *arg, FAR void *addr)
{
FAR struct context_s *ctx = arg;
unsigned int i;
for (i = 0; i < ctx->count; i++)
{
if (ctx->history[i].addr == addr && !ctx->history[i].freed)
{
ctx->history[i].freed = true;
ctx->live--;
free(addr);
return;
}
}
check(false, "backing free ownership");
}
static void multiple_case(FAR const char *name, size_t initial,
size_t chunk, bool legacy, unsigned int fail)
{
static const size_t sizes[] =
{
32, 64, 128
};
FAR struct mempool_multiple_s *mpool;
struct mallinfo info;
size_t first = 0;
size_t expected;
unsigned int count;
unsigned int i;
unsigned int j;
memset(&g_context, 0, sizeof(g_context));
memset(g_objects, 0, sizeof(g_objects));
g_context.fail_call = fail;
if (!legacy && mempool_multiple_init_initial != NULL)
{
mpool = mempool_multiple_init_initial(name, sizes, 3, backing_alloc,
backing_size, backing_free, &g_context, chunk, EXPANDSIZE,
DICTSIZE, initial);
}
else
{
mpool = mempool_multiple_init(name, sizes, 3, backing_alloc,
backing_size, backing_free, &g_context, chunk, EXPANDSIZE,
DICTSIZE);
}
if (fail)
{
check(mpool == NULL, "first backing failure returned");
if (mpool != NULL)
{
mempool_multiple_deinit(mpool);
}
check(g_context.live == 0, "initialization failure cleanup");
printf("MULTI %s calls=%u live=%u\n", name,
g_context.calls, g_context.live);
return;
}
check(mpool != NULL, "multiple initialization");
if (mpool == NULL)
{
return;
}
check(g_context.count == 2, "metadata and dictionary backing");
if (g_context.count >= 2)
{
first = g_context.history[1].size;
if (legacy && chunk != 0)
{
check(first > chunk && first < chunk + 128,
"legacy chunk header bounds");
g_chunk_overhead = first - chunk;
}
expected = initial == 0 || legacy ? chunk : initial;
expected = (expected + sizeof(uintptr_t) - 1) &
~(sizeof(uintptr_t) - 1);
expected = expected < DICTSIZE ? DICTSIZE : expected;
expected = chunk == 0 ? DICTSIZE : expected + g_chunk_overhead;
check(first == expected, "initial backing size");
}
for (i = 0; i < NOBJECTS; i++)
{
size_t request = 32 + (i % 3) * 32;
g_objects[i] = mempool_multiple_alloc(mpool, request);
check(g_objects[i] != NULL, "pool allocation");
if (g_objects[i] == NULL)
{
break;
}
check(mempool_multiple_alloc_size(mpool, g_objects[i]) >= request,
"pool object capacity");
check(mempool_multiple_member(mpool, g_objects[i]),
"pool object membership");
memset(g_objects[i], (unsigned char)i, request);
}
count = i;
info = mempool_multiple_mallinfo(mpool);
check(info.aordblks == count, "live object accounting");
if (chunk != 0)
{
check(g_context.count > 2, "growth exercised");
for (i = 2; i < g_context.count; i++)
{
check(g_context.history[i].size == chunk + g_chunk_overhead,
"subsequent backing size");
}
}
for (i = 0; i < count; i++)
{
FAR unsigned char *data = g_objects[i];
size_t request = 32 + (i % 3) * 32;
bool valid = true;
for (j = 0; j < request; j++)
{
valid = valid && data[j] == (unsigned char)i;
}
check(valid, "allocation contents");
check(mempool_multiple_free(mpool, data) == 0, "pool free");
}
info = mempool_multiple_mallinfo(mpool);
check(info.aordblks == 0, "object count after release");
mempool_multiple_deinit(mpool);
check(g_context.live == 0, "all backing allocations released");
printf("MULTI %s initial=%zu first_bytes=%zu backing_calls=%u live=%u\n",
name, initial, first, g_context.calls, g_context.live);
}
static void heap_case(FAR const char *name, size_t initial, bool legacy,
int custom)
{
static const size_t sizes[] =
{
32, 64, 128
};
struct mm_heap_config_s config;
struct mempool_init_s poolconfig;
FAR const struct mempool_init_s *init = NULL;
FAR struct mm_heap_s *heap;
FAR unsigned char *buffer;
struct mallinfo info;
unsigned int count;
unsigned int i;
buffer = memalign(4096, 262144);
check(buffer != NULL, "heap arena allocation");
if (buffer == NULL)
{
return;
}
memset(&config, 0, sizeof(config));
config.name = name;
config.start = buffer;
config.size = 262144;
memset(&poolconfig, 0, sizeof(poolconfig));
if (custom != 0)
{
init = &poolconfig;
if (custom == 1)
{
poolconfig.poolsize = sizes;
poolconfig.npools = 3;
poolconfig.threshold = 128;
poolconfig.chunksize = CHUNKSIZE;
poolconfig.expandsize = EXPANDSIZE;
poolconfig.dict_expendsize = DICTSIZE;
}
}
if (!legacy && mm_initialize_pool_initial != NULL)
{
heap = mm_initialize_pool_initial(&config, init, initial);
}
else
{
heap = mm_initialize_pool(&config, init);
}
check(heap != NULL, "heap initialization");
if (heap == NULL)
{
free(buffer);
return;
}
info = mm_mallinfo(heap);
printf("HEAP %s initial=%zu arena=%zu used=%zu free=%zu largest=%zu\n",
name, initial, info.arena, info.uordblks, info.fordblks,
info.mxordblk);
for (i = 0; i < NOBJECTS; i++)
{
g_objects[i] = mm_zalloc(heap, 64);
check(g_objects[i] != NULL, "heap pool allocation");
if (g_objects[i] == NULL)
{
break;
}
check(((FAR unsigned char *)g_objects[i])[63] == 0, "heap zero fill");
memset(g_objects[i], (unsigned char)i, 64);
}
count = i;
for (i = 0; i < count; i++)
{
check(((FAR unsigned char *)g_objects[i])[63] == (unsigned char)i,
"heap allocation contents");
mm_free(heap, g_objects[i]);
}
mm_uninitialize(heap);
free(buffer);
}
static void bounds_case(void)
{
static const size_t sizes[] =
{
32, 64, 128
};
FAR struct mempool_multiple_s *mpool;
if (mempool_multiple_init_initial == NULL)
{
printf("SKIP new API overflow rejection: interface unavailable\n");
return;
}
memset(&g_context, 0, sizeof(g_context));
mpool = mempool_multiple_init_initial("overflow", sizes, 3,
backing_alloc, backing_size, backing_free, &g_context,
CHUNKSIZE, EXPANDSIZE, DICTSIZE, SIZE_MAX);
check(mpool == NULL, "oversized first chunk rejected");
check(g_context.calls == 0, "oversized first chunk makes no allocation");
if (mpool != NULL)
{
mempool_multiple_deinit(mpool);
}
}
/****************************************************************************
* Public Functions
****************************************************************************/
int main(int argc, FAR char *argv[])
{
FAR char *name;
unsigned int i;
printf("FSPOOL APIs multiple=%d heap=%d pointer_bits=%zu\n",
mempool_multiple_init_initial != NULL,
mm_initialize_pool_initial != NULL, sizeof(void *) * 8);
multiple_case("legacy", 0, CHUNKSIZE, true, false);
multiple_case("zero", 0, CHUNKSIZE, false, false);
multiple_case("small", 1024, CHUNKSIZE, false, false);
multiple_case("odd", 1025, CHUNKSIZE, false, false);
multiple_case("tiny", 8, CHUNKSIZE, false, false);
multiple_case("large", 16384, CHUNKSIZE, false, false);
multiple_case("direct", 1024, 0, false, false);
multiple_case("metadata-fail", 1024, CHUNKSIZE, false, 1);
multiple_case("first-fail", 1024, CHUNKSIZE, false, 2);
bounds_case();
heap_case("heap-legacy", 0, true, 0);
heap_case("heap-zero", 0, false, 0);
heap_case("heap-small", 8192, false, 0);
heap_case("custom-legacy", 0, true, 1);
heap_case("custom-small", 1024, false, 1);
heap_case("empty-legacy", 0, true, 2);
heap_case("empty-small", 1024, false, 2);
for (i = 0; i < 64; i++)
{
name = fs_heap_strdup("independent-fs-heap");
check(name != NULL, "FS heap allocation");
if (name != NULL)
{
check(strcmp(name, "independent-fs-heap") == 0, "FS heap content");
check(fs_heap_member(name), "FS heap membership");
fs_heap_free(name);
}
}
printf("FSPOOL RESULT checks=%u failures=%u\n", g_checks, g_failures);
return g_failures == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
}
```
</details>
## PR verification Self-Check
- [x] This PR introduces only one functional change.
- [x] I have updated all required description fields above.
- [x] My PR adheres to Contributing Guidelines and Documentation (git commit
title and message, coding standard, etc).
- [ ] My PR is still work in progress (not ready for review).
- [x] My PR is ready for review and can be safely merged into a codebase.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]