HomeFreeBSD

tcp: reduce memory footprint when listing tcp hostcache

Description

tcp: reduce memory footprint when listing tcp hostcache

In tcp_hostcache_list, the sbuf used would need a large (~2MB)
blocking allocation of memory (M_WAITOK), when listing a
full hostcache. This may stall the requestor for an indeterminate
time.

A further optimization is to return the expected userspace
buffersize right away, rather than preparing the output of
each current entry of the hostcase, provided by: @tuexen.

This makes use of the ready-made functions of sbuf to work
with sysctl, and repeatedly drain the much smaller buffer.

PR: 254333
MFC after: 2 weeks
Reviewed By: transport, tuexen
Sponsored by: NetApp, Inc.
Differential Revision: https://reviews.freebsd.org/D29471

(cherry picked from commit cb0dd7e122b8936ad61a141e65ef8ef874bfebe5)

Details

Provenance
rscheffAuthored on Mar 28 2021, 9:12 PM
Reviewer
transport
Differential Revision
D29471: Avoid /sbin/sysctl net.inet.tcp.hostcache.list from stalling when under memory pressure
Parents
rG2e96d6ef392e: Make sbuf_drain safe for external use
Branches
Unknown
Tags
Unknown