Repository navigation
Conversation
In the NuttX VFS implementation, file descriptors are allocated in chunks of CONFIG_NFILE_DESCRIPTORS_PER_BLOCK. The initial block is statically embedded in struct fdlist (fl_prefds) inside each task group (struct task_group_s) to avoid heap allocation overhead during task creation and standard I/O initialization. Previously, NFILE_DESCRIPTORS_PER_BLOCK defaulted unconditionally to 8, unlike other scheduler pre-allocation parameters (SEM_PREALLOCHOLDERS, SIG_PREALLOC_IRQ_ACTIONS, PREALLOC_MQ_MSGS, PREALLOC_TIMERS, PREALLOC_IRQCHAIN) which scale down to 4 when DEFAULT_SMALL is enabled. Defaulting NFILE_DESCRIPTORS_PER_BLOCK to 4 on DEFAULT_SMALL targets reduces the preallocated descriptor table by 4 entries, saving 32 bytes of SRAM per active task group on 32-bit architectures and 64 bytes on 64-bit architectures. Standard POSIX streams (stdin 0, stdout 1, stderr 2) plus one additional descriptor remain available without heap overhead; opening further descriptors continues to extend dynamically in blocks of 4 via fdlist_extend(). Also remove redundant CONFIG_NFILE_DESCRIPTORS_PER_BLOCK=4 settings from 11 board defconfigs (10 AVR targets and stm32vldiscovery:nsh) that now inherit the default, and update documentation in tasks_vs_threads.rst. Assisted-by: Claude:claude-opus-4.6 Signed-off-by: Swatantra Yadav <[email protected]>
Swatantra-66
requested review from
Donny9,
GUIDINGLI,
acassis,
btashton,
jerpelea,
linguini1 and
xiaoxiang781216
as code owners
November 26, 2026 16:53
xiaoxiang781216
approved these changes
Nov 26, 2026
|
GUIDINGLI
approved these changes
Nov 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Addresses Issue #20414
In the NuttX VFS implementation, file descriptors are allocated in chunks of CONFIG_NFILE_DESCRIPTORS_PER_BLOCK. The initial block is statically embedded in struct fdlist (fl_prefds) inside each task group (struct task_group_s) to avoid heap allocation overhead during task creation and standard I/O initialization.
Previously, NFILE_DESCRIPTORS_PER_BLOCK defaulted unconditionally to 8, unlike other scheduler pre-allocation parameters (SEM_PREALLOCHOLDERS, SIG_PREALLOC_IRQ_ACTIONS, PREALLOC_MQ_MSGS, PREALLOC_TIMERS, PREALLOC_IRQCHAIN) which scale down to 4 when DEFAULT_SMALL is enabled.
This patch updates CONFIG_NFILE_DESCRIPTORS_PER_BLOCK to default to 4 when DEFAULT_SMALL is enabled and 8 otherwise. On 32-bit targets, each struct fd consumes 8 bytes (4-byte file pointer plus flags and alignment padding), reducing the pre-allocated descriptor table from 64 bytes to 32 bytes and saving 32 bytes of static RAM per active task group. On 64-bit targets, each struct fd is 16 bytes, saving 64 bytes of RAM per task group.
Standard POSIX streams (stdin 0, stdout 1, stderr 2) and one additional file descriptor are accommodated in the initial pre-allocated block without runtime heap allocation. When a task requires additional descriptors, fdlist_extend() in fs/inode/fs_files.c dynamically allocates further blocks of 4 descriptors, preserving full functional compatibility.
Redundant CONFIG_NFILE_DESCRIPTORS_PER_BLOCK=4 entries are removed from 11 board defconfigs (10 AVR configurations and stm32vldiscovery:nsh) to keep defconfig files canonical, and Documentation/os/scheduling/tasks_vs_threads.rst is updated to reference the modern configuration symbol.
Impact
Testing
Before and After Comparison
Verification Logs
Target with DEFAULT_SMALL=y (stm32f103-minimum:nsh):
Target with DEFAULT_SMALL=n (sam4s-xplained-pro:nsh):
Canonical defconfig check for cleaned board (arduino-mega2560:nsh):
Code style check: