socket: Reorder socket and sockbuf fields to eliminate some padding

This is in preparation for moving sockbuf locks into the owning socket,
in order to provide proper interlocking for listen(2).  In particular,
listening sockets do not use the socket buffers and repurpose that space
in struct socket for their own purposes.  Moving the locks out of the
socket buffers and into the socket proper makes it possible to safely
lock socket buffers and test for a listening socket before deciding how
to proceed.

Reordering these fields saves some space and helps ensure that UMA will
provide the same space efficiency for sockets as before.  No functional
change intended.

Reviewed by:	tuexen, gallatin
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D31656
This commit is contained in:
Mark Johnston 2021-09-07 14:45:22 -04:00
parent 686aa9287c
commit 97cf43ebc5
2 changed files with 4 additions and 4 deletions

View File

@ -85,7 +85,8 @@ struct sockbuf {
struct sx sb_sx; /* prevent I/O interlacing */
struct selinfo *sb_sel; /* process selecting read/write */
short sb_state; /* (a) socket state on sockbuf */
#define sb_startzero sb_mb
#define sb_startzero sb_flags
short sb_flags; /* (a) flags, see above */
struct mbuf *sb_mb; /* (a) the mbuf chain */
struct mbuf *sb_mbtail; /* (a) the last mbuf in the chain */
struct mbuf *sb_lastrecord; /* (a) first mbuf of last
@ -109,7 +110,6 @@ struct sockbuf {
struct ktls_session *sb_tls_info; /* (a + b) TLS state */
struct mbuf *sb_mtls; /* (a) TLS mbuf chain */
struct mbuf *sb_mtlstail; /* (a) last mbuf in TLS chain */
short sb_flags; /* (a) flags, see above */
int (*sb_upcall)(struct socket *, void *, int); /* (a) */
void *sb_upcallarg; /* (a) */
TAILQ_HEAD(, kaiocb) sb_aiojobq; /* (a) pending AIO ops */

View File

@ -91,13 +91,13 @@ struct socket {
volatile u_int so_count; /* (b / refcount) */
struct selinfo so_rdsel; /* (b/cr) for so_rcv/so_comp */
struct selinfo so_wrsel; /* (b/cs) for so_snd */
short so_type; /* (a) generic type, see socket.h */
int so_options; /* (b) from socket call, see socket.h */
short so_linger; /* time to linger close(2) */
short so_type; /* (a) generic type, see socket.h */
short so_state; /* (b) internal state flags SS_* */
void *so_pcb; /* protocol control block */
struct vnet *so_vnet; /* (a) network stack instance */
struct protosw *so_proto; /* (a) protocol handle */
short so_linger; /* time to linger close(2) */
short so_timeo; /* (g) connection timeout */
u_short so_error; /* (f) error affecting connection */
u_short so_rerror; /* (f) error affecting connection */