Swatantra-66 opened a new pull request, #22419:
URL: https://github.com/apache/nuttx/pull/22419

   ## 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
   
   - Is new feature added? No.
   - User: Saves 32 bytes SRAM per task group on 32-bit (64 bytes on 64-bit) 
for all DEFAULT_SMALL targets. Standard builds (!DEFAULT_SMALL) retain default 
8.
   - Build: 11 board defconfigs refreshed to remove redundant entries.
   - Documentation: Updated Documentation/os/scheduling/tasks_vs_threads.rst to 
reference CONFIG_NFILE_DESCRIPTORS_PER_BLOCK.
   
   ## Testing
   
   ### Before and After Comparison
   
   | Configuration | Target Board | Before (master) | After (this patch) | 
Memory Impact |
   | :--- | :--- | :--- | :--- | :--- |
   | DEFAULT_SMALL=y (32-bit) | stm32f103-minimum:nsh | 
NFILE_DESCRIPTORS_PER_BLOCK=8 | NFILE_DESCRIPTORS_PER_BLOCK=4 | -32 B SRAM / 
task group |
   | DEFAULT_SMALL=y (AVR) | arduino-mega2560:nsh | 
NFILE_DESCRIPTORS_PER_BLOCK=4 (manual override) | NFILE_DESCRIPTORS_PER_BLOCK=4 
(default) | 0 B (canonical cleanup) |
   | DEFAULT_SMALL=n (standard) | sam4s-xplained-pro:nsh | 
NFILE_DESCRIPTORS_PER_BLOCK=8 | NFILE_DESCRIPTORS_PER_BLOCK=8 | Unchanged 
(retains 8) |
   
   ### Verification Logs
   
   Target with DEFAULT_SMALL=y (stm32f103-minimum:nsh):
   ```
   $ ./tools/configure.sh -l stm32f103-minimum:nsh
   Loaded configuration '.config'
   Configuration saved to '.config'
   
   $ grep -E '(CONFIG_DEFAULT_SMALL|CONFIG_NFILE_DESCRIPTORS_PER_BLOCK)' .config
   CONFIG_DEFAULT_SMALL=y
   CONFIG_NFILE_DESCRIPTORS_PER_BLOCK=4
   ```
   
   Target with DEFAULT_SMALL=n (sam4s-xplained-pro:nsh):
   ```
   $ ./tools/configure.sh -l sam4s-xplained-pro:nsh
   Loaded configuration '.config'
   Configuration saved to '.config'
   
   $ grep -E '(CONFIG_DEFAULT_SMALL|CONFIG_NFILE_DESCRIPTORS_PER_BLOCK)' .config
   # CONFIG_DEFAULT_SMALL is not set
   CONFIG_NFILE_DESCRIPTORS_PER_BLOCK=8
   ```
   
   Canonical defconfig check for cleaned board (arduino-mega2560:nsh):
   ```
   $ ./tools/configure.sh -l arduino-mega2560:nsh
   Loaded configuration '.config'
   Configuration saved to '.config'
   
   $ grep -E '(CONFIG_DEFAULT_SMALL|CONFIG_NFILE_DESCRIPTORS_PER_BLOCK)' .config
   CONFIG_DEFAULT_SMALL=y
   CONFIG_NFILE_DESCRIPTORS_PER_BLOCK=4
   ```
   
   Code style check:
   ```
   $ git diff --check
   (clean, 0 warnings / errors)
   ```
   


-- 
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]

  • [PR] sched: default NFILE_DES... Swatantra-66 (via GitHub) via commits

Reply via email to