Skip to content

fs/mqueue: change default FS_MQUEUE_NPOLLWAITERS to 2 - #22445

Merged
GUIDINGLI merged 1 commit into
apache:masterfrom
Swatantra-66:fix/mqueue-npollwaiters-default-2
Nov 27, 2026
Merged

GUIDINGLI merged 1 commit into
apache:masterfrom
Swatantra-66:fix/mqueue-npollwaiters-default-2

Conversation

@Swatantra-66

Copy link
Copy Markdown
Contributor

Summary

Addresses Issue #20414

In fs/mqueue/Kconfig, CONFIG_FS_MQUEUE_NPOLLWAITERS currently defaults to 4, which was originally introduced when poll support was added to message queues (PR #2957).

Each POSIX message queue allocates an array of poll descriptors sized by CONFIG_FS_MQUEUE_NPOLLWAITERS:

struct mqueue_inode_s
{
  ...
  FAR struct pollfd_s *fds[CONFIG_FS_MQUEUE_NPOLLWAITERS];
};

When mq_open() creates a message queue, struct mqueue_inode_s is dynamically allocated from heap memory. In typical embedded and RTOS workloads, a message queue has at most one reader and one writer waiting simultaneously on poll/select/epoll events.

This change updates the default of CONFIG_FS_MQUEUE_NPOLLWAITERS from 4 to 2, aligning it with all other IPC and device poll waiter defaults across NuttX:

Applications requiring more than 2 concurrent poll waiters can still configure CONFIG_FS_MQUEUE_NPOLLWAITERS to a larger value via Kconfig.

Impact

  • Is new feature added? No.
  • User: None. Message queues save dynamic heap memory per allocated queue.
  • Build: Zero defconfigs in the tree configure CONFIG_FS_MQUEUE_NPOLLWAITERS, so no defconfig modifications are required.
  • Memory: Saves 8 bytes heap memory per message queue on 32-bit platforms (16 bytes on 64-bit platforms).

Testing

Before and After Comparison

Configuration Target Board Before (master) After (this patch) Memory Impact
DEFAULT_SMALL=y (32-bit) stm32f103-minimum:nsh FS_MQUEUE_NPOLLWAITERS=4 FS_MQUEUE_NPOLLWAITERS=2 -8 B heap / queue
Standard (32-bit) sam4s-xplained-pro:nsh FS_MQUEUE_NPOLLWAITERS=4 FS_MQUEUE_NPOLLWAITERS=2 -8 B heap / queue
Standard (64-bit) generic 64-bit FS_MQUEUE_NPOLLWAITERS=4 FS_MQUEUE_NPOLLWAITERS=2 -16 B heap / queue

Verification Logs

Small profile configuration (stm32f103-minimum:nsh):

$ ./tools/configure.sh -l stm32f103-minimum:nsh
Loaded configuration '.config'
Configuration saved to '.config'

$ grep FS_MQUEUE_NPOLLWAITERS .config
CONFIG_FS_MQUEUE_NPOLLWAITERS=2

Standard profile configuration (sam4s-xplained-pro:nsh):

$ ./tools/configure.sh -l sam4s-xplained-pro:nsh
Loaded configuration '.config'
Configuration saved to '.config'

$ grep FS_MQUEUE_NPOLLWAITERS .config
CONFIG_FS_MQUEUE_NPOLLWAITERS=2

Code style check:

$ git diff --check
(clean, 0 warnings / errors)

In fs/mqueue/Kconfig, CONFIG_FS_MQUEUE_NPOLLWAITERS currently defaults
to 4, which was introduced when poll support was added in PR apache#2957.

Each POSIX message queue pre-allocates an array of poll descriptors
(FAR struct pollfd_s *fds[CONFIG_FS_MQUEUE_NPOLLWAITERS]) inside
struct mqueue_inode_s. When mq_open() creates a queue, this structure
is dynamically allocated from the heap. In typical embedded and RTOS
applications, a message queue has at most one reader and one writer
waiting concurrently on poll/select/epoll events.

This change sets the default of CONFIG_FS_MQUEUE_NPOLLWAITERS to 2,
aligning it with the rest of the IPC poll waiter configurations:
CONFIG_SERIAL_NPOLLWAITERS=2 (PR apache#22228), CONFIG_DEV_PIPE_NPOLLWAITERS=2
(PR apache#22348), CONFIG_EVENT_FD_NPOLLWAITERS=2, CONFIG_TIMER_FD_NPOLLWAITERS=2,
CONFIG_SIGNAL_FD_NPOLLWAITERS=2, and CONFIG_FS_NOTIFY_FD_POLLWAITERS=2.

This saves 8 bytes of heap memory per message queue on 32-bit targets
(16 bytes on 64-bit targets).

Assisted-by: Claude:claude-opus-4.6
Signed-off-by: Swatantra Yadav <[email protected]>
@github-actions github-actions Bot added Area: File System File System issues Size: XS The size of the change in this PR is very small labels Nov 26, 2026
@github-actions

Copy link
Copy Markdown

MemBrowse Memory Report · Explore what changed →

mps2-an500-citest

  • flash: .text -24 B (-0.0%, 248,328 B / 4,194,304 B, total: 6% used)

mps2-an500-citest-protected

  • flash: .text -16 B (-0.0%, 116,904 B / 4,194,304 B, total: 3% used)

qemu-intel64

  • Code: .text -6 B (-0.0%, 8,707,620 B)

No memory changes detected for:


Catch memory regressions in CI with MemBrowse. Free for open source.

@GUIDINGLI
GUIDINGLI merged commit b028185 into apache:master Nov 27, 2026
58 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: File System File System issues Size: XS The size of the change in this PR is very small

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants