casaroli opened a new pull request, #22442:
URL: https://github.com/apache/nuttx/pull/22442

   ## Summary
   
   `mempool_navail()` returns `SIZE_MAX` for every pool without `maxalloc`, 
also for a pool that cannot expand (`MEMPOOL_DEFINE()` with `dynalloc` 0). 
Since the network buffer pools moved from net_bufpool to mempool (#22147 for 
the TCP write buffers, #21985 for the UDP ones, #22332 for CAN), these callers 
see a free buffer when all are in use:
   
   - `tcp_wrbuffer_test()` and `udp_wrbuffer_test()` with 
`CONFIG_NET_TCP_ALLOC_WRBCHAINS=0` or `CONFIG_NET_UDP_ALLOC_WRBCHAINS=0`: 
`poll()` reports `POLLOUT`, and the non-blocking `send()` that follows fails 
with `EAGAIN`. An event loop spins.
   - `can_iob_navail()` returns `(int)SIZE_MAX`, that is -1: a CAN socket with 
`CONFIG_NET_CAN_WRITE_BUFFERS` never reports `POLLOUT` (by reading; not run).
   
   Now a pool that cannot expand gives the number of blocks in its free queue 
(and in its interrupt queue in an interrupt, as `mempool_allocate()` takes 
them), limited by `maxalloc`. A pool that expands on demand gives `SIZE_MAX` or 
the rest of `maxalloc`, as before.
   
   ## Impact
   
   Return value of `mempool_navail()` for pools that cannot expand; its callers 
are `tcp_wrbuffer_test()`, `udp_wrbuffer_test()` and `can_iob_navail()` (`git 
grep`). No API, ABI or Kconfig change. The count walks the free queue of a pool 
that cannot expand, under the pool lock, as `mempool_info()` does; such a pool 
has at most its preallocated blocks. Common code: all build modes and 
architectures.
   
   ## Testing
   
   A test program (not in this PR) on qemu-armv8a:nsh (flat), QEMU TCG, with 
`CONFIG_NET_TCP_NWRBCHAINS=2` and `CONFIG_NET_TCP_ALLOC_WRBCHAINS=0`: two 
loopback clients fill their connections (the peers do not read), so both write 
buffers are in use. Then a third connected socket, with nothing queued, is 
polled for `POLLOUT` (500 ms), and a non-blocking `send()` of 1 byte is tried. 
Then one peer reads everything, and the socket is polled again.
   
   | 3 boots each | master 24f2db7fe8d | this PR |
   |---|---|---|
   | `poll()` with all write buffers in use | `POLLOUT`, then `send()` gives 
`EAGAIN` (3 of 3) | no `POLLOUT` (timeout), `send()` gives `EAGAIN` (3 of 3) |
   | `poll()` after a peer read its data | `POLLOUT`, `send()` OK | `POLLOUT`, 
`send()` OK (the wake-up comes) |
   
   The default configuration (`CONFIG_NET_TCP_ALLOC_WRBCHAINS=1`, a pool that 
expands) is not changed: the whole `cmocka_net_tcp` with this PR, the backlog 
RST PR and the TCP_CORK PR (#22440, #22441) fails only `test_tcp_reset_send`, 
which fails on master too.
   
   Builds with `-Werror` in the CI image (gcc 12.3): qemu-armv8a:nsh (flat) and 
qemu-armv8a:knsh (kernel), also with `CONFIG_NET_TCP_ALLOC_WRBCHAINS=0`, 
rv-virt:netnsh64 (flat) and rv-virt:knetnsh64 (kernel); no new warning. Size: 
+80 bytes of text on qemu-armv8a:knsh.
   


-- 
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] mm/mempool: Count the fr... casaroli (via GitHub) via commits

Reply via email to